Commit 22553dba authored by k88hudson's avatar k88hudson
Browse files

Bug 1398819 - Turn on prerendered version of activity stream in aboutNewTabService r=Mardak

MozReview-Commit-ID: 3v9UR0A9K1z

--HG--
extra : rebase_source : f7d9894ef0a2e168964ff7f0d7284e4165874a47
parent 9ef0b066
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1270,6 +1270,7 @@ pref("browser.newtabpage.directory.source", "https://tiles.services.mozilla.com/

// activates Activity Stream
pref("browser.newtabpage.activity-stream.enabled", true);
pref("browser.newtabpage.activity-stream.prerender", true);
pref("browser.newtabpage.activity-stream.aboutHome.enabled", false);

// Enable the DOM fullscreen API.
+0 −4
Original line number Diff line number Diff line
@@ -87,10 +87,6 @@ var whitelist = [
  {file: "resource://app/modules/NewTabSearchProvider.jsm"},
  {file: "resource://app/modules/NewTabWebChannel.jsm"},

  // browser/extensions/activity-stream/data/content/activity-stream-prerendered.html
  // This will used when Bug 1397875 lands
  {file: "resource://activity-stream/data/content/activity-stream-prerendered.html"},

  // layout/mathml/nsMathMLChar.cpp
  {file: "resource://gre/res/fonts/mathfontSTIXGeneral.properties"},
  {file: "resource://gre/res/fonts/mathfontUnicode.properties"},
+21 −2
Original line number Diff line number Diff line
@@ -17,16 +17,20 @@ const LOCAL_NEWTAB_URL = "chrome://browser/content/newtab/newTab.xhtml";

const ACTIVITY_STREAM_URL = "resource://activity-stream/data/content/activity-stream.html";

const ACTIVITY_STREAM_PRERENDER_URL = "resource://activity-stream/data/content/activity-stream-prerendered.html";

const ABOUT_URL = "about:newtab";

const IS_MAIN_PROCESS = Services.appinfo.processType === Services.appinfo.PROCESS_TYPE_DEFAULT;

// Pref that tells if activity stream is enabled
const PREF_ACTIVITY_STREAM_ENABLED = "browser.newtabpage.activity-stream.enabled";
const PREF_ACTIVITY_STREAM_PRERENDER_ENABLED = "browser.newtabpage.activity-stream.prerender";

function AboutNewTabService() {
  Services.obs.addObserver(this, "quit-application-granted");
  Services.prefs.addObserver(PREF_ACTIVITY_STREAM_ENABLED, this);
  Services.prefs.addObserver(PREF_ACTIVITY_STREAM_PRERENDER_ENABLED, this);
  this.toggleActivityStream();
  if (IS_MAIN_PROCESS) {
    AboutNewTab.init();
@@ -71,6 +75,7 @@ AboutNewTabService.prototype = {

  _newTabURL: ABOUT_URL,
  _activityStreamEnabled: false,
  _activityStreamPrerender: true,
  _overridden: false,

  classID: Components.ID("{dfcd2adc-7867-4d3a-ba70-17501f208142}"),
@@ -85,13 +90,19 @@ AboutNewTabService.prototype = {
  observe(subject, topic, data) {
    switch (topic) {
      case "nsPref:changed":
        if (data === PREF_ACTIVITY_STREAM_ENABLED) {
          if (this.toggleActivityStream()) {
            Services.obs.notifyObservers(null, "newtab-url-changed", ABOUT_URL);
          }
        } else if (data === PREF_ACTIVITY_STREAM_PRERENDER_ENABLED) {
          this._activityStreamPrerender = Services.prefs.getBoolPref(PREF_ACTIVITY_STREAM_PRERENDER_ENABLED);
          Services.obs.notifyObservers(null, "newtab-url-changed", ABOUT_URL);
        }
        break;
      case "quit-application-granted":
        Services.obs.removeObserver(this, "quit-application-granted");
        Services.prefs.removeObserver(PREF_ACTIVITY_STREAM_ENABLED, this);
        Services.prefs.removeObserver(PREF_ACTIVITY_STREAM_PRERENDER_ENABLED, this);
        if (IS_MAIN_PROCESS) {
          AboutNewTab.uninit();
        }
@@ -139,7 +150,7 @@ AboutNewTabService.prototype = {
   */
  get defaultURL() {
    if (this.activityStreamEnabled) {
      return this.activityStreamURL;
      return this.activityStreamPrerender ? this.activityStreamPrerenderURL : this.activityStreamURL;
    }
    return LOCAL_NEWTAB_URL;
  },
@@ -172,10 +183,18 @@ AboutNewTabService.prototype = {
    return this._activityStreamEnabled;
  },

  get activityStreamPrerender() {
    return this._activityStreamPrerender;
  },

  get activityStreamURL() {
    return ACTIVITY_STREAM_URL;
  },

  get activityStreamPrerenderURL() {
    return ACTIVITY_STREAM_PRERENDER_URL;
  },

  resetNewTabURL() {
    this._overridden = false;
    this._newTabURL = ABOUT_URL;
+10 −0
Original line number Diff line number Diff line
@@ -34,11 +34,21 @@ interface nsIAboutNewTabService : nsISupports
   */
  readonly attribute bool activityStreamEnabled;

  /**
   * Returns true if the the prerendering pref for activity stream is true
   */
  readonly attribute bool activityStreamPrerender;

  /**
   * Returns the activity stream resource URL for the newtab page
   */
  readonly attribute ACString activityStreamURL;

  /**
   * Returns the prerendered activity stream resource URL for the newtab page
   */
  readonly attribute ACString activityStreamPrerenderURL;

  /**
   * Resets to the default resource and also resets the
   * overridden attribute to false.
+46 −13
Original line number Diff line number Diff line
@@ -8,17 +8,20 @@ const {utils: Cu} = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Preferences.jsm");

XPCOMUtils.defineLazyServiceGetter(this, "aboutNewTabService",
                                   "@mozilla.org/browser/aboutnewtab-service;1",
                                   "nsIAboutNewTabService");

const DEFAULT_HREF = aboutNewTabService.activityStreamURL;
const ACTIVITY_STREAM_PRERENDER_URL = aboutNewTabService.activityStreamPrerenderURL;

const DEFAULT_CHROME_URL = "chrome://browser/content/newtab/newTab.xhtml";
const DOWNLOADS_URL = "chrome://browser/content/downloads/contentAreaDownloadsView.xul";
const ACTIVITY_STREAM_PREF = "browser.newtabpage.activity-stream.enabled";
const ACTIVITY_STREAM_PRERENDER_PREF = "browser.newtabpage.activity-stream.prerender";

function cleanup() {
  Services.prefs.setBoolPref("browser.newtabpage.activity-stream.enabled", false);
  Services.prefs.clearUserPref(ACTIVITY_STREAM_PREF);
  Services.prefs.clearUserPref(ACTIVITY_STREAM_PRERENDER_PREF);
  aboutNewTabService.resetNewTabURL();
}

@@ -29,7 +32,7 @@ do_register_cleanup(cleanup);
 */
add_task(async function test_override_activity_stream_disabled() {
  let notificationPromise;
  Services.prefs.setBoolPref("browser.newtabpage.activity-stream.enabled", false);
  Services.prefs.setBoolPref(ACTIVITY_STREAM_PREF, false);

  // tests default is the local newtab resource
  Assert.equal(aboutNewTabService.defaultURL, DEFAULT_CHROME_URL,
@@ -62,15 +65,12 @@ add_task(async function test_override_activity_stream_disabled() {
});

add_task(async function test_override_activity_stream_enabled() {
  let notificationPromise;
  // change newtab page to activity stream
  notificationPromise = nextChangeNotificationPromise("about:newtab");
  Services.prefs.setBoolPref("browser.newtabpage.activity-stream.enabled", true);
  await notificationPromise;
  let activityStreamURL = aboutNewTabService.activityStreamURL;
  Assert.equal(aboutNewTabService.defaultURL, activityStreamURL, "Newtab URL should be the default activity stream URL");
  let notificationPromise = await setupASPrerendered();

  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 local newtab page while activity stream is enabled
  notificationPromise = nextChangeNotificationPromise(DEFAULT_CHROME_URL);
@@ -86,6 +86,24 @@ add_task(async function test_override_activity_stream_enabled() {
  cleanup();
});

add_task(async function test_default_url() {
  await setupASPrerendered();
  Assert.equal(aboutNewTabService.defaultURL, ACTIVITY_STREAM_PRERENDER_URL,
               "Newtab defaultURL initially set to prerendered AS url");

  // Change activity-stream.prerendered to false and wait for the required event to fire
  const notificationPromise = nextChangeNotificationPromise(
    "about:newtab", "a notification occurs after changing prerender pref");
  Services.prefs.setBoolPref(ACTIVITY_STREAM_PRERENDER_PREF, false);

  await notificationPromise;

  Assert.equal(aboutNewTabService.defaultURL, aboutNewTabService.activityStreamURL,
               "Newtab defaultURL set to un-prerendered AS url after the pref has been changed");

  cleanup();
});

/**
 * Tests reponse to updates to prefs
 */
@@ -94,7 +112,8 @@ add_task(async function test_updates() {
   * Simulates a "cold-boot" situation, with some pref already set before testing a series
   * of changes.
   */
  Preferences.set("browser.newtabpage.activity-stream.enabled", true);
  await setupASPrerendered();

  aboutNewTabService.resetNewTabURL(); // need to set manually because pref notifs are off
  let notificationPromise;

@@ -110,7 +129,7 @@ add_task(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, DEFAULT_HREF, "Default URL should be the activity stream page");
  Assert.equal(aboutNewTabService.defaultURL, ACTIVITY_STREAM_PRERENDER_URL, "Default URL should be the activity stream page");
  await notificationPromise;

  // reset twice, only one notification for default URL
@@ -131,3 +150,17 @@ function nextChangeNotificationPromise(aNewURL, testMessage) {
    }, "newtab-url-changed");
  });
}

function setupASPrerendered() {
  if (Services.prefs.getBoolPref(ACTIVITY_STREAM_PREF) &&
    Services.prefs.getBoolPref(ACTIVITY_STREAM_PRERENDER_PREF)) {
    return Promise.resolve();
  }

  let notificationPromise;
  // change newtab page to activity stream
  notificationPromise = nextChangeNotificationPromise("about:newtab");
  Services.prefs.setBoolPref(ACTIVITY_STREAM_PREF, true);
  Services.prefs.setBoolPref(ACTIVITY_STREAM_PRERENDER_PREF, true);
  return notificationPromise;
}