summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/is-input-pending/resources/input-onmessage.js
blob: 919c939d1fc8de666f83159778c19a1a91548c8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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,
  }, '*');
}