Backed out changeset f5e6da82e68d (bug 1322383)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Thu, 09 Feb 2017 18:10:13 +0100
changeset 481547 614014c33b90e105b0ded75a26d5e45ffb74bb7b
parent 481546 aa6970ec8561cbd309406d887ac1446f68427811
child 481548 7617c2a06e181b42ec99a6c7b7ddfa7d2d7c45e5
push id44840
push userbmo:rchien@mozilla.com
push dateFri, 10 Feb 2017 01:03:57 +0000
bugs1322383
milestone54.0a1
backs outf5e6da82e68df1d6b2d4912b7425de7c37717efb
Backed out changeset f5e6da82e68d (bug 1322383)
testing/marionette/driver.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -304,51 +304,43 @@ GeckoDriver.prototype.sendTargettedAsync
 
       default:
         throw new WebDriverError(e);
     }
   }
 };
 
 /**
- * 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.
+ * Gets the current active window.
  *
  * @param {Context=} forcedContext
- *     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.
+ *     Optional name of the context to use for the checks.
+ *     Defaults to the current context.
  *
- * @return {ChromeWindow}
- *     The current top-level browsing context.
+ * @return {nsIDOMWindow}
  */
 GeckoDriver.prototype.getCurrentWindow = function (forcedContext = undefined) {
   let context = typeof forcedContext == "undefined" ? this.context : forcedContext;
   let win = null;
 
-  switch (context) {
-    case Context.CHROME:
-      if (this.curFrame !== null) {
-        win = this.curFrame;
-
+  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;
       } else {
-        win = this.curBrowser.window;
+        if (this.curBrowser.tab && browser.getBrowserForTab(this.curBrowser.tab)) {
+          win = this.curBrowser.window;
+        }
       }
-      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;
+    }
+  } else {
+    win = this.curFrame;
   }
 
   return win;
 };
 
 GeckoDriver.prototype.addFrameCloseListener = function (action) {
   let win = this.getCurrentWindow();
   this.mozBrowserClose = e => {
@@ -606,19 +598,18 @@ 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 = Services.wm.getMostRecentWindow("navigator:browser");
-
+  let waitForWindow = function() {
+    let win = this.getCurrentWindow();
     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 => {
@@ -628,18 +619,20 @@ 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) {
-        Services.prompt.alert(win, "", "Click to start execution of marionette tests");
+      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");
       }
       this.startBrowser(win, true);
     }
   };
 
   let runSessionStart = function() {
     if (!Preferences.get(CONTENT_LISTENER_PREF)) {
       waitForWindow.call(this);