From 8dd16259287f58f9273002717ec4d27e97127719 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:43:14 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- dom/notification/test/unit/head_notificationdb.js | 3 + dom/notification/test/unit/test_notificationdb.js | 86 +++++++++++++++++++++++ 2 files changed, 89 insertions(+) (limited to 'dom/notification/test') diff --git a/dom/notification/test/unit/head_notificationdb.js b/dom/notification/test/unit/head_notificationdb.js index 1b23d88729..44b0d7c01b 100644 --- a/dom/notification/test/unit/head_notificationdb.js +++ b/dom/notification/test/unit/head_notificationdb.js @@ -31,6 +31,9 @@ var calendarNotification = getNotificationObject( // Helper to start the NotificationDB function startNotificationDB() { + ChromeUtils.importESModule( + "resource://gre/modules/MemoryNotificationDB.sys.mjs" + ); ChromeUtils.importESModule("resource://gre/modules/NotificationDB.sys.mjs"); } 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