summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_NodeIterator_mutations_1.xhtml
blob: 028734b6aa458e11d684fe710f7b13933070f877 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- NodeIterator mutation tests.
     Originally written by Ian Hickson, Mochi-ified by Zack Weinberg.
     This file based on 00[3-9].xml from
       http://hixie.ch/tests/adhoc/dom/traversal/node-iterator/
  -->
<head>
  <title>DOM Traversal: NodeIterator: Mutations (1/x)</title>
  <script type="text/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">
<span id="X"></span><span id="Y"><span id="root1"><span id="A"><span id="B"><span id="C"><span id="D"><span id="E"></span></span></span></span></span></span></span>
<span id="root2"><span id="F"><span id="FF"></span></span><span id="G"></span><span id="H"><span id="HH"></span></span></span>
<span id="root3"><span id="I"><span id="II"></span></span><span id="J"></span><span id="K"><span id="KK"></span></span></span>
<span id="root4"><span id="L"></span><span id="M"><span id="MM"></span></span><span id="N"></span></span>
<span id="root5"><span id="O"></span><span id="P"><span id="PP"></span></span><span id="Q"></span></span>
<span id="root6"><span id="R"></span><span id="S"><span id="SS"></span></span><span id="T"></span></span>
<span id="root7"><span id="U"></span><span id="V"><span id="VV"></span></span><span id="W"></span></span>
</div>
<pre id="test">
<script class="testbody" type="text/javascript"><![CDATA[
  /** Originally written by Ian Hickson. **/

  function check(f, e, label) {
    var eid = e.id;
    var fid = f ? f.id : 'null';
    is(f, e, label + ': expected ' + eid + ' have ' + fid);
  }

  var childid = 0;
  function addChildTo(a) {
    var x = document.createElementNS('http://www.w3.org/1999/xhtml', 'span');
    x.id = 'X' + childid;
    childid++;
    ok(a, 'parent ' + (a?a.id:'undefined') + ' for child ' + x.id);
    if (a)
      a.appendChild(x);
    return x;
  }
  function remove(a) {
    var p = a.parentNode;
    ok(a && p,
       'removing ' + ( a?(a.id?a.id:'(no id)'):'undefined' )
       + ' with parent ' + ( p?(p.id?p.id:'(no id)'):'undefined' ));
    if (a && p)
      p.removeChild(a);
  }

  /** Removal of nodes that should have no effect **/
  (function () {
    var root = $('root1');
    var A = $('A');
    var B = $('B');
    var C = $('C');
    var D = $('D');
    var E = $('E');

    var iterator = document.createNodeIterator(root, NodeFilter.SHOW_ALL,
					       null);
    check(iterator.nextNode(), root, '1.0');

    // 1. Remove a node unrelated to the reference node
    remove($('X'));
    check(iterator.nextNode(), A, '1.1');

    // 2. Remove an ancestor of the root node
    remove($('Y'));
    check(iterator.nextNode(), B, '1.2');

    // 3. Remove the root node itself
    remove(root);
    check(iterator.nextNode(), C, '1.3');

    // 4. Remove a descendant of the reference node
    remove(E);
    check(iterator.nextNode(), D, '1.4');
  })();

  /** Removal of the reference node **/
  (function () {
    var root = $('root2');
    var F = $('F');
    var FF = $('FF');
    var G = $('G');
    var H = $('H');
    var iterator = document.createNodeIterator(root, NodeFilter.SHOW_ALL,
					       null);

    check(iterator.nextNode(), root, '2.0');
    check(iterator.nextNode(), F,    '2.1');
    check(iterator.nextNode(), FF,   '2.2');
    check(iterator.nextNode(), G,    '2.3');
    remove(G);
    check(iterator.previousNode(), FF, '2.4');
    remove(FF);
    check(iterator.nextNode(), H, '2.5');
  })();

  /** Removal of the reference node (deep check) **/
  (function () {
    var root = $('root3');
    var I = $('I');
    var II = $('II');
    var J = $('J');
    var K = $('K');
    var KK = $('KK');

    var iterator = document.createNodeIterator(root, NodeFilter.SHOW_ALL,
					       null);
    check(iterator.nextNode(), root, '3.0');
    check(iterator.nextNode(), I, '3.1');
    check(iterator.nextNode(), II, '3.2');
    check(iterator.nextNode(), J, '3.3');
    remove(J);
    var X = addChildTo(II);
    check(iterator.nextNode(), X, '3.4');
    check(iterator.previousNode(), X, '3.5');
    remove(X);
    var Y = addChildTo(II);
    check(iterator.previousNode(), Y, '3.6');
    check(iterator.nextNode(), Y, '3.7');
    check(iterator.nextNode(), K, '3.8');
    check(iterator.nextNode(), KK, '3.9');
  })();

  /** Removal of an ancestor of the Reference Node (forwards) **/
  (function () {
    var root = $('root4');
    var L = $('L');
    var M = $('M');
    var MM = $('MM');
    var N = $('N');

    var iterator = document.createNodeIterator(root, NodeFilter.SHOW_ALL,
					       null);
    check(iterator.nextNode(), root, '4.1');
    check(iterator.nextNode(), L, '4.2');
    check(iterator.nextNode(), M, '4.3');
    check(iterator.nextNode(), MM, '4.4');
    remove(M);
    check(iterator.previousNode(), L, '4.5');
  })();

  /** Removal of an ancestor of the Reference Node (forwards) (deep check) **/
  (function () {
    var root = $('root5');
    var O = $('O');
    var P = $('P');
    var PP = $('PP');
    var Q = $('Q');

    var iterator = document.createNodeIterator(root, NodeFilter.SHOW_ALL,
					       null);
    check(iterator.nextNode(), root, '5.1');
    check(iterator.nextNode(), O, '5.2');
    check(iterator.nextNode(), P, '5.3');
    check(iterator.nextNode(), PP, '5.4');
    remove(P);
    var X = addChildTo(O);
    check(iterator.nextNode(), X, '5.5');
  })();

  /** Removal of an ancestor of the Reference Node (backwards) **/
  (function () {
    var root = $('root6');
    var R = $('R');
    var S = $('S');
    var SS = $('SS');
    var T = $('T');

    var iterator = document.createNodeIterator(root, NodeFilter.SHOW_ALL,
					       null);
    check(iterator.nextNode(), root, '6.1');
    check(iterator.nextNode(), R, '6.2');
    check(iterator.nextNode(), S, '6.3');
    check(iterator.nextNode(), SS, '6.4');
    check(iterator.previousNode(), SS, '6.5');
    remove(S);
    check(iterator.nextNode(), T, '6.6');
  })();

  /** Removal of an ancestor of the Reference Node (backwards) (deep check) **/
  (function () {
    var root = $('root7');
    var U = $('U');
    var V = $('V');
    var VV = $('VV');
    var W = $('W');

    var iterator = document.createNodeIterator(root, NodeFilter.SHOW_ALL,
					       null);
    check(iterator.nextNode(), root, '7.1');
    check(iterator.nextNode(), U, '7.2');
    check(iterator.nextNode(), V, '7.3');
    check(iterator.nextNode(), VV, '7.4');
    check(iterator.previousNode(), VV, '7.5');
    remove(V);
    var X = addChildTo(U);
    check(iterator.previousNode(), X, '7.6');
  })();
]]></script></pre></body></html>