Bug 1294456 - Stop Marionette from being confused about which tab it currently cares about in each window. r=automatedtester a=testonly
authorMike Conley <mconley@mozilla.com>
Thu, 25 Aug 2016 15:06:56 -0400
changeset 350000 52ce999aa5949dfce9992f5c7d6e4c1ea27fc793
parent 349999 97238d31562d70a6e1270ffd4869f2880efeb1a8
child 350001 d6b420b13a6a605ae6718ae8dd918fb967c38de4
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester, testonly
bugs1294456
milestone50.0a2
Bug 1294456 - Stop Marionette from being confused about which tab it currently cares about in each window. r=automatedtester a=testonly MozReview-Commit-ID: CW0bWILbIuC
testing/marionette/browser.js
--- a/testing/marionette/browser.js
+++ b/testing/marionette/browser.js
@@ -41,16 +41,22 @@ browser.Context = class {
     // used in B2G to identify the homescreen content page
     this.mainContentId = null;
     // used to set curFrameId upon new session
     this.newSession = true;
     this.seenEls = new element.Store();
     this.setBrowser(win);
 
     // A reference to the tab corresponding to the current window handle, if any.
+    // Specifically, this.tab refers to the last tab that Marionette switched
+    // to in this browser window. Note that this may not equal the currently
+    // selected tab. For example, if Marionette switches to tab A, and then
+    // clicks on a button that opens a new tab B in the same browser window,
+    // this.tab will still point to tab A, despite tab B being the currently
+    // selected tab.
     this.tab = null;
     this.pendingCommands = [];
 
     // we should have one FM per BO so that we can handle modals in each Browser
     this.frameManager = new frame.Manager(driver);
     this.frameRegsPending = 0;
 
     // register all message listeners
@@ -209,27 +215,27 @@ browser.Context = class {
   /**
    * When navigating between pages results in changing a browser's
    * 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) {
+    if (this.driver.appName != "Firefox" ||
+        this.tab === null ||
+        this.browserForTab === null) {
       return false;
     }
 
     if (this._hasRemotenessChange) {
       return true;
     }
 
-    // this.tab can potentially get stale and cause problems, see bug 1227252
-    let currentTab = this.browser.selectedTab;
-    let currentIsRemote = this.browser.getBrowserForTab(currentTab).isRemoteBrowser;
+    let currentIsRemote = this.browserForTab.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.