-
Notifications
You must be signed in to change notification settings - Fork 54
/
activation-transfer-cross-origin-with-click-two-child-frames.sub.tentative.html
90 lines (80 loc) · 3.4 KB
/
activation-transfer-cross-origin-with-click-two-child-frames.sub.tentative.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!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="child1" width="200" height="200"></iframe>
<iframe id="child2" width="200" height="200"></iframe>
<script>
async_test(function(t) {
var child1 = document.getElementById("child1");
var child2 = document.getElementById("child2");
var is_child_four_loaded = false;
var is_child_two_loaded = false;
assert_false(navigator.userActivation.isActive);
assert_false(navigator.userActivation.hasBeenActive);
function tryClickInstructions() {
if (is_child_four_loaded && is_child_two_loaded)
test_driver.click(document.getElementById('instructions'));
}
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 after both child frames load
is_child_four_loaded = true;
tryClickInstructions();
} else if (msg.type == 'child-four-report') {
assert_true(msg.isActive);
assert_true(msg.hasBeenActive);
// check sender's activation state again
assert_false(navigator.userActivation.isActive);
assert_false(navigator.userActivation.hasBeenActive);
child2.contentWindow.postMessage('report', '*');
} else if (msg.type == 'child-two-loaded') {
// state should be false after load
assert_false(msg.isActive);
assert_false(msg.hasBeenActive);
// click in parent document after both child frames load
is_child_two_loaded = true;
tryClickInstructions();
} else if (msg.type == 'child-two-report') {
assert_false(msg.isActive);
assert_false(msg.hasBeenActive);
// check sender's activation state again
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
child1.contentWindow.postMessage("report",
{targetOrigin: "*", transferUserActivation: true});
// sender's activation state is updated synchronously
assert_false(navigator.userActivation.isActive);
assert_false(navigator.userActivation.hasBeenActive);
}));
child1.src = "http://{{domains[www]}}:{{ports[http][0]}}/html/user-activation/resources/child-four.html";
child2.src = "http://{{domains[www1]}}:{{ports[http][0]}}/html/user-activation/resources/child-two.html";
}, "Cross-origin user activation transfer through postMessages");
</script>
</body>
</html>