summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_w3element_traversal_svg.html
blob: 7a1407434a1075c7402746fdb3a14e63e14f8915 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Test for ElementTraversal via SVG</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>

<p id="display"></p>
<div id="content" style="display: none"></div>

<iframe id="svg" src="w3element_traversal.svg"></iframe>

<pre id="test">
<script class="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();

function run()
{
  var doc = $("svg").contentDocument;
  
  //et-namespace.svg
  var parentEl = doc.getElementById("parentEl_namespace");
  var nChild = parentEl.firstElementChild;
  is(nChild && "dill", nChild.localName, "failed to get child with namespace")

  //et-previousElementSibling.svg
  var lec = doc.getElementById("last_element_child_pes");
  var pes = lec.previousElementSibling;
  isnot(pes, null, "previousElementSibling is null");
  is(pes.nodeType, 1, "previousElementSibling returned the wrong node type");
  is(pes.getAttribute("id"), "middle_element_child_pes", "previousElementSibling returned the wrong child");

  //et-sibling_null.svg
  var fec = doc.getElementById("first_element_child_sibnull");
  var pes = fec.previousElementSibling;
  var nes = fec.nextElementSibling;
  is(pes, null, "previousElementSibling is not null");
  is(nes, null, "nextElementSibling is not null");

  //et-nextElementSibling.svg
  fec = doc.getElementById("first_element_child_nes");
  var nes = fec.nextElementSibling;
  isnot(nes, null, "nextElementSibling returned NULL");
  is(nes.nodeType, 1, "nextElementSibling returned wrong node type");
  is(nes.getAttribute("id"), "last_element_child_nes", "nextElementSibling returned wrong node id");

  //et-lastElementChild.svg
  var parentEl = doc.getElementById("parentEl_lec");
  var lec = parentEl.lastElementChild;
  isnot(lec, null, "lastElementChild returned null");
  is(lec.nodeType, 1, "lastElementChild returned wrong nodeType");
  is(lec.getAttribute("id"), "last_element_child_lec", "lastElementChild returned wrong id");

  //et-firstElementChild.svg
  var parentEl = doc.getElementById("parentEl_fec");
  var fec = parentEl.firstElementChild;
  isnot(fec, null, "firstElementChild returned null");
  is(fec.nodeType, 1, "firstElementChild returned wrong nodeType");
  is(fec.getAttribute("id"), "first_element_child_fec", "firstElementChild returned wrong id");

  //et-entity.svg
  var parentEl = doc.getElementById("parentEl_entity");
  var fec = parentEl.firstElementChild;
  isnot(fec, null, "firstElementChild returned null");
  is(fec.nodeType, 1, "firstElementChild returned wrong nodeType");
  is(fec.getAttribute("id"), "first_element_child_entity", "firstElementChild returned wrong id");

  //et-dynamic-remove.svg
  var parentEl = doc.getElementById("parentEl_dynremove");
  var lec = parentEl.lastElementChild;
  parentEl.removeChild( lec );
  is(parentEl.childElementCount && 1, parentEl.childElementCount, "failed to removeChild");

  //et-dynamic-add.svg
  var parentEl = doc.getElementById("parentEl_dynadd");
  var newChild = doc.createElementNS("http://www.w3.org/2000/svg", "tspan");
  parentEl.appendChild( newChild );
  is(parentEl.childElementCount && 2, parentEl.childElementCount, "failed to appendChild");

  //et-childElement-null.svg
  var parentEl = doc.getElementById("parentEl_null");
  var fec = parentEl.firstElementChild;
  var lec = parentEl.lastElementChild;
  is(fec, null, "expected null from firstElementChild");
  is(lec, null, "expected null from lastElementChild");


  //et-childElementCount.svg
  var parentEl = doc.getElementById("parentEl_count");
  is(parentEl.childElementCount && 3, parentEl.childElementCount, "got wrong childElementCount");

  //et-childElementCount-nochild.svg
  var parentEl = doc.getElementById("parentEl_nochild");
  is(0, parentEl.childElementCount, "got wrong childElementCount");
  

  SimpleTest.finish();
}

window.addEventListener("load", run, false);
</script>
</pre>
</body>
</html>