From 54f2dadcee1561e261c03dbdf960b5e369bf9066 Mon Sep 17 00:00:00 2001 From: Wes Kocher Date: Thu, 8 May 2014 16:06:40 -0700 Subject: [PATCH] Backed out changeset 21d743a319c6 (bug 967475) for apparently introducing two hazards to the build --- b2g/components/AlertsHelper.jsm | 13 +- b2g/components/AlertsService.js | 8 +- b2g/installer/package-manifest.in | 2 - browser/installer/package-manifest.in | 2 - dom/bindings/BindingUtils.cpp | 9 - .../notification/nsINotificationStorage.idl | 9 +- dom/src/notification/ChromeNotifications.js | 113 ------------ .../notification/ChromeNotifications.manifest | 3 - dom/src/notification/Notification.cpp | 53 +++--- dom/src/notification/Notification.h | 7 +- dom/src/notification/NotificationDB.jsm | 82 +-------- dom/src/notification/NotificationStorage.js | 6 +- dom/src/notification/moz.build | 2 - .../test/unit/test_notificationdb.js | 113 ------------ .../mochitest/notification/MockServices.js | 54 ++---- .../mochitest/notification/mochitest.ini | 1 - .../notification/test_bug931307.html | 4 +- .../test_notification_basics.html | 2 +- .../test_notification_resend.html | 170 ------------------ .../test_notification_storage.html | 6 +- dom/webidl/ChromeNotifications.webidl | 14 -- dom/webidl/moz.build | 1 - mobile/android/installer/package-manifest.in | 2 - 23 files changed, 62 insertions(+), 614 deletions(-) delete mode 100644 dom/src/notification/ChromeNotifications.js delete mode 100644 dom/src/notification/ChromeNotifications.manifest delete mode 100644 dom/tests/mochitest/notification/test_notification_resend.html delete mode 100644 dom/webidl/ChromeNotifications.webidl diff --git a/b2g/components/AlertsHelper.jsm b/b2g/components/AlertsHelper.jsm index 0089f381eca120..9260c1066af96f 100644 --- a/b2g/components/AlertsHelper.jsm +++ b/b2g/components/AlertsHelper.jsm @@ -144,8 +144,7 @@ let AlertsHelper = { lang: listener.lang, dir: listener.dir, id: listener.id, - tag: listener.tag, - timestamp: listener.timestamp + tag: listener.tag }, Services.io.newURI(listener.target, null, null), Services.io.newURI(listener.manifestURL, null, null) @@ -195,7 +194,7 @@ let AlertsHelper = { }, showNotification: function(imageURL, title, text, textClickable, cookie, - uid, bidi, lang, manifestURL, timestamp) { + uid, bidi, lang, manifestURL) { function send(appName, appIcon) { SystemAppProxy._sendCustomEvent(kMozChromeNotificationEvent, { type: kDesktopNotification, @@ -207,8 +206,7 @@ let AlertsHelper = { lang: lang, appName: appName, appIcon: appIcon, - manifestURL: manifestURL, - timestamp: timestamp + manifestURL: manifestURL }); } @@ -250,13 +248,12 @@ let AlertsHelper = { lang: details.lang || undefined, id: details.id || undefined, dir: details.dir || undefined, - tag: details.tag || undefined, - timestamp: details.timestamp || undefined + tag: details.tag || undefined }; this.registerAppListener(data.uid, listener); this.showNotification(data.imageURL, data.title, data.text, details.textClickable, null, data.uid, details.dir, - details.lang, details.manifestURL, details.timestamp); + details.lang, details.manifestURL); }, closeAlert: function(name) { diff --git a/b2g/components/AlertsService.js b/b2g/components/AlertsService.js index b7b2f1a8cd7ef5..96be4593039fc0 100644 --- a/b2g/components/AlertsService.js +++ b/b2g/components/AlertsService.js @@ -43,7 +43,6 @@ const kMessageAlertNotificationSend = "alert-notification-send"; const kMessageAlertNotificationClose = "alert-notification-close"; const kTopicAlertFinished = "alertfinished"; -const kTopicAlertClickCallback = "alertclickcallback"; function AlertsService() { Services.obs.addObserver(this, "xpcom-shutdown", false); @@ -104,8 +103,7 @@ AlertsService.prototype = { id: aDetails.id || undefined, dbId: aDetails.dbId || undefined, dir: aDetails.dir || undefined, - tag: aDetails.tag || undefined, - timestamp: aDetails.timestamp || undefined + tag: aDetails.tag || undefined }; cpmm.sendAsyncMessage(kMessageAppNotificationSend, { @@ -137,7 +135,6 @@ AlertsService.prototype = { // the notification so the app get a change to react. if (data.target) { gSystemMessenger.sendMessage(kNotificationSystemMessageName, { - clicked: (topic === kTopicAlertClickCallback), title: listener.title, body: listener.text, imageURL: listener.imageURL, @@ -145,8 +142,7 @@ AlertsService.prototype = { dir: listener.dir, id: listener.id, tag: listener.tag, - dbId: listener.dbId, - timestamp: listener.timestamp + dbId: listener.dbId }, Services.io.newURI(data.target, null, null), Services.io.newURI(listener.manifestURL, null, null) diff --git a/b2g/installer/package-manifest.in b/b2g/installer/package-manifest.in index 8a26fc7e293a2a..cc6d99a78af79f 100644 --- a/b2g/installer/package-manifest.in +++ b/b2g/installer/package-manifest.in @@ -336,8 +336,6 @@ @BINPATH@/components/zipwriter.xpt ; JavaScript components -@BINPATH@/components/ChromeNotifications.js -@BINPATH@/components/ChromeNotifications.manifest @BINPATH@/components/ConsoleAPI.manifest @BINPATH@/components/ConsoleAPIStorage.js @BINPATH@/components/BrowserElementParent.manifest diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index baa9f3b329ed3a..8b380fb04de311 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -344,8 +344,6 @@ @BINPATH@/components/telemetry.xpt ; JavaScript components -@BINPATH@/components/ChromeNotifications.js -@BINPATH@/components/ChromeNotifications.manifest @BINPATH@/components/ConsoleAPI.manifest @BINPATH@/components/ConsoleAPIStorage.js @BINPATH@/components/BrowserElementParent.manifest diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index 6d0e48803c0c32..572099a0d8bf8e 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -14,7 +14,6 @@ #include "mozilla/DebugOnly.h" #include "mozilla/FloatingPoint.h" #include "mozilla/Assertions.h" -#include "mozilla/Preferences.h" #include "AccessCheck.h" #include "jsfriendapi.h" @@ -2156,10 +2155,6 @@ ConvertJSValueToByteString(JSContext* cx, JS::Handle v, bool IsInPrivilegedApp(JSContext* aCx, JSObject* aObj) { - if (Preferences::GetBool("dom.ignore_webidl_scope_checks", false)) { - return true; - } - using mozilla::dom::workers::GetWorkerPrivateFromContext; if (!NS_IsMainThread()) { return GetWorkerPrivateFromContext(aCx)->IsInPrivilegedApp(); @@ -2174,10 +2169,6 @@ IsInPrivilegedApp(JSContext* aCx, JSObject* aObj) bool IsInCertifiedApp(JSContext* aCx, JSObject* aObj) { - if (Preferences::GetBool("dom.ignore_webidl_scope_checks", false)) { - return true; - } - using mozilla::dom::workers::GetWorkerPrivateFromContext; if (!NS_IsMainThread()) { return GetWorkerPrivateFromContext(aCx)->IsInCertifiedApp(); diff --git a/dom/interfaces/notification/nsINotificationStorage.idl b/dom/interfaces/notification/nsINotificationStorage.idl index da3b89212e1cf0..a046989222d49a 100644 --- a/dom/interfaces/notification/nsINotificationStorage.idl +++ b/dom/interfaces/notification/nsINotificationStorage.idl @@ -39,7 +39,7 @@ interface nsINotificationStorageCallback : nsISupports /** * Interface for notification persistence layer. */ -[scriptable, uuid(cc4656d7-2a2a-47f1-8016-55891e833d64)] +[scriptable, uuid(b177b080-2a23-11e3-8224-0800200c9a66)] interface nsINotificationStorage : nsISupports { @@ -55,10 +55,6 @@ interface nsINotificationStorage : nsISupports * @param body: the notification body * @param tag: notification tag, will replace any existing * notifications with same origin/tag pair - * @param alertName: the alert identifier as used by system app. - * Stored in the database to avoid re-computing - * it. Built from origin and tag or id depending - * whether there is a tag defined. */ void put(in DOMString origin, in DOMString id, @@ -67,8 +63,7 @@ interface nsINotificationStorage : nsISupports in DOMString lang, in DOMString body, in DOMString tag, - in DOMString icon, - in DOMString alertName); + in DOMString icon); /** * Retrieve a list of notifications. diff --git a/dom/src/notification/ChromeNotifications.js b/dom/src/notification/ChromeNotifications.js deleted file mode 100644 index 11e0af818e32a7..00000000000000 --- a/dom/src/notification/ChromeNotifications.js +++ /dev/null @@ -1,113 +0,0 @@ -/* 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/. */ - -"use strict"; - -const DEBUG = false; - -function debug(s) { - dump("-*- ChromeNotifications.js: " + s + "\n"); -} - -const Ci = Components.interfaces; -const Cu = Components.utils; - -Cu.import("resource://gre/modules/XPCOMUtils.jsm"); - -XPCOMUtils.defineLazyModuleGetter(this, "Services", - "resource://gre/modules/Services.jsm"); - -XPCOMUtils.defineLazyServiceGetter(this, "cpmm", - "@mozilla.org/childprocessmessagemanager;1", - "nsIMessageSender"); - -XPCOMUtils.defineLazyServiceGetter(this, "appNotifier", - "@mozilla.org/system-alerts-service;1", - "nsIAppNotificationService"); - -const CHROMENOTIFICATIONS_CID = "{74f94093-8b37-497e-824f-c3b250a911da}"; -const CHROMENOTIFICATIONS_CONTRACTID = "@mozilla.org/mozChromeNotifications;1"; - -function ChromeNotifications() { - this.innerWindowID = null; - this.resendCallback = null; -} - -ChromeNotifications.prototype = { - - init: function(aWindow) { - let util = aWindow.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIDOMWindowUtils); - this.innerWindowID = util.currentInnerWindowID; - Services.obs.addObserver(this, "inner-window-destroyed", false); - cpmm.addMessageListener("Notification:GetAllCrossOrigin:Return:OK", this); - }, - - performResend: function(notifications) { - let resentNotifications = 0; - - notifications.forEach(function(notification) { - appNotifier.showAppNotification( - notification.icon, - notification.title, - notification.body, - null, - { - manifestURL: notification.origin, - id: notification.alertName, - dir: notification.dir, - lang: notification.lang, - tag: notification.tag, - dbId: notification.id, - timestamp: notification.timestamp - } - ); - resentNotifications++; - }); - - try { - this.resendCallback && this.resendCallback(resentNotifications); - } catch (ex) { - if (DEBUG) debug("Content sent exception: " + ex); - } - }, - - mozResendAllNotifications: function(resendCallback) { - this.resendCallback = resendCallback; - cpmm.sendAsyncMessage("Notification:GetAllCrossOrigin", {}); - }, - - receiveMessage: function(message) { - switch (message.name) { - case "Notification:GetAllCrossOrigin:Return:OK": - this.performResend(message.data.notifications); - break; - - default: - if (DEBUG) { debug("Unrecognized message: " + message.name); } - break; - } - }, - - observe: function(aSubject, aTopic, aData) { - if (DEBUG) debug("Topic: " + aTopic); - if (aTopic == "inner-window-destroyed") { - let wId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data; - if (wId != this.innerWindowID) { - return; - } - Services.obs.removeObserver(this, "inner-window-destroyed"); - cpmm.removeMessageListener("Notification:GetAllCrossOrigin:Return:OK", this); - } - }, - - classID : Components.ID(CHROMENOTIFICATIONS_CID), - contractID : CHROMENOTIFICATIONS_CONTRACTID, - QueryInterface: XPCOMUtils.generateQI([Ci.nsIChromeNotifications, - Ci.nsIDOMGlobalPropertyInitializer, - Ci.nsIObserver, - Ci.nsIMessageListener]), -}; - -this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ChromeNotifications]); diff --git a/dom/src/notification/ChromeNotifications.manifest b/dom/src/notification/ChromeNotifications.manifest deleted file mode 100644 index 74e93107ffd7ff..00000000000000 --- a/dom/src/notification/ChromeNotifications.manifest +++ /dev/null @@ -1,3 +0,0 @@ -# ChromeNotifications.js -component {74f94093-8b37-497e-824f-c3b250a911da} ChromeNotifications.js -contract @mozilla.org/mozChromeNotifications;1 {74f94093-8b37-497e-824f-c3b250a911da} diff --git a/dom/src/notification/Notification.cpp b/dom/src/notification/Notification.cpp index 157203bf870c50..047699c48849c0 100644 --- a/dom/src/notification/Notification.cpp +++ b/dom/src/notification/Notification.cpp @@ -423,22 +423,6 @@ Notification::Notification(const nsAString& aID, const nsAString& aTitle, const mID(aID), mTitle(aTitle), mBody(aBody), mDir(aDir), mLang(aLang), mTag(aTag), mIconUrl(aIconUrl), mIsClosed(false) { - nsAutoString alertName; - DebugOnly rv = GetOrigin(GetOwner(), alertName); - MOZ_ASSERT(NS_SUCCEEDED(rv), "GetOrigin should not have failed"); - - // Get the notification name that is unique per origin + tag/ID. - // The name of the alert is of the form origin#tag/ID. - alertName.AppendLiteral("#"); - if (!mTag.IsEmpty()) { - alertName.Append(NS_LITERAL_STRING("tag:")); - alertName.Append(mTag); - } else { - alertName.Append(NS_LITERAL_STRING("notag:")); - alertName.Append(mID); - } - - mAlertName = alertName; } // static @@ -478,10 +462,6 @@ Notification::Constructor(const GlobalObject& aGlobal, nsString id; notification->GetID(id); - - nsString alertName; - notification->GetAlertName(alertName); - aRv = notificationStorage->Put(origin, id, aTitle, @@ -489,8 +469,7 @@ Notification::Constructor(const GlobalObject& aGlobal, aOptions.mLang, aOptions.mBody, aOptions.mTag, - aOptions.mIcon, - alertName); + aOptions.mIcon); if (aRv.Failed()) { return nullptr; } @@ -578,6 +557,10 @@ Notification::ShowInternal() nsCOMPtr observer = new NotificationObserver(this); + nsString alertName; + rv = GetAlertName(alertName); + NS_ENSURE_SUCCESS_VOID(rv); + #ifdef MOZ_B2G nsCOMPtr appNotifier = do_GetService("@mozilla.org/system-alerts-service;1"); @@ -595,7 +578,7 @@ Notification::ShowInternal() AppNotificationServiceOptions ops; ops.mTextClickable = true; ops.mManifestURL = manifestUrl; - ops.mId = mAlertName; + ops.mId = alertName; ops.mDbId = mID; ops.mDir = DirectionToString(mDir); ops.mLang = mLang; @@ -619,7 +602,7 @@ Notification::ShowInternal() nsString uniqueCookie = NS_LITERAL_STRING("notification:"); uniqueCookie.AppendInt(sCount++); alertService->ShowAlertNotification(absoluteUrl, mTitle, mBody, true, - uniqueCookie, observer, mAlertName, + uniqueCookie, observer, alertName, DirectionToString(mDir), mLang, GetPrincipal()); } @@ -788,8 +771,10 @@ Notification::CloseInternal() nsCOMPtr alertService = do_GetService(NS_ALERTSERVICE_CONTRACTID); if (alertService) { + nsString alertName; + rv = GetAlertName(alertName); if (NS_SUCCEEDED(rv)) { - alertService->CloseAlert(mAlertName, GetPrincipal()); + alertService->CloseAlert(alertName, GetPrincipal()); } } } @@ -827,6 +812,24 @@ Notification::GetOrigin(nsPIDOMWindow* aWindow, nsString& aOrigin) return NS_OK; } +nsresult +Notification::GetAlertName(nsString& aAlertName) +{ + // Get the notification name that is unique per origin + tag/ID. + // The name of the alert is of the form origin#tag/ID. + nsresult rv = GetOrigin(GetOwner(), aAlertName); + NS_ENSURE_SUCCESS(rv, rv); + aAlertName.AppendLiteral("#"); + if (!mTag.IsEmpty()) { + aAlertName.Append(NS_LITERAL_STRING("tag:")); + aAlertName.Append(mTag); + } else { + aAlertName.Append(NS_LITERAL_STRING("notag:")); + aAlertName.Append(mID); + } + return NS_OK; +} + } // namespace dom } // namespace mozilla diff --git a/dom/src/notification/Notification.h b/dom/src/notification/Notification.h index ae83174b7d4f02..cd5de4d69d9fbe 100644 --- a/dom/src/notification/Notification.h +++ b/dom/src/notification/Notification.h @@ -133,10 +133,7 @@ class Notification : public DOMEventTargetHelper static nsresult GetOrigin(nsPIDOMWindow* aWindow, nsString& aOrigin); - void GetAlertName(nsAString& aRetval) - { - aRetval = mAlertName; - } + nsresult GetAlertName(nsString& aAlertName); nsString mID; nsString mTitle; @@ -146,8 +143,6 @@ class Notification : public DOMEventTargetHelper nsString mTag; nsString mIconUrl; - nsString mAlertName; - bool mIsClosed; static uint32_t sCount; diff --git a/dom/src/notification/NotificationDB.jsm b/dom/src/notification/NotificationDB.jsm index 5a53dbe6d28aad..f082176f51daeb 100644 --- a/dom/src/notification/NotificationDB.jsm +++ b/dom/src/notification/NotificationDB.jsm @@ -16,9 +16,6 @@ const Ci = Components.interfaces; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/osfile.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "Services", - "resource://gre/modules/Services.jsm"); - XPCOMUtils.defineLazyServiceGetter(this, "ppmm", "@mozilla.org/parentprocessmessagemanager;1", "nsIMessageListenerManager"); @@ -36,23 +33,8 @@ const NOTIFICATION_STORE_DIR = OS.Constants.Path.profileDir; const NOTIFICATION_STORE_PATH = OS.Path.join(NOTIFICATION_STORE_DIR, "notificationstore.json"); -const kMessages = [ - "Notification:Save", - "Notification:Delete", - "Notification:GetAll", - "Notification:GetAllCrossOrigin" -]; - let NotificationDB = { - - // Ensure we won't call init() while xpcom-shutdown is performed - _shutdownInProgress: false, - init: function() { - if (this._shutdownInProgress) { - return; - } - this.notifications = {}; this.byTag = {}; this.loaded = false; @@ -60,29 +42,9 @@ let NotificationDB = { this.tasks = []; // read/write operation queue this.runningTask = false; - Services.obs.addObserver(this, "xpcom-shutdown", false); - this.registerListeners(); - }, - - registerListeners: function() { - for (let message of kMessages) { - ppmm.addMessageListener(message, this); - } - }, - - unregisterListeners: function() { - for (let message of kMessages) { - ppmm.removeMessageListener(message, this); - } - }, - - observe: function(aSubject, aTopic, aData) { - if (DEBUG) debug("Topic: " + aTopic); - if (aTopic == "xpcom-shutdown") { - this._shutdownInProgress = true; - Services.obs.removeObserver(this, "xpcom-shutdown"); - this.unregisterListeners(); - } + ppmm.addMessageListener("Notification:Save", this); + ppmm.addMessageListener("Notification:Delete", this); + ppmm.addMessageListener("Notification:GetAll", this); }, // Attempt to read notification file, if it's not there we will create it. @@ -198,15 +160,6 @@ let NotificationDB = { }); break; - case "Notification:GetAllCrossOrigin": - this.queueTask("getallaccrossorigin", message.data, - function(notifications) { - returnMessage("Notification:GetAllCrossOrigin:Return:OK", { - notifications: notifications - }); - }); - break; - case "Notification:Save": this.queueTask("save", message.data, function() { returnMessage("Notification:Save:Return:OK", { @@ -240,14 +193,14 @@ let NotificationDB = { // Only run immediately if we aren't currently running another task. if (!this.runningTask) { - if (DEBUG) { debug("Task queue was not running, starting now..."); } + if (DEBUG) { dump("Task queue was not running, starting now..."); } this.runNextTask(); } }, runNextTask: function() { if (this.tasks.length === 0) { - if (DEBUG) { debug("No more tasks to run, queue depleted"); } + if (DEBUG) { dump("No more tasks to run, queue depleted"); } this.runningTask = false; return; } @@ -270,10 +223,6 @@ let NotificationDB = { this.taskGetAll(task.data, wrappedCallback); break; - case "getallaccrossorigin": - this.taskGetAllCrossOrigin(wrappedCallback); - break; - case "save": this.taskSave(task.data, wrappedCallback); break; @@ -296,27 +245,6 @@ let NotificationDB = { callback(notifications); }, - taskGetAllCrossOrigin: function(callback) { - if (DEBUG) { debug("Task, getting all whatever origin"); } - var notifications = []; - for (var origin in this.notifications) { - for (var i in this.notifications[origin]) { - var notification = this.notifications[origin][i]; - - // Notifications without the alertName field cannot be resent by - // mozResendAllNotifications, so we just skip them. They will - // still be available to applications via Notification.get() - if (!('alertName' in notification)) { - continue; - } - - notification.origin = origin; - notifications.push(notification); - } - } - callback(notifications); - }, - taskSave: function(data, callback) { if (DEBUG) { debug("Task, saving"); } var origin = data.origin; diff --git a/dom/src/notification/NotificationStorage.js b/dom/src/notification/NotificationStorage.js index a241a52158b2b4..b8b86ea28113ea 100644 --- a/dom/src/notification/NotificationStorage.js +++ b/dom/src/notification/NotificationStorage.js @@ -36,7 +36,7 @@ function NotificationStorage() { NotificationStorage.prototype = { - put: function(origin, id, title, dir, lang, body, tag, icon, alertName) { + put: function(origin, id, title, dir, lang, body, tag, icon) { if (DEBUG) { debug("PUT: " + id + ": " + title); } var notification = { id: id, @@ -45,9 +45,7 @@ NotificationStorage.prototype = { lang: lang, body: body, tag: tag, - icon: icon, - alertName: alertName, - timestamp: new Date().getTime() + icon: icon }; this._notifications[id] = notification; diff --git a/dom/src/notification/moz.build b/dom/src/notification/moz.build index 45c29b89ee312a..552eb3af0c9735 100644 --- a/dom/src/notification/moz.build +++ b/dom/src/notification/moz.build @@ -5,8 +5,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. EXTRA_COMPONENTS += [ - 'ChromeNotifications.js', - 'ChromeNotifications.manifest', 'NotificationStorage.js', 'NotificationStorage.manifest', ] diff --git a/dom/src/notification/test/unit/test_notificationdb.js b/dom/src/notification/test/unit/test_notificationdb.js index 171324a174ca83..b274b48606bc39 100644 --- a/dom/src/notification/test/unit/test_notificationdb.js +++ b/dom/src/notification/test/unit/test_notificationdb.js @@ -336,116 +336,3 @@ add_test(function test_send_two_get_two() { requestID: (requestID + 1) // 21 }); }); - -// Cleanup previous notification -add_test(function test_delete_previous() { - let requestID = 25; - let msgReply = "Notification:Delete:Return:OK"; - let msgHandler = function(message) { - do_check_eq(requestID, message.data.requestID); - }; - - addAndSend("Notification:Delete", msgReply, msgHandler, { - origin: systemNotification.origin, - id: "{8ef9a628-f0f4-44b4-820d-c117573c33e3}", - requestID: requestID - }); -}); - -// Store two notifications, one without alertName and one with -add_test(function test_send_two_alertName() { - let requestID = 30; - let notifications = [ - { - origin: "app://system.gaiamobile.org/manifest.webapp", - id: "{27ead857-4f43-457f-a770-93b82fbfc223}", - title: "Notification title", - dir: "auto", - lang: "", - body: "Notification body", - tag: "", - icon: "icon.png", - timestamp: new Date().getTime() - }, { - origin: "app://system.gaiamobile.org/manifest.webapp", - id: "{40275e04-58d0-47be-8cc7-540578f793a4}", - title: "Notification title", - dir: "auto", - lang: "", - body: "Notification body", - tag: "", - icon: "icon.png", - alertName: "alertName", - timestamp: new Date().getTime() - } - ]; - let origin = notifications[0].origin; - - let msgGetCrossOriginReply = "Notification:GetAllCrossOrigin:Return:OK"; - let msgGetCrossOriginHandler = { - receiveMessage: function(message) { - if (message.name === msgGetCrossOriginReply) { - cpmm.removeMessageListener( - msgGetCrossOriginReply, msgGetCrossOriginHandler); - - let gotNotifications = message.data.notifications; - - // we expect to have one notification - do_check_eq(1, gotNotifications.length); - - // compare the only notification we should have got back - compareNotification(gotNotifications[0], notifications[1]); - - run_next_test(); - } - } - }; - cpmm.addMessageListener(msgGetCrossOriginReply, msgGetCrossOriginHandler); - - let msgGetReply = "Notification:GetAll:Return:OK"; - let msgGetHandler = { - receiveMessage: function(message) { - if (message.name === msgGetReply) { - cpmm.removeMessageListener(msgGetReply, msgGetHandler); - - let gotNotifications = message.data.notifications; - - // we expect to have two notifications - do_check_eq(2, gotNotifications.length); - - // compare each notification - for (let i = 0; i < gotNotifications.length; i++) { - compareNotification(gotNotifications[i], notifications[i]); - } - - run_next_test(); - } - } - }; - cpmm.addMessageListener(msgGetReply, msgGetHandler); - - let msgSaveReply = "Notification:Save:Return:OK"; - let msgSaveCalls = 0; - let msgSaveHandler = { - receiveMessage: function(message) { - if (message.name === msgSaveReply) { - msgSaveCalls++; - if (msgSaveCalls === 2) { - cpmm.removeMessageListener(msgSaveReply, msgSaveHandler); - // Trigger getall - cpmm.sendAsyncMessage("Notification:GetAll", { - origin: origin - }); - } - } - } - }; - cpmm.addMessageListener(msgSaveReply, msgSaveHandler); - - notifications.forEach(function(n) { - cpmm.sendAsyncMessage("Notification:Save", { - origin: origin, - notification: n - }); - }); -}); diff --git a/dom/tests/mochitest/notification/MockServices.js b/dom/tests/mochitest/notification/MockServices.js index 28c5f7750ae2bd..164cc7e9a91f8c 100644 --- a/dom/tests/mochitest/notification/MockServices.js +++ b/dom/tests/mochitest/notification/MockServices.js @@ -12,66 +12,41 @@ var MockServices = (function () { var registrar = SpecialPowers.wrap(SpecialPowers.Components).manager .QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar); - var activeAlertNotifications = Object.create(null); - - var activeAppNotifications = Object.create(null); + var activeNotifications = Object.create(null); var mockAlertsService = { showAlertNotification: function(imageUrl, title, text, textClickable, cookie, alertListener, name) { var listener = SpecialPowers.wrap(alertListener); - activeAlertNotifications[name] = { + activeNotifications[name] = { listener: listener, cookie: cookie }; // fake async alert show event - if (listener) { - setTimeout(function () { - listener.observe(null, "alertshow", cookie); - }, 100); - } + setTimeout(function () { + listener.observe(null, "alertshow", cookie); + }, 100); // ?? SpecialPowers.wrap(alertListener).observe(null, "alertclickcallback", cookie); }, - showAppNotification: function(aImageUrl, aTitle, aText, aAlertListener, aDetails) { - var listener = aAlertListener || (activeAlertNotifications[aDetails.id] ? activeAlertNotifications[aDetails.id].listener : undefined); - activeAppNotifications[aDetails.id] = { - observer: listener, - title: aTitle, - text: aText, - manifestURL: aDetails.manifestURL, - imageURL: aImageUrl, - lang: aDetails.lang || undefined, - id: aDetails.id || undefined, - dbId: aDetails.dbId || undefined, - dir: aDetails.dir || undefined, - tag: aDetails.tag || undefined, - timestamp: aDetails.timestamp || undefined - }; - this.showAlertNotification(aImageUrl, aTitle, aText, true, "", listener, aDetails.id); + showAppNotification: function(imageUrl, title, text, textClickable, + manifestURL, alertListener, name) { + this.showAlertNotification(imageUrl, title, text, textClickable, "", alertListener, name); }, closeAlert: function(name) { - var alertNotification = activeAlertNotifications[name]; - if (alertNotification) { - if (alertNotification.listener) { - alertNotification.listener.observe(null, "alertfinished", alertNotification.cookie); - } - delete activeAlertNotifications[name]; - } - - var appNotification = activeAppNotifications[name]; - if (appNotification) { - delete activeAppNotifications[name]; + var notification = activeNotifications[name]; + if (notification) { + notification.listener.observe(null, "alertfinished", notification.cookie); + delete activeNotifications[name]; } }, QueryInterface: function(aIID) { if (SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsISupports) || - SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIAlertsService) || - SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIAppNotificationService)) { + SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIAlertsService)) { return this; } throw SpecialPowers.Components.results.NS_ERROR_NO_INTERFACE; @@ -102,8 +77,5 @@ var MockServices = (function () { registrar.unregisterFactory(MOCK_ALERTS_CID, mockAlertsService); registrar.unregisterFactory(MOCK_SYSTEM_ALERTS_CID, mockAlertsService); }, - - activeAlertNotifications: activeAlertNotifications, - activeAppNotifications: activeAppNotifications, }; })(); diff --git a/dom/tests/mochitest/notification/mochitest.ini b/dom/tests/mochitest/notification/mochitest.ini index 89d4e45169c3ec..ac54da8357985f 100644 --- a/dom/tests/mochitest/notification/mochitest.ini +++ b/dom/tests/mochitest/notification/mochitest.ini @@ -9,4 +9,3 @@ support-files = skip-if = (toolkit == 'gonk' && debug) #debug-only timeout [test_bug931307.html] skip-if = (toolkit == 'gonk' && debug) #debug-only timeout -[test_notification_resend.html] diff --git a/dom/tests/mochitest/notification/test_bug931307.html b/dom/tests/mochitest/notification/test_bug931307.html index 03030114fa7d64..9477b1ea621046 100644 --- a/dom/tests/mochitest/notification/test_bug931307.html +++ b/dom/tests/mochitest/notification/test_bug931307.html @@ -13,17 +13,15 @@