summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/clipboard-apis/resources/user-activation.js
blob: ed294bb9cb27b552f23061118fcd260dc6b86a8f (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
'use strict';

// In order to use this function, please import testdriver.js and
// testdriver-vendor.js, and include a <body> element.
async function waitForUserActivation() {
  if (window.opener) {
    throw new Error(
        "waitForUserActivation() only works in the top-level frame");
  }
  const loadedPromise = new Promise(resolve => {
    if(document.readyState == 'complete') {
      resolve();
      return;
    }
    window.addEventListener('load', resolve, {once: true});
  });
  await loadedPromise;

  const clickedPromise = new Promise(resolve => {
    document.body.addEventListener('click', resolve, {once: true});
  });

  test_driver.click(document.body);
  await clickedPromise;
}