summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/is-input-pending/resources/input-onmessage.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/is-input-pending/resources/input-onmessage.js')
-rw-r--r--testing/web-platform/tests/is-input-pending/resources/input-onmessage.js25
1 files changed, 25 insertions, 0 deletions
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,
+ }, '*');
+}