From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../test_updateRecordNoEncryptionKeys_ws.js | 102 +++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 dom/push/test/xpcshell/test_updateRecordNoEncryptionKeys_ws.js (limited to 'dom/push/test/xpcshell/test_updateRecordNoEncryptionKeys_ws.js') diff --git a/dom/push/test/xpcshell/test_updateRecordNoEncryptionKeys_ws.js b/dom/push/test/xpcshell/test_updateRecordNoEncryptionKeys_ws.js new file mode 100644 index 0000000000..b54735c042 --- /dev/null +++ b/dom/push/test/xpcshell/test_updateRecordNoEncryptionKeys_ws.js @@ -0,0 +1,102 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const userAgentID = "4dffd396-6582-471d-8c0c-84f394e9f7db"; + +function run_test() { + do_get_profile(); + setPrefs({ + userAgentID, + }); + run_next_test(); +} + +add_task(async function test_with_data_enabled() { + let db = PushServiceWebSocket.newPushDB(); + registerCleanupFunction(() => { + return db.drop().then(_ => db.close()); + }); + + let [publicKey, privateKey] = await PushCrypto.generateKeys(); + let records = [ + { + channelID: "eb18f12a-cc42-4f14-accb-3bfc1227f1aa", + pushEndpoint: "https://example.org/push/no-key/1", + scope: "https://example.com/page/1", + originAttributes: "", + quota: Infinity, + }, + { + channelID: "0d8886b9-8da1-4778-8f5d-1cf93a877ed6", + pushEndpoint: "https://example.org/push/key", + scope: "https://example.com/page/2", + originAttributes: "", + p256dhPublicKey: publicKey, + p256dhPrivateKey: privateKey, + quota: Infinity, + }, + ]; + for (let record of records) { + await db.put(record); + } + + PushService.init({ + serverURI: "wss://push.example.org/", + db, + makeWebSocket(uri) { + return new MockWebSocket(uri, { + onHello(request) { + ok( + request.use_webpush, + "Should use Web Push if data delivery is enabled" + ); + this.serverSendMsg( + JSON.stringify({ + messageType: "hello", + status: 200, + uaid: request.uaid, + use_webpush: true, + }) + ); + }, + onRegister(request) { + this.serverSendMsg( + JSON.stringify({ + messageType: "register", + status: 200, + uaid: userAgentID, + channelID: request.channelID, + pushEndpoint: "https://example.org/push/new", + }) + ); + }, + }); + }, + }); + + let newRecord = await PushService.register({ + scope: "https://example.com/page/3", + originAttributes: ChromeUtils.originAttributesToSuffix({ + inIsolatedMozBrowser: false, + }), + }); + ok(newRecord.p256dhKey, "Should generate public keys for new records"); + + let record = await db.getByKeyID("eb18f12a-cc42-4f14-accb-3bfc1227f1aa"); + ok(record.p256dhPublicKey, "Should add public key to partial record"); + ok(record.p256dhPrivateKey, "Should add private key to partial record"); + + record = await db.getByKeyID("0d8886b9-8da1-4778-8f5d-1cf93a877ed6"); + deepEqual( + record.p256dhPublicKey, + publicKey, + "Should leave existing public key" + ); + deepEqual( + record.p256dhPrivateKey, + privateKey, + "Should leave existing private key" + ); +}); -- cgit v1.2.3