Bug 1472212 - Make some tests wait longer before navigating to about:home or about:newtab.
This is necessary because both about:home and about:newtab run in the privileged
content process, but existing tests rely on the fact that both of those pages
run in the web content process, ignoring the process flip. This commit waits for
the process flip to occur first before waiting for content-related events.
MozReview-Commit-ID: BCI9iMPewZ5
--- a/browser/base/content/test/about/browser_aboutCertError.js
+++ b/browser/base/content/test/about/browser_aboutCertError.js
@@ -67,19 +67,19 @@ add_task(async function checkReturnToAbo
await ContentTask.spawn(browser, {frame: useFrame}, async function({frame}) {
let doc = frame ? content.document.querySelector("iframe").contentDocument : content.document;
let returnButton = doc.getElementById("returnButton");
if (!frame) {
is(returnButton.getAttribute("autofocus"), "true", "returnButton has autofocus");
}
returnButton.click();
+ });
- await ContentTaskUtils.waitForEvent(this, "pageshow", true);
- });
+ await BrowserTestUtils.waitForLocationChange(gBrowser, "about:home");
is(browser.webNavigation.canGoBack, true, "webNavigation.canGoBack");
is(browser.webNavigation.canGoForward, false, "!webNavigation.canGoForward");
is(gBrowser.currentURI.spec, "about:home", "Went back");
BrowserTestUtils.removeTab(gBrowser.selectedTab);
}
});
--- a/browser/base/content/test/about/head.js
+++ b/browser/base/content/test/about/head.js
@@ -124,27 +124,45 @@ function waitForDocLoadAndStopIt(aExpect
*/
addEventListener("unload", function() {
try {
wp.removeProgressListener(progressListener);
} catch (e) { /* Will most likely fail. */ }
});
}
+ // We are deferring the setup of this promise because there is a possibility
+ // that a process flip will occur.
+ let promise = () => {
+ return new Promise((resolve, reject) => {
+ function complete({ data }) {
+ is(data.uri, aExpectedURL, "waitForDocLoadAndStopIt: The expected URL was loaded");
+ mm.removeMessageListener("Test:WaitForDocLoadAndStopIt", complete);
+ resolve();
+ }
+
+ let mm = aBrowser.messageManager;
+ mm.loadFrameScript("data:,(" + content_script.toString() + ")(" + aStopFromProgressListener + ");", true);
+ mm.addMessageListener("Test:WaitForDocLoadAndStopIt", complete);
+ info("waitForDocLoadAndStopIt: Waiting for URL: " + aExpectedURL);
+ });
+ };
+
+ let win = aBrowser.ownerGlobal;
+ let tab = win.gBrowser.getTabForBrowser(aBrowser);
+ if (!tab ||
+ !win.gMultiProcessBrowser ||
+ E10SUtils.canLoadURIInRemoteType(aExpectedURL, aBrowser.remoteType)) {
+ return promise();
+ }
+
return new Promise((resolve, reject) => {
- function complete({ data }) {
- is(data.uri, aExpectedURL, "waitForDocLoadAndStopIt: The expected URL was loaded");
- mm.removeMessageListener("Test:WaitForDocLoadAndStopIt", complete);
- resolve();
- }
-
- let mm = aBrowser.messageManager;
- mm.loadFrameScript("data:,(" + content_script.toString() + ")(" + aStopFromProgressListener + ");", true);
- mm.addMessageListener("Test:WaitForDocLoadAndStopIt", complete);
- info("waitForDocLoadAndStopIt: Waiting for URL: " + aExpectedURL);
+ tab.addEventListener("TabRemotenessChange", function() {
+ promise().then(resolve, reject);
+ }, {once: true});
});
}
/**
* Wait for the search engine to change.
*/
function promiseContentSearchChange(browser, newEngineName) {
return ContentTask.spawn(browser, { newEngineName }, async function(args) {
--- a/browser/base/content/test/general/browser_bug724239.js
+++ b/browser/base/content/test/general/browser_bug724239.js
@@ -8,17 +8,25 @@ add_task(async function test_blank() {
await BrowserTestUtils.browserLoaded(browser);
ok(!gBrowser.canGoBack, "about:blank wasn't added to session history");
});
});
add_task(async function test_newtab() {
await BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" },
async function(browser) {
+ let tab = gBrowser.getTabForBrowser(browser);
+
// Can't load it directly because that'll use a preloaded tab if present.
BrowserTestUtils.loadURI(browser, "about:newtab");
- await BrowserTestUtils.browserLoaded(browser);
+ await BrowserTestUtils.waitForEvent(tab, "TabRemotenessChange");
+ // We will need to wait for about:newtab to be loaded so that it goes into
+ // the session history.
+ await BrowserTestUtils.browserLoaded(browser, false, "about:newtab");
BrowserTestUtils.loadURI(browser, "http://example.com");
- await BrowserTestUtils.browserLoaded(browser);
+ // We will need to ensure that the process flip has fully completed so that
+ // the navigation history data will be available when we do gBrowser.canGoBack.
+ await BrowserTestUtils.waitForEvent(tab, "SSTabRestored");
+ await BrowserTestUtils.browserLoaded(browser, false, "http://example.com/");
is(gBrowser.canGoBack, true, "about:newtab was added to the session history when AS was enabled.");
});
});
--- a/browser/base/content/test/general/browser_e10s_chrome_process.js
+++ b/browser/base/content/test/general/browser_e10s_chrome_process.js
@@ -10,22 +10,22 @@ function makeTest(name, startURL, startP
if (!gMultiProcessBrowser) {
startProcessIsRemote = false;
endProcessIsRemote = false;
}
// Load the initial URL and make sure we are in the right initial process
info("Loading initial URL");
browser.loadURI(startURL);
- await BrowserTestUtils.browserLoaded(browser);
+ await BrowserTestUtils.browserLoaded(browser, false, startURL);
is(browser.currentURI.spec, startURL, "Shouldn't have been redirected");
is(browser.isRemoteBrowser, startProcessIsRemote, "Should be displayed in the right process");
- let docLoadedPromise = BrowserTestUtils.browserLoaded(browser);
+ let docLoadedPromise = BrowserTestUtils.browserLoaded(browser, false, endURL);
let expectSyncChange = await transitionTask(browser, endURL);
if (expectSyncChange) {
is(browser.isRemoteBrowser, endProcessIsRemote, "Should have switched to the right process synchronously");
}
await docLoadedPromise;
is(browser.currentURI.spec, endURL, "Should have made it to the final URL");
is(browser.isRemoteBrowser, endProcessIsRemote, "Should be displayed in the right process");
--- a/browser/modules/test/browser/browser_UsageTelemetry_content_aboutHome.js
+++ b/browser/modules/test/browser/browser_UsageTelemetry_content_aboutHome.js
@@ -43,31 +43,36 @@ add_task(async function setup() {
add_task(async function test_abouthome_activitystream_simpleQuery() {
// Let's reset the counts.
Services.telemetry.clearScalars();
Services.telemetry.clearEvents();
let search_hist = getAndClearKeyedHistogram("SEARCH_COUNTS");
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
- info("Setup waiting for search input to initialise.");
- let promiseAboutHomeSearchLoaded = BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, "ContentSearchClient", true, null, true).then(() => false);
+ let searchClientPromise = new Promise(resolve => {
+ tab.addEventListener("TabRemotenessChange", function() {
+ BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, "ContentSearchClient", true, null, true).then(resolve);
+ }, {once: true});
+ });
info("Load about:home.");
tab.linkedBrowser.loadURI("about:home");
+ await BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, "about:home");
+
info("Wait for ActivityStream search input.");
- await promiseAboutHomeSearchLoaded;
+ await searchClientPromise;
info("Wait for ContentSearchUI search provider to initialize.");
await ContentTask.spawn(tab.linkedBrowser, null, async function() {
await ContentTaskUtils.waitForCondition(() => content.wrappedJSObject.gContentSearchController.defaultEngine);
});
- info("Trigger a simple serch, just test + enter.");
- let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ info("Trigger a simple search, just test + enter.");
+ let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, "http://example.com/?q=test+query");
await typeInSearchField(tab.linkedBrowser, "test query", "newtab-search-text");
await BrowserTestUtils.synthesizeKey("VK_RETURN", {}, tab.linkedBrowser);
await p;
// Check if the scalars contain the expected values.
const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, false);
checkKeyedScalar(scalars, SCALAR_ABOUT_HOME, "search_enter", 1);
Assert.equal(Object.keys(scalars[SCALAR_ABOUT_HOME]).length, 1,