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

Side by Side Diff: LayoutTests/fast/dom/MutationObserver/observe-childList.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 <title></title> 6 <title></title>
7 </head> 7 </head>
8 <body> 8 <body>
9 <p id=description></p> 9 <p id=description></p>
10 <div id="console"></div> 10 <div id="console"></div>
11 <script> 11 <script>
12 12
13 window.jsTestIsAsync = true; 13 window.jsTestIsAsync = true;
14 var mutations, mutations2; 14 var mutations, mutations2;
15 var calls; 15 var calls;
16 var div, removedDiv1, removedDiv2, addedDiv1, addedDiv2, addedDiv3; 16 var div, removedDiv1, removedDiv2, addedDiv1, addedDiv2, addedDiv3;
17 17
18 function testBasic() { 18 function testBasic() {
19 var div; 19 var div;
20 var observer; 20 var observer;
21 21
22 function start() { 22 function start() {
23 debug('Testing basic aspects of childList observation.'); 23 debug('Testing basic aspects of childList observation.');
24 24
25 mutations = null; 25 mutations = null;
26 div = document.createElement('div'); 26 div = document.createElement('div');
27 observer = new WebKitMutationObserver(function(m) { 27 observer = new MutationObserver(function(m) {
28 mutations = m; 28 mutations = m;
29 }); 29 });
30 30
31 observer.observe(div, { childList: true }); 31 observer.observe(div, { childList: true });
32 removedDiv1 = div.appendChild(document.createElement('div')); 32 removedDiv1 = div.appendChild(document.createElement('div'));
33 setTimeout(checkDisconnectAndMutate, 0); 33 setTimeout(checkDisconnectAndMutate, 0);
34 } 34 }
35 35
36 function checkDisconnectAndMutate() { 36 function checkDisconnectAndMutate() {
37 debug('...can childList changes be observed at all'); 37 debug('...can childList changes be observed at all');
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 function testWrongType() { 78 function testWrongType() {
79 var div; 79 var div;
80 var observer; 80 var observer;
81 81
82 function start() { 82 function start() {
83 debug('Testing that observing without specifying "childList" does not re sult in hearing about childList changes.'); 83 debug('Testing that observing without specifying "childList" does not re sult in hearing about childList changes.');
84 84
85 mutations = null; 85 mutations = null;
86 div = document.createElement('div'); 86 div = document.createElement('div');
87 observer = new WebKitMutationObserver(function(m) { 87 observer = new MutationObserver(function(m) {
88 mutations = m; 88 mutations = m;
89 }); 89 });
90 90
91 observer.observe(div, { attributes: true, characterData: true }); 91 observer.observe(div, { attributes: true, characterData: true });
92 div.appendChild(document.createElement('div')); 92 div.appendChild(document.createElement('div'));
93 setTimeout(finish, 0); 93 setTimeout(finish, 0);
94 } 94 }
95 95
96 function finish() { 96 function finish() {
97 shouldBe('mutations', 'null'); 97 shouldBe('mutations', 'null');
98 observer.disconnect(); 98 observer.disconnect();
99 debug(''); 99 debug('');
100 runNextTest(); 100 runNextTest();
101 } 101 }
102 102
103 start(); 103 start();
104 } 104 }
105 105
106 function testMultipleRegistration() { 106 function testMultipleRegistration() {
107 var div; 107 var div;
108 var observer; 108 var observer;
109 109
110 function start() { 110 function start() {
111 debug('Testing that re-observing the same node with the same observer ha s the effect of resetting the options.'); 111 debug('Testing that re-observing the same node with the same observer ha s the effect of resetting the options.');
112 112
113 calls = 0; 113 calls = 0;
114 mutations = null; 114 mutations = null;
115 div = document.createElement('div'); 115 div = document.createElement('div');
116 observer = new WebKitMutationObserver(function(m) { 116 observer = new MutationObserver(function(m) {
117 mutations = m; 117 mutations = m;
118 calls++; 118 calls++;
119 }); 119 });
120 120
121 observer.observe(div, { childList: true, characterData: true }); 121 observer.observe(div, { childList: true, characterData: true });
122 observer.observe(div, { childList: true }); 122 observer.observe(div, { childList: true });
123 div.appendChild(document.createElement('div')); 123 div.appendChild(document.createElement('div'));
124 setTimeout(checkDisconnectAndMutate, 0); 124 setTimeout(checkDisconnectAndMutate, 0);
125 } 125 }
126 126
(...skipping 20 matching lines...) Expand all
147 147
148 function testMultipleObservers() { 148 function testMultipleObservers() {
149 var div; 149 var div;
150 var observer; 150 var observer;
151 var observer2; 151 var observer2;
152 152
153 function start() { 153 function start() {
154 debug('Testing that multiple observers can be registered to a given node and both receive mutations.'); 154 debug('Testing that multiple observers can be registered to a given node and both receive mutations.');
155 mutations = null; 155 mutations = null;
156 div = document.createElement('div'); 156 div = document.createElement('div');
157 observer = new WebKitMutationObserver(function(m) { 157 observer = new MutationObserver(function(m) {
158 mutations = m; 158 mutations = m;
159 }); 159 });
160 observer2 = new WebKitMutationObserver(function(m) { 160 observer2 = new MutationObserver(function(m) {
161 mutations2 = m; 161 mutations2 = m;
162 }); 162 });
163 observer.observe(div, { childList: true }); 163 observer.observe(div, { childList: true });
164 observer2.observe(div, { childList: true }); 164 observer2.observe(div, { childList: true });
165 div.appendChild(document.createElement('div')); 165 div.appendChild(document.createElement('div'));
166 setTimeout(finish, 0); 166 setTimeout(finish, 0);
167 } 167 }
168 168
169 function finish() { 169 function finish() {
170 shouldBe('mutations.length', '1'); 170 shouldBe('mutations.length', '1');
(...skipping 14 matching lines...) Expand all
185 var observer; 185 var observer;
186 186
187 function start() { 187 function start() {
188 debug('Testing that innerText and innerHTML always result in a single ch ildList mutation.'); 188 debug('Testing that innerText and innerHTML always result in a single ch ildList mutation.');
189 189
190 mutations = null; 190 mutations = null;
191 div = document.createElement('div'); 191 div = document.createElement('div');
192 div.innerHTML = '<span>Foo</span><div>Bar</div>'; 192 div.innerHTML = '<span>Foo</span><div>Bar</div>';
193 removedDiv1 = div.firstChild; 193 removedDiv1 = div.firstChild;
194 removedDiv2 = removedDiv1.nextSibling; 194 removedDiv2 = removedDiv1.nextSibling;
195 observer = new WebKitMutationObserver(function(m) { 195 observer = new MutationObserver(function(m) {
196 mutations = m; 196 mutations = m;
197 }); 197 });
198 198
199 observer.observe(div, { childList: true }); 199 observer.observe(div, { childList: true });
200 div.innerHTML = 'foo<img src="bar.png"><p>Baz</p>'; 200 div.innerHTML = 'foo<img src="bar.png"><p>Baz</p>';
201 addedDiv1 = div.childNodes[0]; 201 addedDiv1 = div.childNodes[0];
202 addedDiv2 = div.childNodes[1]; 202 addedDiv2 = div.childNodes[1];
203 addedDiv3 = div.childNodes[2]; 203 addedDiv3 = div.childNodes[2];
204 setTimeout(checkInnerHTML, 0); 204 setTimeout(checkInnerHTML, 0);
205 } 205 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 var fragment; 243 var fragment;
244 244
245 function start() { 245 function start() {
246 debug('Testing that replaceChild results in minimal childList mutations. '); 246 debug('Testing that replaceChild results in minimal childList mutations. ');
247 247
248 mutations = null; 248 mutations = null;
249 div = document.createElement('div'); 249 div = document.createElement('div');
250 div.innerHTML = '<span>Foo</span><div>Bar</div>'; 250 div.innerHTML = '<span>Foo</span><div>Bar</div>';
251 removedDiv1 = div.firstChild; 251 removedDiv1 = div.firstChild;
252 252
253 observer = new WebKitMutationObserver(function(m) { 253 observer = new MutationObserver(function(m) {
254 mutations = m; 254 mutations = m;
255 }); 255 });
256 256
257 observer.observe(div, { childList: true }); 257 observer.observe(div, { childList: true });
258 addedDiv1 = document.createElement('div'); 258 addedDiv1 = document.createElement('div');
259 div.replaceChild(addedDiv1, div.firstChild); 259 div.replaceChild(addedDiv1, div.firstChild);
260 setTimeout(checkReplaceWithNode, 0); 260 setTimeout(checkReplaceWithNode, 0);
261 } 261 }
262 262
263 function checkReplaceWithNode() { 263 function checkReplaceWithNode() {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 function start() { 308 function start() {
309 debug('Testing that insertBefore results in minimal childList mutations. '); 309 debug('Testing that insertBefore results in minimal childList mutations. ');
310 310
311 mutations = null; 311 mutations = null;
312 div = document.createElement('div'); 312 div = document.createElement('div');
313 div.innerHTML = '<span>Foo</span>'; 313 div.innerHTML = '<span>Foo</span>';
314 fragment = document.createDocumentFragment(); 314 fragment = document.createDocumentFragment();
315 addedDiv1 = fragment.appendChild(document.createElement('div')); 315 addedDiv1 = fragment.appendChild(document.createElement('div'));
316 addedDiv2 = fragment.appendChild(document.createElement('div')); 316 addedDiv2 = fragment.appendChild(document.createElement('div'));
317 317
318 observer = new WebKitMutationObserver(function(m) { 318 observer = new MutationObserver(function(m) {
319 mutations = m; 319 mutations = m;
320 }); 320 });
321 321
322 observer.observe(div, { childList: true }); 322 observer.observe(div, { childList: true });
323 div.insertBefore(fragment, div.firstChild); 323 div.insertBefore(fragment, div.firstChild);
324 setTimeout(finish, 0); 324 setTimeout(finish, 0);
325 } 325 }
326 326
327 327
328 function finish() { 328 function finish() {
(...skipping 20 matching lines...) Expand all
349 function start() { 349 function start() {
350 debug('Testing that appendChild results in minimal childList mutations.' ); 350 debug('Testing that appendChild results in minimal childList mutations.' );
351 351
352 mutations = null; 352 mutations = null;
353 div = document.createElement('div'); 353 div = document.createElement('div');
354 div.innerHTML = '<span>Foo</span>'; 354 div.innerHTML = '<span>Foo</span>';
355 fragment = document.createDocumentFragment(); 355 fragment = document.createDocumentFragment();
356 addedDiv1 = fragment.appendChild(document.createElement('div')); 356 addedDiv1 = fragment.appendChild(document.createElement('div'));
357 addedDiv2 = fragment.appendChild(document.createElement('div')); 357 addedDiv2 = fragment.appendChild(document.createElement('div'));
358 358
359 observer = new WebKitMutationObserver(function(m) { 359 observer = new MutationObserver(function(m) {
360 mutations = m; 360 mutations = m;
361 }); 361 });
362 362
363 observer.observe(div, { childList: true }); 363 observer.observe(div, { childList: true });
364 div.appendChild(fragment); 364 div.appendChild(fragment);
365 setTimeout(finish, 0); 365 setTimeout(finish, 0);
366 } 366 }
367 367
368 function finish() { 368 function finish() {
369 shouldBe('mutations.length', '1'); 369 shouldBe('mutations.length', '1');
(...skipping 10 matching lines...) Expand all
380 380
381 start(); 381 start();
382 } 382 }
383 383
384 function testInnerHTMLEmpty() { 384 function testInnerHTMLEmpty() {
385 function start() { 385 function start() {
386 debug('Setting an empty childlist to the empty string with innerHTML sho uld not assert.'); 386 debug('Setting an empty childlist to the empty string with innerHTML sho uld not assert.');
387 387
388 var div = document.createElement('div'); 388 var div = document.createElement('div');
389 mutations = null; 389 mutations = null;
390 observer = new WebKitMutationObserver(function(mutations) { 390 observer = new MutationObserver(function(mutations) {
391 window.mutations = mutations; 391 window.mutations = mutations;
392 }); 392 });
393 observer.observe(div, {childList: true}); 393 observer.observe(div, {childList: true});
394 div.innerHTML = ''; 394 div.innerHTML = '';
395 setTimeout(finish, 0); 395 setTimeout(finish, 0);
396 } 396 }
397 397
398 function finish() { 398 function finish() {
399 shouldBeNull('mutations'); 399 shouldBeNull('mutations');
400 debug(''); 400 debug('');
(...skipping 13 matching lines...) Expand all
414 finishJSTest(); 414 finishJSTest();
415 } 415 }
416 416
417 description('Test WebKitMutationObserver.observe on attributes.'); 417 description('Test WebKitMutationObserver.observe on attributes.');
418 418
419 runNextTest(); 419 runNextTest();
420 </script> 420 </script>
421 <script src="../../js/resources/js-test-post.js"></script> 421 <script src="../../js/resources/js-test-post.js"></script>
422 </body> 422 </body>
423 </html> 423 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698