Bug 1521527 - [marionette] Don't raise timeout errors for all window manipulation commands. r=ato
authorHenrik Skupin <mail@hskupin.info>
Mon, 21 Jan 2019 18:39:30 +0000
changeset 514742 4aafc1f415adc5a3ab80630b94291968b3a84eb2
parent 514741 243733368484c9c41548d6acef5b6273be5f7948
child 514743 fcef3b13bb1c0ea091dc09a07e35ad758e0a56f2
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
bugs1521527
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 1521527 - [marionette] Don't raise timeout errors for all window manipulation commands. r=ato Marionette should do its best to get the browser into the requested window state, but if it is not possible to do so, it shouldn't raise a timeout error. This is mostly the case when running tests under xvfb with no window manager running. Instead we just log the message for further investigation. Further the timeout value has to be set to a value which wouldn't cause the commands to inappropriately fail due to animations, or a slow machine. Differential Revision: https://phabricator.services.mozilla.com/D17144
testing/marionette/driver.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -85,16 +85,20 @@ const SUPPORTED_STRATEGIES = new Set([
   element.Strategy.Selector,
   element.Strategy.ID,
   element.Strategy.TagName,
   element.Strategy.XPath,
   element.Strategy.Anon,
   element.Strategy.AnonAttribute,
 ]);
 
+// Timeout used to abort fullscreen, maximize, and minimize
+// commands if no window manager is present.
+const TIMEOUT_NO_WINDOW_MANAGER = 5000;
+
 const globalMessageManager = Services.mm;
 
 /**
  * The Marionette WebDriver services provides a standard conforming
  * implementation of the W3C WebDriver specification.
  *
  * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html}
  * @namespace driver
@@ -3029,23 +3033,23 @@ GeckoDriver.prototype.minimizeWindow = a
 
   if (WindowState.from(win.windowState) != WindowState.Minimized) {
     if (WindowState.from(win.windowState) == WindowState.Fullscreen) {
       await exitFullscreen(win);
     }
 
     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});
+    }, {throws: null, timeout: TIMEOUT_NO_WINDOW_MANAGER});
     observer.removeEventListener("visibilitychange", cb);
-
     await new IdlePromise(win);
   }
 
   return this.curBrowser.rect;
 };
 
 /**
  * Synchronously maximizes the user agent window as if the user pressed
@@ -3077,21 +3081,22 @@ GeckoDriver.prototype.maximizeWindow = a
 
     case WindowState.Minimized:
       await restoreWindow(win);
       break;
   }
 
   if (WindowState.from(win.windowState) != WindowState.Maximized) {
     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);
       win.maximize();
-    }, {throws: null});
+    }, {throws: null, timeout: TIMEOUT_NO_WINDOW_MANAGER});
     win.removeEventListener("sizemodechange", cb);
     await new IdlePromise(win);
   }
 
   return this.curBrowser.rect;
 };
 
 /**
@@ -3118,21 +3123,22 @@ GeckoDriver.prototype.fullscreenWindow =
   await this._handleUserPrompts();
 
   if (WindowState.from(win.windowState) == WindowState.Minimized) {
     await restoreWindow(win);
   }
 
   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);
       win.fullScreen = true;
-    }, {throws: null});
+    }, {throws: null, timeout: TIMEOUT_NO_WINDOW_MANAGER});
     win.removeEventListener("sizemodechange", cb);
   }
   await new IdlePromise(win);
 
   return this.curBrowser.rect;
 };
 
 /**
@@ -3619,26 +3625,28 @@ GeckoDriver.prototype.commands = {
 };
 
 function getOuterWindowId(win) {
   return win.windowUtils.outerWindowID;
 }
 
 async function exitFullscreen(window) {
   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;
-  });
+  }, {throws: null, timeout: TIMEOUT_NO_WINDOW_MANAGER});
   window.removeEventListener("sizemodechange", cb);
 }
 
-function restoreWindow(window) {
+async function restoreWindow(window) {
   window.restore();
-  return new PollPromise((resolve, reject) => {
+  // Use a poll promise to abort if no window manager is present
+  await new PollPromise((resolve, reject) => {
     if (WindowState.from(window.windowState) != WindowState.Minimized) {
       resolve();
     } else {
       reject();
     }
-  }, {timeout: 2000});
+  }, {timeout: TIMEOUT_NO_WINDOW_MANAGER});
 }