content/base/test/test_NodeIterator_mutations_3.html

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 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>DOM Traversal: NodeIterator: Mutations (3/x)</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
michael@0 7 </head>
michael@0 8 <p id="display"></p>
michael@0 9 <div id="content" style="display: none">
michael@0 10 <span id=root><span id=B></span><span id=C></span><span id=D></span><span id=E><span id=E1><span id=E11></span></span></span></span>
michael@0 11 </div>
michael@0 12 <pre id="test">
michael@0 13 <script class="testbody" type="text/javascript">
michael@0 14 function removeNode(n) {
michael@0 15 n.parentNode.removeChild(n);
michael@0 16 }
michael@0 17 var initInner = $('content').innerHTML;
michael@0 18 var content = $('content');
michael@0 19
michael@0 20
michael@0 21 function resetContent() {
michael@0 22 content.innerHTML = initInner;
michael@0 23 var checkIt = document.createNodeIterator(content, NodeFilter.SHOW_ELEMENT,
michael@0 24 testNodeFilter);
michael@0 25 var node;
michael@0 26 while ((node = checkIt.nextNode()) != null) {
michael@0 27 if (node.id) {
michael@0 28 window[node.id] = node;
michael@0 29 }
michael@0 30 }
michael@0 31 }
michael@0 32
michael@0 33 function makeSpan(id) {
michael@0 34 var e = document.createElement('span');
michael@0 35 e.id = id;
michael@0 36 return e;
michael@0 37 }
michael@0 38
michael@0 39 function testNodeFilter(n) {
michael@0 40 if (n.tagName == 'SPAN')
michael@0 41 return NodeFilter.FILTER_ACCEPT;
michael@0 42 return NodeFilter.FILTER_SKIP;
michael@0 43 }
michael@0 44
michael@0 45 function checkseq(it, root, expect) {
michael@0 46 var checkIt = document.createNodeIterator(root, NodeFilter.SHOW_ELEMENT,
michael@0 47 testNodeFilter);
michael@0 48 var printedPointer = (it.referenceNode == undefined);
michael@0 49 var string = '';
michael@0 50 var node;
michael@0 51 while ((node = checkIt.nextNode()) != null) {
michael@0 52 if (!printedPointer && it.referenceNode == node) {
michael@0 53 printedPointer = true;
michael@0 54 var s = '[' + node.id + '] ';
michael@0 55 if (it.pointerBeforeReferenceNode)
michael@0 56 string += "* " + s;
michael@0 57 else
michael@0 58 string += s + "* ";
michael@0 59 } else {
michael@0 60 string += node.id + " ";
michael@0 61 }
michael@0 62 }
michael@0 63 is(string.slice(0, -1), expect, "sequence check");
michael@0 64 }
michael@0 65
michael@0 66 resetContent();
michael@0 67 var it = document.createNodeIterator(E, NodeFilter.SHOW_ELEMENT,
michael@0 68 testNodeFilter);
michael@0 69 checkseq(it, root, "root B C D * [E] E1 E11");
michael@0 70
michael@0 71 removeNode(C);
michael@0 72 checkseq(it, root, "root B D * [E] E1 E11");
michael@0 73
michael@0 74 it.nextNode();
michael@0 75 removeNode(D);
michael@0 76 checkseq(it, root, "root B [E] * E1 E11");
michael@0 77
michael@0 78 it.nextNode();
michael@0 79 removeNode(B);
michael@0 80 checkseq(it, root, "root E [E1] * E11");
michael@0 81
michael@0 82 it.nextNode();
michael@0 83 checkseq(it, root, "root E E1 [E11] *");
michael@0 84
michael@0 85 it.nextNode();
michael@0 86 checkseq(it, root, "root E E1 [E11] *");
michael@0 87
michael@0 88 it.previousNode();
michael@0 89 it.previousNode();
michael@0 90 it.previousNode();
michael@0 91 it.previousNode();
michael@0 92 it.previousNode();
michael@0 93 checkseq(it, root, "root * [E] E1 E11");
michael@0 94
michael@0 95 resetContent();
michael@0 96 it = document.createNodeIterator(E, NodeFilter.SHOW_ELEMENT,
michael@0 97 testNodeFilter);
michael@0 98 checkseq(it, root, "root B C D * [E] E1 E11");
michael@0 99
michael@0 100 it.nextNode();
michael@0 101 it.nextNode();
michael@0 102 checkseq(it, root, "root B C D E [E1] * E11");
michael@0 103
michael@0 104 it.previousNode();
michael@0 105 it.previousNode();
michael@0 106 checkseq(it, root, "root B C D * [E] E1 E11");
michael@0 107
michael@0 108 removeNode(D);
michael@0 109 removeNode(B);
michael@0 110 checkseq(it, root, "root C * [E] E1 E11");
michael@0 111
michael@0 112 n = makeSpan('n');
michael@0 113 root.insertBefore(n, E);
michael@0 114 checkseq(it, root, "root C n * [E] E1 E11");
michael@0 115
michael@0 116 n2 = makeSpan('n2');
michael@0 117 root.insertBefore(n2, C);
michael@0 118 checkseq(it, root, "root n2 C n * [E] E1 E11");
michael@0 119
michael@0 120 resetContent();
michael@0 121 it = document.createNodeIterator(E, NodeFilter.SHOW_ELEMENT,
michael@0 122 testNodeFilter);
michael@0 123 checkseq(it, root, "root B C D * [E] E1 E11");
michael@0 124
michael@0 125 removeNode(root);
michael@0 126 checkseq(it, root, "root B C D * [E] E1 E11");
michael@0 127
michael@0 128 removeNode(B);
michael@0 129 checkseq(it, root, "root C D * [E] E1 E11");
michael@0 130
michael@0 131 removeNode(D);
michael@0 132 checkseq(it, root, "root C * [E] E1 E11");
michael@0 133
michael@0 134 it.nextNode();
michael@0 135 it.nextNode();
michael@0 136 it.nextNode();
michael@0 137 checkseq(it, root, "root C E E1 [E11] *");
michael@0 138
michael@0 139 removeNode(E1);
michael@0 140 checkseq(it, root, "root C [E] *");
michael@0 141
michael@0 142 n = makeSpan('n');
michael@0 143 root.insertBefore(n, E);
michael@0 144 checkseq(it, root, "root C n [E] *");
michael@0 145
michael@0 146 n2 = makeSpan('n2');
michael@0 147 E.appendChild(n2);
michael@0 148 checkseq(it, root, "root C n [E] * n2");
michael@0 149
michael@0 150 it.nextNode();
michael@0 151 checkseq(it, root, "root C n E [n2] *");
michael@0 152
michael@0 153 removeNode(E);
michael@0 154 checkseq(it, root, "root C n");
michael@0 155
michael@0 156
michael@0 157 </script>
michael@0 158 </pre>
michael@0 159 </body>
michael@0 160 </html>

mercurial