Wed, 31 Dec 2014 06:09:35 +0100
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 | <!-- |
michael@0 | 3 | https://bugzilla.mozilla.org/show_bug.cgi?id=613662 |
michael@0 | 4 | --> |
michael@0 | 5 | <head> |
michael@0 | 6 | <title>Test for Bug 613662</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 | </head> |
michael@0 | 10 | <body> |
michael@0 | 11 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=613662">Mozilla Bug 613662</a> |
michael@0 | 12 | <p id="display"></p><div id="content" style="display: none"></div><div id="content2" style="display: none"></div><pre id="test"> |
michael@0 | 13 | <script type="application/javascript"><![CDATA[ |
michael@0 | 14 | |
michael@0 | 15 | SimpleTest.expectAssertions(1); |
michael@0 | 16 | |
michael@0 | 17 | /** Test for Bug 613662 **/ |
michael@0 | 18 | |
michael@0 | 19 | function testPositions(node) { |
michael@0 | 20 | node.insertAdjacentHTML("beforeBegin", "\u003Cscript>ok(false, 'script should not have run');\u003C/script><i></i>"); |
michael@0 | 21 | is(node.previousSibling.localName, "i", "Should have had <i> as previous sibling"); |
michael@0 | 22 | node.insertAdjacentHTML("Afterbegin", "<b></b>\u003Cscript>ok(false, 'script should not have run');\u003C/script>"); |
michael@0 | 23 | is(node.firstChild.localName, "b", "Should have had <b> as first child"); |
michael@0 | 24 | node.insertAdjacentHTML("BeforeEnd", "\u003Cscript>ok(false, 'script should not have run');\u003C/script><u></u>"); |
michael@0 | 25 | is(node.lastChild.localName, "u", "Should have had <u> as last child"); |
michael@0 | 26 | node.insertAdjacentHTML("afterend", "<a></a>\u003Cscript>ok(false, 'script should not have run');\u003C/script>"); |
michael@0 | 27 | is(node.nextSibling.localName, "a", "Should have had <a> as next sibling"); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | var content = document.getElementById("content"); |
michael@0 | 31 | testPositions(content); // without next sibling |
michael@0 | 32 | testPositions(content); // test again when there's next sibling |
michael@0 | 33 | |
michael@0 | 34 | try { |
michael@0 | 35 | content.insertAdjacentHTML("bar", "foo"); |
michael@0 | 36 | ok(false, "insertAdjacentHTML should have thrown"); |
michael@0 | 37 | } catch (e) { |
michael@0 | 38 | is(e.name, "SyntaxError", "insertAdjacentHTML should throw SyntaxError"); |
michael@0 | 39 | is(e.code, 12, "insertAdjacentHTML should throw SYNTAX_ERR"); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | var parent = document.createElementNS("http://www.w3.org/1999/xhtml", "div"); |
michael@0 | 43 | var child = document.createElementNS("http://www.w3.org/1999/xhtml", "div"); |
michael@0 | 44 | |
michael@0 | 45 | try { |
michael@0 | 46 | child.insertAdjacentHTML("Beforebegin", "foo"); |
michael@0 | 47 | ok(false, "insertAdjacentHTML should have thrown"); |
michael@0 | 48 | } catch (e) { |
michael@0 | 49 | is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError"); |
michael@0 | 50 | is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR"); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | try { |
michael@0 | 54 | child.insertAdjacentHTML("AfterEnd", "foo"); |
michael@0 | 55 | ok(false, "insertAdjacentHTML should have thrown"); |
michael@0 | 56 | } catch (e) { |
michael@0 | 57 | is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError"); |
michael@0 | 58 | is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR"); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | child.insertAdjacentHTML("afterBegin", "foo"); // mustn't throw |
michael@0 | 62 | child.insertAdjacentHTML("beforeend", "foo"); // mustn't throw |
michael@0 | 63 | |
michael@0 | 64 | parent.appendChild(child); |
michael@0 | 65 | testPositions(child); // node not in tree but has parent |
michael@0 | 66 | |
michael@0 | 67 | content.appendChild(parent); // must not run scripts |
michael@0 | 68 | |
michael@0 | 69 | try { |
michael@0 | 70 | document.documentElement.insertAdjacentHTML("afterend", "<div></div>"); |
michael@0 | 71 | ok(false, "insertAdjacentHTML should have thrown"); |
michael@0 | 72 | } catch (e) { |
michael@0 | 73 | is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError"); |
michael@0 | 74 | is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR"); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | var content2 = document.getElementById("content2"); |
michael@0 | 78 | |
michael@0 | 79 | var events = [ |
michael@0 | 80 | [ "DOMNodeInserted", document.body ], |
michael@0 | 81 | [ "DOMNodeInserted", document.body ], |
michael@0 | 82 | [ "DOMSubtreeModified", null ], |
michael@0 | 83 | [ "DOMNodeInserted", content2 ], |
michael@0 | 84 | [ "DOMNodeInserted", content2 ], |
michael@0 | 85 | [ "DOMSubtreeModified", null ], |
michael@0 | 86 | [ "DOMNodeInserted", content2 ], |
michael@0 | 87 | [ "DOMNodeInserted", content2 ], |
michael@0 | 88 | [ "DOMSubtreeModified", null ], |
michael@0 | 89 | [ "DOMNodeInserted", document.body ], |
michael@0 | 90 | [ "DOMNodeInserted", document.body ], |
michael@0 | 91 | [ "DOMSubtreeModified", null ], |
michael@0 | 92 | [ "DOMNodeInserted", document.body ], |
michael@0 | 93 | [ "DOMNodeInserted", document.body ], |
michael@0 | 94 | [ "DOMSubtreeModified", null ], |
michael@0 | 95 | [ "DOMNodeInserted", content2 ], |
michael@0 | 96 | [ "DOMNodeInserted", content2 ], |
michael@0 | 97 | [ "DOMSubtreeModified", null ], |
michael@0 | 98 | [ "DOMNodeInserted", content2 ], |
michael@0 | 99 | [ "DOMNodeInserted", content2 ], |
michael@0 | 100 | [ "DOMSubtreeModified", null ], |
michael@0 | 101 | [ "DOMNodeInserted", document.body ], |
michael@0 | 102 | [ "DOMNodeInserted", document.body ], |
michael@0 | 103 | [ "DOMSubtreeModified", null ] |
michael@0 | 104 | ]; |
michael@0 | 105 | |
michael@0 | 106 | function mutationEventListener(evt) { |
michael@0 | 107 | var expected = events.shift(); |
michael@0 | 108 | is(evt.type, expected[0], "Unexpected mutation type"); |
michael@0 | 109 | is(evt.relatedNode, expected[1], "Unexpected related node"); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | document.addEventListener("DOMSubtreeModified", mutationEventListener, false); |
michael@0 | 113 | document.addEventListener("DOMNodeInserted", mutationEventListener, false); |
michael@0 | 114 | document.addEventListener("DOMNodeRemoved", mutationEventListener, false); |
michael@0 | 115 | document.addEventListener("DOMNodeRemovedFromDocument", mutationEventListener, false); |
michael@0 | 116 | document.addEventListener("DOMNodeInsertedIntoDocument", mutationEventListener, false); |
michael@0 | 117 | document.addEventListener("DOMAttrModified", mutationEventListener, false); |
michael@0 | 118 | document.addEventListener("DOMCharacterDataModified", mutationEventListener, false); |
michael@0 | 119 | |
michael@0 | 120 | testPositions(content2); // without next sibling |
michael@0 | 121 | testPositions(content2); // test again when there's next sibling |
michael@0 | 122 | |
michael@0 | 123 | is(events.length, 0, "Not all expected events fired."); |
michael@0 | 124 | |
michael@0 | 125 | // XML-only: |
michael@0 | 126 | try { |
michael@0 | 127 | content.insertAdjacentHTML("beforeend", "<p>"); |
michael@0 | 128 | ok(false, "insertAdjacentHTML should have thrown"); |
michael@0 | 129 | } catch (e) { |
michael@0 | 130 | is(e.name, "SyntaxError", "insertAdjacentHTML should throw SyntaxError"); |
michael@0 | 131 | is(e.code, 12, "insertAdjacentHTML should throw SYNTAX_ERR"); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | ]]></script> |
michael@0 | 135 | </pre> |
michael@0 | 136 | </body> |
michael@0 | 137 | </html> |