Bug 1522408 - [marionette] Restore maximized window first before entering fullscreen or minimizing the window. r=ato
authorHenrik Skupin <mail@hskupin.info>
Fri, 25 Jan 2019 13:16:24 +0000
changeset 515434 d4740a86555216ae73ef92a0b1998e0f83c378e3
parent 515433 ecb5dd14837867573107db48990a88e7c14a7c78
child 515449 a7918210d2f16d02f02f7a322375a358fe710e3a
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1522408
milestone66.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 1522408 - [marionette] Restore maximized window first before entering fullscreen or minimizing the window. r=ato The window should always be restored first to the normal window state, before a special state like fullscreen or minimized can be entered. Right now this isn't done when going from a maximized window into fullscreen mode, or when minimizing the window. Differential Revision: https://phabricator.services.mozilla.com/D17472
testing/marionette/driver.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -3026,21 +3026,27 @@ GeckoDriver.prototype.setScreenOrientati
  * @throws {UnexpectedAlertOpenError}
  *     A modal dialog is open, blocking this operation.
  */
 GeckoDriver.prototype.minimizeWindow = async function() {
   assert.firefox();
   const win = assert.open(this.getCurrentWindow());
   await this._handleUserPrompts();
 
-  if (WindowState.from(win.windowState) != WindowState.Minimized) {
-    if (WindowState.from(win.windowState) == WindowState.Fullscreen) {
+  switch (WindowState.from(win.windowState)) {
+    case WindowState.Fullscreen:
       await exitFullscreen(win);
-    }
-
+      break;
+
+    case WindowState.Maximized:
+      await restoreWindow(win);
+      break;
+  }
+
+  if (WindowState.from(win.windowState) != WindowState.Minimized) {
     let cb;
     let observer = new WebElementEventTarget(this.curBrowser.messageManager);
     // Use a timed promise to abort if no window manager is present
     await new TimedPromise(resolve => {
       cb = new DebounceCallback(resolve);
       observer.addEventListener("visibilitychange", cb);
       win.minimize();
     }, {throws: null, timeout: TIMEOUT_NO_WINDOW_MANAGER});
@@ -3117,18 +3123,21 @@ GeckoDriver.prototype.maximizeWindow = a
  * @throws {UnexpectedAlertOpenError}
  *     A modal dialog is open, blocking this operation.
  */
 GeckoDriver.prototype.fullscreenWindow = async function() {
   assert.firefox();
   const win = assert.open(this.getCurrentWindow());
   await this._handleUserPrompts();
 
-  if (WindowState.from(win.windowState) == WindowState.Minimized) {
-    await restoreWindow(win);
+  switch (WindowState.from(win.windowState)) {
+    case WindowState.Maximized:
+    case WindowState.Minimized:
+      await restoreWindow(win);
+      break;
   }
 
   if (WindowState.from(win.windowState) != WindowState.Fullscreen) {
     let cb;
     // Use a timed promise to abort if no window manager is present
     await new TimedPromise(resolve => {
       cb = new DebounceCallback(resolve);
       win.addEventListener("sizemodechange", cb);
@@ -3623,30 +3632,30 @@ GeckoDriver.prototype.commands = {
   "WebDriver:SwitchToWindow": GeckoDriver.prototype.switchToWindow,
   "WebDriver:TakeScreenshot": GeckoDriver.prototype.takeScreenshot,
 };
 
 function getOuterWindowId(win) {
   return win.windowUtils.outerWindowID;
 }
 
-async function exitFullscreen(window) {
+async function exitFullscreen(win) {
   let cb;
   // Use a timed promise to abort if no window manager is present
   await new TimedPromise(resolve => {
     cb = new DebounceCallback(resolve);
-    window.addEventListener("sizemodechange", cb);
-    window.fullScreen = false;
+    win.addEventListener("sizemodechange", cb);
+    win.fullScreen = false;
   }, {throws: null, timeout: TIMEOUT_NO_WINDOW_MANAGER});
-  window.removeEventListener("sizemodechange", cb);
+  win.removeEventListener("sizemodechange", cb);
 }
 
-async function restoreWindow(window) {
-  window.restore();
+async function restoreWindow(win) {
+  win.restore();
   // Use a poll promise to abort if no window manager is present
   await new PollPromise((resolve, reject) => {
-    if (WindowState.from(window.windowState) != WindowState.Minimized) {
+    if (WindowState.from(win.windowState) == WindowState.Normal) {
       resolve();
     } else {
       reject();
     }
   }, {timeout: TIMEOUT_NO_WINDOW_MANAGER});
 }