From edabc2f6a2d045dbed91a5677e270216f780b37d Mon Sep 17 00:00:00 2001 From: Mustaq Ahmed Date: Thu, 30 Sep 2021 11:19:05 -0700 Subject: [PATCH] Added WPTs for user-activation from keypress and keyup events. These tests are for the following HTML PR: https://github.com/whatwg/html/pull/6818 Also renamed the existing click event test for consistency. Change-Id: If77750f4159828b68bd91a4b48f46606421b7df6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3159551 Reviewed-by: Robert Flack Commit-Queue: Mustaq Ahmed Cr-Commit-Position: refs/heads/main@{#926812} --- .../activation-trigger-click.html | 25 +++++++++++++ .../activation-trigger-keypress.html | 36 +++++++++++++++++++ html/user-activation/basic.html | 30 ---------------- html/user-activation/resources/utils.js | 24 +++++++++++++ 4 files changed, 85 insertions(+), 30 deletions(-) create mode 100644 html/user-activation/activation-trigger-click.html create mode 100644 html/user-activation/activation-trigger-keypress.html delete mode 100644 html/user-activation/basic.html diff --git a/html/user-activation/activation-trigger-click.html b/html/user-activation/activation-trigger-click.html new file mode 100644 index 00000000000000..abf685f9220e33 --- /dev/null +++ b/html/user-activation/activation-trigger-click.html @@ -0,0 +1,25 @@ + + + + + + + + + + +

Test for click activation trigger

+

Tests that a popup is allowed with user activation from a click event.

+
    +
  1. Click anywhere in the document. +
+ + + diff --git a/html/user-activation/activation-trigger-keypress.html b/html/user-activation/activation-trigger-keypress.html new file mode 100644 index 00000000000000..cf3816fd95e9b6 --- /dev/null +++ b/html/user-activation/activation-trigger-keypress.html @@ -0,0 +1,36 @@ + + + + + + + + + + +

Test for keypress activation trigger

+

Tests that a popup is allowed with user activation from a keypress event.

+ +
    +
  1. Press ENTER key. +
+ + + diff --git a/html/user-activation/basic.html b/html/user-activation/basic.html deleted file mode 100644 index fe8cebc1089e6a..00000000000000 --- a/html/user-activation/basic.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - -

Basic user activation test

-

Tests that a popup is allowed with user activation.

-
    -
  1. Click anywhere in the document. -
- - - diff --git a/html/user-activation/resources/utils.js b/html/user-activation/resources/utils.js index 06bf0183283809..f4ff426825612c 100644 --- a/html/user-activation/resources/utils.js +++ b/html/user-activation/resources/utils.js @@ -7,3 +7,27 @@ function delayByFrames(f, num_frames) { } recurse(num_frames); } + +// Returns a Promise which is resolved with the event object when the event is +// fired. +function getEvent(eventType) { + return new Promise(resolve => { + document.body.addEventListener(eventType, e => resolve(e), {once: true}); + }); +} + + +// Returns a Promise which is resolved with a "true" iff transient activation +// was available and successfully consumed. +// +// This function relies on Fullscreen API to check/consume user activation +// state. +async function consumeTransientActivation() { + try { + await document.body.requestFullscreen(); + await document.exitFullscreen(); + return true; + } catch(e) { + return false; + } +}