Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: LayoutTests/fast/dom/MutationObserver/observe-characterdata.html

Issue 12317072: Merge 143386 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1410/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <meta charset="utf-8"> 4 <meta charset="utf-8">
5 <script src="../../js/resources/js-test-pre.js"></script> 5 <script src="../../js/resources/js-test-pre.js"></script>
6 </head> 6 </head>
7 <body> 7 <body>
8 <p id=description></p> 8 <p id=description></p>
9 <div id="console"></div> 9 <div id="console"></div>
10 <script> 10 <script>
11 11
12 window.jsTestIsAsync = true; 12 window.jsTestIsAsync = true;
13 var mutations; 13 var mutations;
14 var mutations2; 14 var mutations2;
15 var mutationsWithOldValue; 15 var mutationsWithOldValue;
16 var calls; 16 var calls;
17 var charDataNode; 17 var charDataNode;
18 18
19 function testBasic() { 19 function testBasic() {
20 var div; 20 var div;
21 var observer; 21 var observer;
22 22
23 function start() { 23 function start() {
24 debug('Testing basic aspects of characterData observation.'); 24 debug('Testing basic aspects of characterData observation.');
25 25
26 mutations = null; 26 mutations = null;
27 div = document.createElement('div'); 27 div = document.createElement('div');
28 div.textContent = 'foo'; 28 div.textContent = 'foo';
29 charDataNode = div.firstChild; 29 charDataNode = div.firstChild;
30 observer = new WebKitMutationObserver(function(m) { 30 observer = new MutationObserver(function(m) {
31 mutations = m; 31 mutations = m;
32 }); 32 });
33 33
34 observer.observe(charDataNode, {characterData: true}); 34 observer.observe(charDataNode, {characterData: true});
35 charDataNode.textContent = 'bar'; 35 charDataNode.textContent = 'bar';
36 setTimeout(checkDisconnectAndMutate, 0); 36 setTimeout(checkDisconnectAndMutate, 0);
37 } 37 }
38 38
39 function checkDisconnectAndMutate() { 39 function checkDisconnectAndMutate() {
40 debug('...can characterData changes be observed at all'); 40 debug('...can characterData changes be observed at all');
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 var div; 80 var div;
81 var observer; 81 var observer;
82 82
83 function start() { 83 function start() {
84 debug('Testing that observing without specifying "characterData" does no t result in hearing about characterData changes.'); 84 debug('Testing that observing without specifying "characterData" does no t result in hearing about characterData changes.');
85 85
86 mutations = null; 86 mutations = null;
87 div = document.createElement('div'); 87 div = document.createElement('div');
88 div.textContent = 'hello'; 88 div.textContent = 'hello';
89 charDataNode = div.firstChild; 89 charDataNode = div.firstChild;
90 observer = new WebKitMutationObserver(function(m) { 90 observer = new MutationObserver(function(m) {
91 mutations = m; 91 mutations = m;
92 }); 92 });
93 93
94 observer.observe(charDataNode, {childList: true, attributes: true}); 94 observer.observe(charDataNode, {childList: true, attributes: true});
95 charDataNode = 'goodbye'; 95 charDataNode = 'goodbye';
96 setTimeout(finish, 0); 96 setTimeout(finish, 0);
97 } 97 }
98 98
99 function finish() { 99 function finish() {
100 shouldBe('mutations', 'null'); 100 shouldBe('mutations', 'null');
101 observer.disconnect(); 101 observer.disconnect();
102 debug(''); 102 debug('');
103 runNextTest(); 103 runNextTest();
104 } 104 }
105 105
106 start(); 106 start();
107 } 107 }
108 108
109 function testMultipleObservers() { 109 function testMultipleObservers() {
110 var div; 110 var div;
111 var observer; 111 var observer;
112 var observer2; 112 var observer2;
113 113
114 function start() { 114 function start() {
115 debug('Testing that multiple observers can be registered to a given node and both receive mutations.'); 115 debug('Testing that multiple observers can be registered to a given node and both receive mutations.');
116 mutations = null; 116 mutations = null;
117 div = document.createElement('div'); 117 div = document.createElement('div');
118 div.textContent = 'foo'; 118 div.textContent = 'foo';
119 charDataNode = div.firstChild; 119 charDataNode = div.firstChild;
120 observer = new WebKitMutationObserver(function(m) { 120 observer = new MutationObserver(function(m) {
121 mutations = m; 121 mutations = m;
122 }); 122 });
123 observer2 = new WebKitMutationObserver(function(m) { 123 observer2 = new MutationObserver(function(m) {
124 mutations2 = m; 124 mutations2 = m;
125 }); 125 });
126 observer.observe(charDataNode, {characterData: true}); 126 observer.observe(charDataNode, {characterData: true});
127 observer2.observe(charDataNode, {characterData: true}); 127 observer2.observe(charDataNode, {characterData: true});
128 charDataNode.textContent = 'bar'; 128 charDataNode.textContent = 'bar';
129 setTimeout(finish, 0); 129 setTimeout(finish, 0);
130 } 130 }
131 131
132 function finish() { 132 function finish() {
133 shouldBe('mutations.length', '1'); 133 shouldBe('mutations.length', '1');
(...skipping 20 matching lines...) Expand all
154 debug('Testing mutation records are enqueued for characterData before DO MSubtreeModified is dispatched.'); 154 debug('Testing mutation records are enqueued for characterData before DO MSubtreeModified is dispatched.');
155 155
156 mutations = null; 156 mutations = null;
157 div = document.body.appendChild(document.createElement('div')); 157 div = document.body.appendChild(document.createElement('div'));
158 div2 = document.body.appendChild(document.createElement('div')); 158 div2 = document.body.appendChild(document.createElement('div'));
159 159
160 subDiv = div.appendChild(document.createElement('div')); 160 subDiv = div.appendChild(document.createElement('div'));
161 subDiv.textContent = 'foo'; 161 subDiv.textContent = 'foo';
162 charDataNode = subDiv.firstChild; 162 charDataNode = subDiv.firstChild;
163 163
164 observer = new WebKitMutationObserver(function(m) { 164 observer = new MutationObserver(function(m) {
165 mutations = m; 165 mutations = m;
166 }); 166 });
167 167
168 listener = function(e) { 168 listener = function(e) {
169 div2.setAttribute('baz', 'bat'); 169 div2.setAttribute('baz', 'bat');
170 } 170 }
171 171
172 div.addEventListener('DOMSubtreeModified', listener); 172 div.addEventListener('DOMSubtreeModified', listener);
173 observer.observe(charDataNode, {characterData: true}); 173 observer.observe(charDataNode, {characterData: true});
174 observer.observe(div2, {attributes: true}); 174 observer.observe(div2, {attributes: true});
(...skipping 20 matching lines...) Expand all
195 function testOldValue() { 195 function testOldValue() {
196 var div; 196 var div;
197 var observer; 197 var observer;
198 198
199 function start() { 199 function start() {
200 debug('Testing that oldValue is returned when requested.'); 200 debug('Testing that oldValue is returned when requested.');
201 mutations = null; 201 mutations = null;
202 div = document.createElement('div'); 202 div = document.createElement('div');
203 div.textContent = 'foo'; 203 div.textContent = 'foo';
204 charDataNode = div.firstChild; 204 charDataNode = div.firstChild;
205 observer = new WebKitMutationObserver(function(mutations) { 205 observer = new MutationObserver(function(mutations) {
206 window.mutations = mutations; 206 window.mutations = mutations;
207 }); 207 });
208 observer.observe(charDataNode, {characterData: true, characterDataOldVal ue: true}); 208 observer.observe(charDataNode, {characterData: true, characterDataOldVal ue: true});
209 charDataNode.textContent = 'bar'; 209 charDataNode.textContent = 'bar';
210 charDataNode.textContent = 'baz'; 210 charDataNode.textContent = 'baz';
211 setTimeout(finish, 0); 211 setTimeout(finish, 0);
212 } 212 }
213 213
214 function finish() { 214 function finish() {
215 shouldBe('mutations.length', '2'); 215 shouldBe('mutations.length', '2');
(...skipping 16 matching lines...) Expand all
232 var observerWithOldValue; 232 var observerWithOldValue;
233 var observer; 233 var observer;
234 234
235 function start() { 235 function start() {
236 debug('Testing that oldValue is delivered as requested (or not).'); 236 debug('Testing that oldValue is delivered as requested (or not).');
237 mutations = null; 237 mutations = null;
238 mutationsWithOldValue = null; 238 mutationsWithOldValue = null;
239 div = document.createElement('div'); 239 div = document.createElement('div');
240 div.textContent = 'foo'; 240 div.textContent = 'foo';
241 charDataNode = div.firstChild; 241 charDataNode = div.firstChild;
242 observerWithOldValue = new WebKitMutationObserver(function(mutations) { 242 observerWithOldValue = new MutationObserver(function(mutations) {
243 window.mutationsWithOldValue = mutations; 243 window.mutationsWithOldValue = mutations;
244 }); 244 });
245 observer = new WebKitMutationObserver(function(mutations) { 245 observer = new MutationObserver(function(mutations) {
246 window.mutations = mutations; 246 window.mutations = mutations;
247 }); 247 });
248 observerWithOldValue.observe(charDataNode, {characterData: true, charact erDataOldValue: true}); 248 observerWithOldValue.observe(charDataNode, {characterData: true, charact erDataOldValue: true});
249 observer.observe(charDataNode, {characterData: true}); 249 observer.observe(charDataNode, {characterData: true});
250 charDataNode.textContent = 'bar'; 250 charDataNode.textContent = 'bar';
251 setTimeout(finish, 0); 251 setTimeout(finish, 0);
252 } 252 }
253 253
254 function finish() { 254 function finish() {
255 shouldBe('mutationsWithOldValue.length', '1'); 255 shouldBe('mutationsWithOldValue.length', '1');
(...skipping 14 matching lines...) Expand all
270 function testOldValueUnionMultipleObservations() { 270 function testOldValueUnionMultipleObservations() {
271 var div; 271 var div;
272 var observer; 272 var observer;
273 273
274 function start() { 274 function start() {
275 debug('An observer with multiple observations will get characterDataOldV alue if any entries request it.'); 275 debug('An observer with multiple observations will get characterDataOldV alue if any entries request it.');
276 mutations = null; 276 mutations = null;
277 div = document.createElement('div'); 277 div = document.createElement('div');
278 div.textContent = 'foo'; 278 div.textContent = 'foo';
279 charDataNode = div.firstChild; 279 charDataNode = div.firstChild;
280 observer = new WebKitMutationObserver(function(mutations) { 280 observer = new MutationObserver(function(mutations) {
281 window.mutations = mutations; 281 window.mutations = mutations;
282 }); 282 });
283 observer.observe(div, {characterData: true, characterDataOldValue: true, subtree: true}); 283 observer.observe(div, {characterData: true, characterDataOldValue: true, subtree: true});
284 observer.observe(charDataNode, {characterData: true}); 284 observer.observe(charDataNode, {characterData: true});
285 charDataNode.textContent = 'bar'; 285 charDataNode.textContent = 'bar';
286 setTimeout(finish, 0); 286 setTimeout(finish, 0);
287 } 287 }
288 288
289 function finish() { 289 function finish() {
290 shouldBe('mutations.length', '1'); 290 shouldBe('mutations.length', '1');
(...skipping 25 matching lines...) Expand all
316 finishJSTest(); 316 finishJSTest();
317 } 317 }
318 318
319 description('Test WebKitMutationObserver.observe on CharacterData nodes'); 319 description('Test WebKitMutationObserver.observe on CharacterData nodes');
320 320
321 runNextTest(); 321 runNextTest();
322 </script> 322 </script>
323 <script src="../../js/resources/js-test-post.js"></script> 323 <script src="../../js/resources/js-test-post.js"></script>
324 </body> 324 </body>
325 </html> 325 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698