Skip to content

Commit

Permalink
DOM: Add WPTs for removing steps
Browse files Browse the repository at this point in the history
This CL adds WPTs for removing steps, to ensure that script is never
executed during the removing steps hook [1], which are invoked
synchronously during per-node removal (that is, they are not batched,
but run this way per-node).

This CL:
 1. Augments the existing iframe removing steps WPT, to include
    `pagehide` events. At the time of writing this, all browsers deviate
    from the HTML Standard, and fail this test.
 2. Adds new tests for `<input>` and `<button>` to assert that when they
    are focused and subsequently removed from the DOM, the `blur` event
    is *not* fired, per the HTML Standard. Chromium fails this test,
    while Safari and Firefox pass it.

[1]: https://dom.spec.whatwg.org/#concept-node-remove-ext

Bug: 40150299
Change-Id: I0aa43755ccac8ea432056800c5c4167d8e4460e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5323158
Commit-Queue: Dominic Farolino <dom@chromium.org>
Reviewed-by: Mason Freed <masonf@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1266801}
  • Loading branch information
domfarolino authored and chromium-wpt-export-bot committed Feb 29, 2024
1 parent a0038b4 commit 0be97ae
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
19 changes: 19 additions & 0 deletions dom/nodes/insertion-removing-steps/blur-event.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
test(() => {
const input = document.body.appendChild(document.createElement('input'));
input.focus();

let blurCalled = false;
input.onblur = e => blurCalled = true;
input.remove();
assert_false(blurCalled, "Blur event was not fired");
}, "<input> element does not fire blur event upon DOM removal");

test(() => {
const button = document.body.appendChild(document.createElement('button'));
button.focus();

let blurCalled = false;
button.onblur = e => blurCalled = true;
button.remove();
assert_false(blurCalled, "Blur event was not fired");
}, "<button> element does not fire blur event upon DOM removal");
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ function runRemovalTest(removal_method) {
t.add_cleanup(() => removalObserver.disconnect());

let iframe1UnloadFired = false, iframe2UnloadFired = false;
let iframe1PagehideFired = false, iframe2PagehideFired = false;
iframe1.contentWindow.addEventListener('pagehide', e => {
assert_false(iframe1UnloadFired, "iframe1 pagehide fires before unload");
iframe1PagehideFired = true;
});
iframe2.contentWindow.addEventListener('pagehide', e => {
assert_false(iframe2UnloadFired, "iframe2 pagehide fires before unload");
iframe2PagehideFired = true;
});
iframe1.contentWindow.addEventListener('unload', e => iframe1UnloadFired = true);
iframe2.contentWindow.addEventListener('unload', e => iframe2UnloadFired = true);

Expand All @@ -126,6 +135,8 @@ function runRemovalTest(removal_method) {
div.innerHTML = '';
}

assert_false(iframe1PagehideFired, "iframe1 pagehide did not fire");
assert_false(iframe2PagehideFired, "iframe2 pagehide did not fire");
assert_false(iframe1UnloadFired, "iframe1 unload did not fire");
assert_false(iframe2UnloadFired, "iframe2 unload did not fire");

Expand Down

0 comments on commit 0be97ae

Please sign in to comment.