Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android' OR os == 'linux'
- Manifest: dom/push/test/xpcshell/xpcshell.toml
/* Any copyright is dedicated to the Public Domain.
"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",
originAttributes: "",
quota: Infinity,
},
{
channelID: "0d8886b9-8da1-4778-8f5d-1cf93a877ed6",
originAttributes: "",
p256dhPublicKey: publicKey,
p256dhPrivateKey: privateKey,
quota: Infinity,
},
];
for (let record of records) {
await db.put(record);
}
PushService.init({
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,
})
);
},
});
},
});
let newRecord = await PushService.register({
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"
);
});