summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/window-management
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/window-management')
-rw-r--r--testing/web-platform/tests/window-management/META.yml4
-rw-r--r--testing/web-platform/tests/window-management/README.md7
-rw-r--r--testing/web-platform/tests/window-management/multi-screen-fullscreen-companion.tentative.https.html54
-rw-r--r--testing/web-platform/tests/window-management/multi-screen-fullscreen-enter.tentative.https.html36
-rw-r--r--testing/web-platform/tests/window-management/multi-screen-fullscreen-move.tentative.https.html39
-rw-r--r--testing/web-platform/tests/window-management/multi-screen-window-open-fullscreen.tentative.https.html51
-rw-r--r--testing/web-platform/tests/window-management/multi-screen-window-open.tentative.https.html39
-rw-r--r--testing/web-platform/tests/window-management/resources/helpers.js126
8 files changed, 356 insertions, 0 deletions
diff --git a/testing/web-platform/tests/window-management/META.yml b/testing/web-platform/tests/window-management/META.yml
new file mode 100644
index 0000000000..74f926f230
--- /dev/null
+++ b/testing/web-platform/tests/window-management/META.yml
@@ -0,0 +1,4 @@
+spec: https://w3c.github.io/window-management/
+suggested_reviewers:
+ - michaelwasserman
+ - bradtriebwasser
diff --git a/testing/web-platform/tests/window-management/README.md b/testing/web-platform/tests/window-management/README.md
new file mode 100644
index 0000000000..e96a8a00b8
--- /dev/null
+++ b/testing/web-platform/tests/window-management/README.md
@@ -0,0 +1,7 @@
+# Window Management Testing
+
+[Window Management Specification](https://w3c.github.io/window-management/)
+
+The tests in this directory require at least 2 displays on the host machine to
+yield meaningful results. An example configuration is 2 displays with 1920x1080
+resolution arranged horizontally (primary on the left, secondary on the right).
diff --git a/testing/web-platform/tests/window-management/multi-screen-fullscreen-companion.tentative.https.html b/testing/web-platform/tests/window-management/multi-screen-fullscreen-companion.tentative.https.html
new file mode 100644
index 0000000000..a4b09f3d5a
--- /dev/null
+++ b/testing/web-platform/tests/window-management/multi-screen-fullscreen-companion.tentative.https.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<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>Window Management test: Fullscreen Companion Window</title>
+<link rel="help" href="https://w3c.github.io/window-management/">
+Tests use of multi-screen details to enter fullscreen and open a 'companion'
+popup window in the same user activation.<br>
+The host device must have 2+ screens to yield meaningful results.<br><br>
+<button id="closeButton" onclick="closePopups">Close popups</button><br>
+<input id="autoClose" type="checkbox" checked=true>Auto-close popups</input>
+<ul id="list"></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 = [];
+function closePopups() {
+ popups.forEach(p => p.close());
+ popups = [];
+}
+
+promise_test(async setUpTest => {
+ await setUpWindowManagement(setUpTest);
+ const screens = window.screenDetails.screens;
+ const originalScreen = window.screenDetails.currentScreen;
+ for (const [i, screenA] of screens.entries()) {
+ const screenB = screens[(i + 1) % screens.length];
+ let name = `Fullscreen on '${screenA.label}'; popup on '${screenB.label}'`;
+ promise_test(async test => {
+ await buttonClick(test, name);
+ await document.documentElement.requestFullscreen({ screen: screenA });
+ await assertWindowOnScreen(window, screenA);
+ // Expect the popup to open if multiple screens are available.
+ const assertPlacement = screens.length > 1;
+ const popup = await openPopupOnScreen(screenB, assertPlacement);
+ if (!!popup)
+ popups.push(popup);
+ // Exit fullscreen; `window` should move back to `originalScreen`.
+ await buttonClick(test, `Exit fullscreen`);
+ await document.exitFullscreen();
+ await assertWindowOnScreen(window, originalScreen);
+ assert_false(!!document.fullscreenElement);
+ if (autoClose.checked)
+ closePopups();
+ }, name);
+ }
+}, 'Enter fullscreen and open a popup from one transient activation.');
+</script>
diff --git a/testing/web-platform/tests/window-management/multi-screen-fullscreen-enter.tentative.https.html b/testing/web-platform/tests/window-management/multi-screen-fullscreen-enter.tentative.https.html
new file mode 100644
index 0000000000..b67907807b
--- /dev/null
+++ b/testing/web-platform/tests/window-management/multi-screen-fullscreen-enter.tentative.https.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<meta name="timeout" content="long">
+<title>Window Management test: target-screen element.requestFullscreen()</title>
+<link rel="help" href="https://w3c.github.io/window-management/">
+Tests use of multi-screen details to enter fullscreen on specific screens.<br>
+The host device must have 2+ screens to yield meaningful results.<br><br>
+<ul id="list"></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';
+
+promise_test(async setUpTest => {
+ await setUpWindowManagement(setUpTest);
+ const originalScreen = window.screenDetails.currentScreen;
+ for (const s of window.screenDetails.screens) {
+ const name = `Request fullscreen on '${s.label}`;
+ await promise_test(async test => {
+ // Request fullscreen on screen `s`; `window` should move there.
+ await buttonClick(test, name);
+ await document.documentElement.requestFullscreen({ screen: s });
+ await assertWindowOnScreen(window, s);
+ assert_true(!!document.fullscreenElement);
+
+ // Exit fullscreen; `window` should move back to `originalScreen`.
+ await buttonClick(test, `Exit fullscreen`);
+ await document.exitFullscreen();
+ await assertWindowOnScreen(window, originalScreen);
+ assert_false(!!document.fullscreenElement);
+ }, name);
+ }
+}, 'Use multi-screen details to enter fullscreen on specific screens');
+</script>
diff --git a/testing/web-platform/tests/window-management/multi-screen-fullscreen-move.tentative.https.html b/testing/web-platform/tests/window-management/multi-screen-fullscreen-move.tentative.https.html
new file mode 100644
index 0000000000..b91ee4cdc4
--- /dev/null
+++ b/testing/web-platform/tests/window-management/multi-screen-fullscreen-move.tentative.https.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<meta name="timeout" content="long">
+<title>Window Management test: target-screen element.requestFullscreen()</title>
+<link rel="help" href="https://w3c.github.io/window-management/">
+Tests use of multi-screen details to move fullscreen between screens.<br>
+The host device must have 2+ screens to yield meaningful results.<br><br>
+<ul id="list"></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';
+
+promise_test(async test => {
+ await setUpWindowManagement(test);
+ const originalScreen = window.screenDetails.currentScreen;
+ // Request fullscreen on the current screen; the window should stay there.
+ await buttonClick(test, `Request fullscreen on '${originalScreen.label}'`);
+ await document.documentElement.requestFullscreen({ screen: originalScreen });
+ await assertWindowOnScreen(window, originalScreen);
+ assert_true(!!document.fullscreenElement);
+
+ for (const s of window.screenDetails.screens) {
+ // Request fullscreen on screen `s`; `window` should move there.
+ await buttonClick(test, `Request fullscreen on '${s.label}'`);
+ await document.documentElement.requestFullscreen({ screen: s });
+ await assertWindowOnScreen(window, s);
+ assert_true(!!document.fullscreenElement);
+ }
+
+ // Exit fullscreen; `window` should move back to `originalScreen`.
+ await buttonClick(test, `Exit fullscreen`);
+ await document.exitFullscreen();
+ await assertWindowOnScreen(window, originalScreen);
+ assert_false(!!document.fullscreenElement);
+}, 'Use multi-screen details to move fullscreen between screens');
+</script>
diff --git a/testing/web-platform/tests/window-management/multi-screen-window-open-fullscreen.tentative.https.html b/testing/web-platform/tests/window-management/multi-screen-window-open-fullscreen.tentative.https.html
new file mode 100644
index 0000000000..008c53d4e7
--- /dev/null
+++ b/testing/web-platform/tests/window-management/multi-screen-window-open-fullscreen.tentative.https.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<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>Window Management test: Fullscreen popups with window.open()</title>
+<link rel="help" href="https://w3c.github.io/window-management/">
+Tests the ability to open a fullscreen popup window on each screen.<br>
+The host device must have 2+ screens to test cross-screen fullscreen popups.
+<br><br>
+<button id="closeButton" onclick="closePopups">Close popups</button><br>
+<input id="autoClose" type="checkbox" checked=true>Auto-close popups</input>
+<ul id="list"></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 = [];
+ function closePopups() {
+ popups.forEach(p => p.close());
+ popups = [];
+ }
+
+ promise_test(async setUpTest => {
+ await setUpWindowManagement(setUpTest);
+ for (const [i, s] of window.screenDetails.screens.entries()) {
+ const name = `Open a fullscreen popup on '${s.label || i}'`;
+ await promise_test(async test => {
+ await buttonClick(test, name);
+ const popup = await openPopupOnScreen(s, /*assertPlacement=*/false,
+ /*fullscreen=*/true);
+ popups.push(popup);
+ await poll(() => {
+ return popup.document.fullscreenElement ==
+ popup.document.documentElement
+ });
+ const context = `popup: ${windowLog(popup)}, ${screenLog(screen)}`;
+ assert_equals(popup.screenLeft, s.availLeft, context)
+ assert_equals(popup.screenRight, s.availRight, context);
+ assert_equals(popup.screen.availHeight, s.availHeight, context);
+ assert_equals(popup.screen.availWidth, s.availWidth, context);
+ if (autoClose.checked)
+ closePopups();
+ }, name);
+ }
+ }, 'Use multi-screen details to open a fullscreen popup window on each screen');
+</script>
diff --git a/testing/web-platform/tests/window-management/multi-screen-window-open.tentative.https.html b/testing/web-platform/tests/window-management/multi-screen-window-open.tentative.https.html
new file mode 100644
index 0000000000..708e571c27
--- /dev/null
+++ b/testing/web-platform/tests/window-management/multi-screen-window-open.tentative.https.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<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>Window Management test: target-screen window.open()</title>
+<link rel="help" href="https://w3c.github.io/window-management/">
+Tests use of multi-screen details to open a popup window on each screen.<br>
+The host device must have 2+ screens to yield meaningful results.<br><br>
+<button id="closeButton" onclick="closePopups">Close popups</button><br>
+<input id="autoClose" type="checkbox" checked=true>Auto-close popups</input>
+<ul id="list"></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 = [];
+function closePopups() {
+ popups.forEach(p => p.close());
+ popups = [];
+}
+
+promise_test(async setUpTest => {
+ await setUpWindowManagement(setUpTest);
+ for (const s of window.screenDetails.screens) {
+ const name = `Open a popup on '${s.label}'`;
+ await promise_test(async test => {
+ await buttonClick(test, name);
+ popups.push(await openPopupOnScreen(s));
+ if (autoClose.checked)
+ closePopups();
+ }, name);
+ }
+}, 'Use multi-screen details to open a popup window on each screen');
+</script>
diff --git a/testing/web-platform/tests/window-management/resources/helpers.js b/testing/web-platform/tests/window-management/resources/helpers.js
new file mode 100644
index 0000000000..ee77fd8d30
--- /dev/null
+++ b/testing/web-platform/tests/window-management/resources/helpers.js
@@ -0,0 +1,126 @@
+// Appends a list item with `innerHTML` to the document's 'list' element.
+function log(innerHTML) {
+ const li = document.createElement('li');
+ li.innerHTML = innerHTML;
+ document.getElementById('list').appendChild(li);
+}
+
+// Returns a string with the label and bounds of screen `s` for logging.
+function screenLog(s) {
+ return `'${s.label}': (${s.left},${s.top} ${s.width}x${s.height})`;
+}
+
+// Returns a string with the bounds of window `w` for logging.
+function windowLog(w) {
+ return `(${w.screenLeft},${w.screenTop} ${w.outerWidth}x${w.outerHeight})`;
+}
+
+// Appends a button with `innerHTML` to the document's `list` element.
+// Waits for a test driver or manual click, and disables the button afterwards.
+async function buttonClick(test, innerHTML) {
+ const button = document.createElement('button');
+ button.innerHTML = innerHTML;
+ const li = document.createElement('li');
+ li.appendChild(button)
+ document.getElementById('list').appendChild(li);
+ const click = new EventWatcher(test, button, ['click']).wait_for('click');
+ try { // Support manual testing where test_driver is not running.
+ await test_driver.click(button);
+ } catch {
+ }
+ await click;
+ button.disabled = true;
+}
+
+// Grants `window-management` permission and caches `window.screenDetails`.
+async function setUpWindowManagement(test) {
+ assert_implements(
+ 'getScreenDetails' in self && 'isExtended' in screen,
+ `API not supported; use Chrome or Chromium (not content_shell)`);
+ if (!screen.isExtended)
+ log(`WARNING: Use multiple screens for full test coverage`);
+ if (window.location.href.startsWith('file'))
+ log(`WARNING: Run via 'wpt serve'; file URLs lack permission support`);
+
+ try { // Support manual testing where test_driver is not running.
+ await test_driver.set_permission({ name: 'window-management' }, 'granted');
+ } catch {
+ }
+ await buttonClick(test, 'Request screen details');
+ window.screenDetails = await window.getScreenDetails();
+ assert_true(!!window.screenDetails, 'Error getting screen details');
+}
+
+// Polls until `condition` is true, with the given `interval` and `duration`.
+// Returns a promise that will be resolved on success or timeout.
+async function poll(condition, interval = 100, duration = 3000) {
+ const timeout = Date.now() + duration;
+ const loop = (resolve) => {
+ if (condition() || Date.now() > timeout)
+ resolve();
+ else
+ step_timeout(loop, interval, resolve);
+ }
+ return new Promise(loop);
+}
+
+// Open and return a popup on `screen`, optionally asserting placement.
+async function openPopupOnScreen(screen, assertPlacement = true, fullscreen = false) {
+ const left = screen.availLeft + Math.floor(screen.availWidth / 2) - 150;
+ const top = screen.availTop + Math.floor(screen.availHeight / 2) - 50;
+ let features = `left=${left},top=${top},width=300,height=100`;
+ if (fullscreen) {
+ features += ",fullscreen";
+ }
+ log(`Opening a popup with features '${features}' on ${screenLog(screen)}`);
+ // Window.open() synchronously returns a Window with estimated screenLeft|Top,
+ // which may be clamped to the opener's screen or incompletely initialized.
+ let popup = window.open('/resources/blank.html', '', features);
+
+ if (assertPlacement) {
+ // Assert the popup is eventually placed at the expected location.
+ // This may occur after window load, document ready and visible, etc.
+ const initialBounds = windowLog(popup);
+ log(`<div style='margin-left: 40px'>Initial: ${initialBounds}</div>`);
+ await poll(() => { return popup.screenLeft == left &&
+ popup.screenTop == top });
+ popup.document.write(`Requested: (${left},${top} 300x100) <br> \
+ Initial: ${initialBounds} <br> \
+ Resolved: ${windowLog(popup)}`);
+ log(`<div style='margin-left: 40px'>Resolved: ${windowLog(popup)}</div>`);
+ const context = `popup: ${windowLog(popup)}, ${screenLog(screen)}`;
+ assert_equals(popup.screenLeft, left, context);
+ assert_equals(popup.screenTop, top, context);
+ }
+
+ return popup;
+}
+
+// Returns true if window `w` bounds are on screen `s` with threshold `t`.
+function isWindowOnScreen(w, s, t = 100) {
+ return (w.screenLeft >= s.left - t) && (w.screenTop >= s.top - t) &&
+ (w.screenLeft + w.outerWidth <= s.left + s.width + t) &&
+ (w.screenTop + w.outerHeight <= s.top + s.height + t);
+}
+
+// Asserts window `w` currentScreen matches screen `s`. Awaits pending changes,
+// e.g. fullscreen promises may resolve before screen change: crbug.com/1330724.
+async function assertWindowHasCurrentScreen(w, s) {
+ log(`assertWindowHasCurrentScreen w: ${windowLog(w)} s: ${screenLog(s)}`);
+ await poll(() => { return s === w.screenDetails.currentScreen; });
+ assert_equals(screenLog(s), screenLog(w.screenDetails.currentScreen));
+}
+
+// Asserts window `w` bounds roughly match screen `s`. Awaits pending changes,
+// e.g. fullscreen promises may resolve before bounds change: crbug.com/1330724.
+async function assertWindowBoundsOnScreen(w, s) {
+ log(`assertWindowBoundsOnScreen w: ${windowLog(w)} s: ${screenLog(s)}`);
+ await poll(() => { return isWindowOnScreen(w, s); });
+ assert_true(isWindowOnScreen(w, s), `${windowLog(w)} on ${screenLog(s)}`);
+}
+
+// Asserts window `w` bounds and currentScreen match screen `s`.
+async function assertWindowOnScreen(w, s) {
+ await assertWindowHasCurrentScreen(w, s);
+ await assertWindowBoundsOnScreen(w, s);
+}