diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/is-input-pending/resources | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/is-input-pending/resources')
3 files changed, 95 insertions, 0 deletions
diff --git a/testing/web-platform/tests/is-input-pending/resources/blank.html b/testing/web-platform/tests/is-input-pending/resources/blank.html new file mode 100644 index 0000000000..f27d7148d3 --- /dev/null +++ b/testing/web-platform/tests/is-input-pending/resources/blank.html @@ -0,0 +1,2 @@ +<!DOCTYPE html> +<script src="input-onmessage.js"></script> diff --git a/testing/web-platform/tests/is-input-pending/resources/input-onmessage.js b/testing/web-platform/tests/is-input-pending/resources/input-onmessage.js new file mode 100644 index 0000000000..919c939d1f --- /dev/null +++ b/testing/web-platform/tests/is-input-pending/resources/input-onmessage.js @@ -0,0 +1,25 @@ +// Responds to onmessage events from other frames to check for pending input. +onmessage = async e => { + if (e.data !== 'check-input') return; + + const discreteOptions = { includeContinuous: false }; + const continuousOptions = { includeContinuous: true }; + + // Use a reasonable time to wait after dispatching events, since we want to be + // able to test for cases where isInputPending returns false. + const DISPATCH_WAIT_TIME_MS = 500; + + // Wait a reasonable amount of time for the event to be enqueued. + const end = performance.now() + DISPATCH_WAIT_TIME_MS; + let hasDiscrete; + let hasContinuous; + do { + hasDiscrete = navigator.scheduling.isInputPending(discreteOptions); + hasContinuous = navigator.scheduling.isInputPending(continuousOptions); + } while (performance.now() < end && !(hasDiscrete && hasContinuous)); + + e.source.postMessage({ + discrete: hasDiscrete, + continuous: hasContinuous, + }, '*'); +} diff --git a/testing/web-platform/tests/is-input-pending/resources/pending-input-utils.js b/testing/web-platform/tests/is-input-pending/resources/pending-input-utils.js new file mode 100644 index 0000000000..489c16827a --- /dev/null +++ b/testing/web-platform/tests/is-input-pending/resources/pending-input-utils.js @@ -0,0 +1,68 @@ +// Dispatches the given sequence of actions and verifies isInputPending state +// after dispatch according to expectations. Returns when all dispatched input +// has been handled. +const pendingActionTest = async (label, target, actionCallback, expectations) => { + promise_test(async () => { + // Give focus to the page first, before running the test. + await new test_driver.Actions() + .pointerMove(0, 0) + .pointerDown() + .pointerUp() + .send(); + + // Register a handler to fetch the result of isInputPending from the target + // window. + const resultPromise = new Promise(res => { + window.addEventListener('message', function handler(e) { + if (e.data === 'check-input') return; + res(e.data); + window.removeEventListener('message', handler); + }); + }); + + // Signal to the target window to monitor isInputPending. + target.postMessage('check-input', '*'); + + const actions = actionCallback(); + const actionsPromise = actions.send(); + + const {discrete, continuous} = await resultPromise; + + assert_equals(discrete, expectations.discrete, 'detected discrete input'); + assert_equals(continuous, expectations.continuous, 'detected continuous input'); + + await actionsPromise; + }, label); +} + +const PendingInputUtils = { + testDetectNoPendingInput(target, actionCallback, label) { + pendingActionTest(label, target, actionCallback, { + discrete: false, + continuous: false, + }); + }, + + testDetectDiscretePendingInput(target, actionCallback, label) { + pendingActionTest(label, target, actionCallback, { + discrete: true, + continuous: true, + }); + }, + + testDetectContinuousPendingInput(target, actionCallback, label) { + pendingActionTest(label, target, actionCallback, { + discrete: false, + continuous: true, + }); + }, + + // Simulates a pointer event at the given coordinates, and tests that the + // given target window cannot access it. Intended for cross-origin compliance + // tests. + testCannotAccessPendingInputAt(target, x, y, label) { + PendingInputUtils.testDetectNoPendingInput(target, () => { + return new test_driver.Actions().pointerMove(x, y).pointerDown().pointerUp(); + }, label); + }, +} |