Bug 1507067 - [marionette] Listen for "visibilitychange" event in content process. r=ato a=test-only
authorHenrik Skupin <mail@hskupin.info>
Thu, 10 Jan 2019 14:26:52 +0000
changeset 506629 189f49635cfd710ab47ad45f24247966bed3dee1
parent 506628 482eb149ad4a01dd0d192c9136d3dcd3197f4446
child 506630 7583fb564e19718bd74ad012b9d35a5aeeb629e1
push id10489
push userapavel@mozilla.com
push dateFri, 11 Jan 2019 11:14:05 +0000
treeherdermozilla-beta@189f49635cfd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1507067
milestone65.0
Bug 1507067 - [marionette] Listen for "visibilitychange" event in content process. r=ato a=test-only 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,
@@ -2990,20 +2993,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