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
91
92
93
94
95
96
97
98
99
100
101
102
|
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/utils.js"></script>
<title>Test fenced frame notifyEvent() functionality with iframes</title>
<body>
<script>
async function runNestedIFrameTest(frame_type) {
// Create a fenced frame that will respond to window.fence.notifyEvent().
const fencedframe = await attachFencedFrameContext(
{generator_api: 'fledge'});
let notified = false;
fencedframe.element.addEventListener('fencedtreeclick', () => notified = true);
await fencedframe.execute(async (frame_type) => {
window.addEventListener('message', (event) => {
window.click_error = event.data;
});
let iframe = null;
if (frame_type === 'same-origin') {
iframe = await attachIFrameContext({
origin: get_host_info().HTTPS_ORIGIN
});
} else if (frame_type === 'cross-origin') {
iframe = await attachIFrameContext({
origin: get_host_info().HTTPS_REMOTE_ORIGIN
});
}
// Calling notifyEvent() on click in the iframe should fail, but we need
// to move the exception out of the click handler to assert on it.
await iframe.execute(() => {
document.addEventListener('click', (e) => {
try {
window.fence.notifyEvent(e);
} catch (err) {
window.parent.postMessage(err, '*');
return;
}
window.parent.postMessage(new TypeError('No exception'), '*');
});
});
}, [frame_type]);
await multiClick(10, 10, fencedframe.element);
// Ensure the correct exception was thrown.
await fencedframe.execute(() => {
assert_equals(window.click_error.name, 'SecurityError');
assert_equals(window.click_error.message,
"Failed to execute 'notifyEvent' on 'Fence': notifyEvent is only available in fenced frame roots.");
});
// Because the notifyEvent() call failed, no event was sent to the
// top-level fenced frame.
assert_false(notified);
}
promise_test(async (t) => {
return runNestedIFrameTest('same-origin');
}, "Test that fenced frame notifyEvent() fails in a nested same-origin iframe.");
promise_test(async (t) => {
return runNestedIFrameTest('cross-origin');
}, "Test that fenced frame notifyEvent() fails in a nested cross-origin iframe.");
promise_test(async (t) => {
window.addEventListener('message', (event) => {
window.click_error = event.data;
});
const urn_iframe = await attachIFrameContext(
{generator_api: 'fledge'});
await urn_iframe.execute(() => {
document.addEventListener('click', (e) => {
try {
window.fence.notifyEvent(e);
} catch (err) {
window.parent.postMessage(err, '*');
return;
}
window.parent.postMessage(new TypeError('No exception'), '*');
});
});
await multiClick(10, 10, urn_iframe.element);
assert_equals(window.click_error.name, 'SecurityError');
assert_equals(window.click_error.message,
"Failed to execute 'notifyEvent' on 'Fence': notifyEvent is only available in fenced frame roots.");
}, "Test that notifyEvent() fails in a URN iframe.");
</script>
</body>
|