gecko-dev/dom/push/test/xpcshell/test_notification_incomplete.js
Kit Cambridge cfda49a5ee Bug 1150683 - Add xpcshell tests for nsIPushNotificationService. r=dougt
---
 dom/push/moz.build                                 |   4 +
 dom/push/test/xpcshell/head.js                     | 450 +++++++++++++++++++++
 dom/push/test/xpcshell/test_notification_ack.js    | 127 ++++++
 .../test/xpcshell/test_notification_duplicate.js   |  82 ++++
 dom/push/test/xpcshell/test_notification_error.js  | 127 ++++++
 .../test/xpcshell/test_notification_incomplete.js  | 109 +++++
 .../xpcshell/test_notification_version_string.js   |  72 ++++
 dom/push/test/xpcshell/test_register_case.js       |  64 +++
 dom/push/test/xpcshell/test_register_flush.js      | 103 +++++
 .../test/xpcshell/test_register_invalid_channel.js |  60 +++
 .../xpcshell/test_register_invalid_endpoint.js     |  62 +++
 .../test/xpcshell/test_register_invalid_json.js    |  61 +++
 dom/push/test/xpcshell/test_register_no_id.js      |  65 +++
 .../test/xpcshell/test_register_request_queue.js   |  65 +++
 dom/push/test/xpcshell/test_register_rollback.js   |  88 ++++
 dom/push/test/xpcshell/test_register_success.js    |  76 ++++
 dom/push/test/xpcshell/test_register_timeout.js    | 102 +++++
 dom/push/test/xpcshell/test_register_wrong_id.js   |  71 ++++
 dom/push/test/xpcshell/test_register_wrong_type.js |  67 +++
 dom/push/test/xpcshell/test_registration_error.js  |  39 ++
 .../xpcshell/test_registration_missing_scope.js    |  28 ++
 dom/push/test/xpcshell/test_registration_none.js   |  28 ++
 .../test/xpcshell/test_registration_success.js     |  67 +++
 .../test/xpcshell/test_unregister_empty_scope.js   |  37 ++
 dom/push/test/xpcshell/test_unregister_error.js    |  65 +++
 .../test/xpcshell/test_unregister_invalid_json.js  |  78 ++++
 .../test/xpcshell/test_unregister_not_found.js     |  35 ++
 dom/push/test/xpcshell/test_unregister_success.js  |  60 +++
 dom/push/test/xpcshell/xpcshell.ini                |  32 ++
 29 files changed, 2324 insertions(+)
 create mode 100644 dom/push/test/xpcshell/head.js
 create mode 100644 dom/push/test/xpcshell/test_notification_ack.js
 create mode 100644 dom/push/test/xpcshell/test_notification_duplicate.js
 create mode 100644 dom/push/test/xpcshell/test_notification_error.js
 create mode 100644 dom/push/test/xpcshell/test_notification_incomplete.js
 create mode 100644 dom/push/test/xpcshell/test_notification_version_string.js
 create mode 100644 dom/push/test/xpcshell/test_register_case.js
 create mode 100644 dom/push/test/xpcshell/test_register_flush.js
 create mode 100644 dom/push/test/xpcshell/test_register_invalid_channel.js
 create mode 100644 dom/push/test/xpcshell/test_register_invalid_endpoint.js
 create mode 100644 dom/push/test/xpcshell/test_register_invalid_json.js
 create mode 100644 dom/push/test/xpcshell/test_register_no_id.js
 create mode 100644 dom/push/test/xpcshell/test_register_request_queue.js
 create mode 100644 dom/push/test/xpcshell/test_register_rollback.js
 create mode 100644 dom/push/test/xpcshell/test_register_success.js
 create mode 100644 dom/push/test/xpcshell/test_register_timeout.js
 create mode 100644 dom/push/test/xpcshell/test_register_wrong_id.js
 create mode 100644 dom/push/test/xpcshell/test_register_wrong_type.js
 create mode 100644 dom/push/test/xpcshell/test_registration_error.js
 create mode 100644 dom/push/test/xpcshell/test_registration_missing_scope.js
 create mode 100644 dom/push/test/xpcshell/test_registration_none.js
 create mode 100644 dom/push/test/xpcshell/test_registration_success.js
 create mode 100644 dom/push/test/xpcshell/test_unregister_empty_scope.js
 create mode 100644 dom/push/test/xpcshell/test_unregister_error.js
 create mode 100644 dom/push/test/xpcshell/test_unregister_invalid_json.js
 create mode 100644 dom/push/test/xpcshell/test_unregister_not_found.js
 create mode 100644 dom/push/test/xpcshell/test_unregister_success.js
 create mode 100644 dom/push/test/xpcshell/xpcshell.ini
2015-04-19 12:06:31 +02:00

110 lines
3.4 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
const {PushDB, PushService} = serviceExports;
function run_test() {
do_get_profile();
setPrefs();
disableServiceWorkerEvents(
'https://example.com/page/1',
'https://example.com/page/2',
'https://example.com/page/3',
'https://example.com/page/4'
);
run_next_test();
}
add_task(function* test_notification_incomplete() {
let db = new PushDB();
let promiseDB = promisifyDatabase(db);
do_register_cleanup(() => cleanupDatabase(db));
let records = [{
channelID: '123',
pushEndpoint: 'https://example.org/update/1',
scope: 'https://example.com/page/1',
version: 1
}, {
channelID: '3ad1ed95-d37a-4d88-950f-22cbe2e240d7',
pushEndpoint: 'https://example.org/update/2',
scope: 'https://example.com/page/2',
version: 1
}, {
channelID: 'd239498b-1c85-4486-b99b-205866e82d1f',
pushEndpoint: 'https://example.org/update/3',
scope: 'https://example.com/page/3',
version: 3
}, {
channelID: 'a50de97d-b496-43ce-8b53-05522feb78db',
pushEndpoint: 'https://example.org/update/4',
scope: 'https://example.com/page/4',
version: 10
}];
for (let record of records) {
promiseDB.put(record);
}
Services.obs.addObserver(function observe(subject, topic, data) {
ok(false, 'Should not deliver malformed updates');
}, 'push-notification', false);
let notificationDefer = Promise.defer();
let notificationDone = after(2, notificationDefer.resolve);
let prevHandler = PushService._handleNotificationReply;
PushService._handleNotificationReply = function _handleNotificationReply() {
notificationDone();
return prevHandler.apply(this, arguments);
};
PushService.init({
networkInfo: new MockDesktopNetworkInfo(),
db,
makeWebSocket(uri) {
return new MockWebSocket(uri, {
onHello(request) {
this.serverSendMsg(JSON.stringify({
messageType: 'hello',
status: 200,
uaid: '1ca1cf66-eeb4-4df7-87c1-d5c92906ab90'
}));
this.serverSendMsg(JSON.stringify({
// Missing "updates" field; should ignore message.
messageType: 'notification'
}));
this.serverSendMsg(JSON.stringify({
messageType: 'notification',
updates: [{
// Wrong channel ID field type.
channelID: 123,
version: 3
}, {
// Missing version field.
channelID: '3ad1ed95-d37a-4d88-950f-22cbe2e240d7'
}, {
// Wrong version field type.
channelID: 'd239498b-1c85-4486-b99b-205866e82d1f',
version: true
}, {
// Negative versions should be ignored.
channelID: 'a50de97d-b496-43ce-8b53-05522feb78db',
version: -5
}]
}));
},
onACK() {
ok(false, 'Should not acknowledge malformed updates');
}
});
}
});
yield waitForPromise(notificationDefer.promise, DEFAULT_TIMEOUT,
'Timed out waiting for incomplete notifications');
let storeRecords = yield promiseDB.getAllChannelIDs();
storeRecords.sort(({pushEndpoint: a}, {pushEndpoint: b}) =>
compareAscending(a, b));
deepEqual(records, storeRecords, 'Should not update malformed records');
});