mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-26 11:45:37 +00:00
47b180edd6
--- 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
62 lines
1.6 KiB
JavaScript
62 lines
1.6 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
'use strict';
|
|
|
|
const {PushDB, PushService} = serviceExports;
|
|
|
|
const userAgentID = '8271186b-8073-43a3-adf6-225bd44a8b0a';
|
|
const channelID = '2d08571e-feab-48a0-9f05-8254c3c7e61f';
|
|
|
|
function run_test() {
|
|
do_get_profile();
|
|
setPrefs({
|
|
requestTimeout: 1000,
|
|
retryBaseInterval: 150
|
|
});
|
|
disableServiceWorkerEvents(
|
|
'https://example.net/page/invalid-json'
|
|
);
|
|
run_next_test();
|
|
}
|
|
|
|
add_task(function* test_register_invalid_json() {
|
|
let helloDefer = Promise.defer();
|
|
let helloDone = after(2, helloDefer.resolve);
|
|
let registers = 0;
|
|
|
|
PushService._generateID = () => channelID;
|
|
PushService.init({
|
|
networkInfo: new MockDesktopNetworkInfo(),
|
|
makeWebSocket(uri) {
|
|
return new MockWebSocket(uri, {
|
|
onHello(request) {
|
|
this.serverSendMsg(JSON.stringify({
|
|
messageType: 'hello',
|
|
status: 200,
|
|
uaid: userAgentID
|
|
}));
|
|
helloDone();
|
|
},
|
|
onRegister(request) {
|
|
equal(request.channelID, channelID, 'Register: wrong channel ID');
|
|
this.serverSendMsg(');alert(1);(');
|
|
registers++;
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
yield rejects(
|
|
PushNotificationService.register('https://example.net/page/invalid-json'),
|
|
function(error) {
|
|
return error == 'TimeoutError';
|
|
},
|
|
'Wrong error for invalid JSON response'
|
|
);
|
|
|
|
yield waitForPromise(helloDefer.promise, DEFAULT_TIMEOUT,
|
|
'Reconnect after invalid JSON response timed out');
|
|
equal(registers, 1, 'Wrong register count');
|
|
});
|