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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
<!DOCTYPE html>
<title>
Element#requestFullscreen() works properly with a tree of cross-origin iframes
</title>
<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>
<body>
<script>
function waitFor(action, frameName) {
return new Promise((resolve) => {
window.addEventListener("message", function listener(e) {
if (e.data.action === action && e.data.name === frameName) {
window.removeEventListener("message", listener);
resolve(event.data);
}
});
});
}
function compare_report(report, expectedEvents) {
assert_equals(
report.events.length,
expectedEvents.length,
`Expected report for iframe "${report.frame}" to have ${expectedEvents.length} events: [${expectedEvents}]`
);
report.events.forEach((value, i) => {
assert_equals(
value,
expectedEvents[i],
"Event type matches in order expected"
);
});
report.events.length
? assert_false(
report.fullscreenElementIsNull,
"Event fired, fullscreenElement is set"
)
: assert_true(
report.fullscreenElementIsNull,
"No event fired, fullscreenElement is null"
);
}
const iframes = [
{
name: "A",
src: "http://{{hosts[][]}}:{{ports[http][0]}}/fullscreen/api/resources/recursive-iframe-fullscreen.html?a",
allow_fullscreen: true,
expectedEvents: ["fullscreenchange"],
},
{
name: "B",
src: "http://{{hosts[][]}}:{{ports[http][1]}}/fullscreen/api/resources/recursive-iframe-fullscreen.html?b",
allow_fullscreen: true,
expectedEvents: ["fullscreenchange"],
},
{
name: "C",
src: "http://{{hosts[alt][]}}:{{ports[http][0]}}/fullscreen/api/resources/recursive-iframe-fullscreen.html?c",
allow_fullscreen: true,
expectedEvents: ["fullscreenchange"],
},
{
name: "D",
src: "http://{{hosts[alt][]}}:{{ports[http][1]}}/fullscreen/api/resources/recursive-iframe-fullscreen.html?d",
allow_fullscreen: true,
expectedEvents: ["fullscreenchange"],
},
{
name: "E",
src: "http://{{hosts[][]}}:{{ports[http][0]}}/fullscreen/api/resources/recursive-iframe-fullscreen.html?e",
allow_fullscreen: true,
expectedEvents: [],
},
];
promise_setup(async () => {
// Add the first iframe.
const iframeDetails = iframes[0];
const child_frame = document.createElement("iframe");
child_frame.allow = iframeDetails.allow_fullscreen ? "fullscreen" : "";
child_frame.name = iframeDetails.name;
child_frame.style.width = "100%";
child_frame.style.height = "100%";
child_frame.src = iframeDetails.src;
await new Promise((resolve) => {
child_frame.onload = resolve;
document.body.appendChild(child_frame);
});
// Create the nested iframes.
for (let i = 1; i < iframes.length; i++) {
const parentName = iframes[i - 1].name;
const details = iframes[i];
child_frame.contentWindow.postMessage(
{ action: "addIframe", iframe: details, name: parentName },
"*"
);
await waitFor("load", details.name);
}
});
promise_test(async (t) => {
t.add_cleanup(() => {
if (document.fullscreenElement) {
return document.exitFullscreen();
}
});
document.onfullscreenerror = t.unreached_func(
"fullscreenerror event fired"
);
const fsChangeFiredPromise = new Promise((resolve) => {
document.onfullscreenchange = resolve;
});
const child_frame = document.querySelector("iframe[name=A]");
child_frame.contentWindow.postMessage(
{
action: "requestFullscreen",
name: "D",
},
"*"
);
await waitFor("requestFullscreen", "D");
for (const frame of iframes.slice(1)) {
const data = {
action: "requestReport",
name: frame.name,
};
child_frame.contentWindow.postMessage(data, "*");
const { report } = await waitFor("report", frame.name);
compare_report(report, frame.expectedEvents);
}
await fsChangeFiredPromise;
}, "Element#requestFullscreen() works properly with a tree of cross-origin iframes");
</script>
</body>
|