2015-04-21 18:10:50 +00:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2015-06-02 11:14:00 +00:00
|
|
|
const {PushDB, PushService, PushServiceWebSocket} = serviceExports;
|
2015-04-21 18:10:50 +00:00
|
|
|
|
2015-10-03 21:59:24 +00:00
|
|
|
const userAgentID = 'ba31ac13-88d4-4984-8e6b-8731315a7cf8';
|
|
|
|
|
2015-04-21 18:10:50 +00:00
|
|
|
function run_test() {
|
|
|
|
do_get_profile();
|
2015-10-03 21:59:24 +00:00
|
|
|
setPrefs({
|
|
|
|
userAgentID: userAgentID,
|
|
|
|
});
|
2015-04-21 18:10:50 +00:00
|
|
|
run_next_test();
|
|
|
|
}
|
|
|
|
|
2017-06-22 10:51:42 +00:00
|
|
|
add_task(async function test_notification_version_string() {
|
2015-06-02 11:14:00 +00:00
|
|
|
let db = PushServiceWebSocket.newPushDB();
|
2017-12-21 10:10:23 +00:00
|
|
|
registerCleanupFunction(() => {return db.drop().then(_ => db.close());});
|
2017-06-22 10:51:42 +00:00
|
|
|
await db.put({
|
2015-04-21 18:10:50 +00:00
|
|
|
channelID: '6ff97d56-d0c0-43bc-8f5b-61b855e1d93b',
|
|
|
|
pushEndpoint: 'https://example.org/updates/1',
|
|
|
|
scope: 'https://example.com/page/1',
|
2015-06-24 20:34:54 +00:00
|
|
|
originAttributes: '',
|
2015-06-25 21:52:57 +00:00
|
|
|
version: 2,
|
|
|
|
quota: Infinity,
|
2015-12-16 17:21:22 +00:00
|
|
|
systemRecord: true,
|
2015-04-21 18:10:50 +00:00
|
|
|
});
|
|
|
|
|
2016-03-03 22:37:10 +00:00
|
|
|
let notifyPromise = promiseObserverNotification(PushServiceComponent.pushTopic);
|
2015-04-21 18:10:50 +00:00
|
|
|
|
2015-08-15 00:26:07 +00:00
|
|
|
let ackDone;
|
|
|
|
let ackPromise = new Promise(resolve => ackDone = resolve);
|
2015-04-21 18:10:50 +00:00
|
|
|
PushService.init({
|
2015-06-02 11:14:00 +00:00
|
|
|
serverURI: "wss://push.example.org/",
|
2015-04-21 18:10:50 +00:00
|
|
|
db,
|
|
|
|
makeWebSocket(uri) {
|
|
|
|
return new MockWebSocket(uri, {
|
|
|
|
onHello(request) {
|
|
|
|
this.serverSendMsg(JSON.stringify({
|
|
|
|
messageType: 'hello',
|
|
|
|
status: 200,
|
2015-10-03 21:59:24 +00:00
|
|
|
uaid: userAgentID,
|
2015-04-21 18:10:50 +00:00
|
|
|
}));
|
|
|
|
this.serverSendMsg(JSON.stringify({
|
|
|
|
messageType: 'notification',
|
|
|
|
updates: [{
|
|
|
|
channelID: '6ff97d56-d0c0-43bc-8f5b-61b855e1d93b',
|
|
|
|
version: '4'
|
|
|
|
}]
|
|
|
|
}));
|
|
|
|
},
|
2015-08-15 00:26:07 +00:00
|
|
|
onACK: ackDone
|
2015-04-21 18:10:50 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-22 10:51:42 +00:00
|
|
|
let {subject: message, data: scope} = await notifyPromise;
|
2016-05-02 16:38:47 +00:00
|
|
|
equal(message.QueryInterface(Ci.nsIPushMessage).data, null,
|
|
|
|
'Unexpected data for Simple Push message');
|
2015-04-21 18:10:50 +00:00
|
|
|
|
2017-06-22 10:51:42 +00:00
|
|
|
await ackPromise;
|
2015-04-21 18:10:50 +00:00
|
|
|
|
2017-06-22 10:51:42 +00:00
|
|
|
let storeRecord = await db.getByKeyID(
|
2015-04-21 18:10:50 +00:00
|
|
|
'6ff97d56-d0c0-43bc-8f5b-61b855e1d93b');
|
|
|
|
strictEqual(storeRecord.version, 4, 'Wrong record version');
|
2015-06-25 21:52:57 +00:00
|
|
|
equal(storeRecord.quota, Infinity, 'Wrong quota');
|
2015-04-21 18:10:50 +00:00
|
|
|
});
|