Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize some DOM events tests #49211

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

ptomato
Copy link
Contributor

@ptomato ptomato commented Nov 16, 2024

See discussion in #41966. A few of these .html tests can be converted directly to .any.js tests. Some can be converted to .window.js tests to avoid boilerplate even though they use document.createEvent() or dispatch events on DOM nodes.

For the latter, also add .any.js versions that use Event constructors and dispatch evens on plain EventTarget instances. These tests will also execute in Workers, and after #41966 in ShadowRealms.

Probably best reviewed commit by commit if you want the details for how I processed each file.

Rename existing test to CustomEvent-createEvent.window.js, and add a
version that doesn't depend on document.createEvent() as
CustomEvent.any.js.
Rename the original test to Event-cancelBubble-dom.html and keep only the
parts that depend on bubbling up through DOM elements in that file. Add a
new file, Event-cancelBubble.window.js and move the rest there, to avoid
the HTML boilerplate.
Rename existing test to Event-cancelBubble-createEvent.window.js, and add
a version that doesn't depend on document.createEvent() as
Event-cancelBubble.any.js.
Rename existing test to Event-constants-createEvent.window.js, and add a
version that doesn't depend on document.createEvent() as
Event-constants.any.js.

Also, make sure to expose the export on globalThis in the support script.
…test

Rename existing test to
Event-defaultPrevented-after-dispatch-createEvent.html, and add a version
that doesn't depend on document.createEvent() or DOM elements, as
Event-defaultPrevented-after-dispatch.any.js.
Rename existing test to Event-defaultPrevented-createEvent.window.js, and
add a version that doesn't depend on document.createEvent() as
Event-defaultPrevented.any.js.
Rename the existing test to
Event-init-while-dispatching-dom-events.window.js and keep only the tests
for the window-specific DOM events in that file. Move the tests for Event
and CustomEvent, which are [Exposed=*], to a separate file, named
Event-init-while-dispatching.any.js.
Rename existing test to Event-initEvent-createEvent.window.js, and add a
version that doesn't depend on document.createEvent() as
Event-initEvent.any.js.
Most of this test can be an .any.js test. Keep only the existing test for
what happens when Event.returnValue is set in between document.createEvent
and initEvent, in a separate file named
Event-returnValue-createEvent.window.js.
Rename existing test to Event-stopImmediatePropagation-dom.html, and add a
version that uses an EventTarget object instead of a DOM node as
Event-stopImmediatePropagation.any.js.
Rename the existing test to
Event-subclasses-constructors-dom-events.window.js and keep only the tests
for the window-specific DOM events in that file. Move the tests for the
event subclass, and copy the tests for Event, which is [Exposed=*], to a
separate file, named Event-subclasses-constructors.any.js.

We have to keep the Event tests in the original file as well, for parent
property information.
Rename existing test to Event-type-empty-createEvent.window.js, and add a
version that doesn't depend on document.createEvent() as
Event-type-empty.any.js.

While we're here, add some assertion messages to the original test because
I found them helpful during debugging.
The test using the constructor goes in its own .any.js file. Rename the
remaining tests that depend on document.createEvent to
Event-type-createEvent.window.js.
Rename existing test to EventTarget-this-of-listener-dom.window.js, and
add a version that uses EventTarget instances instead of DOM nodes as
EventTarget-this-of-listener.any.js.
Rename existing test to remove-all-listeners-dom.window.js, and add a
version that uses EventTarget instances instead of DOM nodes as
remove-all-listeners.any.js.
Renames the existing test to Event-propagation-dom-node.window.js, and
adds a copy in Event-propagation-EventTarget.any.js that uses a plain
EventTarget instance instead of a DOM node. The difference is that
EventTarget doesn't have bubbling/capture behaviour, so the expectations
after stopPropagation() and cancelBubble=true are different.
Rename existing test to EventListener-handleEvent-dom-node.window.js, and
add a version that uses EventTarget instances instead of DOM nodes as
EventListener-handleEvent.any.js.

While we're here, fix a typo in the original test.
Rename existing test to EventTarget-dispatchEvent-dom.window.js, and add a
version that uses EventTarget instances instead of DOM nodes and doesn't
test the document.createEvent()-specific stuff, as
EventTarget-dispatchEvent.any.js.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants