Commit 47383259 authored by Lan Wei's avatar Lan Wei Committed by Commit Bot

Write web-platform-test for user-activation-delegation API

user-activation-delegation API allows to transfer user activation state
to any target window in the frame tree through postMessages with
"transferUserActivation" set to be true.

Bug: 931885
Change-Id: I224f5fb04b2e08f751c33f5cba867562664fbe0b
Reviewed-on: https://chromium-review.googlesource.com/c/1477911
Commit-Queue: Lan Wei <lanwei@chromium.org>
Reviewed-by: default avatarMustaq Ahmed <mustaq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636498}
parent 32d93073
......@@ -87,6 +87,11 @@ crbug.com/922725 fullscreen/full-screen-iframe-zIndex.html [ Timeout ]
crbug.com/922725 virtual/android/fullscreen/full-screen-iframe-zIndex.html [ Timeout ]
crbug.com/922725 virtual/user-activation-v2/fullscreen/full-screen-iframe-zIndex.html [ Timeout ]
# The following tests would pass with User Activation Delegation.
crbug.com/928838 external/wpt/html/user-activation/activation-transfer-with-click.tentative.html [ Failure ]
crbug.com/928838 external/wpt/html/user-activation/activation-transfer-without-click.tentative.html [ Failure ]
crbug.com/928838 external/wpt/html/user-activation/activation-transfer-cross-origin-with-click.sub.tentative.html [ Failure ]
# The following fail only on Mac.
crbug.com/891427 [ Mac ] fast/events/touch/gesture/touch-gesture-scroll-listbox.html [ Pass Failure Timeout Crash ]
crbug.com/891427 [ Mac ] virtual/scroll_customization/fast/events/touch/gesture/touch-gesture-scroll-listbox.html [ Pass Failure Timeout Crash ]
......
<!DOCTYPE html>
<!--
Tentative due to:
https://github.com/whatwg/html/issues/4364
-->
<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>User activation can be transferred to a cross-origin child frame via a postMessage option.</h1>
<ol id="instructions">
<li>Click this instruction text.
</ol>
<iframe id="child" width="200" height="200"></iframe>
<script>
async_test(function(t) {
var child = document.getElementById("child");
assert_false(navigator.userActivation.isActive);
assert_false(navigator.userActivation.hasBeenActive);
window.addEventListener("message", t.step_func(event => {
var msg = JSON.parse(event.data);
if (msg.type == 'child-four-loaded') {
// state should be false after load
assert_false(msg.isActive);
assert_false(msg.hasBeenActive);
// click in parent document
test_driver.click(document.getElementById('instructions'));
} else if (msg.type == 'child-four-report') {
assert_true(msg.isActive);
assert_true(msg.hasBeenActive);
assert_false(navigator.userActivation.isActive);
assert_false(navigator.userActivation.hasBeenActive);
t.done();
}
}));
window.addEventListener("click", t.step_func(event => {
assert_true(navigator.userActivation.isActive);
assert_true(navigator.userActivation.hasBeenActive);
// transfer user activation to the child frame
child.contentWindow.postMessage("transfer_user_activation", {targetOrigin: "*", transferUserActivation: true});
}));
child.src = "http://{{domains[www]}}:{{ports[http][0]}}/html/user-activation/resources/child-four.html";
}, "Cross-origin user activation transfer through postMessages");
</script>
</body>
</html>
<!DOCTYPE html>
<!--
Tentative due to:
https://github.com/whatwg/html/issues/4364
-->
<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>User activation can be transferred to a child frame via a postMessage option.</h1>
<ol id="instructions">
<li>Click this instruction text.
</ol>
<iframe id="child" width="200" height="200"></iframe>
<script>
async_test(function(t) {
var child = document.getElementById("child");
assert_false(navigator.userActivation.isActive);
assert_false(navigator.userActivation.hasBeenActive);
window.addEventListener("message", t.step_func(event => {
var msg = JSON.parse(event.data);
if (msg.type == 'child-four-loaded') {
// state should be false after load
assert_false(msg.isActive);
assert_false(msg.hasBeenActive);
// click in parent document
test_driver.click(document.getElementById('instructions'));
} else if (msg.type == 'child-four-report') {
assert_true(msg.isActive);
assert_true(msg.hasBeenActive);
assert_false(navigator.userActivation.isActive);
assert_false(navigator.userActivation.hasBeenActive);
t.done();
}
}));
window.addEventListener("click", t.step_func(event => {
assert_true(navigator.userActivation.isActive);
assert_true(navigator.userActivation.hasBeenActive);
// transfer user activation to the child frame
child.contentWindow.postMessage("transfer_user_activation", {transferUserActivation: true});
}));
child.src = "resources/child-four.html";
}, "User activation transfer through postMessages");
</script>
</body>
</html>
<!DOCTYPE html>
<!--
Tentative due to:
https://github.com/whatwg/html/issues/4364
-->
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>User activation transfer request from an inactive frame is ignored.</h1>
<iframe id="child" width="200" height="200"></iframe>
<script>
async_test(function(t) {
var child = document.getElementById("child");
var is_page_loaded = false;
var is_child_four_loaded = false;
assert_false(navigator.userActivation.isActive);
assert_false(navigator.userActivation.hasBeenActive);
function tryPostMessaging() {
if (is_page_loaded && is_child_four_loaded)
child.contentWindow.postMessage("transfer_user_activation", {transferUserActivation: true});
}
window.addEventListener("message", t.step_func(event => {
var msg = JSON.parse(event.data);
if (msg.type == 'child-four-loaded') {
// state should be false after load
assert_false(msg.isActive);
assert_false(msg.hasBeenActive);
is_child_four_loaded = true;
tryPostMessaging();
} else if (msg.type == 'child-four-report') {
assert_false(msg.isActive);
assert_false(msg.hasBeenActive);
assert_false(navigator.userActivation.isActive);
assert_false(navigator.userActivation.hasBeenActive);
t.done();
}
}));
window.addEventListener("load", function(event) {
is_page_loaded = true;
tryPostMessaging();
});
child.src = "resources/child-four.html";
}, "User activation transfer from inactive frame");
</script>
</body>
</html>
<!DOCTYPE html>
<body style="background: lightgrey;">
<script>
window.parent.postMessage(JSON.stringify({"type": "child-four-loaded", "isActive": navigator.userActivation.isActive,
"hasBeenActive": navigator.userActivation.hasBeenActive}), "*");
window.addEventListener("message", event => {
if (event.source === window.parent && event.data == "transfer_user_activation") {
window.parent.postMessage(JSON.stringify({"type": "child-four-report", "isActive": navigator.userActivation.isActive,
"hasBeenActive": navigator.userActivation.hasBeenActive}), "*");
}
});
</script>
</body>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment