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
|
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="timeout" content="long">
<!-- user agents are not required to support open features other than `noopener`
and on some platforms position and size features don't make sense -->
<meta name="flags" content="may">
<title>Multi-Screen Window Management test: Fullscreen Companion Window</title>
<link rel="help" href="https://w3c.github.io/window-placement/">
This test uses multi-screen details to request fullscreen and open a pop-up<br>
(companion window) in the same user activation.<br>
It runs manually with `wpt serve` and a compatible browser.<br><br>
<button id="setUpButton">Request screen details</button>
<ul id="popupButtons"></ul>
<button id="cleanUpButton">Close any open popups</button><br>
<input id="autoCleanUp" type="checkbox" checked=true>Auto-close popups</input>
<ul id="logger"></ul>
<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/helpers.js"></script>
<script>
'use strict';
let popups = [];
cleanUpButton.addEventListener('click', async () => {
popups.forEach(p => p.close());
});
// expectPopup should be true if the test should expect the pop-up to be
// created, or false if the popup is not expected to be created (blocked).
async function testPopupOnScreen(popupTest, screen, expectPopup) {
// Show a popup child window on the associated screen.
const left = screen.availLeft + Math.floor(screen.availWidth / 2) - 150;
const top = screen.availTop + Math.floor(screen.availHeight / 2) - 50;
log(`Opening a popup on '${screen.label}' at (${left}, ${top})`);
let popup = window.open(
'/resources/blank.html', '',
`left=${left},top=${top},width=300,height=100`);
assert_equals(!!popup, expectPopup, 'Popup reference');
if (popup === null)
return;
assert_equals(!popup.closed, expectPopup, 'Popup open');
popups.push(popup);
if (autoCleanUp.checked) {
// TODO(crbug.com/1338645): Remove this workaround (delay) after browser code is
// fixed.
popupTest.add_cleanup(()=>{
setTimeout(popup.close, 1000);
});
}
}
promise_test(async setUpTest => {
await setUpWindowManagement(setUpTest, setUpButton);
const screenDetails = await getScreenDetails();
assert_true(!!screenDetails, 'Error getting screen details');
for (const [i, fullscreenScreen] of screenDetails.screens.entries()) {
const popupScreen =
screenDetails.screens[(i + 1) % screenDetails.screens.length];
let testName =
`Fullscreen on '${fullscreenScreen.label}' and open popup on '${popupScreen.label}'`;
promise_test(async popupTest => {
await addTestTriggerButtonAndAwaitClick(popupButtons,
testName,
popupTest);
await document.documentElement.requestFullscreen(
{ screen: fullscreenScreen }
);
await testPopupOnScreen(popupTest, popupScreen,
/*expectPopup=*/screenDetails.screens.length > 1);
}, testName);
}
}, 'Use multi-screen details to request fullscreen and open a pop-up in the same user activation.');
</script>
|