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
404var tests = [
405 testBasic,
406 testWrongType,
407 testMultipleRegistration,
408 testMultipleObservers,
409 testNamespaceURI,
410 testPropertyAccess,
411 testOrderingWrtDOMSubtreeModified,
412 testOldValue,
413 testOldValueAsRequested,
414 testOldValueUnionMultipleObservations
415];