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 = "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",
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({
db,
makeWebSocket(uri) {
return new MockWebSocket(uri, {
onHello() {
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,
})
);
},
onACK: ackDone,
});
},
});
let newRecord = await PushService.register({
originAttributes: "",
});
equal(
newRecord.endpoint,
"Wrong push endpoint in record"
);
let { data: scope } = await notifyPromise;
await ackPromise;
let prevRecord = await db.getByKeyID("9bcc7efb-86c7-4457-93ea-e24e6eb59b74");
equal(
prevRecord.pushEndpoint,
"Wrong existing push endpoint"
);
strictEqual(
prevRecord.version,
3,
"Should record version updates sent before register responses"
);
let registeredRecord = await db.getByPushEndpoint(
);
ok(!registeredRecord.version, "Should not record premature updates");
});