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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
<!doctype html>
<meta charset=utf-8>
<title></title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
async function test() {
let testElement1 = async_test("Setting Element.textContent");
let el = document.createElement("div");
let m = new MutationObserver((records) => testElement1.step(()=> {
assert_equals(records.length, 1, "Should have one record");
assert_equals(records[0].addedNodes[0].nodeType, Node.TEXT_NODE, "Should have gotten a text node as a child.");
assert_equals(records[0].addedNodes[0].data, "foo");
m.disconnect();
testElement1.done();
}));
m.observe(el, { childList: true });
el.textContent = "foo";
await Promise.resolve(); // Run microtasks
let testElement2 = async_test("Setting Element.textContent to the same value");
m = new MutationObserver((records) => testElement2.step(()=> {
assert_equals(records.length, 1, "Should have one record");
assert_equals(records[0].removedNodes[0].nodeType, Node.TEXT_NODE, "Should have removed a text node.");
assert_equals(records[0].removedNodes[0].data, "foo");
assert_equals(records[0].addedNodes[0].nodeType, Node.TEXT_NODE, "Should have gotten a text node as a child.");
assert_equals(records[0].addedNodes[0].data, "foo");
m.disconnect();
testElement2.done();
}));
m.observe(el, { childList: true });
testElement2.step(() => { assert_equals(el.textContent, "foo"); });
el.textContent = "foo";
await Promise.resolve(); // Run microtasks
let testElement3 = async_test("Setting Element.textContent to a different value");
m = new MutationObserver((records) => testElement3.step(()=> {
assert_equals(records.length, 1, "Should have one record");
assert_equals(records[0].removedNodes[0].nodeType, Node.TEXT_NODE, "Should have removed a text node.");
assert_equals(records[0].removedNodes[0].data, "foo");
assert_equals(records[0].addedNodes[0].nodeType, Node.TEXT_NODE, "Should have gotten a text node as a child.");
assert_equals(records[0].addedNodes[0].data, "bar");
m.disconnect();
testElement3.done();
}));
m.observe(el, { childList: true });
testElement3.step(() => { assert_equals(el.textContent, "foo"); });
el.textContent = "bar";
await Promise.resolve(); // Run microtasks
let testElement4 = async_test("Setting Element.textContent to the same value when the old node is a CDATASection");
let xml = new DOMParser().parseFromString("<root></root>", "text/xml");
el = xml.createElement("somelement");
el.appendChild(xml.createCDATASection("foo"));
m = new MutationObserver((records) => testElement4.step(()=> {
assert_equals(records.length, 1, "Should have one record");
assert_equals(records[0].removedNodes[0].nodeType, Node.CDATA_SECTION_NODE, "Should have removed a cdata node.");
assert_equals(records[0].removedNodes[0].data, "foo");
assert_equals(records[0].addedNodes[0].nodeType, Node.TEXT_NODE, "Should have gotten a text node as a child.");
assert_equals(records[0].addedNodes[0].data, "foo");
m.disconnect();
testElement4.done();
}));
m.observe(el, { childList: true });
testElement4.step(() => { assert_equals(el.textContent, "foo"); });
el.textContent = "foo";
}
test();
</script>
|