Skip to content

Commit

Permalink
Added WPTs for user-activation from keypress and keyup events.
Browse files Browse the repository at this point in the history
These tests are for the following HTML PR:
whatwg/html#6818

Also renamed the existing click event test for consistency.

Change-Id: If77750f4159828b68bd91a4b48f46606421b7df6
  • Loading branch information
mustaqahmed authored and chromium-wpt-export-bot committed Sep 22, 2021
1 parent 2d6d77b commit af66014
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 30 deletions.
30 changes: 30 additions & 0 deletions html/user-activation/activation-trigger-click.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/utils.js"></script>
</head>
<body>
<h1>Test for click activation trigger</h1>
<p>Tests that a popup is allowed with user activation from a click event.</p>
<ol id="instructions">
<li>Click anywhere in the document.
</ol>
<script>
let test_mouse_event = async_test("Activation through click");

window.addEventListener("click", async () => {
let consumed = await consumeTransientActivation();
test_mouse_event.step_func(() => {
assert_true(consumed, "click event should activate");
});
test_mouse_event.done();
});

test_driver.click(document.body);
</script>
</body>
</html>
39 changes: 39 additions & 0 deletions html/user-activation/activation-trigger-keypress.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/utils.js"></script>
</head>
<body>
<h1>Test for keypress activation trigger</h1>
<p>Tests that a popup is allowed with user activation from a keypress event.</p>
<input type="text" autofocus />
<ol id="instructions">
<li>Press ENTER key.
</ol>
<script>
const ENTER_KEY = '\uE007';
let test_key_event = async_test("Activation through keyboard event");

window.addEventListener("keypress", async () => {
let consumed = await consumeTransientActivation();
test_key_event.step_func(() => {
assert_true(consumed, "ENTER keypress event should activate");
});
});

window.addEventListener("keyup", async () => {
let consumed = await consumeTransientActivation();
test_key_event.step_func(() => {
assert_false(consumed, "ENTER keyup event should not activate");
});
test_key_event.done();
});

test_driver.send_keys(document.body, ENTER_KEY);
</script>
</body>
</html>
30 changes: 0 additions & 30 deletions html/user-activation/basic.html

This file was deleted.

15 changes: 15 additions & 0 deletions html/user-activation/resources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,18 @@ function delayByFrames(f, num_frames) {
}
recurse(num_frames);
}

// Returns true if transient activation was availble and was consumed
// successfully.
//
// 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;
}
}

0 comments on commit af66014

Please sign in to comment.