-
Notifications
You must be signed in to change notification settings - Fork 3k
/
portals-focus.sub.html
104 lines (94 loc) · 3.73 KB
/
portals-focus.sub.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<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>
<script src="resources/open-blank-host.js"></script>
<body>
<script>
async function createPortal(doc, url) {
let portal = doc.createElement("portal");
portal.src = url;
doc.body.appendChild(portal);
await new Promise(r => portal.onload = r);
return portal;
}
promise_test(async t => {
let portal = await createPortal(document, new URL("resources/focus-page-with-button.html", location.href));
try {
portal.onmessage = t.step_func(e => {
assert_unreached("button inside portal should not be focused");
});
portal.postMessage("focus", "*");
await new Promise(r => t.step_timeout(r, 500));
} finally {
document.body.removeChild(portal);
}
}, "test that an element inside a portal cannot steal focus");
promise_test(async t => {
let portal = await createPortal(document, new URL("resources/focus-page-with-x-origin-iframe.sub.html", location.href));
try {
portal.onmessage = t.step_func(e => {
assert_unreached("button inside portal should not be focused");
});
portal.postMessage("focus", "*");
await new Promise(r => t.step_timeout(r, 500));
} finally {
document.body.removeChild(portal);
}
}, "test that an element inside a portal's x-origin subframe cannot steal focus");
promise_test(async t => {
let win = await openBlankPortalHost();
let doc = win.document;
try {
let portal = await createPortal(doc, new URL("resources/simple-portal-adopts-predecessor.html", location.href));
let button = doc.createElement("button");
doc.body.appendChild(button);
await portal.activate();
doc.body.removeChild(portal);
button.onfocus = t.step_func(() => {
assert_unreached("button inside adopted portal should not be focused");
});
button.focus();
await new Promise(r => t.step_timeout(r, 500));
} finally {
win.close();
}
}, "test that an element inside an adopted portal cannot steal focus");
promise_test(async t => {
let win = await openBlankPortalHost();
let doc = win.document;
try {
let portal = await createPortal(doc, new URL("resources/simple-portal-adopts-predecessor.html", location.href));
let iframe = doc.createElement("iframe");
iframe.src = new URL("resources/focus-page-with-button.html",
"http://{{hosts[alt][www]}}:{{ports[http][0]}}/portals/");
doc.body.appendChild(iframe);
await new Promise(r => iframe.onload = r);
await portal.activate();
doc.body.removeChild(portal);
iframe.contentWindow.postMessage("focus", "*");
window.onmessage = t.step_func(() => {
assert_unreached("button inside x-origin iframe inside a portal should not be focused");
});
await new Promise(r => t.step_timeout(r, 500));
} finally {
win.close();
}
}, "test that a x-origin iframe inside an adopted portal cannot steal focus");
const TAB = "\ue004"; // https://w3c.github.io/webdriver/#keyboard-actions
promise_test(async t => {
let portal = await createPortal(document, "resources/focus-page-with-button.html");
try {
portal.tabIndex = 0;
await test_driver.send_keys(document.body, TAB);
portal.onmessage = t.step_func(e => {
assert_unreached("button inside portal should not be focused");
});
await new Promise(r => t.step_timeout(r, 500));
} finally {
document.body.removeChild(portal);
}
}, "test that we cannot tab into a portal's contents");
</script>
</body>