diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/push/test/xpcshell/test_notification_error.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/push/test/xpcshell/test_notification_error.js')
-rw-r--r-- | dom/push/test/xpcshell/test_notification_error.js | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/dom/push/test/xpcshell/test_notification_error.js b/dom/push/test/xpcshell/test_notification_error.js new file mode 100644 index 0000000000..21ab7ab94f --- /dev/null +++ b/dom/push/test/xpcshell/test_notification_error.js @@ -0,0 +1,151 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const userAgentID = "3c7462fc-270f-45be-a459-b9d631b0d093"; + +function run_test() { + do_get_profile(); + setPrefs({ + userAgentID, + }); + run_next_test(); +} + +add_task(async function test_notification_error() { + let db = PushServiceWebSocket.newPushDB(); + registerCleanupFunction(() => { + return db.drop().then(_ => db.close()); + }); + + let originAttributes = ""; + let records = [ + { + channelID: "f04f1e46-9139-4826-b2d1-9411b0821283", + pushEndpoint: "https://example.org/update/success-1", + scope: "https://example.com/a", + originAttributes, + version: 1, + quota: Infinity, + systemRecord: true, + }, + { + channelID: "3c3930ba-44de-40dc-a7ca-8a133ec1a866", + pushEndpoint: "https://example.org/update/error", + scope: "https://example.com/b", + originAttributes, + version: 2, + quota: Infinity, + systemRecord: true, + }, + { + channelID: "b63f7bef-0a0d-4236-b41e-086a69dfd316", + pushEndpoint: "https://example.org/update/success-2", + scope: "https://example.com/c", + originAttributes, + version: 3, + quota: Infinity, + systemRecord: true, + }, + ]; + for (let record of records) { + await db.put(record); + } + + let scopes = []; + let notifyPromise = promiseObserverNotification( + PushServiceComponent.pushTopic, + (subject, data) => scopes.push(data) == 2 + ); + + let ackDone; + let ackPromise = new Promise( + resolve => (ackDone = after(records.length, resolve)) + ); + PushService.init({ + serverURI: "wss://push.example.org/", + db: makeStub(db, { + getByKeyID(prev, channelID) { + if (channelID == "3c3930ba-44de-40dc-a7ca-8a133ec1a866") { + return Promise.reject("splines not reticulated"); + } + return prev.call(this, channelID); + }, + }), + makeWebSocket(uri) { + return new MockWebSocket(uri, { + onHello(request) { + this.serverSendMsg( + JSON.stringify({ + messageType: "hello", + status: 200, + uaid: userAgentID, + }) + ); + this.serverSendMsg( + JSON.stringify({ + messageType: "notification", + updates: records.map(({ channelID, version }) => ({ + channelID, + version: ++version, + })), + }) + ); + }, + // Should acknowledge all received updates, even if updating + // IndexedDB fails. + onACK: ackDone, + }); + }, + }); + + await notifyPromise; + ok( + scopes.includes("https://example.com/a"), + "Missing scope for notification A" + ); + ok( + scopes.includes("https://example.com/c"), + "Missing scope for notification C" + ); + + await ackPromise; + + let aRecord = await db.getByIdentifiers({ + scope: "https://example.com/a", + originAttributes, + }); + equal( + aRecord.channelID, + "f04f1e46-9139-4826-b2d1-9411b0821283", + "Wrong channel ID for record A" + ); + strictEqual(aRecord.version, 2, "Should return the new version for record A"); + + let bRecord = await db.getByIdentifiers({ + scope: "https://example.com/b", + originAttributes, + }); + equal( + bRecord.channelID, + "3c3930ba-44de-40dc-a7ca-8a133ec1a866", + "Wrong channel ID for record B" + ); + strictEqual( + bRecord.version, + 2, + "Should return the previous version for record B" + ); + + let cRecord = await db.getByIdentifiers({ + scope: "https://example.com/c", + originAttributes, + }); + equal( + cRecord.channelID, + "b63f7bef-0a0d-4236-b41e-086a69dfd316", + "Wrong channel ID for record C" + ); + strictEqual(cRecord.version, 4, "Should return the new version for record C"); +}); |