Bug 1322383 - getCurrentWindow() has to only return the currently selected window. r=ato,maja_zf
☠☠ backed out by 614014c33b90 ☠ ☠
authorHenrik Skupin <mail@hskupin.info>
Wed, 08 Feb 2017 12:58:45 +0100
changeset 481535 f5e6da82e68df1d6b2d4912b7425de7c37717efb
parent 481534 deb5b08545fd6eee0195646593fbb437a3b8b25c
child 481536 be39185b68b08eb5037fc592ba99f769dfb67089
push id44840
push userbmo:rchien@mozilla.com
push dateFri, 10 Feb 2017 01:03:57 +0000
reviewersato, maja_zf
bugs1322383
milestone54.0a1
Bug 1322383 - getCurrentWindow() has to only return the currently selected window. r=ato,maja_zf Given that this method will be used in each command for checks of a valid window, we have to return the currently active window. It means the window mediator should only be used during setting up the session to find the first browser window. At the same time the code in this method is getting split-up for chrome and content scopes. MozReview-Commit-ID: KyzxYk63RgA
testing/marionette/driver.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -304,43 +304,51 @@ GeckoDriver.prototype.sendTargettedAsync
 
       default:
         throw new WebDriverError(e);
     }
   }
 };
 
 /**
- * Gets the current active window.
+ * Get the session's current top-level browsing context.
+ *
+ * It will return the outer {@ChromeWindow} previously selected by window handle
+ * through {@code #switchToWindow}, or the first window that was registered.
  *
  * @param {Context=} forcedContext
- *     Optional name of the context to use for the checks.
- *     Defaults to the current context.
+ *     Optional name of the context to use for finding the window. It will be required
+ *     if a command always needs a specific context, whether which context is
+ *     currently set. Defaults to the current context.
  *
- * @return {nsIDOMWindow}
+ * @return {ChromeWindow}
+ *     The current top-level browsing context.
  */
 GeckoDriver.prototype.getCurrentWindow = function (forcedContext = undefined) {
   let context = typeof forcedContext == "undefined" ? this.context : forcedContext;
   let win = null;
 
-  if (this.curFrame === null) {
-    if (this.curBrowser === null) {
-      let typ = (context === Context.CONTENT) ? "navigator:browser" : null;
-      win = Services.wm.getMostRecentWindow(typ);
-    } else {
-      if (context === Context.CHROME) {
-        win = this.curBrowser.window;
+  switch (context) {
+    case Context.CHROME:
+      if (this.curFrame !== null) {
+        win = this.curFrame;
+
       } else {
-        if (this.curBrowser.tab && browser.getBrowserForTab(this.curBrowser.tab)) {
-          win = this.curBrowser.window;
-        }
+        win = this.curBrowser.window;
       }
-    }
-  } else {
-    win = this.curFrame;
+      break;
+
+    case Context.CONTENT:
+      if (this.curFrame !== null) {
+        win = this.curFrame;
+
+      } else if (this.curBrowser.tab && browser.getBrowserForTab(this.curBrowser.tab)) {
+        win = this.curBrowser.window;
+      }
+      break;
   }
 
   return win;
 };
 
 GeckoDriver.prototype.addFrameCloseListener = function (action) {
   let win = this.getCurrentWindow();
   this.mozBrowserClose = e => {
@@ -598,18 +606,19 @@ GeckoDriver.prototype.newSession = funct
   // services hanging around.
   if (this.a11yChecks && accessibility.service) {
     logger.info("Preemptively starting accessibility service in Chrome");
   }
 
   let registerBrowsers = this.registerPromise();
   let browserListening = this.listeningPromise();
 
-  let waitForWindow = function() {
-    let win = this.getCurrentWindow();
+  let waitForWindow = function () {
+    let win = Services.wm.getMostRecentWindow("navigator:browser");
+
     if (!win) {
       // if the window isn't even created, just poll wait for it
       let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
       checkTimer.initWithCallback(waitForWindow.bind(this), 100,
           Ci.nsITimer.TYPE_ONE_SHOT);
     } else if (win.document.readyState != "complete") {
       // otherwise, wait for it to be fully loaded before proceeding
       let listener = ev => {
@@ -619,20 +628,18 @@ GeckoDriver.prototype.newSession = funct
           return;
         }
         win.removeEventListener("load", listener);
         waitForWindow.call(this);
       };
       win.addEventListener("load", listener, true);
     } else {
       let clickToStart = Preferences.get(CLICK_TO_START_PREF);
-      if (clickToStart && (this.appName != "B2G")) {
-        let pService = Cc["@mozilla.org/embedcomp/prompt-service;1"]
-            .getService(Ci.nsIPromptService);
-        pService.alert(win, "", "Click to start execution of marionette tests");
+      if (clickToStart) {
+        Services.prompt.alert(win, "", "Click to start execution of marionette tests");
       }
       this.startBrowser(win, true);
     }
   };
 
   let runSessionStart = function() {
     if (!Preferences.get(CONTENT_LISTENER_PREF)) {
       waitForWindow.call(this);