Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- NodeIterator mutation tests, 2. |
michael@0 | 4 | Originally part of WebKit, Mochi-ified by Zack Weinberg. |
michael@0 | 5 | This file based on node-iterator-00[...].html from |
michael@0 | 6 | http://svn.webkit.org/repository/webkit/trunk/LayoutTests/traversal/ |
michael@0 | 7 | --> |
michael@0 | 8 | <head> |
michael@0 | 9 | <title>DOM Traversal: NodeIterator: Mutations (2/x)</title> |
michael@0 | 10 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 11 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"> |
michael@0 | 12 | </head> |
michael@0 | 13 | <p id="display"></p> |
michael@0 | 14 | <div id="content" style="display: none"> |
michael@0 | 15 | </div> |
michael@0 | 16 | <pre id="test"> |
michael@0 | 17 | <script class="testbody" type="text/javascript"> |
michael@0 | 18 | function resetContent() { |
michael@0 | 19 | var content = $('content'); |
michael@0 | 20 | content.innerHTML = ('<span id="A"><\/span><span id="B"><\/span>' |
michael@0 | 21 | + '<span id="C"><\/span><span id="D"><\/span>' |
michael@0 | 22 | + '<span id="E"><\/span><span id="F"><\/span>' |
michael@0 | 23 | + '<span id="G"><\/span><span id="H"><\/span>' |
michael@0 | 24 | + '<span id="I"><\/span>'); |
michael@0 | 25 | return content; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function makeSpan(id) { |
michael@0 | 29 | var e = document.createElement('span'); |
michael@0 | 30 | e.id = id; |
michael@0 | 31 | return e; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function testNodeFilter(n) { |
michael@0 | 35 | if (n.tagName == 'SPAN') |
michael@0 | 36 | return NodeFilter.FILTER_ACCEPT; |
michael@0 | 37 | return NodeFilter.FILTER_SKIP; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | function checkseq(it, root, expect) { |
michael@0 | 41 | var checkIt = document.createNodeIterator(root, NodeFilter.SHOW_ELEMENT, |
michael@0 | 42 | testNodeFilter); |
michael@0 | 43 | var printedPointer = (it.referenceNode == undefined); |
michael@0 | 44 | var string = ''; |
michael@0 | 45 | var node; |
michael@0 | 46 | while ((node = checkIt.nextNode()) != null) { |
michael@0 | 47 | if (!printedPointer && it.referenceNode == node) { |
michael@0 | 48 | printedPointer = true; |
michael@0 | 49 | var s = '[' + node.id + '] '; |
michael@0 | 50 | if (it.pointerBeforeReferenceNode) |
michael@0 | 51 | string += "* " + s; |
michael@0 | 52 | else |
michael@0 | 53 | string += s + "* "; |
michael@0 | 54 | } else { |
michael@0 | 55 | string += node.id + " "; |
michael@0 | 56 | } |
michael@0 | 57 | } |
michael@0 | 58 | is(string.slice(0, -1), expect, "sequence check"); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | // first a basic sanity check [node-iterator-001] |
michael@0 | 62 | (function(){ |
michael@0 | 63 | var root = resetContent(); |
michael@0 | 64 | var it = document.createNodeIterator(root, NodeFilter.SHOW_ELEMENT, |
michael@0 | 65 | testNodeFilter); |
michael@0 | 66 | |
michael@0 | 67 | checkseq(it, root, 'A B C D E F G H I'); |
michael@0 | 68 | it.nextNode(); |
michael@0 | 69 | checkseq(it, root, '[A] * B C D E F G H I'); |
michael@0 | 70 | it.previousNode(); |
michael@0 | 71 | checkseq(it, root, '* [A] B C D E F G H I'); |
michael@0 | 72 | it.previousNode(); |
michael@0 | 73 | checkseq(it, root, '* [A] B C D E F G H I'); |
michael@0 | 74 | })(); |
michael@0 | 75 | |
michael@0 | 76 | // Mutations that should not move the iterator [node-iterator-002] |
michael@0 | 77 | (function(){ |
michael@0 | 78 | var root = resetContent(); |
michael@0 | 79 | var it = document.createNodeIterator(root, NodeFilter.SHOW_ELEMENT, |
michael@0 | 80 | testNodeFilter); |
michael@0 | 81 | |
michael@0 | 82 | for (var i = 0; i < 4; i++) |
michael@0 | 83 | it.nextNode(); |
michael@0 | 84 | checkseq(it, root, 'A B C [D] * E F G H I'); |
michael@0 | 85 | |
michael@0 | 86 | root.removeChild($('E')); |
michael@0 | 87 | checkseq(it, root, 'A B C [D] * F G H I'); |
michael@0 | 88 | |
michael@0 | 89 | var X = makeSpan('X'); |
michael@0 | 90 | root.insertBefore(X, $('F')); |
michael@0 | 91 | checkseq(it, root, 'A B C [D] * X F G H I'); |
michael@0 | 92 | |
michael@0 | 93 | var I = $('I'); |
michael@0 | 94 | root.removeChild(I); |
michael@0 | 95 | root.insertBefore(I, X); |
michael@0 | 96 | checkseq(it, root, 'A B C [D] * I X F G H'); |
michael@0 | 97 | })(); |
michael@0 | 98 | |
michael@0 | 99 | // 002 complete |
michael@0 | 100 | |
michael@0 | 101 | /* Template |
michael@0 | 102 | (function(){ |
michael@0 | 103 | var root = resetContent(); |
michael@0 | 104 | var it = document.createNodeIterator(root, NodeFilter.SHOW_ELEMENT, |
michael@0 | 105 | testNodeFilter); |
michael@0 | 106 | |
michael@0 | 107 | })(); |
michael@0 | 108 | */ |
michael@0 | 109 | </script> |
michael@0 | 110 | </pre> |
michael@0 | 111 | </body> |
michael@0 | 112 | </html> |