From 59203c63bb777a3bacec32fb8830fba33540e809 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:35:29 +0200 Subject: Adding upstream version 127.0. Signed-off-by: Daniel Baumann --- dom/notification/test/unit/test_notificationdb.js | 86 +++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'dom/notification/test/unit/test_notificationdb.js') 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, + } + ); +}); -- cgit v1.2.3