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 | <html xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 2 | <!-- |
michael@0 | 3 | https://bugzilla.mozilla.org/show_bug.cgi?id=522601 |
michael@0 | 4 | --> |
michael@0 | 5 | <head> |
michael@0 | 6 | <title>Test for Bug 522601</title> |
michael@0 | 7 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 8 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 9 | |
michael@0 | 10 | <bindings xmlns="http://www.mozilla.org/xbl"> |
michael@0 | 11 | <binding id="testBinding"> |
michael@0 | 12 | <content><div><children/></div><children includes="span"/></content> |
michael@0 | 13 | </binding> |
michael@0 | 14 | </bindings> |
michael@0 | 15 | </head> |
michael@0 | 16 | <body> |
michael@0 | 17 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=522601">Mozilla Bug 522601</a> |
michael@0 | 18 | <p id="display" style="-moz-binding: url(#testBinding)"> |
michael@0 | 19 | <span id="s">This is some text</span> |
michael@0 | 20 | More text |
michael@0 | 21 | <b id="b">Even more <i id="i1">Italic</i>text<i id="i2">And more italic</i></b></p> |
michael@0 | 22 | <div id="content" style="display: none"> |
michael@0 | 23 | |
michael@0 | 24 | </div> |
michael@0 | 25 | <pre id="test"> |
michael@0 | 26 | <script type="application/javascript"> |
michael@0 | 27 | <![CDATA[ |
michael@0 | 28 | |
michael@0 | 29 | /** Test for Bug 522601 **/ |
michael@0 | 30 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 31 | |
michael@0 | 32 | function testFunc(walker, func, expectedNode, str) { |
michael@0 | 33 | var oldCurrent = SpecialPowers.unwrap(walker.currentNode); |
michael@0 | 34 | var newNode = SpecialPowers.unwrap(walker[func]()); |
michael@0 | 35 | is(newNode, expectedNode, "Unexpected node after " + str); |
michael@0 | 36 | is(SpecialPowers.unwrap(walker.currentNode), newNode ? newNode : oldCurrent, |
michael@0 | 37 | "Unexpected current node after " + str); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | addLoadEvent(function() { |
michael@0 | 41 | var walkerNonAnon = |
michael@0 | 42 | SpecialPowers.Cc["@mozilla.org/inspector/deep-tree-walker;1"] |
michael@0 | 43 | .createInstance(SpecialPowers.Ci.inIDeepTreeWalker); |
michael@0 | 44 | walkerNonAnon.init($("display"), NodeFilter.SHOW_ALL); |
michael@0 | 45 | walkerNonAnon.showAnonymousContent = false; |
michael@0 | 46 | |
michael@0 | 47 | is(SpecialPowers.unwrap(walkerNonAnon.currentNode), $("display"), "Unexpected non-anon root"); |
michael@0 | 48 | testFunc(walkerNonAnon, "nextNode", $("s").previousSibling, |
michael@0 | 49 | "step to some text"); |
michael@0 | 50 | testFunc(walkerNonAnon, "nextNode", $("s"), "step to span"); |
michael@0 | 51 | testFunc(walkerNonAnon, "nextNode", $("s").firstChild, "step to span text"); |
michael@0 | 52 | testFunc(walkerNonAnon, "nextNode", $("s").nextSibling, "step to more text"); |
michael@0 | 53 | testFunc(walkerNonAnon, "nextNode", $("b"), "step to bold"); |
michael@0 | 54 | testFunc(walkerNonAnon, "nextNode", $("b").firstChild, "step to bold text"); |
michael@0 | 55 | testFunc(walkerNonAnon, "nextNode", $("i1"), "step to first italic"); |
michael@0 | 56 | testFunc(walkerNonAnon, "nextNode", $("i1").firstChild, |
michael@0 | 57 | "step to first italic text"); |
michael@0 | 58 | testFunc(walkerNonAnon, "nextNode", $("i1").nextSibling, |
michael@0 | 59 | "step to more bold text"); |
michael@0 | 60 | testFunc(walkerNonAnon, "nextNode", $("i2"), "step to second italic"); |
michael@0 | 61 | testFunc(walkerNonAnon, "nextNode", $("i2").firstChild, |
michael@0 | 62 | "step to second italic text"); |
michael@0 | 63 | testFunc(walkerNonAnon, "nextNode", null, "step past end"); |
michael@0 | 64 | testFunc(walkerNonAnon, "parentNode", $("i2"), "step up to second italic"); |
michael@0 | 65 | testFunc(walkerNonAnon, "parentNode", $("b"), "step up to bold"); |
michael@0 | 66 | testFunc(walkerNonAnon, "nextNode", $("b").firstChild, "step to bold text again"); |
michael@0 | 67 | testFunc(walkerNonAnon, "parentNode", $("b"), "step up to bold again"); |
michael@0 | 68 | testFunc(walkerNonAnon, "parentNode", $("display"), "step up to display"); |
michael@0 | 69 | testFunc(walkerNonAnon, "parentNode", null, "step up past root"); |
michael@0 | 70 | testFunc(walkerNonAnon, "firstChild", $("s").previousSibling, |
michael@0 | 71 | "step firstChild to display first child"); |
michael@0 | 72 | testFunc(walkerNonAnon, "nextSibling", $("s"), |
michael@0 | 73 | "step nextSibling to span"); |
michael@0 | 74 | testFunc(walkerNonAnon, "nextSibling", $("s").nextSibling, |
michael@0 | 75 | "step nextSibling to more text"); |
michael@0 | 76 | testFunc(walkerNonAnon, "nextSibling", $("b"), "step nextSibling to bold"); |
michael@0 | 77 | testFunc(walkerNonAnon, "nextSibling", null, "step nextSibling past end"); |
michael@0 | 78 | testFunc(walkerNonAnon, "previousSibling", $("s").nextSibling, |
michael@0 | 79 | "step previousSibling to more text"); |
michael@0 | 80 | testFunc(walkerNonAnon, "previousSibling", $("s"), |
michael@0 | 81 | "step previousSibling to span"); |
michael@0 | 82 | testFunc(walkerNonAnon, "previousSibling", $("s").previousSibling, |
michael@0 | 83 | "step previousSibling to display first child"); |
michael@0 | 84 | testFunc(walkerNonAnon, "previousSibling", null, |
michael@0 | 85 | "step previousSibling past end"); |
michael@0 | 86 | |
michael@0 | 87 | // Move the walker over to the end |
michael@0 | 88 | while (walkerNonAnon.nextNode()) { /* do nothing */ } |
michael@0 | 89 | is(SpecialPowers.unwrap(walkerNonAnon.currentNode), $("i2").firstChild, "unexpected last node"); |
michael@0 | 90 | testFunc(walkerNonAnon, "previousNode", $("i2"), "step back to second italic"); |
michael@0 | 91 | testFunc(walkerNonAnon, "previousNode", $("i1").nextSibling, |
michael@0 | 92 | "step back to more bold text"); |
michael@0 | 93 | testFunc(walkerNonAnon, "previousNode", $("i1").firstChild, |
michael@0 | 94 | "step back to first italic text"); |
michael@0 | 95 | testFunc(walkerNonAnon, "previousNode", $("i1"), "step back to first italic"); |
michael@0 | 96 | testFunc(walkerNonAnon, "previousNode", $("b").firstChild, |
michael@0 | 97 | "step back to bold text"); |
michael@0 | 98 | testFunc(walkerNonAnon, "previousNode", $("b"), "step back to bold"); |
michael@0 | 99 | testFunc(walkerNonAnon, "previousNode", $("s").nextSibling, "step back to more text"); |
michael@0 | 100 | testFunc(walkerNonAnon, "previousNode", $("s").firstChild, "step back to span text"); |
michael@0 | 101 | testFunc(walkerNonAnon, "previousNode", $("s"), "step back to span"); |
michael@0 | 102 | testFunc(walkerNonAnon, "previousNode", $("s").previousSibling, |
michael@0 | 103 | "step back to some text"); |
michael@0 | 104 | testFunc(walkerNonAnon, "previousNode", $("display"), |
michael@0 | 105 | "step back to root"); |
michael@0 | 106 | testFunc(walkerNonAnon, "previousNode", null, |
michael@0 | 107 | "step back past root"); |
michael@0 | 108 | |
michael@0 | 109 | var anonDiv = SpecialPowers.unwrap(SpecialPowers.wrap(document).getAnonymousNodes($("display")))[0]; |
michael@0 | 110 | |
michael@0 | 111 | var walkerAnon = |
michael@0 | 112 | SpecialPowers.Cc["@mozilla.org/inspector/deep-tree-walker;1"] |
michael@0 | 113 | .createInstance(SpecialPowers.Ci.inIDeepTreeWalker); |
michael@0 | 114 | walkerAnon.showAnonymousContent = true; |
michael@0 | 115 | walkerAnon.init($("display"), NodeFilter.SHOW_ALL); |
michael@0 | 116 | |
michael@0 | 117 | is(SpecialPowers.unwrap(walkerAnon.currentNode), $("display"), "Unexpected anon root"); |
michael@0 | 118 | testFunc(walkerAnon, "nextNode", anonDiv, |
michael@0 | 119 | "step to anonymous div"); |
michael@0 | 120 | testFunc(walkerAnon, "nextNode", $("s").previousSibling, |
michael@0 | 121 | "step to some text (anon)"); |
michael@0 | 122 | testFunc(walkerAnon, "nextNode", $("s").nextSibling, "step to more text (anon)"); |
michael@0 | 123 | testFunc(walkerAnon, "nextNode", $("b"), "step to bold (anon)"); |
michael@0 | 124 | testFunc(walkerAnon, "nextNode", $("b").firstChild, "step to bold text (anon)"); |
michael@0 | 125 | testFunc(walkerAnon, "nextNode", $("i1"), "step to first italic (anon)"); |
michael@0 | 126 | testFunc(walkerAnon, "nextNode", $("i1").firstChild, |
michael@0 | 127 | "step to first italic text (anon)"); |
michael@0 | 128 | testFunc(walkerAnon, "nextNode", $("i1").nextSibling, |
michael@0 | 129 | "step to more bold text (anon)"); |
michael@0 | 130 | testFunc(walkerAnon, "nextNode", $("i2"), "step to second italic (anon)"); |
michael@0 | 131 | testFunc(walkerAnon, "nextNode", $("i2").firstChild, |
michael@0 | 132 | "step to second italic text (anon)"); |
michael@0 | 133 | testFunc(walkerAnon, "nextNode", $("s"), "step to span (anon)"); |
michael@0 | 134 | testFunc(walkerAnon, "nextNode", $("s").firstChild, "step to span text (anon)"); |
michael@0 | 135 | testFunc(walkerAnon, "nextNode", null, "step past end (anon)"); |
michael@0 | 136 | testFunc(walkerAnon, "parentNode", $("s"), "step up to span (anon)"); |
michael@0 | 137 | testFunc(walkerAnon, "parentNode", $("display"), "step up to display (anon)"); |
michael@0 | 138 | testFunc(walkerAnon, "nextNode", anonDiv, "step to anonymous div again"); |
michael@0 | 139 | testFunc(walkerAnon, "parentNode", $("display"), |
michael@0 | 140 | "step up to display again (anon)"); |
michael@0 | 141 | testFunc(walkerAnon, "parentNode", null, "step up past root (anon)"); |
michael@0 | 142 | testFunc(walkerAnon, "firstChild", anonDiv, |
michael@0 | 143 | "step firstChild to display first child (anon)"); |
michael@0 | 144 | testFunc(walkerAnon, "nextSibling", $("s"), |
michael@0 | 145 | "step nextSibling to span (anon)"); |
michael@0 | 146 | testFunc(walkerAnon, "nextSibling", null, "step nextSibling past end (anon)"); |
michael@0 | 147 | testFunc(walkerAnon, "previousSibling", anonDiv, |
michael@0 | 148 | "step previousSibling to anonymous div"); |
michael@0 | 149 | testFunc(walkerAnon, "previousSibling", null, "step previousSibling past end (anon)"); |
michael@0 | 150 | |
michael@0 | 151 | // Move the walker over to the end |
michael@0 | 152 | while (walkerAnon.nextNode()) { /* do nothing */ } |
michael@0 | 153 | testFunc(walkerAnon, "previousNode", $("s"), "step back to span (anon)"); |
michael@0 | 154 | testFunc(walkerAnon, "previousNode", $("i2").firstChild, |
michael@0 | 155 | "step back to second italic text (anon)"); |
michael@0 | 156 | testFunc(walkerAnon, "previousNode", $("i2"), "step back to second italic (anon)"); |
michael@0 | 157 | testFunc(walkerAnon, "previousNode", $("i1").nextSibling, |
michael@0 | 158 | "step back to more bold text (anon)"); |
michael@0 | 159 | testFunc(walkerAnon, "previousNode", $("i1").firstChild, |
michael@0 | 160 | "step back to first italic text (anon)"); |
michael@0 | 161 | testFunc(walkerAnon, "previousNode", $("i1"), "step back to first italic (anon)"); |
michael@0 | 162 | testFunc(walkerAnon, "previousNode", $("b").firstChild, "step back to bold text (anon)"); |
michael@0 | 163 | testFunc(walkerAnon, "previousNode", $("b"), "step back to bold (anon)"); |
michael@0 | 164 | testFunc(walkerAnon, "previousNode", $("s").nextSibling, "step back to more text (anon)"); |
michael@0 | 165 | testFunc(walkerAnon, "previousNode", $("s").previousSibling, |
michael@0 | 166 | "step back to some text (anon)"); |
michael@0 | 167 | testFunc(walkerAnon, "previousNode", anonDiv, |
michael@0 | 168 | "step back to anonymous div"); |
michael@0 | 169 | testFunc(walkerAnon, "previousNode", $("display"), "step back to root (anon)"); |
michael@0 | 170 | testFunc(walkerAnon, "previousNode", null, "step back past root (anon)"); |
michael@0 | 171 | |
michael@0 | 172 | SimpleTest.finish(); |
michael@0 | 173 | }); |
michael@0 | 174 | |
michael@0 | 175 | ]]> |
michael@0 | 176 | </script> |
michael@0 | 177 | </pre> |
michael@0 | 178 | </body> |
michael@0 | 179 | </html> |