mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1024090 - Ensure proper loading of Notification database. r=gwagner
This commit is contained in:
parent
74da862e65
commit
d9e6fb974a
@ -82,9 +82,9 @@ let NotificationDB = {
|
||||
var promise = OS.File.read(NOTIFICATION_STORE_PATH, { encoding: "utf-8"});
|
||||
return promise.then(
|
||||
function onSuccess(data) {
|
||||
// JSON parsing failure will get handled by a later catch in the promise
|
||||
// chain
|
||||
this.notifications = JSON.parse(data);
|
||||
if (data.length > 0) {
|
||||
this.notifications = JSON.parse(data);
|
||||
}
|
||||
// populate the list of notifications by tag
|
||||
if (this.notifications) {
|
||||
for (var origin in this.notifications) {
|
||||
|
@ -150,9 +150,12 @@ NotificationStorage.prototype = {
|
||||
} catch (e) {
|
||||
debug("Error calling callback done: " + e);
|
||||
}
|
||||
case kMessageNotificationSaveOk:
|
||||
case kMessageNotificationDeleteOk:
|
||||
debug("Error received when treating: '" + message.name + "': " + message.data.errorMsg);
|
||||
case kMessageNotificationSaveKo:
|
||||
case kMessageNotificationDeleteKo:
|
||||
if (DEBUG) {
|
||||
debug("Error received when treating: '" + message.name +
|
||||
"': " + message.data.errorMsg);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
63
dom/src/notification/test/unit/common_test_notificationdb.js
Normal file
63
dom/src/notification/test/unit/common_test_notificationdb.js
Normal file
@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
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"
|
||||
};
|
||||
|
||||
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"
|
||||
};
|
||||
|
||||
// Helper to start the NotificationDB
|
||||
function startNotificationDB() {
|
||||
Cu.import("resource://gre/modules/NotificationDB.jsm");
|
||||
}
|
||||
|
||||
// Helper function to add a listener, send message and treat the reply
|
||||
function addAndSend(msg, reply, callback, payload, runNext = true) {
|
||||
let handler = {
|
||||
receiveMessage: function(message) {
|
||||
if (message.name === reply) {
|
||||
cpmm.removeMessageListener(reply, handler);
|
||||
callback(message);
|
||||
if (runNext) {
|
||||
run_next_test();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
cpmm.addMessageListener(reply, handler);
|
||||
cpmm.sendAsyncMessage(msg, payload);
|
||||
}
|
||||
|
||||
// helper fonction, comparing two notifications
|
||||
function compareNotification(notif1, notif2) {
|
||||
// retrieved notification should be the second one sent
|
||||
for (let prop in notif1) {
|
||||
// compare each property
|
||||
do_check_eq(notif1[prop], notif2[prop]);
|
||||
}
|
||||
}
|
@ -1,66 +1,11 @@
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
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"
|
||||
};
|
||||
|
||||
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"
|
||||
};
|
||||
"use strict";
|
||||
|
||||
function run_test() {
|
||||
do_get_profile();
|
||||
Cu.import("resource://gre/modules/NotificationDB.jsm");
|
||||
startNotificationDB();
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
// Helper function to add a listener, send message and treat the reply
|
||||
function addAndSend(msg, reply, callback, payload, runNext = true) {
|
||||
let handler = {
|
||||
receiveMessage: function(message) {
|
||||
if (message.name === reply) {
|
||||
cpmm.removeMessageListener(reply, handler);
|
||||
callback(message);
|
||||
if (runNext) {
|
||||
run_next_test();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
cpmm.addMessageListener(reply, handler);
|
||||
cpmm.sendAsyncMessage(msg, payload);
|
||||
}
|
||||
|
||||
// helper fonction, comparing two notifications
|
||||
function compareNotification(notif1, notif2) {
|
||||
// retrieved notification should be the second one sent
|
||||
for (let prop in notif1) {
|
||||
// compare each property
|
||||
do_check_eq(notif1[prop], notif2[prop]);
|
||||
}
|
||||
}
|
||||
|
||||
// Get one notification, none exists
|
||||
add_test(function test_get_none() {
|
||||
let requestID = 0;
|
||||
|
@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
|
||||
function run_test() {
|
||||
do_get_profile();
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
/// For bug 1024090: test edge case of notificationstore.json
|
||||
add_test(function test_bug1024090_purge() {
|
||||
Cu.import("resource://gre/modules/osfile.jsm");
|
||||
const NOTIFICATION_STORE_PATH =
|
||||
OS.Path.join(OS.Constants.Path.profileDir, "notificationstore.json");
|
||||
let cleanup = OS.File.writeAtomic(NOTIFICATION_STORE_PATH, "");
|
||||
cleanup.then(
|
||||
function onSuccess() {
|
||||
ok(true, "Notification database cleaned.");
|
||||
},
|
||||
function onError(reason) {
|
||||
ok(false, "Notification database error when cleaning: " + reason);
|
||||
}
|
||||
).then(function next() {
|
||||
do_print("Cleanup steps completed: " + NOTIFICATION_STORE_PATH);
|
||||
startNotificationDB();
|
||||
run_next_test();
|
||||
});
|
||||
});
|
||||
|
||||
// Store one notification
|
||||
add_test(function test_bug1024090_send_one() {
|
||||
let requestID = 1;
|
||||
let msgReply = "Notification:Save:Return:OK";
|
||||
let msgHandler = function(message) {
|
||||
equal(requestID, message.data.requestID, "Checking requestID");
|
||||
};
|
||||
|
||||
addAndSend("Notification:Save", msgReply, msgHandler, {
|
||||
origin: systemNotification.origin,
|
||||
notification: systemNotification,
|
||||
requestID: requestID
|
||||
});
|
||||
});
|
||||
|
||||
// Get one notification, one exists
|
||||
add_test(function test_bug1024090_get_one() {
|
||||
let requestID = 2;
|
||||
let msgReply = "Notification:GetAll:Return:OK";
|
||||
let msgHandler = function(message) {
|
||||
equal(requestID, message.data.requestID, "Checking requestID");
|
||||
equal(1, message.data.notifications.length, "One notification stored");
|
||||
};
|
||||
|
||||
addAndSend("Notification:GetAll", msgReply, msgHandler, {
|
||||
origin: systemNotification.origin,
|
||||
requestID: requestID
|
||||
});
|
||||
});
|
@ -1,5 +1,6 @@
|
||||
[DEFAULT]
|
||||
head =
|
||||
head = common_test_notificationdb.js
|
||||
tail =
|
||||
|
||||
[test_notificationdb.js]
|
||||
[test_notificationdb_bug1024090.js]
|
||||
|
Loading…
Reference in New Issue
Block a user