Bug 1138638 - Make Loop's browser sharing work properly in e10s mode and enable the mochitest. r=mikedeboer
authorMark Banner <standard8@mozilla.com>
Thu, 31 Mar 2016 12:12:21 +0100
changeset 291399 a1df259b9ea322baaff78eeafa3bbf7b5f366e8b
parent 291398 9b5113e833ff005d4845e88d8de1041985a8c5c7
child 291400 320b39130851d20d0f4dd654e1b6f8f322c686fb
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1138638
milestone48.0a1
Bug 1138638 - Make Loop's browser sharing work properly in e10s mode and enable the mochitest. r=mikedeboer
browser/extensions/loop/bootstrap.js
browser/extensions/loop/chrome/test/mochitest/browser.ini
browser/extensions/loop/chrome/test/mochitest/browser_mozLoop_sharingListeners.js
--- a/browser/extensions/loop/bootstrap.js
+++ b/browser/extensions/loop/bootstrap.js
@@ -531,18 +531,29 @@ var WindowListener = {
           // it for each individual tab's browsers.
           gBrowser.addEventListener("mousemove", this);
           gBrowser.addEventListener("click", this);
         }
 
         this._maybeShowBrowserSharingInfoBar();
 
         // Get the first window Id for the listener.
-        this.LoopAPI.broadcastPushMessage("BrowserSwitch",
-          gBrowser.selectedBrowser.outerWindowID);
+        let browser = gBrowser.selectedBrowser;
+        return new Promise(resolve => {
+          if (browser.outerWindowID) {
+            resolve(browser.outerWindowID);
+            return;
+          }
+
+          browser.messageManager.addMessageListener("Browser:Init", function initListener() {
+            browser.messageManager.removeMessageListener("Browser:Init", initListener);
+            resolve(browser.outerWindowID);
+          });
+        }).then(outerWindowID =>
+          this.LoopAPI.broadcastPushMessage("BrowserSwitch", outerWindowID));
       },
 
       /**
        * Stop listening to selected tab changes.
        */
       stopBrowserSharing: function() {
         if (!this._listeningToTabSelect) {
           return;
--- a/browser/extensions/loop/chrome/test/mochitest/browser.ini
+++ b/browser/extensions/loop/chrome/test/mochitest/browser.ini
@@ -9,11 +9,10 @@ support-files =
 [browser_loop_fxa_server.js]
 [browser_LoopRooms_channel.js]
 [browser_menuitem.js]
 [browser_mozLoop_appVersionInfo.js]
 [browser_mozLoop_chat.js]
 [browser_mozLoop_context.js]
 [browser_mozLoop_socialShare.js]
 [browser_mozLoop_sharingListeners.js]
-skip-if = e10s
 [browser_mozLoop_telemetry.js]
 [browser_toolbarbutton.js]
--- a/browser/extensions/loop/chrome/test/mochitest/browser_mozLoop_sharingListeners.js
+++ b/browser/extensions/loop/chrome/test/mochitest/browser_mozLoop_sharingListeners.js
@@ -46,20 +46,26 @@ function* promiseWindowIdReceivedNewTab(
   for (let handler of handlersParam) {
     handler.windowId = windowId;
   }
 }
 
 function promiseNewTabLocation() {
   BrowserOpenTab();
   let tab = gBrowser.selectedTab;
+  let browser = tab.linkedBrowser;
   createdTabs.push(tab);
 
-  // Have the tab's content process pass back its location as a promise
-  return ContentTask.spawn(tab.linkedBrowser, null, () => content.location.href);
+  // If we're already loaded, then just get the location.
+  if (browser.contentDocument.readyState === "complete") {
+    return ContentTask.spawn(browser, null, () => content.location.href);
+  }
+
+  // Otherwise, wait for the load to complete.
+  return BrowserTestUtils.browserLoaded(browser);
 }
 
 function promiseRemoveTab(tab) {
   return new Promise(resolve => {
     gBrowser.tabContainer.addEventListener("TabClose", function onTabClose() {
       gBrowser.tabContainer.removeEventListener("TabClose", onTabClose);
       resolve();
     });
@@ -195,16 +201,17 @@ add_task(function* test_infoBar() {
 add_task(function* test_newtabLocation() {
   // Check location before sharing
   let locationBeforeSharing = yield promiseNewTabLocation();
   Assert.equal(locationBeforeSharing, "about:newtab");
 
   // Check location after sharing
   yield promiseWindowIdReceivedOnAdd(handlers[0]);
   let locationAfterSharing = yield promiseNewTabLocation();
+  info("Location after sharing: " + locationAfterSharing);
   Assert.ok(locationAfterSharing.match(/about:?home/));
 
   // Check location after stopping sharing
   gHandlers.RemoveBrowserSharingListener({ data: [listenerIds.pop()] }, function() {});
   let locationAfterStopping = yield promiseNewTabLocation();
   Assert.equal(locationAfterStopping, "about:newtab");
 
   yield removeTabs();