Bug 1167508 - Fix tests that expect a sync remoteness change after calling .loadURI() r=billm
☠☠ backed out by 986f641d87e4 ☠ ☠
authorTim Taubert <ttaubert@mozilla.com>
Sat, 23 May 2015 15:47:56 +0200
changeset 248033 97b5372b89506a986eb23f13e91e2ded2ac4e87d
parent 248032 00eb943a27b21e92204c525a656c59ec17e3c50e
child 248034 5080433ff6105dcd9b2280319a99406c349af245
push id60888
push userkwierso@gmail.com
push dateThu, 11 Jun 2015 01:38:38 +0000
treeherdermozilla-inbound@39e638ed06bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1167508
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 1167508 - Fix tests that expect a sync remoteness change after calling .loadURI() r=billm
browser/base/content/test/general/browser_e10s_chrome_process.js
browser/base/content/test/general/browser_e10s_switchbrowser.js
browser/base/content/test/general/browser_testOpenNewRemoteTabsFromNonRemoteBrowsers.js
browser/components/customizableui/test/browser_934951_zoom_in_toolbar.js
browser/components/sessionstore/test/browser_async_remove_tab.js
browser/components/sessionstore/test/browser_sessionHistory.js
browser/components/sessionstore/test/head.js
netwerk/test/browser/browser_child_resource.js
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
--- a/browser/base/content/test/general/browser_e10s_chrome_process.js
+++ b/browser/base/content/test/general/browser_e10s_chrome_process.js
@@ -117,17 +117,17 @@ let TESTS = [
   ],
 ];
 
 // The different ways to transition from one page to another
 let TRANSITIONS = [
 // Loads the new page by calling browser.loadURI directly
 function* loadURI(browser, uri) {
   info("Calling browser.loadURI");
-  browser.loadURI(uri);
+  yield BrowserTestUtils.loadURI(browser, uri);
   return true;
 },
 
 // Loads the new page by finding a link with the right href in the document and
 // clicking it
 function* clickLink(browser, uri) {
   info("Clicking link");
 
--- a/browser/base/content/test/general/browser_e10s_switchbrowser.js
+++ b/browser/base/content/test/general/browser_e10s_switchbrowser.js
@@ -192,28 +192,28 @@ add_task(function* test_synchronous() {
   let {permanentKey} = gBrowser.selectedBrowser;
   yield waitForLoad("http://example.org/" + DUMMY_PATH);
   is(gBrowser.selectedBrowser.isRemoteBrowser, expectedRemote, "Remote attribute should be correct");
   is(gBrowser.selectedBrowser.permanentKey, permanentKey, "browser.permanentKey is still the same");
 
   info("2");
   // Load another page
   info("Loading about:robots");
-  gBrowser.selectedBrowser.loadURI("about:robots");
+  yield BrowserTestUtils.loadURI(gBrowser.selectedBrowser, "about:robots");
   is(gBrowser.selectedBrowser.isRemoteBrowser, false, "Remote attribute should be correct");
   is(gBrowser.selectedBrowser.permanentKey, permanentKey, "browser.permanentKey is still the same");
 
   yield waitForDocLoadComplete();
   is(gBrowser.selectedBrowser.isRemoteBrowser, false, "Remote attribute should be correct");
   is(gBrowser.selectedBrowser.permanentKey, permanentKey, "browser.permanentKey is still the same");
 
   info("3");
   // Load the remote page again
   info("Loading http://example.org/" + DUMMY_PATH);
-  gBrowser.loadURI("http://example.org/" + DUMMY_PATH);
+  yield BrowserTestUtils.loadURI(gBrowser.selectedBrowser, "http://example.org/" + DUMMY_PATH);
   is(gBrowser.selectedBrowser.isRemoteBrowser, expectedRemote, "Remote attribute should be correct");
   is(gBrowser.selectedBrowser.permanentKey, permanentKey, "browser.permanentKey is still the same");
 
   yield waitForDocLoadComplete();
   is(gBrowser.selectedBrowser.isRemoteBrowser, expectedRemote, "Remote attribute should be correct");
   is(gBrowser.selectedBrowser.permanentKey, permanentKey, "browser.permanentKey is still the same");
 
   info("4");
--- a/browser/base/content/test/general/browser_testOpenNewRemoteTabsFromNonRemoteBrowsers.js
+++ b/browser/base/content/test/general/browser_testOpenNewRemoteTabsFromNonRemoteBrowsers.js
@@ -21,17 +21,17 @@ function frame_script() {
 /**
  * Takes some browser in some window, and forces that browser
  * to become non-remote, and then navigates it to a page that
  * we're not supposed to be displaying remotely. Returns a
  * Promise that resolves when the browser is no longer remote.
  */
 function prepareNonRemoteBrowser(aWindow, browser) {
   browser.loadURI(NON_REMOTE_PAGE);
-  return waitForDocLoadComplete(browser);
+  return BrowserTestUtils.browserLoaded(browser);
 }
 
 registerCleanupFunction(() => {
   Services.prefs.clearUserPref(OPEN_LOCATION_PREF);
 });
 
 /**
  * Test that if we open a new tab from a link in a non-remote
--- a/browser/components/customizableui/test/browser_934951_zoom_in_toolbar.js
+++ b/browser/components/customizableui/test/browser_934951_zoom_in_toolbar.js
@@ -5,17 +5,19 @@
 "use strict";
 
 const kTimeoutInMS = 20000;
 
 // Bug 934951 - Zoom controls percentage label doesn't update when it's in the toolbar and you navigate.
 add_task(function() {
   CustomizableUI.addWidgetToArea("zoom-controls", CustomizableUI.AREA_NAVBAR);
   let tab1 = gBrowser.addTab("about:mozilla");
-  let tab2 = gBrowser.addTab("about:newtab");
+  yield BrowserTestUtils.browserLoaded(tab1.linkedBrowser);
+  let tab2 = gBrowser.addTab("about:robots");
+  yield BrowserTestUtils.browserLoaded(tab2.linkedBrowser);
   gBrowser.selectedTab = tab1;
   let zoomResetButton = document.getElementById("zoom-reset-button");
 
   registerCleanupFunction(() => {
     info("Cleaning up.");
     CustomizableUI.reset();
     gBrowser.removeTab(tab2);
     gBrowser.removeTab(tab1);
@@ -25,17 +27,17 @@ add_task(function() {
   let zoomChangePromise = promiseObserverNotification("browser-fullZoom:zoomChange");
   FullZoom.enlarge();
   yield zoomChangePromise;
   is(parseInt(zoomResetButton.label, 10), 110, "Zoom is changed to 110% for about:mozilla");
 
   let tabSelectPromise = promiseTabSelect();
   gBrowser.selectedTab = tab2;
   yield tabSelectPromise;
-  is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:newtab");
+  is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:robots");
 
   gBrowser.selectedTab = tab1;
   let zoomResetPromise = promiseObserverNotification("browser-fullZoom:zoomReset");
   FullZoom.reset();
   yield zoomResetPromise;
   is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:mozilla");
 
   // Test zoom label updates while navigating pages in the same tab.
@@ -47,16 +49,17 @@ add_task(function() {
   });
   yield promiseTabLoadEvent(tab1, "about:home");
   yield attributeChangePromise;
   is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:home");
   yield promiseTabHistoryNavigation(-1, function() {
     return parseInt(zoomResetButton.label, 10) == 110;
   });
   is(parseInt(zoomResetButton.label, 10), 110, "Zoom is still 110% for about:mozilla");
+  FullZoom.reset();
 });
 
 function promiseObserverNotification(aObserver) {
   let deferred = Promise.defer();
   function notificationCallback(e) {
     Services.obs.removeObserver(notificationCallback, aObserver, false);
     clearTimeout(timeoutId);
     deferred.resolve();
--- a/browser/components/sessionstore/test/browser_async_remove_tab.js
+++ b/browser/components/sessionstore/test/browser_async_remove_tab.js
@@ -157,17 +157,17 @@ add_task(function* save_worthy_tabs_remo
 });
 
 add_task(function* save_worthy_tabs_nonremote_final() {
   let {tab, r} = yield createTabWithRandomValue("about:blank");
   let browser = tab.linkedBrowser;
   ok(browser.isRemoteBrowser, "browser is remote");
 
   // Replace about:blank with a non-remote entry.
-  browser.loadURI("about:robots");
+  yield BrowserTestUtils.loadURI(browser, "about:robots");
   ok(!browser.isRemoteBrowser, "browser is not remote anymore");
 
   // Wait until the new entry replaces about:blank.
   yield promiseHistoryEntryReplacedNonRemote(browser);
 
   // Remove the tab before the update arrives.
   let promise = promiseRemoveTab(tab);
 
--- a/browser/components/sessionstore/test/browser_sessionHistory.js
+++ b/browser/components/sessionstore/test/browser_sessionHistory.js
@@ -7,18 +7,20 @@
  * Ensure that starting a load invalidates shistory.
  */
 add_task(function test_load_start() {
   // Create a new tab.
   let tab = gBrowser.addTab("about:blank");
   let browser = tab.linkedBrowser;
   yield promiseBrowserLoaded(browser);
 
-  // Load a new URI but remove the tab before it has finished loading.
-  browser.loadURI("about:mozilla");
+  // Load a new URI.
+  yield BrowserTestUtils.loadURI(browser, "about:mozilla");
+
+  // Remove the tab before it has finished loading.
   yield promiseContentMessage(browser, "ss-test:OnHistoryReplaceEntry");
   yield promiseRemoveTab(tab);
 
   // Undo close the tab.
   tab = ss.undoCloseTab(window, 0);
   browser = tab.linkedBrowser;
   yield promiseTabRestored(tab);
 
--- a/browser/components/sessionstore/test/head.js
+++ b/browser/components/sessionstore/test/head.js
@@ -423,18 +423,31 @@ function whenNewWindowLoaded(aOptions, a
   let url = "about:blank";
 
   if (aOptions && aOptions.private || false) {
     features = ",private";
     url = "about:privatebrowsing";
   }
 
   let win = openDialog(getBrowserURL(), "", "chrome,all,dialog=no" + features, url);
-  whenDelayedStartupFinished(win, () => aCallback(win));
-  return win;
+  let delayedStartup = promiseDelayedStartupFinished(win);
+
+  let browserLoaded = new Promise(resolve => {
+    if (url == "about:blank") {
+      resolve();
+      return;
+    }
+
+    win.addEventListener("load", function onLoad() {
+      win.removeEventListener("load", onLoad);
+      resolve(promiseBrowserLoaded(win.gBrowser.selectedBrowser));
+    });
+  });
+
+  Promise.all([delayedStartup, browserLoaded]).then(() => aCallback(win));
 }
 function promiseNewWindowLoaded(aOptions) {
   return new Promise(resolve => whenNewWindowLoaded(aOptions, resolve));
 }
 
 /**
  * Chrome windows aren't closed synchronously. Provide a helper method to close
  * a window and wait until we received the "domwindowclosed" notification for it.
--- a/netwerk/test/browser/browser_child_resource.js
+++ b/netwerk/test/browser/browser_child_resource.js
@@ -133,17 +133,17 @@ let restart = Task.async(function*() {
   if (browser.getAttribute("remote") != "true")
     return browser;
 
   browser.messageManager.sendAsyncMessage("Test:Crash");
   yield waitForEvent(browser, "AboutTabCrashedLoad", false, true);
 
   browser.reload();
 
-  yield waitForEvent(browser, "load", true);
+  yield BrowserTestUtils.browserLoaded(browser);
   is(browser.getAttribute("remote"), expectedRemote, "Browser should be in the right process");
   browser.messageManager.loadFrameScript("data:,(" + frameScript.toString() + ")();", true);
   return browser;
 });
 
 // Sanity check that this test is going to be useful
 add_task(function*() {
   let browser = yield loadTestTab();
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -23,16 +23,19 @@ Cu.import("resource://gre/modules/Task.j
 Cu.import("resource://gre/modules/Timer.jsm");
 Cu.import("resource://testing-common/TestUtils.jsm");
 
 Cc["@mozilla.org/globalmessagemanager;1"]
   .getService(Ci.nsIMessageListenerManager)
   .loadFrameScript(
     "chrome://mochikit/content/tests/BrowserTestUtils/content-utils.js", true);
 
+XPCOMUtils.defineLazyModuleGetter(this, "E10SUtils",
+  "resource:///modules/E10SUtils.jsm");
+
 this.BrowserTestUtils = {
   /**
    * Loads a page in a new tab, executes a Task and closes the tab.
    *
    * @param options
    *        An object with the following properties:
    *        {
    *          gBrowser:
@@ -146,16 +149,50 @@ this.BrowserTestUtils = {
           mm.removeMessageListener("browser-test-utils:loadEvent", onLoad);
           resolve();
         }
       });
     });
   },
 
   /**
+   * Loads a new URI in the given browser and waits until we really started
+   * loading. In e10s browser.loadURI() can be an asynchronous operation due
+   * to having to switch the browser's remoteness and keep its shistory data.
+   *
+   * @param {xul:browser} browser
+   *        A xul:browser.
+   * @param {string} uri
+   *        The URI to load.
+   *
+   * @return {Promise}
+   * @resolves When we started loading the given URI.
+   */
+  loadURI: Task.async(function* (browser, uri) {
+    // Load the new URI.
+    browser.loadURI(uri);
+
+    // Nothing to do in non-e10s mode.
+    if (!browser.ownerDocument.defaultView.gMultiProcessBrowser) {
+      return;
+    }
+
+    // Retrieve the given browser's current process type.
+    let process = browser.isRemoteBrowser ? Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT
+                                          : Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
+
+    // If the new URI can't load in the browser's current process then we
+    // should wait for the new frameLoader to be created. This will happen
+    // asynchronously when the browser's remoteness changes.
+    if (!E10SUtils.canLoadURIInProcess(uri, process)) {
+      yield this.waitForEvent(browser, "XULFrameLoaderCreated");
+    }
+  }),
+
+  /**
    * @return {Promise}
    *         A Promise which resolves when a "domwindowopened" notification
    *         has been fired by the window watcher.
    */
   domWindowOpened() {
     return new Promise(resolve => {
       function observer(subject, topic, data) {
         if (topic != "domwindowopened") { return; }