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
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
do_get_profile();
|
|
|
|
setPrefs();
|
|
|
|
disableServiceWorkerEvents(
|
|
|
|
'https://example.com/1',
|
|
|
|
'https://example.com/2'
|
|
|
|
);
|
|
|
|
run_next_test();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should acknowledge duplicate notifications, but not notify apps.
|
|
|
|
add_task(function* test_notification_duplicate() {
|
2015-06-02 11:14:00 +00:00
|
|
|
let db = PushServiceWebSocket.newPushDB();
|
2015-05-12 16:08:00 +00:00
|
|
|
do_register_cleanup(() => {return db.drop().then(_ => db.close());});
|
2015-04-21 18:10:50 +00:00
|
|
|
let records = [{
|
|
|
|
channelID: '8d2d9400-3597-4c5a-8a38-c546b0043bcc',
|
|
|
|
pushEndpoint: 'https://example.org/update/1',
|
|
|
|
scope: 'https://example.com/1',
|
2015-06-24 20:34:54 +00:00
|
|
|
originAttributes: "",
|
2015-06-25 21:52:57 +00:00
|
|
|
version: 2,
|
|
|
|
quota: Infinity,
|
2015-04-21 18:10:50 +00:00
|
|
|
}, {
|
|
|
|
channelID: '27d1e393-03ef-4c72-a5e6-9e890dfccad0',
|
|
|
|
pushEndpoint: 'https://example.org/update/2',
|
|
|
|
scope: 'https://example.com/2',
|
2015-06-24 20:34:54 +00:00
|
|
|
originAttributes: "",
|
2015-06-25 21:52:57 +00:00
|
|
|
version: 2,
|
|
|
|
quota: Infinity,
|
2015-04-21 18:10:50 +00:00
|
|
|
}];
|
|
|
|
for (let record of records) {
|
2015-05-12 16:08:00 +00:00
|
|
|
yield db.put(record);
|
2015-04-21 18:10:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let notifyPromise = promiseObserverNotification('push-notification');
|
|
|
|
|
|
|
|
let acks = 0;
|
|
|
|
let ackDefer = Promise.defer();
|
|
|
|
let ackDone = after(2, ackDefer.resolve);
|
|
|
|
PushService.init({
|
2015-06-02 11:14:00 +00:00
|
|
|
serverURI: "wss://push.example.org/",
|
2015-04-21 18:10:50 +00:00
|
|
|
networkInfo: new MockDesktopNetworkInfo(),
|
|
|
|
db,
|
|
|
|
makeWebSocket(uri) {
|
|
|
|
return new MockWebSocket(uri, {
|
|
|
|
onHello(request) {
|
|
|
|
this.serverSendMsg(JSON.stringify({
|
|
|
|
messageType: 'hello',
|
|
|
|
status: 200,
|
|
|
|
uaid: '1500e7d9-8cbe-4ee6-98da-7fa5d6a39852'
|
|
|
|
}));
|
|
|
|
this.serverSendMsg(JSON.stringify({
|
|
|
|
messageType: 'notification',
|
|
|
|
updates: [{
|
|
|
|
channelID: '8d2d9400-3597-4c5a-8a38-c546b0043bcc',
|
|
|
|
version: 2
|
|
|
|
}, {
|
|
|
|
channelID: '27d1e393-03ef-4c72-a5e6-9e890dfccad0',
|
|
|
|
version: 3
|
|
|
|
}]
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
onACK: ackDone
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
yield waitForPromise(notifyPromise, DEFAULT_TIMEOUT,
|
|
|
|
'Timed out waiting for notifications');
|
|
|
|
yield waitForPromise(ackDefer.promise, DEFAULT_TIMEOUT,
|
|
|
|
'Timed out waiting for stale acknowledgement');
|
|
|
|
|
2015-06-03 12:06:00 +00:00
|
|
|
let staleRecord = yield db.getByKeyID(
|
2015-04-21 18:10:50 +00:00
|
|
|
'8d2d9400-3597-4c5a-8a38-c546b0043bcc');
|
|
|
|
strictEqual(staleRecord.version, 2, 'Wrong stale record version');
|
|
|
|
|
2015-06-03 12:06:00 +00:00
|
|
|
let updatedRecord = yield db.getByKeyID(
|
2015-04-21 18:10:50 +00:00
|
|
|
'27d1e393-03ef-4c72-a5e6-9e890dfccad0');
|
|
|
|
strictEqual(updatedRecord.version, 3, 'Wrong updated record version');
|
|
|
|
});
|