Bug 1169798 - Refresh the marionette server's window reference when switching between windows to avoid intermittent exception.;r=ato a=test-only
authorChris Manchester <cmanchester@mozilla.com>
Mon, 01 Jun 2015 13:26:15 -0700
changeset 266168 d8904a3f0278
parent 266167 082a23c146bd
child 266169 6d8c0c9dc553
push id4772
push usercmanchester@mozilla.com
push date2015-06-02 21:24 +0000
treeherdermozilla-beta@d8904a3f0278 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1169798
milestone39.0
Bug 1169798 - Refresh the marionette server's window reference when switching between windows to avoid intermittent exception.;r=ato a=test-only
testing/marionette/driver.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -1608,17 +1608,16 @@ GeckoDriver.prototype.switchToWindow = f
       for (let i = 0; i < tabbrowser.browsers.length; ++i) {
         let browser = tabbrowser.getBrowserAtIndex(i);
         let contentWindowId = this.getIdForBrowser(browser);
         if (byNameOrId(win.name, contentWindowId, outerId)) {
           found = {
             win: win,
             outerId: outerId,
             tabIndex: i,
-            contentId: contentWindowId
           };
           break;
         }
       }
     } else {
       if (byNameOrId(win.name, outerId)) {
         found = {win: win, outerId: outerId};
         break;
@@ -1631,33 +1630,33 @@ GeckoDriver.prototype.switchToWindow = f
     // for reuse.
     this.sandbox = null;
 
     // Initialise Marionette if browser has not been seen before,
     // otherwise switch to known browser and activate the tab if it's a
     // content browser.
     if (!(found.outerId in this.browsers)) {
       let registerBrowsers, browserListening;
-      if (found.contentId) {
+      if ("tabIndex" in found) {
         registerBrowsers = this.registerPromise();
         browserListening = this.listeningPromise();
       }
 
       this.startBrowser(found.win, false /* isNewSession */);
 
       if (registerBrowsers && browserListening) {
         yield registerBrowsers;
         yield browserListening;
       }
     } else {
       utils.window = found.win;
       this.curBrowser = this.browsers[found.outerId];
 
-      if (found.contentId) {
-        this.curBrowser.switchToTab(found.tabIndex);
+      if ("tabIndex" in found) {
+        this.curBrowser.switchToTab(found.tabIndex, found.win);
       }
     }
   } else {
     throw new NoSuchWindowError(`Unable to locate window: ${switchTo}`);
   }
 };
 
 GeckoDriver.prototype.getActiveFrame = function(cmd, resp) {
@@ -3210,22 +3209,27 @@ BrowserObj.prototype.closeTab = function
  *      URI to open.
  */
 BrowserObj.prototype.addTab = function(uri) {
   return this.browser.addTab(uri, true);
 };
 
 /**
  * Re-sets this BrowserObject's current tab and updates remoteness tracking.
+ * If a window is provided, this BrowserObj's internal reference is updated
+ * before proceeding.
  */
-BrowserObj.prototype.switchToTab = function(ind) {
-  if (this.browser) {
-    this.browser.selectTabAtIndex(ind);
-    this.tab = this.browser.selectedTab;
+BrowserObj.prototype.switchToTab = function(ind, win) {
+  if (win) {
+    this.window = win;
+    this.setBrowser(win);
   }
+
+  this.browser.selectTabAtIndex(ind);
+  this.tab = this.browser.selectedTab;
   this._browserWasRemote = this.browserForTab.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.