1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/parser/htmlparser/tests/mochitest/test_bug613662.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,132 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=613662 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 613662</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.13 +</head> 1.14 +<body> 1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=613662">Mozilla Bug 613662</a> 1.16 +<p id="display"></p><div id="content" style="display: none"></div><div id="content2" style="display: none"></div><pre id="test"> 1.17 +<script type="application/javascript"> 1.18 + 1.19 +/** Test for Bug 613662 **/ 1.20 + 1.21 +function testPositions(node) { 1.22 + node.insertAdjacentHTML("beforeBegin", "\u003Cscript>ok(false, 'script should not have run');\u003C/script><i></i>"); 1.23 + is(node.previousSibling.localName, "i", "Should have had <i> as previous sibling"); 1.24 + node.insertAdjacentHTML("Afterbegin", "<b></b>\u003Cscript>ok(false, 'script should not have run');\u003C/script>"); 1.25 + is(node.firstChild.localName, "b", "Should have had <b> as first child"); 1.26 + node.insertAdjacentHTML("BeforeEnd", "\u003Cscript>ok(false, 'script should not have run');\u003C/script><u></u>"); 1.27 + is(node.lastChild.localName, "u", "Should have had <u> as last child"); 1.28 + node.insertAdjacentHTML("afterend", "<a></a>\u003Cscript>ok(false, 'script should not have run');\u003C/script>"); 1.29 + is(node.nextSibling.localName, "a", "Should have had <a> as next sibling"); 1.30 +} 1.31 + 1.32 +var content = document.getElementById("content"); 1.33 +testPositions(content); // without next sibling 1.34 +testPositions(content); // test again when there's next sibling 1.35 + 1.36 +try { 1.37 + content.insertAdjacentHTML("bar", "foo"); 1.38 + ok(false, "insertAdjacentHTML should have thrown"); 1.39 +} catch (e) { 1.40 + is(e.name, "SyntaxError", "insertAdjacentHTML should throw SyntaxError"); 1.41 + is(e.code, 12, "insertAdjacentHTML should throw SYNTAX_ERR"); 1.42 +} 1.43 + 1.44 +var parent = document.createElement("div"); 1.45 +var child = document.createElement("div"); 1.46 + 1.47 +try { 1.48 + child.insertAdjacentHTML("Beforebegin", "foo"); 1.49 + ok(false, "insertAdjacentHTML should have thrown"); 1.50 +} catch (e) { 1.51 + is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError"); 1.52 + is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR"); 1.53 +} 1.54 + 1.55 +try { 1.56 + child.insertAdjacentHTML("AfterEnd", "foo"); 1.57 + ok(false, "insertAdjacentHTML should have thrown"); 1.58 +} catch (e) { 1.59 + is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError"); 1.60 + is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR"); 1.61 +} 1.62 + 1.63 +child.insertAdjacentHTML("afterBegin", "foo"); // mustn't throw 1.64 +child.insertAdjacentHTML("beforeend", "foo"); // mustn't throw 1.65 + 1.66 +parent.appendChild(child); 1.67 +testPositions(child); // node not in tree but has parent 1.68 + 1.69 +content.appendChild(parent); // must not run scripts 1.70 + 1.71 +try { 1.72 + document.documentElement.insertAdjacentHTML("afterend", "<div></div>"); 1.73 + ok(false, "insertAdjacentHTML should have thrown"); 1.74 +} catch (e) { 1.75 + is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError"); 1.76 + is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR"); 1.77 +} 1.78 + 1.79 +var content2 = document.getElementById("content2"); 1.80 + 1.81 +var events = [ 1.82 + [ "DOMNodeInserted", document.body ], 1.83 + [ "DOMNodeInserted", document.body ], 1.84 + [ "DOMSubtreeModified", null ], 1.85 + [ "DOMNodeInserted", content2 ], 1.86 + [ "DOMNodeInserted", content2 ], 1.87 + [ "DOMSubtreeModified", null ], 1.88 + [ "DOMNodeInserted", content2 ], 1.89 + [ "DOMNodeInserted", content2 ], 1.90 + [ "DOMSubtreeModified", null ], 1.91 + [ "DOMNodeInserted", document.body ], 1.92 + [ "DOMNodeInserted", document.body ], 1.93 + [ "DOMSubtreeModified", null ], 1.94 + [ "DOMNodeInserted", document.body ], 1.95 + [ "DOMNodeInserted", document.body ], 1.96 + [ "DOMSubtreeModified", null ], 1.97 + [ "DOMNodeInserted", content2 ], 1.98 + [ "DOMNodeInserted", content2 ], 1.99 + [ "DOMSubtreeModified", null ], 1.100 + [ "DOMNodeInserted", content2 ], 1.101 + [ "DOMNodeInserted", content2 ], 1.102 + [ "DOMSubtreeModified", null ], 1.103 + [ "DOMNodeInserted", document.body ], 1.104 + [ "DOMNodeInserted", document.body ], 1.105 + [ "DOMSubtreeModified", null ] 1.106 +]; 1.107 + 1.108 +function mutationEventListener(evt) { 1.109 + var expected = events.shift(); 1.110 + is(evt.type, expected[0], "Unexpected mutation type"); 1.111 + is(evt.relatedNode, expected[1], "Unexpected related node"); 1.112 +} 1.113 +/* 1.114 +document.addEventListener("DOMSubtreeModified", mutationEventListener, false); 1.115 +document.addEventListener("DOMNodeInserted", mutationEventListener, false); 1.116 +document.addEventListener("DOMNodeRemoved", mutationEventListener, false); 1.117 +document.addEventListener("DOMNodeRemovedFromDocument", mutationEventListener, false); 1.118 +document.addEventListener("DOMNodeInsertedIntoDocument", mutationEventListener, false); 1.119 +document.addEventListener("DOMAttrModified", mutationEventListener, false); 1.120 +document.addEventListener("DOMCharacterDataModified", mutationEventListener, false); 1.121 + 1.122 +testPositions(content2); // without next sibling 1.123 +testPositions(content2); // test again when there's next sibling 1.124 + 1.125 +is(events.length, 0, "Not all expected events fired."); 1.126 +*/ 1.127 +// HTML only 1.128 +document.body.insertAdjacentHTML("afterend", "<p>"); 1.129 +document.head.insertAdjacentHTML("beforebegin", "<p>"); 1.130 +is(document.getElementsByTagName("head").length, 1, "Should still have one head"); 1.131 +is(document.getElementsByTagName("body").length, 1, "Should still have one body"); 1.132 + 1.133 +</script> 1.134 +</pre> 1.135 +</body></html>