content/base/test/test_NodeIterator_mutations_1.xhtml

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <html xmlns="http://www.w3.org/1999/xhtml">
michael@0 2 <!-- NodeIterator mutation tests.
michael@0 3 Originally written by Ian Hickson, Mochi-ified by Zack Weinberg.
michael@0 4 This file based on 00[3-9].xml from
michael@0 5 http://hixie.ch/tests/adhoc/dom/traversal/node-iterator/
michael@0 6 -->
michael@0 7 <head>
michael@0 8 <title>DOM Traversal: NodeIterator: Mutations (1/x)</title>
michael@0 9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <p id="display"></p>
michael@0 14 <div id="content" style="display: none">
michael@0 15 <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>
michael@0 16 <span id="root2"><span id="F"><span id="FF"></span></span><span id="G"></span><span id="H"><span id="HH"></span></span></span>
michael@0 17 <span id="root3"><span id="I"><span id="II"></span></span><span id="J"></span><span id="K"><span id="KK"></span></span></span>
michael@0 18 <span id="root4"><span id="L"></span><span id="M"><span id="MM"></span></span><span id="N"></span></span>
michael@0 19 <span id="root5"><span id="O"></span><span id="P"><span id="PP"></span></span><span id="Q"></span></span>
michael@0 20 <span id="root6"><span id="R"></span><span id="S"><span id="SS"></span></span><span id="T"></span></span>
michael@0 21 <span id="root7"><span id="U"></span><span id="V"><span id="VV"></span></span><span id="W"></span></span>
michael@0 22 </div>
michael@0 23 <pre id="test">
michael@0 24 <script class="testbody" type="text/javascript"><![CDATA[
michael@0 25 /** Originally written by Ian Hickson. **/
michael@0 26
michael@0 27 function check(f, e, label) {
michael@0 28 var eid = e.id;
michael@0 29 var fid = f ? f.id : 'null';
michael@0 30 is(f, e, label + ': expected ' + eid + ' have ' + fid);
michael@0 31 }
michael@0 32
michael@0 33 var childid = 0;
michael@0 34 function addChildTo(a) {
michael@0 35 var x = document.createElementNS('http://www.w3.org/1999/xhtml', 'span');
michael@0 36 x.id = 'X' + childid;
michael@0 37 childid++;
michael@0 38 ok(a, 'parent ' + (a?a.id:'undefined') + ' for child ' + x.id);
michael@0 39 if (a)
michael@0 40 a.appendChild(x);
michael@0 41 return x;
michael@0 42 }
michael@0 43 function remove(a) {
michael@0 44 var p = a.parentNode;
michael@0 45 ok(a && p,
michael@0 46 'removing ' + ( a?(a.id?a.id:'(no id)'):'undefined' )
michael@0 47 + ' with parent ' + ( p?(p.id?p.id:'(no id)'):'undefined' ));
michael@0 48 if (a && p)
michael@0 49 p.removeChild(a);
michael@0 50 }
michael@0 51
michael@0 52 /** Removal of nodes that should have no effect **/
michael@0 53 (function () {
michael@0 54 var root = $('root1');
michael@0 55 var A = $('A');
michael@0 56 var B = $('B');
michael@0 57 var C = $('C');
michael@0 58 var D = $('D');
michael@0 59 var E = $('E');
michael@0 60
michael@0 61 var iterator = document.createNodeIterator(root, NodeFilter.SHOW_ALL,
michael@0 62 null);
michael@0 63 check(iterator.nextNode(), root, '1.0');
michael@0 64
michael@0 65 // 1. Remove a node unrelated to the reference node
michael@0 66 remove($('X'));
michael@0 67 check(iterator.nextNode(), A, '1.1');
michael@0 68
michael@0 69 // 2. Remove an ancestor of the root node
michael@0 70 remove($('Y'));
michael@0 71 check(iterator.nextNode(), B, '1.2');
michael@0 72
michael@0 73 // 3. Remove the root node itself
michael@0 74 remove(root);
michael@0 75 check(iterator.nextNode(), C, '1.3');
michael@0 76
michael@0 77 // 4. Remove a descendant of the reference node
michael@0 78 remove(E);
michael@0 79 check(iterator.nextNode(), D, '1.4');
michael@0 80 })();
michael@0 81
michael@0 82 /** Removal of the reference node **/
michael@0 83 (function () {
michael@0 84 var root = $('root2');
michael@0 85 var F = $('F');
michael@0 86 var FF = $('FF');
michael@0 87 var G = $('G');
michael@0 88 var H = $('H');
michael@0 89 var iterator = document.createNodeIterator(root, NodeFilter.SHOW_ALL,
michael@0 90 null);
michael@0 91
michael@0 92 check(iterator.nextNode(), root, '2.0');
michael@0 93 check(iterator.nextNode(), F, '2.1');
michael@0 94 check(iterator.nextNode(), FF, '2.2');
michael@0 95 check(iterator.nextNode(), G, '2.3');
michael@0 96 remove(G);
michael@0 97 check(iterator.previousNode(), FF, '2.4');
michael@0 98 remove(FF);
michael@0 99 check(iterator.nextNode(), H, '2.5');
michael@0 100 })();
michael@0 101
michael@0 102 /** Removal of the reference node (deep check) **/
michael@0 103 (function () {
michael@0 104 var root = $('root3');
michael@0 105 var I = $('I');
michael@0 106 var II = $('II');
michael@0 107 var J = $('J');
michael@0 108 var K = $('K');
michael@0 109 var KK = $('KK');
michael@0 110
michael@0 111 var iterator = document.createNodeIterator(root, NodeFilter.SHOW_ALL,
michael@0 112 null);
michael@0 113 check(iterator.nextNode(), root, '3.0');
michael@0 114 check(iterator.nextNode(), I, '3.1');
michael@0 115 check(iterator.nextNode(), II, '3.2');
michael@0 116 check(iterator.nextNode(), J, '3.3');
michael@0 117 remove(J);
michael@0 118 var X = addChildTo(II);
michael@0 119 check(iterator.nextNode(), X, '3.4');
michael@0 120 check(iterator.previousNode(), X, '3.5');
michael@0 121 remove(X);
michael@0 122 var Y = addChildTo(II);
michael@0 123 check(iterator.previousNode(), Y, '3.6');
michael@0 124 check(iterator.nextNode(), Y, '3.7');
michael@0 125 check(iterator.nextNode(), K, '3.8');
michael@0 126 check(iterator.nextNode(), KK, '3.9');
michael@0 127 })();
michael@0 128
michael@0 129 /** Removal of an ancestor of the Reference Node (forwards) **/
michael@0 130 (function () {
michael@0 131 var root = $('root4');
michael@0 132 var L = $('L');
michael@0 133 var M = $('M');
michael@0 134 var MM = $('MM');
michael@0 135 var N = $('N');
michael@0 136
michael@0 137 var iterator = document.createNodeIterator(root, NodeFilter.SHOW_ALL,
michael@0 138 null);
michael@0 139 check(iterator.nextNode(), root, '4.1');
michael@0 140 check(iterator.nextNode(), L, '4.2');
michael@0 141 check(iterator.nextNode(), M, '4.3');
michael@0 142 check(iterator.nextNode(), MM, '4.4');
michael@0 143 remove(M);
michael@0 144 check(iterator.previousNode(), L, '4.5');
michael@0 145 })();
michael@0 146
michael@0 147 /** Removal of an ancestor of the Reference Node (forwards) (deep check) **/
michael@0 148 (function () {
michael@0 149 var root = $('root5');
michael@0 150 var O = $('O');
michael@0 151 var P = $('P');
michael@0 152 var PP = $('PP');
michael@0 153 var Q = $('Q');
michael@0 154
michael@0 155 var iterator = document.createNodeIterator(root, NodeFilter.SHOW_ALL,
michael@0 156 null);
michael@0 157 check(iterator.nextNode(), root, '5.1');
michael@0 158 check(iterator.nextNode(), O, '5.2');
michael@0 159 check(iterator.nextNode(), P, '5.3');
michael@0 160 check(iterator.nextNode(), PP, '5.4');
michael@0 161 remove(P);
michael@0 162 var X = addChildTo(O);
michael@0 163 check(iterator.nextNode(), X, '5.5');
michael@0 164 })();
michael@0 165
michael@0 166 /** Removal of an ancestor of the Reference Node (backwards) **/
michael@0 167 (function () {
michael@0 168 var root = $('root6');
michael@0 169 var R = $('R');
michael@0 170 var S = $('S');
michael@0 171 var SS = $('SS');
michael@0 172 var T = $('T');
michael@0 173
michael@0 174 var iterator = document.createNodeIterator(root, NodeFilter.SHOW_ALL,
michael@0 175 null);
michael@0 176 check(iterator.nextNode(), root, '6.1');
michael@0 177 check(iterator.nextNode(), R, '6.2');
michael@0 178 check(iterator.nextNode(), S, '6.3');
michael@0 179 check(iterator.nextNode(), SS, '6.4');
michael@0 180 check(iterator.previousNode(), SS, '6.5');
michael@0 181 remove(S);
michael@0 182 check(iterator.nextNode(), T, '6.6');
michael@0 183 })();
michael@0 184
michael@0 185 /** Removal of an ancestor of the Reference Node (backwards) (deep check) **/
michael@0 186 (function () {
michael@0 187 var root = $('root7');
michael@0 188 var U = $('U');
michael@0 189 var V = $('V');
michael@0 190 var VV = $('VV');
michael@0 191 var W = $('W');
michael@0 192
michael@0 193 var iterator = document.createNodeIterator(root, NodeFilter.SHOW_ALL,
michael@0 194 null);
michael@0 195 check(iterator.nextNode(), root, '7.1');
michael@0 196 check(iterator.nextNode(), U, '7.2');
michael@0 197 check(iterator.nextNode(), V, '7.3');
michael@0 198 check(iterator.nextNode(), VV, '7.4');
michael@0 199 check(iterator.previousNode(), VV, '7.5');
michael@0 200 remove(V);
michael@0 201 var X = addChildTo(U);
michael@0 202 check(iterator.previousNode(), X, '7.6');
michael@0 203 })();
michael@0 204 ]]></script></pre></body></html>

mercurial