Skip to content

Commit

Permalink
Add mutation events to "historical" WPT
Browse files Browse the repository at this point in the history
This set of tests goes along with this spec PR:

  whatwg/html#10573

Bug: 40268638
Change-Id: I39aafcc0ec1f36704cdc3a263c798c1873333b11
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5803663
Reviewed-by: David Baron <[email protected]>
Auto-Submit: Mason Freed <[email protected]>
Commit-Queue: Mason Freed <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1345088}
  • Loading branch information
Mason Freed authored and chromium-wpt-export-bot committed Aug 21, 2024
1 parent ccc8901 commit e0c3477
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions dom/historical.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"Entity",
"EntityReference",
"EventException", // DOM Events
"MutationEvent",
"NameList",
"Notation",
"TypeInfo",
Expand Down Expand Up @@ -219,4 +220,46 @@
assert_equals((new Event("test"))[name], undefined)
}, "Event.prototype should not have this property: " + name)
})

// For reference, these events were defined in
// https://www.w3.org/TR/2003/NOTE-DOM-Level-3-Events-20031107/DOM3-Events.html#events-Events-EventTypes-complete
const mutationEvents = [
'DOMSubtreeModified',
'DOMNodeInserted',
'DOMNodeRemoved',
'DOMNodeRemovedFromDocument',
'DOMNodeInsertedIntoDocument',
'DOMCharacterDataModified',
'DOMAttrModified',
'DOMAttributeNameChanged',
'DOMElementNameChanged',
];
mutationEvents.forEach(evt => {
promise_test(async (t) => {
const target = document.createElement('div');
let fired = false;
function listener(event) {
fired = true;
}
target.addEventListener(evt,listener);
document.body.addEventListener(evt,listener);
target.append('here');
t.add_cleanup(() => target.remove());
document.body.appendChild(target);

// Trigger all mutation types except DOMElementNameChanged, which could
// only be triggered by a call to the (deprecated, removed)
// Document.renameNode() API.
target.remove();
document.body.appendChild(target);
target.setAttribute('test','foo');
target.attributes[0].value='bar';
target.attributes[0].name='baz';
target.firstChild.textContent = "bar";
// Mutation events were synchronous, but ensure even async versions
// would fail this test.
await new Promise(resolve=>t.step_timeout(resolve,0));
assert_false(fired,'Event was fired');
}, `The ${evt} mutation event must not be fired.`);
});
</script>

0 comments on commit e0c3477

Please sign in to comment.