Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added WPTs for user-activation from keypress and keyup events. #30777

Merged
merged 1 commit into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions html/user-activation/activation-trigger-click.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!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>
promise_test(async () => {
test_driver.click(document.body);
await getEvent('click');
let consumed = await consumeTransientActivation();
assert_true(consumed, "click event should result in activation");
}, "Activation through mouse event");
</script>
</body>
</html>
36 changes: 36 additions & 0 deletions html/user-activation/activation-trigger-keypress.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!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>
promise_test(async () => {
const ENTER_KEY = '\uE007';
test_driver.send_keys(document.body, ENTER_KEY);

let keyup_event = getEvent('keyup');

await getEvent('keypress');
let consumed = await consumeTransientActivation();
assert_true(consumed,
"ENTER keypress event should result in activation");

await keyup_event;
consumed = await consumeTransientActivation();
assert_false(consumed,
"ENTER keyup should have no activation after keypress consumption");
}, "Activation through keyboard event");
</script>
</body>
</html>
30 changes: 0 additions & 30 deletions html/user-activation/basic.html

This file was deleted.

24 changes: 24 additions & 0 deletions html/user-activation/resources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}