diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/push/test/xpcshell/test_register_success.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/push/test/xpcshell/test_register_success.js')
-rw-r--r-- | dom/push/test/xpcshell/test_register_success.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/dom/push/test/xpcshell/test_register_success.js b/dom/push/test/xpcshell/test_register_success.js new file mode 100644 index 0000000000..9b6692ca25 --- /dev/null +++ b/dom/push/test/xpcshell/test_register_success.js @@ -0,0 +1,93 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const userAgentID = "bd744428-f125-436a-b6d0-dd0c9845837f"; +const channelID = "0ef2ad4a-6c49-41ad-af6e-95d2425276bf"; + +function run_test() { + do_get_profile(); + setPrefs({ + userAgentID, + requestTimeout: 1000, + retryBaseInterval: 150, + }); + run_next_test(); +} + +add_task(async function test_register_success() { + let db = PushServiceWebSocket.newPushDB(); + registerCleanupFunction(() => { + return db.drop().then(_ => db.close()); + }); + + PushServiceWebSocket._generateID = () => channelID; + PushService.init({ + serverURI: "wss://push.example.org/", + db, + makeWebSocket(uri) { + return new MockWebSocket(uri, { + onHello(data) { + equal(data.messageType, "hello", "Handshake: wrong message type"); + ok( + !data.uaid, + "Should not send UAID in handshake without local subscriptions" + ); + this.serverSendMsg( + JSON.stringify({ + messageType: "hello", + status: 200, + uaid: userAgentID, + }) + ); + }, + onRegister(data) { + equal(data.messageType, "register", "Register: wrong message type"); + equal(data.channelID, channelID, "Register: wrong channel ID"); + this.serverSendMsg( + JSON.stringify({ + messageType: "register", + status: 200, + channelID, + uaid: userAgentID, + pushEndpoint: "https://example.com/update/1", + }) + ); + }, + }); + }, + }); + + let subModifiedPromise = promiseObserverNotification( + PushServiceComponent.subscriptionModifiedTopic + ); + + let newRecord = await PushService.register({ + scope: "https://example.org/1", + originAttributes: ChromeUtils.originAttributesToSuffix({ + inIsolatedMozBrowser: false, + }), + }); + equal( + newRecord.endpoint, + "https://example.com/update/1", + "Wrong push endpoint in registration record" + ); + + let { data: subModifiedScope } = await subModifiedPromise; + equal( + subModifiedScope, + "https://example.org/1", + "Should fire a subscription modified event after subscribing" + ); + + let record = await db.getByKeyID(channelID); + equal(record.channelID, channelID, "Wrong channel ID in database record"); + equal( + record.pushEndpoint, + "https://example.com/update/1", + "Wrong push endpoint in database record" + ); + equal(record.quota, 16, "Wrong quota in database record"); +}); |