Skip to content

Commit

Permalink
Bug 1914289 [wpt PR 47727] - Add mutation events to "historical" WPT,…
Browse files Browse the repository at this point in the history
… a=testonly

Automatic update from web-platform-tests
Add mutation events to "historical" WPT

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 <dbaron@chromium.org>
Auto-Submit: Mason Freed <masonf@chromium.org>
Commit-Queue: Mason Freed <masonf@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1345088}

--

wpt-commits: e0c3477d2cff8aaaefd421ca6543198ec30dc3ef
wpt-pr: 47727
  • Loading branch information
mfreed7 authored and moz-wptsync-bot committed Aug 23, 2024
1 parent d990e4d commit eb5d200
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions testing/web-platform/tests/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 eb5d200

Please sign in to comment.