OLD | NEW |
| (Empty) |
1 <!DOCTYPE HTML> | |
2 <meta charset=utf-8> | |
3 <title>MutationObservers: takeRecords</title> | |
4 <script src="../../../../resources/testharness.js"></script> | |
5 <script src="../../../../resources/testharnessreport.js"></script> | |
6 <script src="mutationobservers.js"></script> | |
7 <h1>MutationObservers: document mutations</h1> | |
8 <div id="log"></div> | |
9 | |
10 <script id='s001'> | |
11 var setupTest = async_test("setup test"); | |
12 var insertionTest = async_test("parser insertion mutations"); | |
13 var insertionTest2 = async_test("parser script insertion mutation"); | |
14 var testCounter = 0; | |
15 | |
16 function masterMO(sequence, obs) { | |
17 testCounter++; | |
18 if (testCounter == 1) { | |
19 insertionTest.step( | |
20 function () { | |
21 checkRecords(document, sequence, | |
22 [{type: "childList", | |
23 addedNodes: function () { | |
24 return [ document.getElementById("n00") ]; | |
25 }, | |
26 previousSibling: function () { | |
27 return document.getElementById("s001"); | |
28 }, | |
29 target: document.body}, | |
30 {type: "childList", | |
31 addedNodes: function () { | |
32 return [ document.getElementById("s002") ]; | |
33 }, | |
34 previousSibling: function () { | |
35 return document.getElementById("n00"); | |
36 }, | |
37 target: document.body}, | |
38 {type: "childList", | |
39 addedNodes: function () { | |
40 return [ document.getElementById("s002").firstChild ]
; | |
41 }, | |
42 target: function () { | |
43 return document.getElementById("s002"); | |
44 }}]); | |
45 }); | |
46 } else if (testCounter == 2) { | |
47 insertionTest2.step( | |
48 function () { | |
49 checkRecords(document, sequence, | |
50 [{type: "childList", | |
51 addedNodes: function () { | |
52 return [ document.getElementById("inserted_script") ]
; | |
53 }, | |
54 target: function () { | |
55 return document.getElementById("n00"); | |
56 }}, | |
57 {type: "childList", | |
58 addedNodes: function () { | |
59 return [ document.getElementById("inserted_element")
]; | |
60 }, | |
61 previousSibling: function () { | |
62 return document.getElementById("s002"); | |
63 }, | |
64 target: document.body} | |
65 ]); | |
66 }); | |
67 } | |
68 } | |
69 var document_observer; | |
70 var newElement; | |
71 setupTest.step(function() { | |
72 document_observer = new MutationObserver(masterMO); | |
73 newElement = document.createElement("span"); | |
74 document_observer.observe(document, {subtree:true,childList:true}); | |
75 newElement.id = "inserted_element"; | |
76 newElement.setAttribute("style", "display: none"); | |
77 newElement.textContent = "my new span for n00"; | |
78 }); | |
79 </script><p id='n00'></p><script id='s002'> | |
80 var newScript = document.createElement("script"); | |
81 setupTest.step(function() { | |
82 newScript.textContent = "document.body.appendChild(newElement);"; | |
83 newScript.id = "inserted_script"; | |
84 document.getElementById("n00").appendChild(newScript); | |
85 }); | |
86 if (testCounter < 1) { | |
87 insertionTest.step( | |
88 function () { | |
89 assert_unreached("document observer did not trigger"); | |
90 }); | |
91 } | |
92 </script><script id='s003'> | |
93 setupTest.step(function() { | |
94 document_observer.disconnect(); | |
95 }); | |
96 if (testCounter < 2) { | |
97 insertionTest2.step( | |
98 function () { | |
99 assert_unreached("document observer did not trigger"); | |
100 }); | |
101 } | |
102 insertionTest.done(); | |
103 insertionTest2.done(); | |
104 </script> | |
105 | |
106 <p id='n012'></p><div id='d01'> | |
107 <script id='s011'> | |
108 var removalTest = async_test("removal of parent during parsing"); | |
109 var d01 = document.getElementById("d01"); | |
110 testCounter = 0; | |
111 | |
112 function removalMO(sequence, obs) { | |
113 testCounter++; | |
114 if (testCounter == 1) { | |
115 removalTest.step( | |
116 function () { | |
117 checkRecords(document, sequence, | |
118 [{type: "childList", | |
119 removedNodes: function () { | |
120 return [ d01 ]; | |
121 }, | |
122 previousSibling: function () { | |
123 return document.getElementById("n012"); | |
124 }, | |
125 target: document.body}]); | |
126 }); | |
127 } else if (testCounter == 2) { | |
128 removalTest.step( | |
129 function () { | |
130 checkRecords(document, sequence, | |
131 [{type: "childList", | |
132 addedNodes: function () { | |
133 return [ document.getElementById("s012") ]; | |
134 }, | |
135 previousSibling: function () { | |
136 return document.getElementById("n012"); | |
137 }, | |
138 target: document.body}, | |
139 {type: "childList", | |
140 addedNodes: function () { | |
141 return [ document.getElementById("s012").firstChild
]; | |
142 }, | |
143 target: function () { | |
144 return document.getElementById("s012"); | |
145 }}]); | |
146 }); | |
147 } | |
148 } | |
149 var document2_observer; | |
150 setupTest.step(function() { | |
151 document2_observer = new MutationObserver(removalMO); | |
152 document2_observer.observe(document, {subtree:true,childList:true}); | |
153 d01.parentNode.removeChild(d01); | |
154 }); | |
155 </script><p id='n01'></p></div><script id='s012'> | |
156 setupTest.step(function() { | |
157 document2_observer.disconnect(); | |
158 }); | |
159 if (testCounter < 2) { | |
160 removalTest.step( | |
161 function () { | |
162 assert_unreached("document observer did not trigger"); | |
163 }); | |
164 } | |
165 removalTest.done(); | |
166 setupTest.done(); | |
167 </script> | |
OLD | NEW |