Bug 1471243 - Do not prerender ActivityStream for about:welcome r=k88hudson

MozReview-Commit-ID: IDyWGnuMndy

--HG--
extra : rebase_source : bd20b556d7680624113696f2caeecf8a6e8bd51e
This commit is contained in:
ahillier 2018-07-09 15:11:03 -07:00
Родитель 638dfe2577
Коммит ee9dbcb8e0
4 изменённых файлов: 55 добавлений и 2 удалений

Просмотреть файл

@ -167,8 +167,7 @@ AboutRedirector::NewChannel(nsIURI* aURI,
// Let the aboutNewTabService decide where to redirect for about:home and
// enabled about:newtab. Disabledx about:newtab page uses fallback.
if (path.EqualsLiteral("home") ||
(sNewTabPageEnabled && path.EqualsLiteral("newtab")) ||
path.EqualsLiteral("welcome")) {
(sNewTabPageEnabled && path.EqualsLiteral("newtab"))) {
nsCOMPtr<nsIAboutNewTabService> aboutNewTabService =
do_GetService("@mozilla.org/browser/aboutnewtab-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
@ -176,6 +175,14 @@ AboutRedirector::NewChannel(nsIURI* aURI,
NS_ENSURE_SUCCESS(rv, rv);
}
if (path.EqualsLiteral("welcome")) {
nsCOMPtr<nsIAboutNewTabService> aboutNewTabService =
do_GetService("@mozilla.org/browser/aboutnewtab-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = aboutNewTabService->GetWelcomeURL(url);
NS_ENSURE_SUCCESS(rv, rv);
}
if (sNewCertErrorPageEnabled && path.EqualsLiteral("certerror")) {
url.AssignASCII("chrome://browser/content/aboutNetError-new.xhtml");
}

Просмотреть файл

@ -258,6 +258,20 @@ AboutNewTabService.prototype = {
].join("");
},
/*
* Returns the about:welcome URL
*
* This is calculated in the same way the default URL is, except that we don't
* allow prerendering.
*/
get welcomeURL() {
const prerenderEnabled = this._activityStreamPrerender;
this._activityStreamPrerender = false;
const url = this.defaultURL;
this._activityStreamPrerender = prerenderEnabled;
return url;
},
get newTabURL() {
return this._newTabURL;
},

Просмотреть файл

@ -23,6 +23,11 @@ interface nsIAboutNewTabService : nsISupports
*/
attribute ACString defaultURL;
/**
* Returns the about:welcome URL.
*/
attribute ACString welcomeURL;
/**
* Returns true if opening the New Tab page will notify the user of a change.
*/

Просмотреть файл

@ -129,6 +129,33 @@ add_task(async function test_default_url() {
cleanup();
});
add_task(async function test_welcome_url() {
await setupASPrerendered();
Assert.equal(aboutNewTabService.activityStreamPrerender, true,
"Prerendering is enabled by default.");
Assert.equal(aboutNewTabService.welcomeURL, ACTIVITY_STREAM_URL,
"Newtab welcomeURL set to un-prerendered AS when prerendering enabled and debug disabled.");
await setBoolPrefAndWaitForChange(ACTIVITY_STREAM_PRERENDER_PREF, false,
"A notification occurs after changing the prerender pref to false.");
Assert.equal(aboutNewTabService.welcomeURL, aboutNewTabService.defaultURL,
"Newtab welcomeURL is equal to defaultURL when prerendering disabled and debug disabled.");
// Only debug variants aren't available on release/beta
if (!IS_RELEASE_OR_BETA) {
await setBoolPrefAndWaitForChange(ACTIVITY_STREAM_DEBUG_PREF, true,
"A notification occurs after changing the debug pref to true.");
Assert.equal(aboutNewTabService.welcomeURL, aboutNewTabService.welcomeURL,
"Newtab welcomeURL is equal to defaultURL when prerendering disabled and debug enabled.");
await setBoolPrefAndWaitForChange(ACTIVITY_STREAM_PRERENDER_PREF, true,
"A notification occurs after changing the prerender pref to true.");
Assert.equal(aboutNewTabService.welcomeURL, ACTIVITY_STREAM_DEBUG_URL,
"Newtab welcomeURL set to un-prerendered debug AS when prerendering enabled and debug enabled");
}
cleanup();
});
add_task(function test_locale() {
Assert.equal(aboutNewTabService.activityStreamLocale, "en-US",
"The locale for testing should be en-US");