Skip to content

Commit

Permalink
Add an API to query whether the window has seen a user gesture.
Browse files Browse the repository at this point in the history
Add a variable on the navigator object to query whether the frame has
seen a user activation ever.

The postMessage part of the proposal will be done in a separate patch,
this change is limited to just adding the object definition and
exposing it on navigator.

https://github.com/dtapuska/useractivation
whatwg/html#1983

BUG=846858

Change-Id: I6ca4c80f4096bfae9ca13b175b46df6b4486a6dd
  • Loading branch information
dtapuska authored and Chrome-bot committed Jun 27, 2018
1 parent bb801df commit 729bfa0
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
33 changes: 33 additions & 0 deletions html/user-activation/activation-api-click.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE HTML>
<!--
Tentative due to:
https://github.com/whatwg/html/issues/1983
-->
<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>
</head>
<body>
<h1>Clicking on document sets user activation</h1>
<p>Click anywhere in the document.</p>
<script>
async_test(function(t) {
assert_false(navigator.userActivation.hasBeenActive);
assert_false(navigator.userActivation.isActive);
window.addEventListener("click", t.step_func_done(event => {
assert_true(navigator.userActivation.hasBeenActive);
assert_true(navigator.userActivation.isActive);

// Opening a window should consume the activation.
window.open('404.html');
assert_true(navigator.userActivation.hasBeenActive);
assert_false(navigator.userActivation.isActive);
}));
test_driver.click(document.body);
}, "Values adjust on activity");
</script>
</body>
</html>
36 changes: 36 additions & 0 deletions html/user-activation/activation-api-setTimeout.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE HTML>
<!--
Tentative due to:
https://github.com/whatwg/html/issues/1983
-->
<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>
</head>
<body>
<h1>Clicking on document sets user activation even after setTimeout</h1>
<p>Click anywhere in the document.</p>
<script>
async_test(function(t) {
assert_false(navigator.userActivation.hasBeenActive);
assert_false(navigator.userActivation.isActive);
window.addEventListener("click", event => {
t.step_timeout(() => {
assert_true(navigator.userActivation.hasBeenActive);
assert_true(navigator.userActivation.isActive);

// Opening a window should consume the activation.
window.open('404.html');
assert_true(navigator.userActivation.hasBeenActive);
assert_false(navigator.userActivation.isActive);
t.done();
}, 0);
});
test_driver.click(document.body);
}, "Values adjust on activity");
</script>
</body>
</html>

0 comments on commit 729bfa0

Please sign in to comment.