Bug 1555390 - Remove prerendering in AboutNewTabService (#5078)

* Bug 1555390 - Remove prerendering in AboutNewTabService

* mochitest fix
This commit is contained in:
punamdahiya 2019-05-29 14:24:42 -07:00 коммит произвёл GitHub
Родитель ec29d528e2
Коммит 3910c0deb2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 16 добавлений и 87 удалений

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

@ -31,14 +31,12 @@ const IS_PRIVILEGED_PROCESS = Services.appinfo.remoteType === E10SUtils.PRIVILEG
const IS_RELEASE_OR_BETA = AppConstants.RELEASE_OR_BETA;
const PREF_SEPARATE_PRIVILEGEDABOUT_CONTENT_PROCESS = "browser.tabs.remote.separatePrivilegedContentProcess";
const PREF_ACTIVITY_STREAM_PRERENDER_ENABLED = "browser.newtabpage.activity-stream.prerender";
const PREF_ACTIVITY_STREAM_DEBUG = "browser.newtabpage.activity-stream.debug";
function AboutNewTabService() {
Services.obs.addObserver(this, TOPIC_APP_QUIT);
Services.obs.addObserver(this, TOPIC_LOCALES_CHANGE);
Services.prefs.addObserver(PREF_SEPARATE_PRIVILEGEDABOUT_CONTENT_PROCESS, this);
Services.prefs.addObserver(PREF_ACTIVITY_STREAM_PRERENDER_ENABLED, this);
if (!IS_RELEASE_OR_BETA) {
Services.prefs.addObserver(PREF_ACTIVITY_STREAM_DEBUG, this);
}
@ -90,7 +88,6 @@ AboutNewTabService.prototype = {
_newTabURL: ABOUT_URL,
_activityStreamEnabled: false,
_activityStreamPrerender: false,
_activityStreamPath: "",
_activityStreamDebug: false,
_privilegedAboutContentProcess: false,
@ -110,9 +107,6 @@ AboutNewTabService.prototype = {
this._privilegedAboutContentProcess = Services.prefs.getBoolPref(PREF_SEPARATE_PRIVILEGEDABOUT_CONTENT_PROCESS);
this.updatePrerenderedPath();
this.notifyChange();
} else if (data === PREF_ACTIVITY_STREAM_PRERENDER_ENABLED) {
this._activityStreamPrerender = Services.prefs.getBoolPref(PREF_ACTIVITY_STREAM_PRERENDER_ENABLED);
this.notifyChange();
} else if (!IS_RELEASE_OR_BETA && data === PREF_ACTIVITY_STREAM_DEBUG) {
this._activityStreamDebug = Services.prefs.getBoolPref(PREF_ACTIVITY_STREAM_DEBUG, false);
this.updatePrerenderedPath();
@ -158,10 +152,6 @@ AboutNewTabService.prototype = {
`${BASE_URL}data/content/activity-stream.bundle.js`,
];
if (this._activityStreamPrerender) {
scripts.unshift(`${BASE_URL}prerendered/static/activity-stream-initial-state.js`);
}
for (let script of scripts) {
Services.scriptloader.loadSubScript(script, win); // Synchronous call
}
@ -217,7 +207,6 @@ AboutNewTabService.prototype = {
this._activityStreamEnabled = false;
}
this._privilegedAboutContentProcess = Services.prefs.getBoolPref(PREF_SEPARATE_PRIVILEGEDABOUT_CONTENT_PROCESS);
this._activityStreamPrerender = Services.prefs.getBoolPref(PREF_ACTIVITY_STREAM_PRERENDER_ENABLED);
if (!IS_RELEASE_OR_BETA) {
this._activityStreamDebug = Services.prefs.getBoolPref(PREF_ACTIVITY_STREAM_DEBUG, false);
}
@ -245,13 +234,11 @@ AboutNewTabService.prototype = {
get defaultURL() {
// Generate the desired activity stream resource depending on state, e.g.,
// resource://activity-stream/prerendered/ar/activity-stream.html
// resource://activity-stream/prerendered/en-US/activity-stream-prerendered.html
// resource://activity-stream/prerendered/static/activity-stream-debug.html
return [
"resource://activity-stream/prerendered/",
this._activityStreamPath,
"activity-stream",
this._activityStreamPrerender ? "-prerendered" : "",
// Debug version loads dev scripts but noscripts separately loads scripts
this._activityStreamDebug && !this._privilegedAboutContentProcess ? "-debug" : "",
this._privilegedAboutContentProcess ? "-noscripts" : "",
@ -262,15 +249,10 @@ AboutNewTabService.prototype = {
/*
* Returns the about:welcome URL
*
* This is calculated in the same way the default URL is, except that we don't
* allow prerendering.
* This is calculated in the same way the default URL is.
*/
get welcomeURL() {
const prerenderEnabled = this._activityStreamPrerender;
this._activityStreamPrerender = false;
const url = this.defaultURL;
this._activityStreamPrerender = prerenderEnabled;
return url;
return this.defaultURL;
},
get newTabURL() {
@ -301,10 +283,6 @@ AboutNewTabService.prototype = {
return this._activityStreamEnabled;
},
get activityStreamPrerender() {
return this._activityStreamPrerender;
},
get activityStreamDebug() {
return this._activityStreamDebug;
},
@ -352,7 +330,6 @@ AboutNewTabService.prototype = {
Services.obs.removeObserver(this, TOPIC_APP_QUIT);
Services.obs.removeObserver(this, TOPIC_LOCALES_CHANGE);
Services.prefs.removeObserver(PREF_SEPARATE_PRIVILEGEDABOUT_CONTENT_PROCESS, this);
Services.prefs.removeObserver(PREF_ACTIVITY_STREAM_PRERENDER_ENABLED, this);
if (!IS_RELEASE_OR_BETA) {
Services.prefs.removeObserver(PREF_ACTIVITY_STREAM_DEBUG, this);
}

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

@ -44,11 +44,6 @@ interface nsIAboutNewTabService : nsISupports
*/
readonly attribute bool activityStreamEnabled;
/**
* Returns true if the the prerendering pref for activity stream is true
*/
readonly attribute bool activityStreamPrerender;
/**
* Returns true if the the debug pref for activity stream is true
*/

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

@ -4,8 +4,8 @@ XPCOMUtils.defineLazyServiceGetter(this, "aboutNewTabService",
// Tests are by default run with non-debug en-US configuration
const DEFAULT_URL = SpecialPowers.getBoolPref("browser.tabs.remote.separatePrivilegedContentProcess") ?
"resource://activity-stream/prerendered/en-US/activity-stream-prerendered-noscripts.html" :
"resource://activity-stream/prerendered/en-US/activity-stream-prerendered.html";
"resource://activity-stream/prerendered/en-US/activity-stream-noscripts.html" :
"resource://activity-stream/prerendered/en-US/activity-stream.html";
/**
* Temporarily change the app locale to get the localized activity stream url

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

@ -15,36 +15,28 @@ const IS_RELEASE_OR_BETA = AppConstants.RELEASE_OR_BETA;
const DOWNLOADS_URL = "chrome://browser/content/downloads/contentAreaDownloadsView.xul";
const SEPARATE_PRIVILEGED_CONTENT_PROCESS_PREF = "browser.tabs.remote.separatePrivilegedContentProcess";
const ACTIVITY_STREAM_PRERENDER_PREF = "browser.newtabpage.activity-stream.prerender";
const ACTIVITY_STREAM_DEBUG_PREF = "browser.newtabpage.activity-stream.debug";
function cleanup() {
Services.prefs.clearUserPref(SEPARATE_PRIVILEGED_CONTENT_PROCESS_PREF);
Services.prefs.clearUserPref(ACTIVITY_STREAM_PRERENDER_PREF);
Services.prefs.clearUserPref(ACTIVITY_STREAM_DEBUG_PREF);
aboutNewTabService.resetNewTabURL();
}
registerCleanupFunction(cleanup);
let ACTIVITY_STREAM_PRERENDER_URL;
let ACTIVITY_STREAM_PRERENDER_DEBUG_URL;
let ACTIVITY_STREAM_URL;
let ACTIVITY_STREAM_DEBUG_URL;
function setExpectedUrlsWithScripts() {
ACTIVITY_STREAM_PRERENDER_URL = "resource://activity-stream/prerendered/en-US/activity-stream-prerendered.html";
ACTIVITY_STREAM_PRERENDER_DEBUG_URL = "resource://activity-stream/prerendered/static/activity-stream-prerendered-debug.html";
ACTIVITY_STREAM_URL = "resource://activity-stream/prerendered/en-US/activity-stream.html";
ACTIVITY_STREAM_DEBUG_URL = "resource://activity-stream/prerendered/static/activity-stream-debug.html";
}
function setExpectedUrlsWithoutScripts() {
ACTIVITY_STREAM_PRERENDER_URL = "resource://activity-stream/prerendered/en-US/activity-stream-prerendered-noscripts.html";
ACTIVITY_STREAM_URL = "resource://activity-stream/prerendered/en-US/activity-stream-noscripts.html";
// Debug urls are the same as non-debug because debug scripts load dynamically
ACTIVITY_STREAM_PRERENDER_DEBUG_URL = ACTIVITY_STREAM_PRERENDER_URL;
ACTIVITY_STREAM_DEBUG_URL = ACTIVITY_STREAM_URL;
}
@ -96,21 +88,9 @@ function setBoolPrefAndWaitForChange(pref, value, testMessage) {
});
}
function setupASPrerendered() {
if (Services.prefs.getBoolPref(ACTIVITY_STREAM_PRERENDER_PREF)) {
return Promise.resolve();
}
let notificationPromise = nextChangeNotificationPromise("about:newtab");
Services.prefs.setBoolPref(ACTIVITY_STREAM_PRERENDER_PREF, true);
return notificationPromise;
}
add_task(async function test_as_and_prerender_initialized() {
add_task(async function test_as_initial_values() {
Assert.ok(aboutNewTabService.activityStreamEnabled,
".activityStreamEnabled should be set to the correct initial value");
Assert.equal(aboutNewTabService.activityStreamPrerender, Services.prefs.getBoolPref(ACTIVITY_STREAM_PRERENDER_PREF),
".activityStreamPrerender should be set to the correct initial value");
// This pref isn't defined on release or beta, so we fall back to false
Assert.equal(aboutNewTabService.activityStreamDebug, Services.prefs.getBoolPref(ACTIVITY_STREAM_DEBUG_PREF, false),
".activityStreamDebug should be set to the correct initial value");
@ -149,22 +129,19 @@ add_task(async function test_override_activity_stream_disabled() {
});
addTestsWithPrivilegedContentProcessPref(async function test_override_activity_stream_enabled() {
let notificationPromise = await setupASPrerendered();
Assert.equal(aboutNewTabService.defaultURL, ACTIVITY_STREAM_PRERENDER_URL,
"Newtab URL should be the default activity stream prerendered URL");
Assert.equal(aboutNewTabService.defaultURL, ACTIVITY_STREAM_URL,
"Newtab URL should be the default activity stream URL");
Assert.ok(!aboutNewTabService.overridden, "Newtab URL should not be overridden");
Assert.ok(aboutNewTabService.activityStreamEnabled, "Activity Stream should be enabled");
Assert.ok(aboutNewTabService.activityStreamPrerender, "Activity Stream should be prerendered");
// change to a chrome URL while activity stream is enabled
notificationPromise = nextChangeNotificationPromise(DOWNLOADS_URL);
let notificationPromise = nextChangeNotificationPromise(DOWNLOADS_URL);
aboutNewTabService.newTabURL = DOWNLOADS_URL;
await notificationPromise;
Assert.equal(aboutNewTabService.newTabURL, DOWNLOADS_URL,
"Newtab URL set to chrome url");
Assert.equal(aboutNewTabService.defaultURL, ACTIVITY_STREAM_PRERENDER_URL,
"Newtab URL defaultURL still set to the default activity stream prerendered URL");
Assert.equal(aboutNewTabService.defaultURL, ACTIVITY_STREAM_URL,
"Newtab URL defaultURL still set to the default activity stream URL");
Assert.ok(aboutNewTabService.overridden, "Newtab URL should be overridden");
Assert.ok(!aboutNewTabService.activityStreamEnabled, "Activity Stream should not be enabled");
@ -172,10 +149,8 @@ addTestsWithPrivilegedContentProcessPref(async function test_override_activity_s
});
addTestsWithPrivilegedContentProcessPref(async function test_default_url() {
await setupASPrerendered();
Assert.equal(aboutNewTabService.defaultURL, ACTIVITY_STREAM_PRERENDER_URL,
"Newtab defaultURL initially set to prerendered AS url");
Assert.equal(aboutNewTabService.defaultURL, ACTIVITY_STREAM_URL,
"Newtab defaultURL initially set to AS url");
// Only debug variants aren't available on release/beta
if (!IS_RELEASE_OR_BETA) {
@ -183,12 +158,8 @@ addTestsWithPrivilegedContentProcessPref(async function test_default_url() {
"A notification occurs after changing the debug pref to true");
Assert.equal(aboutNewTabService.activityStreamDebug, true,
"the .activityStreamDebug property is set to true");
Assert.equal(aboutNewTabService.defaultURL, ACTIVITY_STREAM_PRERENDER_DEBUG_URL,
"Newtab defaultURL set to debug prerendered AS url after the pref has been changed");
await setBoolPrefAndWaitForChange(ACTIVITY_STREAM_PRERENDER_PREF, false,
"A notification occurs after changing the prerender pref to false");
Assert.equal(aboutNewTabService.defaultURL, ACTIVITY_STREAM_DEBUG_URL,
"Newtab defaultURL set to un-prerendered AS with debug if prerender is false and debug is true");
"Newtab defaultURL set to debug AS url after the pref has been changed");
await setBoolPrefAndWaitForChange(ACTIVITY_STREAM_DEBUG_PREF, false,
"A notification occurs after changing the debug pref to false");
} else {
@ -196,8 +167,6 @@ addTestsWithPrivilegedContentProcessPref(async function test_default_url() {
Assert.equal(aboutNewTabService.activityStreamDebug, false,
"the .activityStreamDebug property is remains false");
await setBoolPrefAndWaitForChange(ACTIVITY_STREAM_PRERENDER_PREF, false,
"A notification occurs after changing the prerender pref to false");
}
Assert.equal(aboutNewTabService.defaultURL, ACTIVITY_STREAM_URL,
@ -207,14 +176,8 @@ addTestsWithPrivilegedContentProcessPref(async function test_default_url() {
});
addTestsWithPrivilegedContentProcessPref(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.");
"Newtab welcomeURL set to un-prerendered AS when debug disabled.");
Assert.equal(aboutNewTabService.welcomeURL, aboutNewTabService.defaultURL,
"Newtab welcomeURL is equal to defaultURL when prerendering disabled and debug disabled.");
@ -222,12 +185,8 @@ addTestsWithPrivilegedContentProcessPref(async function test_welcome_url() {
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");
"Newtab welcomeURL set to un-prerendered debug AS when debug enabled");
}
cleanup();
@ -244,8 +203,6 @@ add_task(function test_locale() {
addTestsWithPrivilegedContentProcessPref(async function test_updates() {
// Simulates a "cold-boot" situation, with some pref already set before testing a series
// of changes.
await setupASPrerendered();
aboutNewTabService.resetNewTabURL(); // need to set manually because pref notifs are off
let notificationPromise;
@ -261,7 +218,7 @@ addTestsWithPrivilegedContentProcessPref(async function test_updates() {
"about:newtab", "a notification occurs on reset");
aboutNewTabService.resetNewTabURL();
Assert.ok(aboutNewTabService.activityStreamEnabled, "Activity Stream should be enabled");
Assert.equal(aboutNewTabService.defaultURL, ACTIVITY_STREAM_PRERENDER_URL, "Default URL should be the activity stream page");
Assert.equal(aboutNewTabService.defaultURL, ACTIVITY_STREAM_URL, "Default URL should be the activity stream page");
await notificationPromise;
// reset twice, only one notification for default URL