Source code

Revision control

Copy as Markdown

Other Tools

<!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="">
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>
'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 =
'/resources/blank.html', '',
assert_equals(!!popup, expectPopup, 'Popup reference');
if (popup === null)
assert_equals(!popup.closed, expectPopup, 'Popup open');
if (autoCleanUp.checked) {
// TODO( Remove this workaround (delay) after browser code is
// fixed.
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,
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.');