Bug 1169600 - Remove message listeners intended to coordinate registering a new browser with marionette once the browser has been registered. r=ato
authorChris Manchester <cmanchester@mozilla.com>
Wed, 24 Jun 2015 00:10:10 -0700
changeset 280857 affd99e9228e6c04ce9c69e0501d8bdec7fb8a9a
parent 280856 5cf6909e84691a9c932333e1e5b72dabfe4f8809
child 280858 4267b74ee795e8127ffce4d45d00384cd8170130
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1169600
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1169600 - Remove message listeners intended to coordinate registering a new browser with marionette once the browser has been registered. r=ato
testing/marionette/client/marionette/tests/unit/test_about_pages.py
testing/marionette/driver.js
--- a/testing/marionette/client/marionette/tests/unit/test_about_pages.py
+++ b/testing/marionette/client/marionette/tests/unit/test_about_pages.py
@@ -1,49 +1,31 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 from marionette_driver.keys import Keys
+from marionette_driver.by import By
 
 class TestAboutPages(MarionetteTestCase):
 
     def setUp(self):
         MarionetteTestCase.setUp(self)
 
         if self.marionette.session_capabilities['platformName'] == 'DARWIN':
             self.mod_key = Keys.META
         else:
             self.mod_key = Keys.CONTROL
 
         self.remote_uri = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(self.remote_uri)
 
-    def purge_history(self):
-        with self.marionette.using_context("chrome"):
-            self.marionette.execute_script("""
-              let sh = gBrowser.webNavigation.sessionHistory;
-              if (sh.count) {
-                sh.PurgeHistory(sh.count - 1);
-              }
-            """)
-            self.wait_for_condition(
-                lambda mn: mn.execute_script("""
-                  return gBrowser.webNavigation.sessionHistory.count === 1;
-                """))
-
     def test_back_forward(self):
         self.marionette.navigate("about:blank")
-
-        # Something about this sequence goes wrong when run in a tab with a lot
-        # of history (you have to "go_back" twice to get back to the remote
-        # uri). Running in a tab with less history effectively works around
-        # this. This is reproducible without marionette, filed as bug 1134518.
-        self.purge_history()
         self.marionette.navigate(self.remote_uri)
 
         self.marionette.navigate("about:preferences")
 
         self.marionette.go_back()
 
         self.wait_for_condition(
             lambda mn: mn.get_url() == self.remote_uri)
@@ -85,8 +67,25 @@ class TestAboutPages(MarionetteTestCase)
         self.marionette.navigate("about:preferences")
         with self.marionette.using_context("chrome"):
             urlbar = self.marionette.find_element('id', 'urlbar')
             urlbar.send_keys(self.mod_key + 'a')
             urlbar.send_keys(self.mod_key + 'x')
             urlbar.send_keys(self.remote_uri + Keys.ENTER)
 
         self.wait_for_condition(lambda mn: mn.get_url() == self.remote_uri)
+
+    def test_hang(self):
+        self.marionette.set_context('chrome')
+        initial_tab = self.marionette.window_handles[0]
+
+        # Open a new tab and close the first one
+        new_tab = self.marionette.find_element(By.ID, 'menu_newNavigatorTab')
+        new_tab.click()
+
+        new_tab = [handle for handle in self.marionette.window_handles if
+                   handle != initial_tab][0]
+
+        self.marionette.close()
+        self.marionette.switch_to_window(new_tab)
+
+        with self.marionette.using_context('content'):
+            self.marionette.navigate(self.remote_uri)
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -460,43 +460,45 @@ GeckoDriver.prototype.registerBrowser = 
 
   return [reg, mainContent];
 };
 
 GeckoDriver.prototype.registerPromise = function() {
   const li = "Marionette:register";
 
   return new Promise((resolve) => {
-    this.mm.addMessageListener(li, function cb(msg) {
+    let cb = (msg) => {
       let wid = msg.json.value;
       let be = msg.target;
       let rv = this.registerBrowser(wid, be);
 
       if (this.curBrowser.frameRegsPending > 0) {
         this.curBrowser.frameRegsPending--;
       }
 
       if (this.curBrowser.frameRegsPending === 0) {
         this.mm.removeMessageListener(li, cb);
         resolve();
       }
 
       // this is a sync message and listeners expect the ID back
       return rv;
-    }.bind(this));
+    };
+    this.mm.addMessageListener(li, cb);
   });
 };
 
 GeckoDriver.prototype.listeningPromise = function() {
   const li = "Marionette:listenersAttached";
   return new Promise((resolve) => {
-    this.mm.addMessageListener(li, function() {
-      this.mm.removeMessageListener(li, this);
+    let cb = () => {
+      this.mm.removeMessageListener(li, cb);
       resolve();
-    }.bind(this));
+    };
+    this.mm.addMessageListener(li, cb);
   });
 };
 
 /** Create a new session. */
 GeckoDriver.prototype.newSession = function(cmd, resp) {
   this.sessionId = cmd.parameters.sessionId ||
       cmd.parameters.session_id ||
       uuidGen.generateUUID().toString();
@@ -3179,18 +3181,17 @@ BrowserObj.prototype.register = function
 /**
  * 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.
  */
 BrowserObj.prototype.hasRemotenessChange = function() {
   // 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 ||
-      !this.browserForTab) {
+  if (this.driver.appName != "Firefox" || this.tab === null) {
     return false;
   }
 
   if (this._hasRemotenessChange) {
     return true;
   }
 
   let currentIsRemote = this.browserForTab.isRemoteBrowser;