Bug 1294456 - Stop Marionette from being confused about which tab it currently cares about in each window. r?automatedtester draft
authorMike Conley <mconley@mozilla.com>
Thu, 25 Aug 2016 15:06:56 -0400
changeset 406299 b2e797f26a55240b60ed811e5fa2d2aaeb67a985
parent 405855 a551f534773cf2d6933f78ce7d82a7a33a99643e
child 406300 a6469411ed3f6e0cd0ccb9a77aadcd0768b0d286
push id27683
push usermconley@mozilla.com
push dateFri, 26 Aug 2016 21:22:37 +0000
reviewersautomatedtester
bugs1294456
milestone51.0a1
Bug 1294456 - Stop Marionette from being confused about which tab it currently cares about in each window. r?automatedtester 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.