Bug 1239119 - Move provider init for newtab to NewTabMessages.jsm r=ursula
authorOlivier Yiptong <olivier@olivieryiptong.com>
Wed, 16 Mar 2016 16:17:57 -0400
changeset 291235 e17ded471c3ff88d278ac451f42fe62b00fc6509
parent 291234 c8728788af45309519fa8f54fd982f504f06296d
child 291236 14ebae70ac3783e47cc16dc94817f9ea0daaf1be
push id74528
push userolivier@olivieryiptong.com
push dateFri, 01 Apr 2016 17:54:49 +0000
treeherdermozilla-inbound@14ebae70ac37 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersursula
bugs1239119
milestone48.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 1239119 - Move provider init for newtab to NewTabMessages.jsm r=ursula MozReview-Commit-ID: DE3AqHXF4jl
browser/components/newtab/NewTabMessages.jsm
browser/components/newtab/tests/browser/browser_newtabmessages.js
browser/components/newtab/tests/browser/browser_newtabwebchannel.js
browser/components/nsBrowserGlue.js
--- a/browser/components/newtab/NewTabMessages.jsm
+++ b/browser/components/newtab/NewTabMessages.jsm
@@ -63,16 +63,19 @@ let NewTabMessages = {
         this.uninit();
       } else if (!this._prefs.enabled && value) {
         this.init();
       }
     }
   },
 
   init() {
+    NewTabPrefsProvider.prefs.init();
+    NewTabWebChannel.init();
+
     this._prefs.enabled = Preferences.get(PREF_ENABLED, false);
 
     if (this._prefs.enabled) {
       NewTabWebChannel.on(ACTIONS.prefs.inPrefs, this.handlePrefRequest.bind(this));
       NewTabPrefsProvider.prefs.on(PREF_ENABLED, this._handleEnabledChange.bind(this));
 
       for (let pref of NewTabPrefsProvider.newtabPagePrefSet) {
         NewTabPrefsProvider.prefs.on(pref, this.handlePrefChange.bind(this));
@@ -86,10 +89,13 @@ let NewTabMessages = {
     if (this._prefs.enabled) {
       NewTabPrefsProvider.prefs.off(PREF_ENABLED, this._handleEnabledChange);
 
       NewTabWebChannel.off(ACTIONS.prefs.inPrefs, this.handlePrefRequest);
       for (let pref of NewTabPrefsProvider.newtabPagePrefSet) {
         NewTabPrefsProvider.prefs.off(pref, this.handlePrefChange);
       }
     }
+
+    NewTabPrefsProvider.prefs.uninit();
+    NewTabWebChannel.uninit();
   }
 };
--- a/browser/components/newtab/tests/browser/browser_newtabmessages.js
+++ b/browser/components/newtab/tests/browser/browser_newtabmessages.js
@@ -12,17 +12,16 @@ function setup() {
   Preferences.set("browser.newtabpage.enhanced", true);
   Preferences.set("browser.newtabpage.remote.mode", "test");
   Preferences.set("browser.newtabpage.remote", true);
   NewTabMessages.init();
 }
 
 function cleanup() {
   NewTabMessages.uninit();
-  NewTabWebChannel.tearDownState();
   Preferences.set("browser.newtabpage.remote", false);
   Preferences.set("browser.newtabpage.remote.mode", "production");
 }
 registerCleanupFunction(cleanup);
 
 /*
  * Sanity tests for pref messages
  */
--- a/browser/components/newtab/tests/browser/browser_newtabwebchannel.js
+++ b/browser/components/newtab/tests/browser/browser_newtabwebchannel.js
@@ -2,33 +2,42 @@
 
 "use strict";
 
 Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "NewTabWebChannel",
                                   "resource:///modules/NewTabWebChannel.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "NewTabMessages",
+                                  "resource:///modules/NewTabMessages.jsm");
 
 const TEST_URL = "https://example.com/browser/browser/components/newtab/tests/browser/newtabwebchannel_basic.html";
 const TEST_URL_2 = "http://mochi.test:8888/browser/browser/components/newtab/tests/browser/newtabwebchannel_basic.html";
 
+function setup(mode = "test") {
+  Preferences.set("browser.newtabpage.remote.mode", mode);
+  Preferences.set("browser.newtabpage.remote", true);
+  NewTabWebChannel.init();
+  NewTabMessages.init();
+}
+
 function cleanup() {
-  NewTabWebChannel.tearDownState();
+  NewTabMessages.uninit();
+  NewTabWebChannel.uninit();
   Preferences.set("browser.newtabpage.remote", false);
   Preferences.set("browser.newtabpage.remote.mode", "production");
 }
 registerCleanupFunction(cleanup);
 
 /*
  * Tests flow of messages from newtab to chrome and chrome to newtab
  */
 add_task(function* open_webchannel_basic() {
-  Preferences.set("browser.newtabpage.remote.mode", "test");
-  Preferences.set("browser.newtabpage.remote", true);
+  setup();
 
   let tabOptions = {
     gBrowser,
     url: TEST_URL
   };
 
   let messagePromise = new Promise(resolve => {
     NewTabWebChannel.once("foo", function(name, msg) {
@@ -67,18 +76,17 @@ add_task(function* open_webchannel_basic
   yield unloadPromise;
   cleanup();
 });
 
 /*
  * Tests message broadcast reaches all open newtab pages
  */
 add_task(function* webchannel_broadcast() {
-  Preferences.set("browser.newtabpage.remote.mode", "test");
-  Preferences.set("browser.newtabpage.remote", true);
+  setup();
 
   let countingMessagePromise = new Promise(resolve => {
     let count = 0;
     NewTabWebChannel.on("foo", function test_message(name, msg) {
       count += 1;
       if (count === 2) {
         NewTabWebChannel.off("foo", test_message);
         resolve(msg.target);
@@ -128,18 +136,17 @@ add_task(function* webchannel_broadcast(
   yield countingUnloadPromise;
   cleanup();
 });
 
 /*
  * Tests switching modes
  */
 add_task(function* webchannel_switch() {
-  Preferences.set("browser.newtabpage.remote.mode", "test");
-  Preferences.set("browser.newtabpage.remote", true);
+  setup();
 
   function newMessagePromise() {
     return new Promise(resolve => {
       NewTabWebChannel.once("foo", function(name, msg) {
         resolve(msg.target);
       }.bind(this));
     });
   }
@@ -190,18 +197,17 @@ add_task(function* webchannel_switch() {
 
   Cu.forceGC();
   is(NewTabWebChannel.numBrowsers, 0, "Sanity check");
   yield unloadPromise;
   cleanup();
 });
 
 add_task(function* open_webchannel_reload() {
-  Preferences.set("browser.newtabpage.remote.mode", "test");
-  Preferences.set("browser.newtabpage.remote", true);
+  setup();
 
   let tabOptions = {
     gBrowser,
     url: TEST_URL
   };
 
   let messagePromise = new Promise(resolve => {
     NewTabWebChannel.once("foo", function(name, msg) {
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -22,22 +22,16 @@ XPCOMUtils.defineLazyModuleGetter(this, 
                                   "resource:///modules/AboutNewTab.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "DirectoryLinksProvider",
                                   "resource:///modules/DirectoryLinksProvider.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "NewTabUtils",
                                   "resource://gre/modules/NewTabUtils.jsm");
 
-XPCOMUtils.defineLazyModuleGetter(this, "NewTabPrefsProvider",
-                                  "resource:///modules/NewTabPrefsProvider.jsm");
-
-XPCOMUtils.defineLazyModuleGetter(this, "NewTabWebChannel",
-                                  "resource:///modules/NewTabWebChannel.jsm");
-
 XPCOMUtils.defineLazyModuleGetter(this, "NewTabMessages",
                                   "resource:///modules/NewTabMessages.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "UITour",
                                   "resource:///modules/UITour.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
                                   "resource://gre/modules/AddonManager.jsm");
@@ -754,18 +748,16 @@ BrowserGlue.prototype = {
     webrtcUI.init();
     AboutHome.init();
 
     DirectoryLinksProvider.init();
     NewTabUtils.init();
     NewTabUtils.links.addProvider(DirectoryLinksProvider);
     AboutNewTab.init();
 
-    NewTabPrefsProvider.prefs.init();
-    NewTabWebChannel.init();
     NewTabMessages.init();
 
     SessionStore.init();
     BrowserUITelemetry.init();
     ContentSearch.init();
     FormValidationHandler.init();
 
     ContentClick.init();
@@ -1061,18 +1053,16 @@ BrowserGlue.prototype = {
       let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"]
                          .getService(Ci.nsIAppStartup);
       appStartup.trackStartupCrashEnd();
     } catch (e) {
       Cu.reportError("Could not end startup crash tracking in quit-application-granted: " + e);
     }
 
     SelfSupportBackend.uninit();
-    NewTabPrefsProvider.prefs.uninit();
-    NewTabWebChannel.uninit();
     NewTabMessages.uninit();
 
     AboutNewTab.uninit();
     webrtcUI.uninit();
     FormValidationHandler.uninit();
     if (AppConstants.NIGHTLY_BUILD) {
       AddonWatcher.uninit();
     }