Bug 1178152 - Provide a notification when the newtab URL changes. r=florian, a=ritu
authorNihanth Subramanya <nhnt11@gmail.com>
Tue, 30 Jun 2015 13:45:24 -0700
changeset 281396 1d71a95a50bbe1fccb5ba7b0349544085657e005
parent 281395 f3cfb1740978f2ecbb41077b048ddf9127ae8275
child 281397 e796c66eb475951c6235d0cbd055ea0a94d301f5
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian, ritu
bugs1178152
milestone41.0a2
Bug 1178152 - Provide a notification when the newtab URL changes. r=florian, a=ritu
browser/modules/NewTabURL.jsm
browser/modules/test/xpcshell/test_NewTabURL.js
--- a/browser/modules/NewTabURL.jsm
+++ b/browser/modules/NewTabURL.jsm
@@ -5,30 +5,34 @@
 "use strict";
 
 let Cc = Components.classes;
 let Ci = Components.interfaces;
 let Cu = Components.utils;
 
 this.EXPORTED_SYMBOLS = [ "NewTabURL" ];
 
+Components.utils.import("resource://gre/modules/Services.jsm");
+
 this.NewTabURL = {
   _url: "about:newtab",
   _overridden: false,
 
   get: function() {
     return this._url;
   },
 
   get overridden() {
     return this._overridden;
   },
 
   override: function(newURL) {
     this._url = newURL;
     this._overridden = true;
+    Services.obs.notifyObservers(null, "newtab-url-changed", this._url);
   },
 
   reset: function() {
     this._url = "about:newtab";
     this._overridden = false;
+    Services.obs.notifyObservers(null, "newtab-url-changed", this._url);
   }
 };
--- a/browser/modules/test/xpcshell/test_NewTabURL.js
+++ b/browser/modules/test/xpcshell/test_NewTabURL.js
@@ -1,17 +1,33 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 "use strict";
 
 Components.utils.import("resource:///modules/NewTabURL.jsm");
+Components.utils.import("resource://gre/modules/Services.jsm");
 
-function run_test() {
+add_task(function* () {
   Assert.equal(NewTabURL.get(), "about:newtab", "Default newtab URL should be about:newtab");
   let url = "http://example.com/";
+  let notificationPromise = promiseNewtabURLNotification(url);
   NewTabURL.override(url);
+  yield notificationPromise;
   Assert.ok(NewTabURL.overridden, "Newtab URL should be overridden");
   Assert.equal(NewTabURL.get(), url, "Newtab URL should be the custom URL");
+
+  notificationPromise = promiseNewtabURLNotification("about:newtab");
   NewTabURL.reset();
+  yield notificationPromise;
   Assert.ok(!NewTabURL.overridden, "Newtab URL should not be overridden");
   Assert.equal(NewTabURL.get(), "about:newtab", "Newtab URL should be the about:newtab");
+});
+
+function promiseNewtabURLNotification(aNewURL) {
+  return new Promise(resolve => {
+    Services.obs.addObserver(function observer(aSubject, aTopic, aData) {
+      Services.obs.removeObserver(observer, aTopic);
+      Assert.equal(aData, aNewURL, "Data for newtab-url-changed notification should be new URL.");
+      resolve();
+    }, "newtab-url-changed", false);
+  });
 }