From 07904e6d993cdca0d80d7ac6201b59250aac0765 Mon Sep 17 00:00:00 2001 From: Mason Freed Date: Wed, 21 Aug 2024 15:16:43 -0700 Subject: [PATCH] Add mutation events to "historical" WPT This set of tests goes along with this spec PR: https://github.com/whatwg/html/pull/10573 Bug: 40268638 Change-Id: I39aafcc0ec1f36704cdc3a263c798c1873333b11 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5803663 Reviewed-by: David Baron Auto-Submit: Mason Freed Commit-Queue: Mason Freed Cr-Commit-Position: refs/heads/main@{#1345088} --- dom/historical.html | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/dom/historical.html b/dom/historical.html index 1bc209ec0e7750..390b40ed57a060 100644 --- a/dom/historical.html +++ b/dom/historical.html @@ -25,6 +25,7 @@ "Entity", "EntityReference", "EventException", // DOM Events + "MutationEvent", "NameList", "Notation", "TypeInfo", @@ -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.`); +});