Bug 754062 - Add skeleton for browser notifications service; r=gps
authorGregory Szorc <gps@mozilla.com>
Fri, 22 Jun 2012 09:24:39 -0700
changeset 102965 b4b7fb6242427f47f4528c8e4660d60c560ec523
parent 102964 e2b108c9411d89e24fd84f1e0ac2b607b4fedc55
child 102966 be2ab5deb078f9daa36f139d15f2945609c61cd3
push id191
push userlsblakk@mozilla.com
push dateFri, 05 Oct 2012 17:12:53 +0000
treeherdermozilla-release@ddb22ac6c03b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs754062
milestone16.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 754062 - Add skeleton for browser notifications service; r=gps This is a reland. The original commit was c53f474c502b and was backed out in 591fd1c696f0. The next commit is required to make xpcshell tests not fail.
browser/installer/package-manifest.in
services/Makefile.in
services/makefiles.sh
services/notifications/Makefile.in
services/notifications/NotificationsComponents.manifest
services/notifications/README
services/notifications/service.js
services/notifications/services-notifications.js
services/notifications/tests/Makefile.in
services/notifications/tests/unit/head_helpers.js
services/notifications/tests/unit/test_service_start.js
services/notifications/tests/unit/xpcshell.ini
testing/xpcshell/xpcshell.ini
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -448,16 +448,19 @@
 @BINPATH@/components/nsPrompter.manifest
 @BINPATH@/components/nsPrompter.js
 #ifdef MOZ_SERVICES_SYNC
 @BINPATH@/components/SyncComponents.manifest
 @BINPATH@/components/AitcComponents.manifest
 @BINPATH@/components/Weave.js
 @BINPATH@/components/Aitc.js
 #endif
+#ifdef MOZ_SERVICES_NOTIFICATIONS
+@BINPATH@/components/NotificationsComponents.manifest
+#endif
 @BINPATH@/components/TelemetryPing.js
 @BINPATH@/components/TelemetryPing.manifest
 @BINPATH@/components/messageWakeupService.js
 @BINPATH@/components/messageWakeupService.manifest
 @BINPATH@/components/SettingsManager.js
 @BINPATH@/components/SettingsManager.manifest
 @BINPATH@/components/Webapps.js
 @BINPATH@/components/Webapps.manifest
--- a/services/Makefile.in
+++ b/services/Makefile.in
@@ -6,12 +6,12 @@
 DEPTH     = ..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 ifdef MOZ_SERVICES_SYNC
-PARALLEL_DIRS += aitc common crypto sync
+PARALLEL_DIRS += aitc common crypto notifications sync
 endif
 
 include $(topsrcdir)/config/rules.mk
--- a/services/makefiles.sh
+++ b/services/makefiles.sh
@@ -3,19 +3,21 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 add_makefiles "
   services/Makefile
   services/common/Makefile
   services/crypto/Makefile
   services/crypto/component/Makefile
+  services/notifications/Makefile
   services/sync/Makefile
   services/sync/locales/Makefile
 "
 
 if [ "$ENABLE_TESTS" ]; then
   add_makefiles "
     services/common/tests/Makefile
     services/crypto/tests/Makefile
+    services/notifications/tests/Makefile
     services/sync/tests/Makefile
   "
 fi
new file mode 100644
--- /dev/null
+++ b/services/notifications/Makefile.in
@@ -0,0 +1,32 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+DEPTH     = ../..
+topsrcdir = @top_srcdir@
+srcdir    = @srcdir@
+VPATH     = @srcdir@
+
+include $(DEPTH)/config/autoconf.mk
+
+EXTRA_COMPONENTS = \
+  NotificationsComponents.manifest \
+  $(NULL)
+
+PREF_JS_EXPORTS = $(srcdir)/services-notifications.js
+
+modules := \
+  service.js \
+  $(NULL)
+
+source_modules = $(foreach module,$(modules),$(srcdir)/$(module))
+module_dir = $(FINAL_TARGET)/modules/services-notifications
+
+GENERATED_DIRS += $(module_dir)
+
+libs::
+	$(NSINSTALL) $(source_modules) $(module_dir)
+
+TEST_DIRS += tests
+
+include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/services/notifications/NotificationsComponents.manifest
@@ -0,0 +1,2 @@
+# Register resource aliases
+resource services-notifications resource:///modules/services-notifications/
new file mode 100644
--- /dev/null
+++ b/services/notifications/README
@@ -0,0 +1,11 @@
+Here lies most of the moving parts for push notifcations in the browser. DOM
+and UI bindings will live elsewhere; these files deal with talking to the API,
+storing messages, and creating persistent connections to the notification
+server.
+
+Structure:
+
+services.js::Service
+  This is a singleton that manages API calls and message storage. It's an
+  instance of the NotificationSvc class. Messages and state are persisted to a
+  JSON file on disk.
new file mode 100644
--- /dev/null
+++ b/services/notifications/service.js
@@ -0,0 +1,28 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const EXPORTED_SYMBOLS = ["Service"];
+
+const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
+
+Cu.import("resource://services-common/preferences.js");
+
+const PREFS_BRANCH = "services.notifications.";
+
+
+function NotificationSvc() {
+  this.ready = false;
+  this.prefs = new Preferences(PREFS_BRANCH);
+}
+NotificationSvc.prototype = {
+
+  get serverURL() this.prefs.get("serverURL"),
+
+  onStartup: function onStartup() {
+    this.ready = true;
+  }
+};
+
+let Service = new NotificationSvc();
+Service.onStartup();
new file mode 100644
--- /dev/null
+++ b/services/notifications/services-notifications.js
@@ -0,0 +1,1 @@
+pref("services.notifications.serverURL", "https://notifications.mozilla.org/");
new file mode 100644
--- /dev/null
+++ b/services/notifications/tests/Makefile.in
@@ -0,0 +1,16 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+DEPTH          = ../../..
+topsrcdir      = @top_srcdir@
+srcdir         = @srcdir@
+VPATH          = @srcdir@
+relativesrcdir = services/notifications/tests
+
+include $(DEPTH)/config/autoconf.mk
+
+MODULE = test_services_notifications
+XPCSHELL_TESTS = unit
+
+include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/services/notifications/tests/unit/head_helpers.js
@@ -0,0 +1,3 @@
+const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
+
+let _ = function() print(Array.slice(arguments).join(" "));
new file mode 100644
--- /dev/null
+++ b/services/notifications/tests/unit/test_service_start.js
@@ -0,0 +1,8 @@
+// Check that everything is getting hooked together properly.
+function run_test() {
+  _("When imported, Service.onStartup is called.");
+  Cu.import("resource://services-notifications/service.js");
+
+  do_check_eq(Service.serverURL, "https://notifications.mozilla.org/");
+  do_check_eq(Service.ready, true);
+}
new file mode 100644
--- /dev/null
+++ b/services/notifications/tests/unit/xpcshell.ini
@@ -0,0 +1,5 @@
+[DEFAULT]
+head = head_helpers.js
+tail =
+
+[test_service_start.js]
--- a/testing/xpcshell/xpcshell.ini
+++ b/testing/xpcshell/xpcshell.ini
@@ -72,16 +72,17 @@ skip-if = os == "android"
 [include:widget/tests/unit/xpcshell.ini]
 [include:content/base/test/unit/xpcshell.ini]
 [include:content/test/unit/xpcshell.ini]
 [include:toolkit/components/url-classifier/tests/unit/xpcshell.ini]
 [include:services/aitc/tests/unit/xpcshell.ini]
 [include:services/common/tests/unit/xpcshell.ini]
 [include:services/crypto/tests/unit/xpcshell.ini]
 [include:services/crypto/components/tests/unit/xpcshell.ini]
+[include:services/notifications/tests/unit/xpcshell.ini]
 [include:services/sync/tests/unit/xpcshell.ini]
 # Bug 676978: tests hang on Android
 skip-if = os == "android"
 [include:browser/components/dirprovider/tests/unit/xpcshell.ini]
 [include:browser/components/downloads/test/unit/xpcshell.ini]
 [include:browser/components/feeds/test/unit/xpcshell.ini]
 [include:browser/components/migration/tests/unit/xpcshell.ini]
 [include:browser/components/places/tests/unit/xpcshell.ini]