Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android'
- Manifest: dom/push/test/xpcshell/xpcshell.toml
/* Any copyright is dedicated to the Public Domain.
"use strict";
const userAgentID = "52b2b04c-b6cc-42c6-abdf-bef9cbdbea00";
const channelID = "cafed00d";
function run_test() {
do_get_profile();
setPrefs();
run_next_test();
}
add_task(async function test_register_invalid_channel() {
let db = PushServiceWebSocket.newPushDB();
registerCleanupFunction(() => {
return db.drop().then(_ => db.close());
});
PushServiceWebSocket._generateID = () => channelID;
PushService.init({
db,
makeWebSocket(uri) {
return new MockWebSocket(uri, {
onHello() {
this.serverSendMsg(
JSON.stringify({
messageType: "hello",
uaid: userAgentID,
status: 200,
})
);
},
onRegister() {
this.serverSendMsg(
JSON.stringify({
messageType: "register",
status: 403,
channelID,
error: "Invalid channel ID",
})
);
},
});
},
});
await Assert.rejects(
PushService.register({
originAttributes: ChromeUtils.originAttributesToSuffix({
inIsolatedMozBrowser: false,
}),
}),
/Registration error/,
"Expected error for invalid channel ID"
);
let record = await db.getByKeyID(channelID);
ok(!record, "Should not store records for error responses");
});