|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=288392 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 288392</title> |
|
8 <script type="text/javascript" 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=288392">Mozilla Bug 288392</a> |
|
13 <p id="display"></p> |
|
14 <div id="content" style="display: none"> |
|
15 <div id="mutationTarget"> |
|
16 </div> |
|
17 </div> |
|
18 <pre id="test"> |
|
19 <script class="testbody" type="text/javascript"> |
|
20 |
|
21 /** Test for Bug 288392 **/ |
|
22 var subtreeModifiedCount; |
|
23 |
|
24 function subtreeModified(e) |
|
25 { |
|
26 ++subtreeModifiedCount; |
|
27 } |
|
28 |
|
29 function doTest() { |
|
30 var targetNode = document.getElementById("mutationTarget"); |
|
31 targetNode.addEventListener("DOMSubtreeModified", subtreeModified, false); |
|
32 |
|
33 subtreeModifiedCount = 0; |
|
34 var temp = document.createElement("DIV"); |
|
35 targetNode.appendChild(temp); |
|
36 is(subtreeModifiedCount, 1, |
|
37 "Appending a child node should have dispatched a DOMSubtreeModified event"); |
|
38 |
|
39 subtreeModifiedCount = 0; |
|
40 temp.setAttribute("foo", "bar"); |
|
41 is(subtreeModifiedCount, 1, |
|
42 "Setting an attribute should have dispatched a DOMSubtreeModified event"); |
|
43 |
|
44 subtreeModifiedCount = 0; |
|
45 targetNode.removeChild(temp); |
|
46 is(subtreeModifiedCount, 1, |
|
47 "Removing a child node should have dispatched a DOMSubtreeModified event"); |
|
48 |
|
49 // Testing events in a subtree, which is not in the document. |
|
50 var subtree = document.createElement("div"); |
|
51 var s = "<e1 attr1='value1'>Something1</e1><e2 attr2='value2'>Something2</e2>"; |
|
52 subtree.innerHTML = s; |
|
53 subtree.addEventListener("DOMSubtreeModified", subtreeModified, false); |
|
54 |
|
55 subtreeModifiedCount = 0; |
|
56 subtree.firstChild.firstChild.data = "foo"; |
|
57 is(subtreeModifiedCount, 1, |
|
58 "Editing character data should have dispatched a DOMSubtreeModified event"); |
|
59 |
|
60 subtreeModifiedCount = 0; |
|
61 subtree.firstChild.removeChild(subtree.firstChild.firstChild); |
|
62 is(subtreeModifiedCount, 1, |
|
63 "Removing a child node should have dispatched a DOMSubtreeModified event"); |
|
64 |
|
65 subtreeModifiedCount = 0; |
|
66 subtree.firstChild.setAttribute("foo", "bar"); |
|
67 is(subtreeModifiedCount, 1, |
|
68 "Setting an attribute should have dispatched a DOMSubtreeModified event"); |
|
69 |
|
70 subtreeModifiedCount = 0; |
|
71 subtree.textContent = "foobar"; |
|
72 is(subtreeModifiedCount, 1, |
|
73 "Setting .textContent should have dispatched a DOMSubtreeModified event"); |
|
74 |
|
75 subtreeModifiedCount = 0; |
|
76 subtree.innerHTML = s; |
|
77 is(subtreeModifiedCount, 1, |
|
78 "Setting .innerHTML should have dispatched a DOMSubtreeModified event"); |
|
79 |
|
80 subtreeModifiedCount = 0; |
|
81 subtree.removeEventListener("DOMSubtreeModified", subtreeModified, false); |
|
82 subtree.appendChild(document.createTextNode("")); |
|
83 subtree.addEventListener("DOMSubtreeModified", subtreeModified, false); |
|
84 subtree.normalize(); |
|
85 is(subtreeModifiedCount, 1, |
|
86 "Calling normalize() should have dispatched a DOMSubtreeModified event"); |
|
87 } |
|
88 |
|
89 SimpleTest.waitForExplicitFinish(); |
|
90 addLoadEvent(doTest); |
|
91 addLoadEvent(SimpleTest.finish); |
|
92 |
|
93 </script> |
|
94 </pre> |
|
95 </body> |
|
96 </html> |
|
97 |