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

mercurial