Bug 1398111 - [marionette] Virtually set Firefox as top-most application in WebDriver:NewSession. r=ato a=test-only
authorHenrik Skupin <mail@hskupin.info>
Thu, 07 Jun 2018 08:59:42 +0200
changeset 492419 0b67c71093360c70ae5a66673ef07cdf8bddcec7
parent 492418 e511024df8706eec5cc0ad7d7abf3d12d07ca2a1
child 492420 08f205f8d6aaa9c39173f392b0547b696677306a
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1398111
milestone63.0
Bug 1398111 - [marionette] Virtually set Firefox as top-most application in WebDriver:NewSession. r=ato a=test-only To allow the focusmanager testmode to raise focus events even with the Firefox window in the background, the current chrome window has to be virtually brought into foreground. This should be at least always done when creating a new session.
testing/marionette/driver.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -112,17 +112,17 @@ this.GeckoDriver = function(appId, serve
   this.appId = appId;
   this._server = server;
 
   this.sessionID = null;
   this.wins = new browser.Windows();
   this.browsers = {};
   // points to current browser
   this.curBrowser = null;
-  // topmost chrome frame
+  // top-most chrome window
   this.mainFrame = null;
   // chrome iframe that currently has focus
   this.curFrame = null;
   this.currentFrameElement = null;
   this.observing = null;
   this._browserIds = new WeakMap();
 
   // Use content context by default
@@ -751,16 +751,20 @@ GeckoDriver.prototype.newSession = async
     this.whenBrowserStarted(win, false);
   } else {
     throw new WebDriverError("Session already running");
   }
 
   await registerBrowsers;
   await browserListening;
 
+  if (this.mainFrame) {
+    this.mainFrame.focus();
+  }
+
   if (this.curBrowser.tab) {
     this.curBrowser.contentBrowser.focus();
   }
 
   // Setup global listener for modal dialogs, and check if there is already
   // one open for the currently selected browser window.
   modal.addHandler(this.dialogHandler);
   this.dialog = modal.findModalDialogs(this.curBrowser);
@@ -2817,25 +2821,19 @@ GeckoDriver.prototype.deleteSession = fu
         win.messageManager.removeDelayedFrameScript(FRAME_SCRIPT);
       } else {
         logger.error(
             `Could not remove listener from page ${win.location.href}`);
       }
     }
   }
 
-  // reset frame to the top-most frame
+  // reset frame to the top-most frame, and clear reference to chrome window
   this.curFrame = null;
-  if (this.mainFrame) {
-    try {
-      this.mainFrame.focus();
-    } catch (e) {
-      this.mainFrame = null;
-    }
-  }
+  this.mainFrame = null;
 
   if (this.observing !== null) {
     for (let topic in this.observing) {
       Services.obs.removeObserver(this.observing[topic], topic);
     }
     this.observing = null;
   }