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 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=372086 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 372086</title> |
michael@0 | 8 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 10 | </head> |
michael@0 | 11 | <body> |
michael@0 | 12 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=372086">Mozilla Bug 372086</a> |
michael@0 | 13 | <p id="display"> |
michael@0 | 14 | <!-- Binding is: |
michael@0 | 15 | <bindings xmlns="http://www.mozilla.org/xbl"> |
michael@0 | 16 | <binding id="test"> |
michael@0 | 17 | <content>ghi<children/>jkl</content> |
michael@0 | 18 | </binding> |
michael@0 | 19 | </bindings> |
michael@0 | 20 | --> |
michael@0 | 21 | <div id="d" style="-moz-binding: url(data:application/xml,%3Cbindings%20xmlns%3D%22http%3A%2F%2Fwww.mozilla.org%2Fxbl%22%3E%3Cbinding%20id%3D%22test%22%3E%3Ccontent%3Eghi%3Cchildren%2F%3Ejkl%3C%2Fcontent%3E%3C%2Fbinding%3E%3C%2Fbindings%3E)">abc</div>def |
michael@0 | 22 | </p> |
michael@0 | 23 | <div id="content" style="display: none"> |
michael@0 | 24 | |
michael@0 | 25 | </div> |
michael@0 | 26 | <pre id="test"> |
michael@0 | 27 | <script class="testbody" type="text/javascript"> |
michael@0 | 28 | |
michael@0 | 29 | /** Test for Bug 372086 **/ |
michael@0 | 30 | |
michael@0 | 31 | // Note that we could avoid a lot of SpecialPowers.unwrap calls if the SpecialPowers |
michael@0 | 32 | // wrappers could be made to preserve identity. See bug 718543. |
michael@0 | 33 | |
michael@0 | 34 | function runTest() { |
michael@0 | 35 | var range = SpecialPowers.wrap(document.createRange()); |
michael@0 | 36 | |
michael@0 | 37 | var c = $("d").firstChild; |
michael@0 | 38 | var a = $("d").nextSibling; |
michael@0 | 39 | |
michael@0 | 40 | range.setStart(c, 1); |
michael@0 | 41 | range.setEnd(c, 3); |
michael@0 | 42 | is(SpecialPowers.unwrap(range.startContainer), c, "Unexpected start container"); |
michael@0 | 43 | is(range.startOffset, 1, "Unexpected start offset"); |
michael@0 | 44 | is(SpecialPowers.unwrap(range.endContainer), c, "Unexpected end container"); |
michael@0 | 45 | is(range.endOffset, 3, "Unexpected end offset"); |
michael@0 | 46 | is(range.toString(), "bc", "Unexpected range serialization"); |
michael@0 | 47 | |
michael@0 | 48 | var anon = SpecialPowers.wrap(document).getAnonymousNodes($("d"))[0]; |
michael@0 | 49 | // Should collapse the range, because can't determine order |
michael@0 | 50 | range.setEnd(anon, 2); |
michael@0 | 51 | is(SpecialPowers.unwrap(range.startContainer), SpecialPowers.unwrap(anon), |
michael@0 | 52 | "Unexpected collapsed start container"); |
michael@0 | 53 | is(range.startOffset, 2, "Unexpected collapsed start offset"); |
michael@0 | 54 | is(SpecialPowers.unwrap(range.endContainer), SpecialPowers.unwrap(anon), |
michael@0 | 55 | "Unexpected collapsed end container"); |
michael@0 | 56 | is(range.endOffset, 2, "Unexpected collapsed end offset"); |
michael@0 | 57 | is(range.toString(), "", "Unexpected collapsed range serialization"); |
michael@0 | 58 | |
michael@0 | 59 | range.setEnd(a, 2); |
michael@0 | 60 | range.setStart(a, 0); |
michael@0 | 61 | is(SpecialPowers.unwrap(range.startContainer), a, "Unexpected start container after"); |
michael@0 | 62 | is(range.startOffset, 0, "Unexpected start offset after"); |
michael@0 | 63 | is(SpecialPowers.unwrap(range.endContainer), a, "Unexpected end container after"); |
michael@0 | 64 | is(range.endOffset, 2, "Unexpected end offset after"); |
michael@0 | 65 | is(range.toString(), "de", "Unexpected range serialization after"); |
michael@0 | 66 | |
michael@0 | 67 | anon = SpecialPowers.wrap(document).getAnonymousNodes($("d"))[2]; |
michael@0 | 68 | // Collapses because one endpoint is anonymous from point of view of |
michael@0 | 69 | // the other. |
michael@0 | 70 | range.setStart(anon, 1); |
michael@0 | 71 | is(SpecialPowers.unwrap(range.startContainer), |
michael@0 | 72 | SpecialPowers.unwrap(anon), "Unexpected newly collapsed start container"); |
michael@0 | 73 | is(range.startOffset, 1, "Unexpected newly collapsed start offset"); |
michael@0 | 74 | is(SpecialPowers.unwrap(range.endContainer), SpecialPowers.unwrap(anon), |
michael@0 | 75 | "Unexpected newly collapsed end container"); |
michael@0 | 76 | is(range.endOffset, 1, "Unexpected newly collapsed end offset"); |
michael@0 | 77 | is(range.toString(), "", "Unexpected collapsed range serialization"); |
michael@0 | 78 | |
michael@0 | 79 | range.setEnd(anon, 3); |
michael@0 | 80 | is(SpecialPowers.unwrap(range.startContainer), |
michael@0 | 81 | SpecialPowers.unwrap(anon), "Unexpected anon start container"); |
michael@0 | 82 | is(range.startOffset, 1, "Unexpected anon start offset"); |
michael@0 | 83 | is(SpecialPowers.unwrap(range.endContainer), |
michael@0 | 84 | SpecialPowers.unwrap(anon), "Unexpected anon end container"); |
michael@0 | 85 | is(range.endOffset, 3, "Unexpected anon end offset"); |
michael@0 | 86 | is(range.toString(), "kl", "Unexpected anon range serialization"); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 90 | addLoadEvent(runTest); |
michael@0 | 91 | addLoadEvent(SimpleTest.finish) |
michael@0 | 92 | </script> |
michael@0 | 93 | </pre> |
michael@0 | 94 | </body> |
michael@0 | 95 | </html> |
michael@0 | 96 |