Bug 1052435 - Fix handling of Notification with tag. r=mhenretty

This commit fixes two bugs. When sending two notifications with the same
tag, the NotificationDB this.byTag member was not properly updated. This
resulted in multiple notifications with the same tag being saved.
NotificationStorage's cache may hide this during the running session,
but on B2G the resend of notifications at reboot would expose the issue.
The second bug fixed is the test that makes sure we properly overwrite
notifications with the same tag in the database: the way we handled fake
notification object made them sharing the same ID. This, NotificationDB
would not even consider the tags and this lead to hiding the bug.
This commit is contained in:
Alexandre Lissy 2014-08-12 10:15:00 -04:00
parent aad3e91183
commit 8fad0a23c3
3 changed files with 41 additions and 30 deletions

View File

@ -331,9 +331,11 @@ let NotificationDB = {
// We might have existing notification with this tag,
// if so we need to remove it before saving the new one.
if (notification.tag && this.byTag[origin][notification.tag]) {
if (notification.tag) {
var oldNotification = this.byTag[origin][notification.tag];
delete this.notifications[origin][oldNotification.id];
if (oldNotification) {
delete this.notifications[origin][oldNotification.id];
}
this.byTag[origin][notification.tag] = notification;
}

View File

@ -9,27 +9,24 @@ XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
"@mozilla.org/childprocessmessagemanager;1",
"nsIMessageSender");
let systemNotification = {
origin: "app://system.gaiamobile.org/manifest.webapp",
id: "{2bc883bf-2809-4432-b0f4-f54e10372764}",
title: "SystemNotification:" + Date.now(),
dir: "auto",
lang: "",
body: "System notification body",
tag: "",
icon: "icon.png"
};
function getNotificationObject(app, id, tag) {
return {
origin: "app://" + app + ".gaiamobile.org/manifest.webapp",
id: id,
title: app + "Notification:" + Date.now(),
dir: "auto",
lang: "",
body: app + " notification body",
tag: tag || "",
icon: "icon.png"
};
}
let calendarNotification = {
origin: "app://calendar.gaiamobile.org/manifest.webapp",
id: "{d8d11299-a58e-429b-9a9a-57c562982fbf}",
title: "CalendarNotification:" + Date.now(),
dir: "auto",
lang: "",
body: "Calendar notification body",
tag: "",
icon: "icon.png"
};
let systemNotification =
getNotificationObject("system", "{2bc883bf-2809-4432-b0f4-f54e10372764}");
let calendarNotification =
getNotificationObject("calendar", "{d8d11299-a58e-429b-9a9a-57c562982fbf}");
// Helper to start the NotificationDB
function startNotificationDB() {

View File

@ -155,13 +155,10 @@ add_test(function test_send_two_get_one() {
let requestID = 10;
let tag = "voicemail";
let systemNotification1 = systemNotification;
systemNotification1.id = "{f271f9ee-3955-4c10-b1f2-af552fb270ee}";
systemNotification1.tag = tag;
let systemNotification2 = systemNotification;
systemNotification2.id = "{8ef9a628-f0f4-44b4-820d-c117573c33e3}";
systemNotification2.tag = tag;
let systemNotification1 =
getNotificationObject("system", "{f271f9ee-3955-4c10-b1f2-af552fb270ee}", tag);
let systemNotification2 =
getNotificationObject("system", "{8ef9a628-f0f4-44b4-820d-c117573c33e3}", tag);
let msgGetReply = "Notification:GetAll:Return:OK";
let msgGetNotifHandler = {
@ -206,6 +203,21 @@ add_test(function test_send_two_get_one() {
}, false);
});
// Delete previous notification
add_test(function test_delete_previous() {
let requestID = 15;
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 from two origins with the same tag
add_test(function test_send_two_get_two() {
let requestID = 20;
@ -292,7 +304,7 @@ add_test(function test_delete_previous() {
addAndSend("Notification:Delete", msgReply, msgHandler, {
origin: systemNotification.origin,
id: "{8ef9a628-f0f4-44b4-820d-c117573c33e3}",
id: "{2bc883bf-2809-4432-b0f4-f54e10372764}",
requestID: requestID
});
});