Bug 1167508 - Fix tests that expect a sync remoteness change after calling .loadURI() r=billm

This commit is contained in:
Tim Taubert 2015-06-09 22:11:58 +02:00
parent 9127c398c7
commit c1ae08df38
9 changed files with 67 additions and 12 deletions

View File

@ -122,7 +122,7 @@ 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;
},

View File

@ -197,7 +197,7 @@ add_task(function* test_synchronous() {
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");
@ -208,7 +208,7 @@ add_task(function* test_synchronous() {
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");

View File

@ -26,7 +26,7 @@ function frame_script() {
*/
function prepareNonRemoteBrowser(aWindow, browser) {
browser.loadURI(NON_REMOTE_PAGE);
return waitForDocLoadComplete(browser);
return BrowserTestUtils.browserLoaded(browser);
}
registerCleanupFunction(() => {

View File

@ -10,7 +10,9 @@ const kTimeoutInMS = 20000;
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");
@ -30,7 +32,7 @@ add_task(function() {
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");
@ -52,6 +54,7 @@ add_task(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) {

View File

@ -162,7 +162,7 @@ add_task(function* save_worthy_tabs_nonremote_final() {
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.

View File

@ -12,8 +12,10 @@ add_task(function test_load_start() {
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);

View File

@ -428,8 +428,21 @@ function whenNewWindowLoaded(aOptions, aCallback) {
}
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));

View File

@ -138,7 +138,7 @@ let restart = Task.async(function*() {
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;

View File

@ -28,6 +28,9 @@ Cc["@mozilla.org/globalmessagemanager;1"]
.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.
@ -150,6 +153,40 @@ this.BrowserTestUtils = {
});
},
/**
* 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