summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/nodes/MutationObserver-disconnect.html
blob: 883edecf74403843b19dc6b295f3b973b9861089 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>MutationObservers: disconnect</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>MutationObservers: disconnect</h1>
<div id="log"></div>
<section style="display: none">
<p id='n00'></p>
</section>
<script>
var n00 = document.getElementById('n00');
var parentTest = async_test("subtree mutations");
function masterMO(sequence, obs) {
  parentTest.step(function() {
    assert_equals(sequence.length, 4, "mutation records must match");
  });
  parentTest.done();
}
parentTest.step(function() {
  (new MutationObserver(masterMO)).observe(n00.parentNode, {"subtree": true, "attributes": true});
});

var disconnectTest = async_test("disconnect discarded some mutations");
function observerCallback(sequence, obs) {
  disconnectTest.step(function() {
    assert_equals(sequence.length, 1);
    assert_equals(sequence[0].type, "attributes");
    assert_equals(sequence[0].attributeName, "id");
    assert_equals(sequence[0].oldValue, "latest");
    disconnectTest.done();
  });
}

var observer;
disconnectTest.step(function() {
  observer = new MutationObserver(observerCallback);
  observer.observe(n00, {"attributes": true});
  n00.id = "foo";
  n00.id = "bar";
  observer.disconnect();
  observer.observe(n00, {"attributes": true, "attributeOldValue": true});
  n00.id = "latest";
  observer.disconnect();
  observer.observe(n00, {"attributes": true, "attributeOldValue": true});
  n00.id = "n0000";
});
</script>