Skip to content

Commit

Permalink
Bug 1784578 [wpt PR 35460] - Move the pop-up "show" event earlier and…
Browse files Browse the repository at this point in the history
… make it cancelable, a=testonly

Automatic update from web-platform-tests
Move the pop-up "show" event earlier and make it cancelable

Per [1], there's a desire from Mozilla to move the show event
earlier in the process, and make it cancelable. I see no issues
with doing that, so pending a discussion (at [1]), I'm going to
make this change.

[1] openui/open-ui#579

Bug: 1307772
Change-Id: I87fcec84146f99434bb88d2af12941a2c9156586
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3826329
Reviewed-by: Joey Arhar <jarhar@chromium.org>
Auto-Submit: Mason Freed <masonf@chromium.org>
Commit-Queue: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1035213}

--

wpt-commits: 6929d9ab93b16ea002b2812b23f3872a36f9bb8f
wpt-pr: 35460
  • Loading branch information
mfreed7 authored and moz-wptsync-bot committed Sep 4, 2022
1 parent 4d98ea1 commit fa70364
Showing 1 changed file with 49 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,54 @@
<div popup>Popup</div>

<script>
promise_test(async t => {
const popup = document.querySelector('[popup]');
let showCount = 0;
let hideCount = 0;
await new Promise(resolve => window.addEventListener('load',() => resolve()));
assert_false(popup.matches(':top-layer'));
document.addEventListener('show',() => ++showCount);
document.addEventListener('hide',() => ++hideCount);
assert_equals(0,showCount);
assert_equals(0,hideCount);
popup.showPopUp();
assert_true(popup.matches(':top-layer'));
assert_equals(1,showCount);
assert_equals(0,hideCount);
await waitForRender();
assert_true(popup.matches(':top-layer'));
popup.hidePopUp();
assert_false(popup.matches(':top-layer'));
assert_equals(1,showCount);
assert_equals(1,hideCount);
await waitForRender();
// No additional events after animation frame
assert_false(popup.matches(':top-layer'));
assert_equals(1,showCount);
assert_equals(1,hideCount);
}, 'Show and hide events get properly dispatched for popups');
window.onload = () => {
promise_test(async t => {
const popup = document.querySelector('[popup]');
let showCount = 0;
let hideCount = 0;
assert_false(popup.matches(':top-layer'));
const controller = new AbortController();
const signal = controller.signal;
t.add_cleanup(() => controller.abort());
document.addEventListener('show',() => ++showCount, {signal});
document.addEventListener('hide',() => ++hideCount, {signal});
assert_equals(0,showCount);
assert_equals(0,hideCount);
popup.showPopUp();
assert_true(popup.matches(':top-layer'));
assert_equals(1,showCount);
assert_equals(0,hideCount);
await waitForRender();
assert_true(popup.matches(':top-layer'));
popup.hidePopUp();
assert_false(popup.matches(':top-layer'));
assert_equals(1,showCount);
assert_equals(1,hideCount);
await waitForRender();
// No additional events after animation frame
assert_false(popup.matches(':top-layer'));
assert_equals(1,showCount);
assert_equals(1,hideCount);
}, 'Show and hide events get properly dispatched for popups');

promise_test(async t => {
const popUp = document.querySelector('[popup]');
const controller = new AbortController();
const signal = controller.signal;
t.add_cleanup(() => controller.abort());
let cancel = true;
popUp.addEventListener('show',(e) => {
if (cancel)
e.preventDefault();
}, {signal});
assert_false(popUp.matches(':top-layer'));
popUp.showPopUp();
assert_false(popUp.matches(':top-layer'),'The "show" event should be cancelable');
cancel = false;
popUp.showPopUp();
assert_true(popUp.matches(':top-layer'));
popUp.hidePopUp();
assert_false(popUp.matches(':top-layer'));
}, 'Show event is cancelable');
};
</script>

0 comments on commit fa70364

Please sign in to comment.