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