Bug 1631735 Part 2: Add a fullscreen test that checks event order, and a test of fs->minimize->fs. r=mstange,emilio
authorBrad Werth <bwerth@mozilla.com>
Mon, 06 Mar 2023 19:38:11 +0000 (2023-03-06)
changeset 655482 98df31ea18e224a8fbd73926289fae3de8d11d8d
parent 655481 c9995ff922538311b6d46689bce8c8f33a94bab0
child 655483 8201fa6c615652109ecc06d4ca7c164844c75da3
push id179734
push userbwerth@mozilla.com
push dateMon, 06 Mar 2023 19:41:32 +0000 (2023-03-06)
treeherderautoland@168ec9dca708 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange, emilio
bugs1631735
milestone112.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1631735 Part 2: Add a fullscreen test that checks event order, and a test of fs->minimize->fs. r=mstange,emilio The transition from fullscreen to minimize and back is not directly allowed in macOS, though our test harness can be forced to request it. The modified test forces this transition explicitly, so we can eliminate it as an accidental occurrence with other tests. The transition from minimize to fullscreen fails on Linux and Windows, so this change marks the entire test as failing on those platforms. New Bugs have been opened on this issue and those are noted in the fail-if. Depends on D166450 Differential Revision: https://phabricator.services.mozilla.com/D164248
browser/base/content/test/fullscreen/browser.ini
browser/base/content/test/fullscreen/browser_fullscreen_from_minimize.js
browser/base/content/test/general/browser.ini
dom/base/test/fullscreen/file_fullscreen-single.html
dom/base/test/fullscreen/mochitest.ini
dom/base/test/fullscreen/test_fullscreen-api.html
--- a/browser/base/content/test/fullscreen/browser.ini
+++ b/browser/base/content/test/fullscreen/browser.ini
@@ -9,16 +9,18 @@ support-files = fullscreen.html fullscre
 [browser_fullscreen_api_fission.js]
 https_first_disabled = true
 support-files = fullscreen.html FullscreenFrame.sys.mjs
 [browser_fullscreen_context_menu.js]
 [browser_fullscreen_cross_origin.js]
 support-files = fullscreen.html fullscreen_frame.html
 [browser_fullscreen_enterInUrlbar.js]
 skip-if = (os == 'mac') || (os == 'linux') # Bug 1648649
+[browser_fullscreen_from_minimize.js]
+skip-if = (os == 'linux') || (os == 'win') # Bug 1818795 and Bug 1818796
 [browser_fullscreen_newtab.js]
 [browser_fullscreen_permissions_prompt.js]
 [browser_fullscreen_warning.js]
 support-files = fullscreen.html
 [browser_fullscreen_window_focus.js]
 skip-if = (os == 'mac') && debug # Bug 1568570
 [browser_fullscreen_window_open.js]
 skip-if = (os == 'linux') && swgl # Bug 1795491
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/fullscreen/browser_fullscreen_from_minimize.js
@@ -0,0 +1,72 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// This test checks whether fullscreen windows can transition to minimized windows,
+// and back again. This is sometimes not directly supported by the OS widgets. For
+// example, in macOS, the minimize button is greyed-out in the title bar of
+// fullscreen windows, making this transition impossible for users to initiate.
+// Still, web APIs do allow arbitrary combinations of window calls, and this test
+// exercises some of those combinations.
+
+add_task(async function() {
+  registerCleanupFunction(function() {
+    window.restore();
+  });
+
+  // We reuse these variables to create new promises for each transition.
+  let promiseSizeModeChange;
+  let promiseFullscreen;
+
+  ok(!window.fullScreen, "Window should be normal at start of test.");
+
+  // Get to fullscreen.
+  info("Requesting fullscreen.");
+  promiseFullscreen = document.documentElement.requestFullscreen();
+  await promiseFullscreen;
+  ok(window.fullScreen, "Window should be fullscreen before being minimized.");
+
+  // Transition between fullscreen and minimize states.
+  info("Requesting minimize on a fullscreen window.");
+  promiseSizeModeChange = BrowserTestUtils.waitForEvent(
+    window,
+    "sizemodechange"
+  );
+  window.minimize();
+  await promiseSizeModeChange;
+  is(
+    window.windowState,
+    window.STATE_MINIMIZED,
+    "Window should be minimized after fullscreen."
+  );
+
+  // Whether or not the previous transition worked, restore the window
+  // and then minimize it.
+  if (window.windowState != window.STATE_NORMAL) {
+    info("Restoring window.");
+    promiseSizeModeChange = BrowserTestUtils.waitForEvent(
+      window,
+      "sizemodechange"
+    );
+    window.restore();
+    await promiseSizeModeChange;
+    is(window.windowState, window.STATE_NORMAL, "Window should be normal.");
+  }
+
+  info("Requesting minimize on a normal window.");
+  promiseSizeModeChange = BrowserTestUtils.waitForEvent(
+    window,
+    "sizemodechange"
+  );
+  window.minimize();
+  await promiseSizeModeChange;
+  is(
+    window.windowState,
+    window.STATE_MINIMIZED,
+    "Window should be minimized before fullscreen."
+  );
+
+  info("Requesting fullscreen on a minimized window.");
+  promiseFullscreen = document.documentElement.requestFullscreen();
+  await promiseFullscreen;
+  ok(window.fullScreen, "Window should be fullscreen after being minimized.");
+});
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -399,17 +399,17 @@ skip-if = true # Bug 1409184 disabled be
 # DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
 [browser_visibleTabs_bookmarkAllPages.js]
 # DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
 [browser_visibleTabs_tabPreview.js]
 skip-if =
   os == "win" && !debug
 # DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
 [browser_windowactivation.js]
-skip-if = 
+skip-if =
   verify
   os == "linux" && debug # Bug 1678774
 support-files =
   file_window_activation.html
   file_window_activation2.html
 # DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
 [browser_zbug569342.js]
 skip-if = true # Bug 1094240 - has findbar-related failures
new file mode 100644
--- /dev/null
+++ b/dom/base/test/fullscreen/file_fullscreen-single.html
@@ -0,0 +1,78 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+
+Open one window, focus it and enter fullscreen, then exit fullscreen.
+
+-->
+<head>
+  <title>Simple Fullscreen Enter and Exit Test</title>
+  <script src="/tests/SimpleTest/EventUtils.js"></script>
+  <script src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="file_fullscreen-utils.js"></script>
+</head>
+<body>
+
+<div id="fullscreen-div"><p>Fullscreen div</p></div>
+
+<script type="application/javascript">
+
+function ok(condition, msg) {
+  opener.ok(condition, "[single] " + msg);
+}
+
+function is(value, expected, msg) {
+  opener.is(value, expected, "[single] " + msg);
+}
+
+function isnot(value, unexpected, msg) {
+  opener.isnot(value, unexpected, "[single] " + msg);
+}
+
+function info(msg) {
+  opener.info("[single] " + msg);
+}
+
+function windowResized() {
+  info(`Window resized to width: ${window.innerWidth}, height: ${window.innerHeight}.`);
+}
+
+async function begin() {
+  window.addEventListener('resize', windowResized);
+
+  info(`Starting window width: ${window.innerWidth}, height: ${window.innerHeight}.`);
+  let windowedWidth = window.innerWidth;
+  let windowedHeight = window.innerHeight;
+
+  info("Requesting fullscreen.");
+  let entryPromise = document.getElementById('fullscreen-div').requestFullscreen()
+  info("Fullscreen requested, waiting for promise to resolve.");
+
+  await entryPromise;
+
+  info("element.requestFullscreen() promise resolved.");
+  info(`Fullscreen window width: ${window.innerWidth}, height: ${window.innerHeight}.`);
+  isnot(document.fullscreenElement, null, "document.fullscreenElement should exist.");
+  ok(window.fullScreen, "window.fullScreen");
+  isnot(windowedWidth, window.innerWidth, "window width should be changed.");
+  isnot(windowedHeight, window.innerHeight, "window height should be changed.");
+
+  info("Requesting fullscreen exit.");
+  let exitPromise = document.exitFullscreen()
+  info("Fullscreen exit requested, waiting for promise to resolve.");
+
+  await exitPromise;
+
+  info("document.exitFullscreen() promise resolved.");
+  info(`Restored window width: ${window.innerWidth}, height: ${window.innerHeight}.`);
+  is(document.fullscreenElement, null, "document.fullscreenElement should be null.");
+  ok(!window.fullScreen, "window.fullScreen should be false.");
+  is(window.innerWidth, windowedWidth, "window width should be restored.");
+  is(window.innerHeight, windowedHeight, "window height should be restored.");
+  opener.nextTest();
+}
+
+</script>
+</pre>
+</body>
+</html>
--- a/dom/base/test/fullscreen/mochitest.ini
+++ b/dom/base/test/fullscreen/mochitest.ini
@@ -1,13 +1,13 @@
 [DEFAULT]
 tags = fullscreen
 support-files =
+  file_fullscreen-api-race.html
   file_fullscreen-api.html
-  file_fullscreen-api-race.html
   file_fullscreen-async.html
   file_fullscreen-backdrop.html
   file_fullscreen-denied-inner.html
   file_fullscreen-denied.html
   file_fullscreen-esc-exit-inner.html
   file_fullscreen-esc-exit.html
   file_fullscreen-event-order.html
   file_fullscreen-featurePolicy.html
@@ -22,26 +22,26 @@ support-files =
   file_fullscreen-navigation.html
   file_fullscreen-nested.html
   file_fullscreen-prefixed.html
   file_fullscreen-resize.html
   file_fullscreen-rollback.html
   file_fullscreen-scrollbar.html
   file_fullscreen-selector.html
   file_fullscreen-shadowdom.html
+  file_fullscreen-single.html
   file_fullscreen-sub-iframe.html
   file_fullscreen-svg-element.html
   file_fullscreen-table.html
   file_fullscreen-top-layer.html
   file_fullscreen-utils.js
   file_fullscreen-with-full-zoom.html
 
+[test_fullscreen-api-race.html]
+skip-if = toolkit == 'android' # same as test_fullscreen-api.html, 1356570
+  os == "mac" && debug
 [test_fullscreen-api.html]
 allow_xul_xbl = true  # XUL is used in file_fullscreen-api.html
 skip-if =
   toolkit == 'android'
   os == 'mac' && bits == 64 && debug # Bug 1579623
-[test_fullscreen-api-race.html]
-skip-if = toolkit == 'android' # same as test_fullscreen-api.html, 1356570
-  verify && debug && os == 'mac'
-  os == "mac" && debug
 [test_fullscreen_meta_viewport.html]
 [test_fullscreen_modal.html]
--- a/dom/base/test/fullscreen/test_fullscreen-api.html
+++ b/dom/base/test/fullscreen/test_fullscreen-api.html
@@ -23,16 +23,17 @@
 
 /** Tests for Bug 545812 **/
 SimpleTest.requestFlakyTimeout("untriaged");
 
 // Run the tests which go full-screen in new windows, as mochitests normally
 // run in an iframe, which by default will not have the allowfullscreen
 // attribute set, so full-screen won't work.
 var gTestWindows = [
+  { test: "file_fullscreen-single.html" },
   { test: "file_fullscreen-multiple.html",
     prefs: [["full-screen-api.exit-on.windowRaise", false],
             ["full-screen-api.exit-on.windowOpen", false]] },
   { test: "file_fullscreen-rollback.html" },
   { test: "file_fullscreen-esc-exit.html" },
   { test: "file_fullscreen-denied.html" },
   { test: "file_fullscreen-api.html" },
   { test: "file_fullscreen-hidden.html" },
@@ -67,16 +68,17 @@ function finish() {
 
 function nextTest() {
   if (testWindow) {
     info("Waiting for focus to return to main window");
     window.addEventListener("focus", function() {
       info("main window focused, starting next test");
       SimpleTest.executeSoon(runNextTest);
     }, {once: true});
+    info("testWindow.close()");
     testWindow.close();
   } else {
     SimpleTest.executeSoon(runNextTest);
   }
 }
 
 function waitForEvent(eventTarget, eventName, checkFn, callback) {
   eventTarget.addEventListener(eventName, function listener(event) {