summaryrefslogtreecommitdiffstats
path: root/dom/notification/test/unit/test_notificationdb.js
diff options
context:
space:
mode:
Diffstat (limited to 'dom/notification/test/unit/test_notificationdb.js')
-rw-r--r--dom/notification/test/unit/test_notificationdb.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/dom/notification/test/unit/test_notificationdb.js b/dom/notification/test/unit/test_notificationdb.js
index b6ca8bd79c..4fc1e6389d 100644
--- a/dom/notification/test/unit/test_notificationdb.js
+++ b/dom/notification/test/unit/test_notificationdb.js
@@ -338,3 +338,89 @@ add_test(function test_delete_previous() {
requestID,
});
});
+
+add_test(function test_notification_onDiskPersistence() {
+ let verifyDisk = async function (expectedId) {
+ const NOTIFICATION_STORE_PATH = PathUtils.join(
+ PathUtils.profileDir,
+ "notificationstore.json"
+ );
+
+ const onDiskNotificationStr = await IOUtils.readUTF8(
+ NOTIFICATION_STORE_PATH
+ );
+ return onDiskNotificationStr.includes(expectedId);
+ };
+
+ let persistedNotification = getNotificationObject(
+ systemNotification.origin,
+ "{315aaf98-6c72-48fe-8e2c-a841e1b00027}",
+ "" /* tag */,
+ true /* scope */
+ );
+
+ addAndSend(
+ "Notification:Save",
+ "Notification:Save:Return:OK",
+ async () => {
+ Assert.ok(await verifyDisk(persistedNotification.id));
+ },
+ {
+ origin: persistedNotification.origin,
+ notification: persistedNotification,
+ requestID: 2,
+ }
+ );
+
+ let nonPersistedNotification = getNotificationObject(
+ systemNotification.origin,
+ "{8110ed62-303f-4f9b-a257-a62487aaa09c}",
+ "" /* tag */,
+ true /* scope */
+ );
+
+ addAndSend(
+ "MemoryNotification:Save",
+ "MemoryNotification:Save:Return:OK",
+ async () => {
+ // memoryonly notification must not exist on disk.
+ Assert.ok(!(await verifyDisk(nonPersistedNotification.id)));
+ },
+ {
+ origin: nonPersistedNotification.origin,
+ notification: nonPersistedNotification,
+ requestID: 3,
+ }
+ );
+
+ let verifyMemory = function (message, expectedId) {
+ return message.data.notifications.some(notification => {
+ return notification.id == expectedId;
+ });
+ };
+
+ addAndSend(
+ "Notification:GetAll",
+ "Notification:GetAll:Return:OK",
+ message => {
+ Assert.ok(verifyMemory(message, persistedNotification.id));
+ },
+ {
+ origin: persistedNotification.origin,
+ requestID: 4,
+ }
+ );
+
+ addAndSend(
+ "MemoryNotification:GetAll",
+ "MemoryNotification:GetAll:Return:OK",
+ message => {
+ // memoryonly notification must exist in-memory
+ Assert.ok(verifyMemory(message, nonPersistedNotification.id));
+ },
+ {
+ origin: persistedNotification.origin,
+ requestID: 5,
+ }
+ );
+});