Bug 1348872 - Add contentBrowser property to browser's Context class. r=ato, a=test-only
authorHenrik Skupin <mail@hskupin.info>
Mon, 27 Mar 2017 11:02:36 +0200
changeset 395625 7362d3d66d546dd03a45f0da705c0f5d1cbe0d55
parent 395624 25af0b16808a9cf6d4721780eb99e6ebeb61dfe9
child 395626 e8935d65268687218e42e00b1e068c139b1cb249
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1348872
milestone54.0a2
Bug 1348872 - Add contentBrowser property to browser's Context class. r=ato, a=test-only Make it easier to access the content browser for the currently selected tab by not requiring to go through the global getBrowserForTab() method. MozReview-Commit-ID: 3zdCGJFanto
testing/marionette/browser.js
testing/marionette/driver.js
--- a/testing/marionette/browser.js
+++ b/testing/marionette/browser.js
@@ -120,42 +120,54 @@ browser.Context = class {
     this.getIdForBrowser = driver.getIdForBrowser.bind(driver);
     this.updateIdForBrowser = driver.updateIdForBrowser.bind(driver);
     this._curFrameId = null;
     this._browserWasRemote = null;
     this._hasRemotenessChange = false;
   }
 
   /**
+   * Returns the content browser for the currently selected tab.
+   * If there is no tab selected, null will be returned.
+   */
+  get contentBrowser() {
+    if (this.tab) {
+      return browser.getBrowserForTab(this.tab);
+    }
+
+    return null;
+  }
+
+  /**
    * The current frame ID is managed per browser element on desktop in
    * case the ID needs to be refreshed. The currently selected window is
    * identified by a tab.
    */
   get curFrameId() {
     let rv = null;
     if (this.driver.appName == "B2G") {
       rv = this._curFrameId;
     } else if (this.tab) {
-      rv = this.getIdForBrowser(browser.getBrowserForTab(this.tab));
+      rv = this.getIdForBrowser(this.contentBrowser);
     }
     return rv;
   }
 
   set curFrameId(id) {
     if (this.driver.appName != "Firefox") {
       this._curFrameId = id;
     }
   }
 
   /**
    * Retrieves the current tabmodal UI object.  According to the browser
    * associated with the currently selected tab.
    */
   getTabModalUI() {
-    let br = browser.getBrowserForTab(this.tab);
+    let br = this.contentBrowser;
     if (!br.hasAttribute("tabmodalPromptShowing")) {
       return null;
     }
 
     // The modal is a direct sibling of the browser element.
     // See tabbrowser.xml's getTabModalPromptBox.
     let modals = br.parentNode.getElementsByTagNameNS(
         XUL_NS, "tabmodalprompt");
@@ -271,17 +283,17 @@ browser.Context = class {
 
         } else {
           throw new UnsupportedOperationError("switchToTab() not supported");
         }
       }
     }
 
     if (this.driver.appName == "Firefox") {
-      this._browserWasRemote = browser.getBrowserForTab(this.tab).isRemoteBrowser;
+      this._browserWasRemote = this.contentBrowser.isRemoteBrowser;
       this._hasRemotenessChange = false;
     }
   }
 
   /**
    * Registers a new frame, and sets its current frame id to this frame
    * if it is not already assigned, and if a) we already have a session
    * or b) we're starting a new session and it is the right start frame.
@@ -295,18 +307,18 @@ browser.Context = class {
     if (this.curFrameId === null || remotenessChange) {
       if (this.tabBrowser) {
         // If we're setting up a new session on Firefox, we only process the
         // registration for this frame if it belongs to the current tab.
         if (!this.tab) {
           this.switchToTab();
         }
 
-        if (target == browser.getBrowserForTab(this.tab)) {
-          this.updateIdForBrowser(browser.getBrowserForTab(this.tab), uid);
+        if (target === this.contentBrowser) {
+          this.updateIdForBrowser(this.contentBrowser, uid);
           this.mainContentId = uid;
         }
       } else {
         this._curFrameId = uid;
         this.mainContentId = uid;
       }
     }
 
@@ -320,25 +332,25 @@ browser.Context = class {
    * process, we need to take measures not to lose contact with a listener
    * script. This function does the necessary bookkeeping.
    */
   hasRemotenessChange() {
     // None of these checks are relevant on b2g or if we don't have a tab yet,
     // and may not apply on Fennec.
     if (this.driver.appName != "Firefox" ||
         this.tab === null ||
-        browser.getBrowserForTab(this.tab) === null) {
+        this.contentBrowser === null) {
       return false;
     }
 
     if (this._hasRemotenessChange) {
       return true;
     }
 
-    let currentIsRemote = browser.getBrowserForTab(this.tab).isRemoteBrowser;
+    let currentIsRemote = this.contentBrowser.isRemoteBrowser;
     this._hasRemotenessChange = this._browserWasRemote !== currentIsRemote;
     this._browserWasRemote = currentIsRemote;
     return this._hasRemotenessChange;
   }
 
   /**
    * Flushes any pending commands queued when a remoteness change is being
    * processed and mark this remotenessUpdate as complete.
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -333,17 +333,17 @@ GeckoDriver.prototype.getCurrentWindow =
 
     case Context.CONTENT:
       if (this.curFrame !== null) {
         win = this.curFrame;
 
       } else if (this.curBrowser !== null) {
         if (browser.getTabBrowser(this.curBrowser.window)) {
           // For browser windows we have to check if the current tab still exists.
-          if (this.curBrowser.tab && browser.getBrowserForTab(this.curBrowser.tab)) {
+          if (this.curBrowser.tab && this.curBrowser.contentBrowser) {
             win = this.curBrowser.window;
           }
         } else {
           // For non-browser windows just return the window.
           win = this.curBrowser.window;
         }
       }
 
@@ -656,17 +656,17 @@ GeckoDriver.prototype.newSession = funct
     throw new WebDriverError("Session already running");
   }
   this.switchToGlobalMessageManager();
 
   yield registerBrowsers;
   yield browserListening;
 
   if (this.curBrowser.tab) {
-    browser.getBrowserForTab(this.curBrowser.tab).focus();
+    this.curBrowser.contentBrowser.focus();
   }
 
   return {
     sessionId: this.sessionId,
     capabilities: this.capabilities,
   };
 };
 
@@ -982,17 +982,18 @@ GeckoDriver.prototype.get = function*(cm
       startTime: new Date().getTime(),
     };
     this.mm.broadcastAsyncMessage(
         "Marionette:pollForReadyState" + this.curBrowser.curFrameId,
         parameters);
   });
 
   yield get;
-  browser.getBrowserForTab(this.curBrowser.tab).focus();
+
+  this.curBrowser.contentBrowser.focus();
 };
 
 /**
  * Get a string representing the current URL.
  *
  * On Desktop this returns a string representation of the URL of the
  * current top level browsing context.  This is equivalent to
  * document.location.href.
@@ -1058,18 +1059,17 @@ GeckoDriver.prototype.goBack = function*
   assert.content(this.context);
   assert.window(this.getCurrentWindow());
 
   if (!this.curBrowser.tab) {
     // Navigation does not work for non-browser windows
     return;
   }
 
-  let contentBrowser = browser.getBrowserForTab(this.curBrowser.tab)
-  if (!contentBrowser.webNavigation.canGoBack) {
+  if (!this.curBrowser.contentBrowser.webNavigation.canGoBack) {
     return;
   }
 
   let currentURL = yield this.listener.getCurrentUrl();
   let goBack = this.listener.goBack({pageTimeout: this.timeouts.pageLoad});
 
   // If a remoteness update interrupts our page load, this will never return
   // We need to re-issue this request to correctly poll for readyState and
@@ -1100,18 +1100,17 @@ GeckoDriver.prototype.goForward = functi
   assert.content(this.context);
   assert.window(this.getCurrentWindow());
 
   if (!this.curBrowser.tab) {
     // Navigation does not work for non-browser windows
     return;
   }
 
-  let contentBrowser = browser.getBrowserForTab(this.curBrowser.tab)
-  if (!contentBrowser.webNavigation.canGoForward) {
+  if (!this.curBrowser.contentBrowser.webNavigation.canGoForward) {
     return;
   }
 
   let currentURL = yield this.listener.getCurrentUrl();
   let goForward = this.listener.goForward({pageTimeout: this.timeouts.pageLoad});
 
   // If a remoteness update interrupts our page load, this will never return
   // We need to re-issue this request to correctly poll for readyState and