diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/event-timing/event-click-visibilitychange.html | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/event-timing/event-click-visibilitychange.html')
-rw-r--r-- | testing/web-platform/tests/event-timing/event-click-visibilitychange.html | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/testing/web-platform/tests/event-timing/event-click-visibilitychange.html b/testing/web-platform/tests/event-timing/event-click-visibilitychange.html new file mode 100644 index 0000000000..3e1c41ea7a --- /dev/null +++ b/testing/web-platform/tests/event-timing/event-click-visibilitychange.html @@ -0,0 +1,98 @@ +<!DOCTYPE html> +<html> +<meta charset=utf-8 /> +<meta name="timeout" content="long"> +<title>Event Timing: visibility change.</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=/resources/testdriver.js></script> +<script src=/resources/testdriver-vendor.js></script> +<script src=/resources/testdriver-actions.js></script> +<script src=/page-visibility/resources/window_state_context.js></script> +<script src=resources/event-timing-test-utils.js></script> + +<body> + <button id='target'>Click me</button> + + <script> + let observedEntries = []; + const map = new Map(); + const events = ['pointerup']; + + promise_test(async t => { + assert_implements(window.PerformanceEventTiming, 'Event Timing is not supported.'); + + const { minimize, restore } = window_state_context(t); + const button = document.getElementById('target'); + + const callback = (entryList) => { observedEntries = observedEntries.concat(entryList.getEntries().filter(filterAndAddToMap(events, map))); }; + const readyToResolve = () => { return observedEntries.length >= 1; }; + const observerPromise = createPerformanceObserverPromise(['event'], callback, readyToResolve); + + const tapEventPromise = new Promise(resolve => { + button.addEventListener('pointerup', async (event) => { + document.body.innerText += "Adding content to force rendering"; + + // await here will yield to event loop, and end event processing time, + // which will allow rendering to continue. + // The visibility change may happen before rendering has a chance + // but it is not guarenteed which will happen first. + await minimize(); + const timeAfterVisibilityFalse = performance.now(); + + await restore(); + const timeAfterVisibilityTrue = performance.now(); + + resolve({ timeAfterVisibilityFalse, timeAfterVisibilityTrue }); + }); + }); + + // A buffered visibility-state PerformanceEntry would have made this test + // cleaner, due to the variability of ordering of events, but it is not + // yet available. + const visibilityEventPromise = new Promise(resolve => { + document.addEventListener('visibilitychange', (event) => { + if (document.visibilityState !== 'visible') { + resolve(performance.now()); + } + }); + }); + + const timeBeforeTap = performance.now(); + await interactAndObserve('tap', button, observerPromise); + + // The order that these events fire is non-deterministic, but we can await + // the result of the promise in any order. + const { timeAfterVisibilityFalse, timeAfterVisibilityTrue } = await tapEventPromise; + const timeOfVisibilityFalse = await visibilityEventPromise; + + assert_equals(observedEntries.length, 1, "Pointerup was measured"); + const entry = observedEntries[0]; + + assert_not_equals(timeBeforeTap, undefined); + assert_not_equals(timeAfterVisibilityFalse, undefined); + assert_not_equals(timeAfterVisibilityTrue, undefined); + assert_not_equals(timeOfVisibilityFalse, undefined); + + assert_less_than( + entry.processingEnd, + timeOfVisibilityFalse, + "event handler ends before visibility event fires" + ); + assert_less_than( + timeOfVisibilityFalse, + timeAfterVisibilityFalse, + "visibility event fires before event handler continues" + ); + assert_less_than_equal( + entry.startTime + entry.duration, + timeAfterVisibilityFalse, + "event duration ends before visibility is changed" + ); + + }, "Event handlers which change visibility should not measure next paint."); + + </script> +</body> + +</html> |