Bug 1472212 - Update URLs to include the noscripts version in xpcshell and browser tests for newtab. r=Mardak
☠☠ backed out by fc21376e28da ☠ ☠
authorimjching <jlim@mozilla.com>
Wed, 11 Jul 2018 17:18:21 -0400
changeset 443312 b4baa63e5b1b
parent 443311 c66693babf02
child 443313 176f3ee14e67
push id109349
push usermconley@mozilla.com
push dateMon, 29 Oct 2018 17:26:56 +0000
treeherdermozilla-inbound@18e46df44cd1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMardak
bugs1472212
milestone65.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 1472212 - Update URLs to include the noscripts version in xpcshell and browser tests for newtab. r=Mardak MozReview-Commit-ID: EA4YminghNs
browser/components/newtab/aboutNewTabService.js
browser/components/newtab/test/browser/browser_packaged_as_locales.js
browser/components/newtab/test/xpcshell/test_AboutNewTabService.js
--- a/browser/components/newtab/aboutNewTabService.js
+++ b/browser/components/newtab/aboutNewTabService.js
@@ -103,16 +103,17 @@ AboutNewTabService.prototype = {
     Ci.nsIObserver,
   ]),
 
   observe(subject, topic, data) {
     switch (topic) {
       case "nsPref:changed":
         if (data === PREF_SEPARATE_PRIVILEGED_CONTENT_PROCESS) {
           this._privilegedContentProcess = Services.prefs.getBoolPref(PREF_SEPARATE_PRIVILEGED_CONTENT_PROCESS);
+          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();
           this.notifyChange();
         }
--- a/browser/components/newtab/test/browser/browser_packaged_as_locales.js
+++ b/browser/components/newtab/test/browser/browser_packaged_as_locales.js
@@ -1,15 +1,17 @@
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 XPCOMUtils.defineLazyServiceGetter(this, "aboutNewTabService",
                                    "@mozilla.org/browser/aboutnewtab-service;1",
                                    "nsIAboutNewTabService");
 
 // Tests are by default run with non-debug en-US configuration
-const DEFAULT_URL = "resource://activity-stream/prerendered/en-US/activity-stream-prerendered.html";
+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";
 
 /**
  * Temporarily change the app locale to get the localized activity stream url
  */
 async function getUrlForLocale(locale) {
   const origAvailable = Services.locale.availableLocales;
   const origRequested = Services.locale.requestedLocales;
   try {
--- a/browser/components/newtab/test/xpcshell/test_AboutNewTabService.js
+++ b/browser/components/newtab/test/xpcshell/test_AboutNewTabService.js
@@ -9,33 +9,65 @@ ChromeUtils.import("resource://gre/modul
 ChromeUtils.import("resource://gre/modules/Preferences.jsm");
 ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 XPCOMUtils.defineLazyServiceGetter(this, "aboutNewTabService",
                                    "@mozilla.org/browser/aboutnewtab-service;1",
                                    "nsIAboutNewTabService");
 
 const IS_RELEASE_OR_BETA = AppConstants.RELEASE_OR_BETA;
 
-const ACTIVITY_STREAM_PRERENDER_URL = "resource://activity-stream/prerendered/en-US/activity-stream-prerendered.html";
-const ACTIVITY_STREAM_PRERENDER_DEBUG_URL = "resource://activity-stream/prerendered/static/activity-stream-prerendered-debug.html";
-const ACTIVITY_STREAM_URL = "resource://activity-stream/prerendered/en-US/activity-stream.html";
-const ACTIVITY_STREAM_DEBUG_URL = "resource://activity-stream/prerendered/static/activity-stream-debug.html";
-
 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_PRERENDER_DEBUG_URL = "resource://activity-stream/prerendered/static/activity-stream-prerendered-debug-noscripts.html";
+  ACTIVITY_STREAM_URL = "resource://activity-stream/prerendered/en-US/activity-stream-noscripts.html";
+  ACTIVITY_STREAM_DEBUG_URL = "resource://activity-stream/prerendered/static/activity-stream-debug-noscripts.html";
+}
+
+// Default expected URLs to files with scripts in them.
+setExpectedUrlsWithScripts();
+
+function addTestsWithPrivilegedContentProcessPref(test) {
+  add_task(async() => {
+    await setPrivilegedContentProcessPref(true);
+    setExpectedUrlsWithoutScripts();
+    await test();
+  });
+  add_task(async() => {
+    await setPrivilegedContentProcessPref(false);
+    setExpectedUrlsWithScripts();
+    await test();
+  });
+}
+
 function nextChangeNotificationPromise(aNewURL, testMessage) {
   return new Promise(resolve => {
     Services.obs.addObserver(function observer(aSubject, aTopic, aData) { // jshint unused:false
       Services.obs.removeObserver(observer, aTopic);
       Assert.equal(aData, aNewURL, testMessage);
       resolve();
     }, "newtab-url-changed");
   });
@@ -58,16 +90,26 @@ function setupASPrerendered() {
     return Promise.resolve();
   }
 
   let notificationPromise = nextChangeNotificationPromise("about:newtab");
   Services.prefs.setBoolPref(ACTIVITY_STREAM_PRERENDER_PREF, true);
   return notificationPromise;
 }
 
+function setPrivilegedContentProcessPref(usePrivilegedContentProcess) {
+  if (usePrivilegedContentProcess === Services.prefs.getBoolPref(SEPARATE_PRIVILEGED_CONTENT_PROCESS_PREF)) {
+    return Promise.resolve();
+  }
+
+  let notificationPromise = nextChangeNotificationPromise("about:newtab");
+  Services.prefs.setBoolPref(SEPARATE_PRIVILEGED_CONTENT_PROCESS_PREF, usePrivilegedContentProcess);
+  return notificationPromise;
+}
+
 add_task(async function test_as_and_prerender_initialized() {
   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");
@@ -100,20 +142,21 @@ add_task(async function test_override_ac
   aboutNewTabService.newTabURL = DOWNLOADS_URL;
   await notificationPromise;
   Assert.ok(aboutNewTabService.overridden, "Newtab URL should be overridden");
   Assert.equal(aboutNewTabService.newTabURL, DOWNLOADS_URL, "Newtab URL should be the custom URL");
 
   cleanup();
 });
 
-add_task(async function test_override_activity_stream_enabled() {
+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_PRERENDER_URL,
+    "Newtab URL should be the default activity stream prerendered 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);
   aboutNewTabService.newTabURL = DOWNLOADS_URL;
   await notificationPromise;
@@ -122,18 +165,19 @@ add_task(async function test_override_ac
   Assert.equal(aboutNewTabService.defaultURL, ACTIVITY_STREAM_PRERENDER_URL,
                "Newtab URL defaultURL still set to the default activity stream prerendered URL");
   Assert.ok(aboutNewTabService.overridden, "Newtab URL should be overridden");
   Assert.ok(!aboutNewTabService.activityStreamEnabled, "Activity Stream should not be enabled");
 
   cleanup();
 });
 
-add_task(async function test_default_url() {
+addTestsWithPrivilegedContentProcessPref(async function test_default_url() {
   await setupASPrerendered();
+
   Assert.equal(aboutNewTabService.defaultURL, ACTIVITY_STREAM_PRERENDER_URL,
     "Newtab defaultURL initially set to prerendered AS url");
 
   // 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.activityStreamDebug, true,
@@ -156,17 +200,17 @@ add_task(async function test_default_url
   }
 
   Assert.equal(aboutNewTabService.defaultURL, ACTIVITY_STREAM_URL,
     "Newtab defaultURL set to un-prerendered AS if prerender is false and debug is false");
 
   cleanup();
 });
 
-add_task(async function test_welcome_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.");
@@ -189,21 +233,21 @@ add_task(async function test_welcome_url
 });
 
 add_task(function test_locale() {
   Assert.equal(aboutNewTabService.activityStreamLocale, "en-US",
     "The locale for testing should be en-US");
 });
 
 /**
- * Tests reponse to updates to prefs
+ * Tests response to updates to prefs
  */
-add_task(async function test_updates() {
-   // Simulates a "cold-boot" situation, with some pref already set before testing a series
-   // of changes.
+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;
 
   // test update fires on override and reset
   let testURL = "https://example.com/";
   notificationPromise = nextChangeNotificationPromise(