297
298function testOldValue() {
299 var div;
300 var observer;
301
302 function start() {
303 debug('Testing basic oldValue delivery.');
304 mutations = null;
305 div = document.createElement('div');
306 observer = new WebKitMutationObserver(function(mutations) {
307 window.mutations = mutations;
308 });
309 observer.observe(div, { attributes: true, attributeOldValue: true });
310 div.setAttribute('foo', 'bar');
311 div.setAttribute('foo', 'baz');
312 setTimeout(finish, 0);
313 }
314
315 function finish() {
316 shouldBe('mutations.length', '2');
317 shouldBe('mutations[0].type', '"attributes"');
318 shouldBe('mutations[0].attributeName', '"foo"');
319 shouldBe('mutations[0].oldValue', 'null');
320 shouldBe('mutations[1].type', '"attributes"');
321 shouldBe('mutations[1].attributeName', '"foo"');
322 shouldBe('mutations[1].oldValue', '"bar"');
323 observer.disconnect();
324 debug('');
325 runNextTest();
326 }
327
328 start();
329}
330
331function testOldValueAsRequested() {
332 var div;
333 var observer;
334 var observer2;
335
336 function start() {
337 debug('Testing that oldValue is delivered as requested (or not).');
338 mutations = null;
339 div = document.createElement('div');
340 div.setAttribute('foo', 'bar');
341 observer = new WebKitMutationObserver(function(mutations) {
342 window.mutations = mutations;
343 });
344 observer2 = new WebKitMutationObserver(function(mutations) {
345 window.mutations2 = mutations;
346 });
347 observer.observe(div, { attributes: true, attributeOldValue: true });
348 observer2.observe(div, { attributes: true });
349 div.setAttribute('foo', 'baz');
350 setTimeout(finish, 0);
351 }
352
353 function finish() {
354 shouldBe('mutations.length', '1');
355 shouldBe('mutations[0].type', '"attributes"');
356 shouldBe('mutations[0].attributeName', '"foo"');
357 shouldBe('mutations[0].oldValue', '"bar"');
358 shouldBe('mutations2.length', '1');
359 shouldBe('mutations2[0].type', '"attributes"');
360 shouldBe('mutations2[0].attributeName', '"foo"');
361 shouldBe('mutations2[0].oldValue', 'null');
362 observer.disconnect();
363 observer2.disconnect();
364 debug('');
365 runNextTest();
366 }
367
368 start();
369}
370
371function testOldValueUnionMultipleObservations() {
372 var div;
373 var span;
374 var observer;
375
376 function start() {
377 debug('An observer with multiple observations will get attributeOldValue if any entries request it.');
378 mutations = null;
379 div = document.createElement('div');
380 span = div.appendChild(document.createElement('span'));
381 span.setAttribute('foo', 'bar');
382 observer = new WebKitMutationObserver(function(mutations) {
383 window.mutations = mutations;
384 });
385 observer.observe(div, { attributes: true, attributeOldValue: true, subtree: true });
386 observer.observe(span, { attributes: true });
387 span.setAttribute('foo', 'baz');
388 setTimeout(finish, 0);
389 }
390
391 function finish() {
392 shouldBe('mutations.length', '1');
393 shouldBe('mutations[0].type', '"attributes"');
394 shouldBe('mutations[0].attributeName', '"foo"');
395 shouldBe('mutations[0].oldValue', '"bar"');
396 observer.disconnect();
397 debug('');
398 runNextTest();
399 }
400
401 start();
402}
403
404function testIDLAttribute() {
405 var div;
406 var observer;
407
408 function start() {
409 debug('Testing setting an attribute via reflected IDL attribute.');
410 mutations = null;
411 div = document.createElement('div');
412 observer = new WebKitMutationObserver(function(mutations) {
413 window.mutations = mutations;
414 });
415 observer.observe(div, { attributes: true, attributeOldValue: true });
416 div.id = 'foo';
417 div.id = 'bar';
418 setTimeout(finish, 0);
419 }
420
421 function finish() {
422 shouldBe('mutations.length', '2');
423 shouldBe('mutations[0].type', '"attributes"');
424 shouldBe('mutations[0].attributeName', '"id"');
425 shouldBe('mutations[0].oldValue', 'null');
426 shouldBe('mutations[1].type', '"attributes"');
427 shouldBe('mutations[1].attributeName', '"id"');
428 shouldBe('mutations[1].oldValue', '"foo"');
429 observer.disconnect();
430 debug('');
431 runNextTest();
432 }
433
434 start();
435}
436
437var tests = [
438 testBasic,
439 testWrongType,
440 testMultipleRegistration,
441 testMultipleObservers,
442 testNamespaceURI,
443 testPropertyAccess,
444 testOrderingWrtDOMSubtreeModified,
445 testOldValue,
446 testOldValueAsRequested,
447 testOldValueUnionMultipleObservations,
448 testIDLAttribute
449];