diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /dom/push/test/xpcshell/test_register_flush.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream/1%115.7.0.tar.xz thunderbird-upstream/1%115.7.0.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/push/test/xpcshell/test_register_flush.js')
-rw-r--r-- | dom/push/test/xpcshell/test_register_flush.js | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/dom/push/test/xpcshell/test_register_flush.js b/dom/push/test/xpcshell/test_register_flush.js new file mode 100644 index 0000000000..2c12ecb9ba --- /dev/null +++ b/dom/push/test/xpcshell/test_register_flush.js @@ -0,0 +1,116 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const userAgentID = "9ce1e6d3-7bdb-4fe9-90a5-def1d64716f1"; + +function run_test() { + do_get_profile(); + setPrefs({ + userAgentID, + requestTimeout: 1000, + retryBaseInterval: 150, + }); + run_next_test(); +} + +add_task(async function test_register_flush() { + let db = PushServiceWebSocket.newPushDB(); + registerCleanupFunction(() => { + return db.drop().then(_ => db.close()); + }); + let record = { + channelID: "9bcc7efb-86c7-4457-93ea-e24e6eb59b74", + pushEndpoint: "https://example.org/update/1", + scope: "https://example.com/page/1", + originAttributes: "", + version: 2, + quota: Infinity, + systemRecord: true, + }; + await db.put(record); + + let notifyPromise = promiseObserverNotification( + PushServiceComponent.pushTopic + ); + + let ackDone; + let ackPromise = new Promise(resolve => (ackDone = after(2, resolve))); + PushService.init({ + serverURI: "wss://push.example.org/", + db, + makeWebSocket(uri) { + return new MockWebSocket(uri, { + onHello(request) { + this.serverSendMsg( + JSON.stringify({ + messageType: "hello", + status: 200, + uaid: userAgentID, + }) + ); + }, + onRegister(request) { + this.serverSendMsg( + JSON.stringify({ + messageType: "notification", + updates: [ + { + channelID: request.channelID, + version: 2, + }, + { + channelID: "9bcc7efb-86c7-4457-93ea-e24e6eb59b74", + version: 3, + }, + ], + }) + ); + this.serverSendMsg( + JSON.stringify({ + messageType: "register", + status: 200, + channelID: request.channelID, + uaid: userAgentID, + pushEndpoint: "https://example.org/update/2", + }) + ); + }, + onACK: ackDone, + }); + }, + }); + + let newRecord = await PushService.register({ + scope: "https://example.com/page/2", + originAttributes: "", + }); + equal( + newRecord.endpoint, + "https://example.org/update/2", + "Wrong push endpoint in record" + ); + + let { data: scope } = await notifyPromise; + equal(scope, "https://example.com/page/1", "Wrong notification scope"); + + await ackPromise; + + let prevRecord = await db.getByKeyID("9bcc7efb-86c7-4457-93ea-e24e6eb59b74"); + equal( + prevRecord.pushEndpoint, + "https://example.org/update/1", + "Wrong existing push endpoint" + ); + strictEqual( + prevRecord.version, + 3, + "Should record version updates sent before register responses" + ); + + let registeredRecord = await db.getByPushEndpoint( + "https://example.org/update/2" + ); + ok(!registeredRecord.version, "Should not record premature updates"); +}); |