Bug 1507067 - [marionette] Listen for "visibilitychange" event in content process. r=ato
authorHenrik Skupin <mail@hskupin.info>
Thu, 10 Jan 2019 14:26:52 +0000
changeset 510384 9b52701eff7f60c2e9ba0dea60acb2ef660dafcd
parent 510383 826014440f864b2e4b3569fab6050d2330b6ca28
child 510385 b2c7cc1f129cedf78d77c097358ecd67a888d74c
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1507067
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 1507067 - [marionette] Listen for "visibilitychange" event in content process. r=ato To detect when the window got minimized usally "visibilitychange" events are fired to the content window. The "WebDriver:MinimizeWindow" command has to wait for those. Depends on D16096 Differential Revision: https://phabricator.services.mozilla.com/D16098
testing/marionette/driver.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -24,16 +24,19 @@ const {
 } = ChromeUtils.import("chrome://marionette/content/capabilities.js", {});
 ChromeUtils.import("chrome://marionette/content/capture.js");
 const {
   CertificateOverrideManager,
   InsecureSweepingOverride,
 } = ChromeUtils.import("chrome://marionette/content/cert.js", {});
 ChromeUtils.import("chrome://marionette/content/cookie.js");
 const {
+  WebElementEventTarget,
+} = ChromeUtils.import("chrome://marionette/content/dom.js", {});
+const {
   ChromeWebElement,
   element,
   WebElement,
 } = ChromeUtils.import("chrome://marionette/content/element.js", {});
 const {
   InsecureCertificateError,
   InvalidArgumentError,
   InvalidCookieDomainError,
@@ -3037,20 +3040,25 @@ GeckoDriver.prototype.minimizeWindow = a
   const win = assert.open(this.getCurrentWindow());
   await this._handleUserPrompts();
 
   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);
     await new TimedPromise(resolve => {
-      win.addEventListener("visibilitychange", resolve, {once: true});
+      cb = new DebounceCallback(resolve);
+      observer.addEventListener("visibilitychange", cb);
       win.minimize();
     }, {throws: null});
+    observer.removeEventListener("visibilitychange", cb);
+
     await new IdlePromise(win);
   }
 
   return this.curBrowser.rect;
 };
 
 /**
  * Synchronously maximizes the user agent window as if the user pressed