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