From 357fec3abc28a00bac4826d5a14f253b4439c33f Mon Sep 17 00:00:00 2001 From: Kit Cambridge Date: Mon, 9 Nov 2015 13:58:50 -0800 Subject: [PATCH] Bug 1210896, Part 2 - Use JS errors to reject internal Push promises. r=mt --- dom/push/PushClient.js | 21 +-- dom/push/PushDB.jsm | 1 + dom/push/PushNotificationService.js | 6 +- dom/push/PushService.jsm | 169 +++++++----------- dom/push/PushServiceHttp2.jsm | 68 +++---- dom/push/PushServiceWebSocket.jsm | 16 +- .../test/xpcshell/test_reconnect_retry.js | 7 +- .../xpcshell/test_register_5xxCode_http2.js | 4 - dom/push/test/xpcshell/test_register_case.js | 6 +- .../xpcshell/test_register_error_http2.js | 30 +--- dom/push/test/xpcshell/test_register_flush.js | 6 +- .../xpcshell/test_register_invalid_channel.js | 5 +- .../test_register_invalid_endpoint.js | 5 +- .../xpcshell/test_register_invalid_json.js | 5 +- dom/push/test/xpcshell/test_register_no_id.js | 5 +- .../xpcshell/test_register_request_queue.js | 8 +- .../test/xpcshell/test_register_rollback.js | 5 +- .../test/xpcshell/test_register_success.js | 8 - .../xpcshell/test_register_success_http2.js | 8 - .../test/xpcshell/test_register_timeout.js | 5 +- .../test/xpcshell/test_register_wrong_id.js | 5 +- .../test/xpcshell/test_register_wrong_type.js | 7 +- .../test_registration_missing_scope.js | 3 - .../xpcshell/test_unregister_empty_scope.js | 5 +- .../test_updateRecordNoEncryptionKeys_ws.js | 3 +- 25 files changed, 129 insertions(+), 282 deletions(-) diff --git a/dom/push/PushClient.js b/dom/push/PushClient.js index 5bb48b98d97..37270421365 100644 --- a/dom/push/PushClient.js +++ b/dom/push/PushClient.js @@ -100,6 +100,10 @@ PushClient.prototype = { }, _deliverPushEndpoint: function(request, registration) { + if (!registration) { + request.onPushEndpoint(Cr.NS_OK, "", 0, null); + return; + } if (registration.p256dhKey) { let key = new Uint8Array(registration.p256dhKey); request.onPushEndpoint(Cr.NS_OK, @@ -125,24 +129,15 @@ PushClient.prototype = { switch (aMessage.name) { case "PushService:Register:OK": - this._deliverPushEndpoint(request, json); - break; - case "PushService:Register:KO": - request.onPushEndpoint(Cr.NS_ERROR_FAILURE, "", 0, null); - break; case "PushService:Registration:OK": - { - let endpoint = ""; - if (!json.registration) { - request.onPushEndpoint(Cr.NS_OK, "", 0, null); - } else { - this._deliverPushEndpoint(request, json.registration); - } + this._deliverPushEndpoint(request, json.result); break; - } + + case "PushService:Register:KO": case "PushService:Registration:KO": request.onPushEndpoint(Cr.NS_ERROR_FAILURE, "", 0, null); break; + case "PushService:Unregister:OK": if (typeof json.result !== "boolean") { console.error("receiveMessage: Expected boolean for unregister response", diff --git a/dom/push/PushDB.jsm b/dom/push/PushDB.jsm index 911c98ca9a6..7139195d6da 100644 --- a/dom/push/PushDB.jsm +++ b/dom/push/PushDB.jsm @@ -8,6 +8,7 @@ const Cu = Components.utils; Cu.import("resource://gre/modules/IndexedDBHelper.jsm"); Cu.import("resource://gre/modules/Preferences.jsm"); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.importGlobalProperties(["indexedDB"]); this.EXPORTED_SYMBOLS = ["PushDB"]; diff --git a/dom/push/PushNotificationService.js b/dom/push/PushNotificationService.js index 8b0452066a1..3ab03c88c4e 100644 --- a/dom/push/PushNotificationService.js +++ b/dom/push/PushNotificationService.js @@ -39,7 +39,7 @@ PushNotificationService.prototype = { Ci.nsIPushNotificationService]), register: function register(scope, originAttributes) { - return PushService._register({ + return PushService.register({ scope: scope, originAttributes: originAttributes, maxQuota: Infinity, @@ -47,11 +47,11 @@ PushNotificationService.prototype = { }, unregister: function unregister(scope, originAttributes) { - return PushService._unregister({scope, originAttributes}); + return PushService.unregister({scope, originAttributes}); }, registration: function registration(scope, originAttributes) { - return PushService._registration({scope, originAttributes}); + return PushService.registration({scope, originAttributes}); }, clearAll: function clearAll() { diff --git a/dom/push/PushService.jsm b/dom/push/PushService.jsm index 337db935995..58be048ced9 100644 --- a/dom/push/PushService.jsm +++ b/dom/push/PushService.jsm @@ -117,7 +117,7 @@ this.PushService = { _activated: null, _checkActivated: function() { if (this._state < PUSH_SERVICE_ACTIVATING) { - return Promise.reject({state: 0, error: "Service not active"}); + return Promise.reject(new Error("Push service not active")); } else if (this._state > PUSH_SERVICE_ACTIVATING) { return Promise.resolve(); } else { @@ -161,7 +161,7 @@ this.PushService = { this._state = aNewState; if (this._notifyActivated) { if (aNewState < PUSH_SERVICE_ACTIVATING) { - this._notifyActivated.reject({state: 0, error: "Service not active"}); + this._notifyActivated.reject(new Error("Push service not active")); } else { this._notifyActivated.resolve(); } @@ -912,12 +912,12 @@ this.PushService = { _sendRequest: function(action, aRecord) { if (this._state == PUSH_SERVICE_CONNECTION_DISABLE) { - return Promise.reject({state: 0, error: "Service not active"}); + return Promise.reject(new Error("Push service disabled")); } else if (this._state == PUSH_SERVICE_ACTIVE_OFFLINE) { if (this._service.serviceType() == "WebSocket" && action == "unregister") { return Promise.resolve(); } - return Promise.reject({state: 0, error: "NetworkError"}); + return Promise.reject(new Error("Push service offline")); } return this._service.request(action, aRecord); }, @@ -935,42 +935,13 @@ this.PushService = { err => this._onRegisterError(err)) .then(record => { this._deletePendingRequest(aPageRecord); - return record; + return record.toRegister(); }, err => { this._deletePendingRequest(aPageRecord); throw err; }); }, - _register: function(aPageRecord) { - console.debug("_register()"); - if (!aPageRecord.scope || aPageRecord.originAttributes === undefined) { - return Promise.reject({state: 0, error: "NotFoundError"}); - } - - return this._checkActivated() - .then(_ => this._db.getByIdentifiers(aPageRecord)) - .then(record => { - if (!record) { - return this._lookupOrPutPendingRequest(aPageRecord); - } - if (record.isExpired()) { - return record.quotaChanged().then(isChanged => { - if (isChanged) { - // If the user revisited the site, drop the expired push - // registration and re-register. - return this._db.delete(record.keyID); - } - throw {state: 0, error: "NotFoundError"}; - }).then(_ => this._lookupOrPutPendingRequest(aPageRecord)); - } - return record; - }, error => { - console.error("register: getByIdentifiers failed", error); - throw error; - }); - }, - _sendUnregister: function(aRecord) { Services.telemetry.getHistogramById("PUSH_API_UNSUBSCRIBE_ATTEMPT").add(); return this._sendRequest("unregister", aRecord).then(function(v) { @@ -1050,51 +1021,67 @@ this.PushService = { } let mm = aMessage.target.QueryInterface(Ci.nsIMessageSender); - let pageRecord = aMessage.data; + let name = aMessage.name.slice("Push:".length); + Promise.resolve().then(_ => { + let pageRecord = this._validatePageRecord(aMessage); + return this[name.toLowerCase()](pageRecord); + }).then(result => { + mm.sendAsyncMessage("PushService:" + name + ":OK", { + requestID: aMessage.data.requestID, + result: result, + }); + }, error => { + console.error("receiveMessage: Error handling message", aMessage, error); + mm.sendAsyncMessage("PushService:" + name + ":KO", { + requestID: aMessage.data.requestID, + }); + }).catch(error => { + console.error("receiveMessage: Error sending reply", error); + }); + }, + + _validatePageRecord: function(aMessage) { let principal = aMessage.principal; if (!principal) { - console.debug("receiveMessage: No principal passed", - pageRecord.requestID); - let message = { - requestID: pageRecord.requestID, - error: "SecurityError" - }; - mm.sendAsyncMessage("PushService:Register:KO", message); - return; + throw new Error("Missing message principal"); + } + + let pageRecord = aMessage.data; + if (!pageRecord.scope) { + throw new Error("Missing page record scope"); } pageRecord.originAttributes = ChromeUtils.originAttributesToSuffix(principal.originAttributes); - if (!pageRecord.scope || pageRecord.originAttributes === undefined) { - console.debug("receiveMessage: Incorrect identifier values set", - pageRecord); - let message = { - requestID: pageRecord.requestID, - error: "SecurityError" - }; - mm.sendAsyncMessage("PushService:Register:KO", message); - return; - } - - this[aMessage.name.slice("Push:".length).toLowerCase()](pageRecord, mm); + return pageRecord; }, - register: function(aPageRecord, aMessageManager) { + register: function(aPageRecord) { console.debug("register()", aPageRecord); - this._register(aPageRecord) + if (!aPageRecord.scope || aPageRecord.originAttributes === undefined) { + return Promise.reject(new Error("Invalid page record")); + } + + return this._checkActivated() + .then(_ => this._db.getByIdentifiers(aPageRecord)) .then(record => { - let message = record.toRegister(); - message.requestID = aPageRecord.requestID; - aMessageManager.sendAsyncMessage("PushService:Register:OK", message); - }, error => { - let message = { - requestID: aPageRecord.requestID, - error - }; - aMessageManager.sendAsyncMessage("PushService:Register:KO", message); + if (!record) { + return this._lookupOrPutPendingRequest(aPageRecord); + } + if (record.isExpired()) { + return record.quotaChanged().then(isChanged => { + if (isChanged) { + // If the user revisited the site, drop the expired push + // registration and re-register. + return this._db.delete(record.keyID); + } + throw new Error("Push subscription expired"); + }).then(_ => this._lookupOrPutPendingRequest(aPageRecord)); + } + return record.toRegister(); }); }, @@ -1123,10 +1110,11 @@ this.PushService = { * client acknowledge. On a server, data is cheap, reliable notification is * not. */ - _unregister: function(aPageRecord) { - console.debug("_unregister()"); + unregister: function(aPageRecord) { + console.debug("unregister()", aPageRecord); + if (!aPageRecord.scope || aPageRecord.originAttributes === undefined) { - return Promise.reject({state: 0, error: "NotFoundError"}); + return Promise.reject(new Error("Invalid page record")); } return this._checkActivated() @@ -1143,24 +1131,6 @@ this.PushService = { }); }, - unregister: function(aPageRecord, aMessageManager) { - console.debug("unregister()", aPageRecord); - - this._unregister(aPageRecord) - .then(result => { - aMessageManager.sendAsyncMessage("PushService:Unregister:OK", { - requestID: aPageRecord.requestID, - result: result, - }) - }, error => { - console.debug("unregister: Error removing registration", error); - aMessageManager.sendAsyncMessage("PushService:Unregister:KO", { - requestID: aPageRecord.requestID, - }) - } - ); - }, - _clearAll: function _clearAll() { return this._checkActivated() .then(_ => this._db.drop()) @@ -1209,13 +1179,10 @@ this.PushService = { }); }, - /** - * Called on message from the child process - */ - _registration: function(aPageRecord) { - console.debug("_registration()"); + registration: function(aPageRecord) { + console.debug("registration()"); if (!aPageRecord.scope || aPageRecord.originAttributes === undefined) { - return Promise.reject({state: 0, error: "NotFoundError"}); + return Promise.reject(new Error("Invalid page record")); } return this._checkActivated() @@ -1236,22 +1203,6 @@ this.PushService = { }); }, - registration: function(aPageRecord, aMessageManager) { - console.debug("registration()"); - - return this._registration(aPageRecord) - .then(registration => - aMessageManager.sendAsyncMessage("PushService:Registration:OK", { - requestID: aPageRecord.requestID, - registration - }), error => - aMessageManager.sendAsyncMessage("PushService:Registration:KO", { - requestID: aPageRecord.requestID, - error - }) - ); - }, - _dropExpiredRegistrations: function() { console.debug("dropExpiredRegistrations()"); diff --git a/dom/push/PushServiceHttp2.jsm b/dom/push/PushServiceHttp2.jsm index 8e3ae66151d..8f167d8cb6c 100644 --- a/dom/push/PushServiceHttp2.jsm +++ b/dom/push/PushServiceHttp2.jsm @@ -227,7 +227,7 @@ PushServiceDelete.prototype = { if (Components.isSuccessCode(aStatusCode)) { this._resolve(); } else { - this._reject({status: 0, error: "NetworkError"}); + this._reject(new Error("Error removing subscription: " + aStatusCode)); } } }; @@ -269,12 +269,12 @@ SubscriptionListener.prototype = { // Check if pushService is still active. if (!this._service.hasmainPushService()) { - this._reject({error: "Service deactivated"}); + this._reject(new Error("Push service unavailable")); return; } if (!Components.isSuccessCode(aStatus)) { - this._reject({error: "Error status" + aStatus}); + this._reject(new Error("Error listening for messages: " + aStatus)); return; } @@ -291,11 +291,11 @@ SubscriptionListener.prototype = { }), retryAfter); } else { - this._reject({error: "Error response code: " + statusCode }); + this._reject(new Error("Unexpected server response: " + statusCode)); } return; } else if (statusCode != 201) { - this._reject({error: "Error response code: " + statusCode }); + this._reject(new Error("Unexpected server response: " + statusCode)); return; } @@ -303,7 +303,7 @@ SubscriptionListener.prototype = { try { subscriptionUri = aRequest.getResponseHeader("location"); } catch (err) { - this._reject({error: "Return code 201, but the answer is bogus"}); + this._reject(new Error("Missing Location header")); return; } @@ -313,19 +313,20 @@ SubscriptionListener.prototype = { try { linkList = aRequest.getResponseHeader("link"); } catch (err) { - this._reject({error: "Return code 201, but the answer is bogus"}); + this._reject(new Error("Missing Link header")); return; } - var linkParserResult = linkParser(linkList, this._serverURI); - if (linkParserResult.error) { - this._reject(linkParserResult); + var linkParserResult; + try { + linkParserResult = linkParser(linkList, this._serverURI); + } catch (e) { + this._reject(e); return; } if (!subscriptionUri) { - this._reject({error: "Return code 201, but the answer is bogus," + - " missing subscriptionUri"}); + this._reject(new Error("Invalid Location header")); return; } try { @@ -333,8 +334,8 @@ SubscriptionListener.prototype = { } catch (e) { console.error("onStopRequest: Invalid subscription URI", subscriptionUri); - this._reject({error: "Return code 201, but URI is bogus. " + - subscriptionUri}); + this._reject(new Error("Invalid subscription endpoint: " + + subscriptionUri)); return; } @@ -372,7 +373,7 @@ function linkParser(linkHeader, serverURI) { var linkList = linkHeader.split(','); if ((linkList.length < 1)) { - return {error: "Return code 201, but the answer is bogus"}; + throw new Error("Invalid Link header"); } var pushEndpoint; @@ -397,28 +398,19 @@ function linkParser(linkHeader, serverURI) { console.debug("linkParser: pushReceiptEndpoint", pushReceiptEndpoint); // Missing pushReceiptEndpoint is allowed. if (!pushEndpoint) { - return {error: "Return code 201, but the answer is bogus, missing" + - " pushEndpoint"}; + throw new Error("Missing push endpoint"); } - var uri; - var resUri = []; - try { - [pushEndpoint, pushReceiptEndpoint].forEach(u => { - if (u) { - uri = u; - resUri[u] = Services.io.newURI(uri, null, serverURI); - } - }); - } catch (e) { - console.debug("linkParser: Invalid URI", uri); - return {error: "Return code 201, but URI is bogus. " + uri}; + var pushURI = Services.io.newURI(pushEndpoint, null, serverURI); + var pushReceiptURI; + if (pushReceiptEndpoint) { + pushReceiptURI = Services.io.newURI(pushReceiptEndpoint, null, + serverURI); } return { - pushEndpoint: resUri[pushEndpoint].spec, - pushReceiptEndpoint: (pushReceiptEndpoint) ? resUri[pushReceiptEndpoint].spec - : "" + pushEndpoint: pushURI.spec, + pushReceiptEndpoint: (pushReceiptURI) ? pushReceiptURI.spec : "", }; } @@ -544,11 +536,7 @@ this.PushServiceHttp2 = { var chan = this._makeChannel(this._serverURI.spec); chan.requestMethod = "POST"; - try { - chan.asyncOpen(listener, null); - } catch(e) { - reject({status: 0, error: "NetworkError"}); - } + chan.asyncOpen(listener, null); }) .catch(err => { if ("retry" in err) { @@ -564,11 +552,7 @@ this.PushServiceHttp2 = { return new Promise((resolve,reject) => { var chan = this._makeChannel(aUri); chan.requestMethod = "DELETE"; - try { - chan.asyncOpen(new PushServiceDelete(resolve, reject), null); - } catch(err) { - reject({status: 0, error: "NetworkError"}); - } + chan.asyncOpen(new PushServiceDelete(resolve, reject), null); }); }, diff --git a/dom/push/PushServiceWebSocket.jsm b/dom/push/PushServiceWebSocket.jsm index 3fbf985a9c4..cc1b634819c 100644 --- a/dom/push/PushServiceWebSocket.jsm +++ b/dom/push/PushServiceWebSocket.jsm @@ -184,11 +184,10 @@ this.PushServiceWebSocket = { // also made to fail, since we are going to be disconnecting the // socket. if (requestTimedOut || duration > this._requestTimeout) { - console.debug("observe: Register request timed out for channel", - channelID); requestTimedOut = true; this._registerRequests[channelID] - .reject({status: 0, error: "TimeoutError"}); + .reject(new Error("Register request timed out for channel ID " + + channelID)); delete this._registerRequests[channelID]; } @@ -873,10 +872,7 @@ this.PushServiceWebSocket = { Services.io.newURI(reply.pushEndpoint, null, null); } catch (e) { - console.error("handleRegisterReply: Invalid pushEndpoint", - reply.pushEndpoint); - tmp.reject({state: 0, error: "Invalid pushEndpoint " + - reply.pushEndpoint}); + tmp.reject(new Error("Invalid push endpoint: " + reply.pushEndpoint)); return; } @@ -892,7 +888,9 @@ this.PushServiceWebSocket = { Services.telemetry.getHistogramById("PUSH_API_SUBSCRIBE_WS_TIME").add(Date.now() - tmp.ctime); tmp.resolve(record); } else { - tmp.reject(reply); + console.error("handleRegisterReply: Unexpected server response", reply); + tmp.reject(new Error("Wrong status code for register reply: " + + reply.status)); } }, @@ -1274,7 +1272,7 @@ this.PushServiceWebSocket = { for (let channelID in this._registerRequests) { let request = this._registerRequests[channelID]; delete this._registerRequests[channelID]; - request.reject({status: 0, error: "AbortError"}); + request.reject(new Error("Register request aborted")); } }, diff --git a/dom/push/test/xpcshell/test_reconnect_retry.js b/dom/push/test/xpcshell/test_reconnect_retry.js index 86022b6f66d..aa264fb5b89 100644 --- a/dom/push/test/xpcshell/test_reconnect_retry.js +++ b/dom/push/test/xpcshell/test_reconnect_retry.js @@ -47,7 +47,7 @@ add_task(function* test_reconnect_retry() { this.serverSendMsg(JSON.stringify({ messageType: 'register', channelID: request.channelID, - pushEndpoint: 'https://example.org/push/' + registers, + pushEndpoint: 'https://example.org/push/' + request.channelID, status: 200, })); } @@ -59,13 +59,14 @@ add_task(function* test_reconnect_retry() { 'https://example.com/page/1', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }) ); - equal(registration.channelID, channelID, 'Wrong channel ID for retried request'); + let retryEndpoint = 'https://example.org/push/' + channelID; + equal(registration.pushEndpoint, retryEndpoint, 'Wrong endpoint for retried request'); registration = yield PushNotificationService.register( 'https://example.com/page/2', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }) ); - notEqual(registration.channelID, channelID, 'Wrong channel ID for new request'); + notEqual(registration.pushEndpoint, retryEndpoint, 'Wrong endpoint for new request') equal(registers, 3, 'Wrong registration count'); }); diff --git a/dom/push/test/xpcshell/test_register_5xxCode_http2.js b/dom/push/test/xpcshell/test_register_5xxCode_http2.js index e8e5649ca6b..64bbbc8b49d 100644 --- a/dom/push/test/xpcshell/test_register_5xxCode_http2.js +++ b/dom/push/test/xpcshell/test_register_5xxCode_http2.js @@ -91,15 +91,11 @@ add_task(function* test1() { var subscriptionUri = serverURL + '/subscription'; var pushEndpoint = serverURL + '/pushEndpoint'; var pushReceiptEndpoint = serverURL + '/receiptPushEndpoint'; - equal(newRecord.subscriptionUri, subscriptionUri, - 'Wrong subscription ID in registration record'); equal(newRecord.pushEndpoint, pushEndpoint, 'Wrong push endpoint in registration record'); equal(newRecord.pushReceiptEndpoint, pushReceiptEndpoint, 'Wrong push endpoint receipt in registration record'); - equal(newRecord.scope, 'https://example.com/retry5xxCode', - 'Wrong scope in registration record'); let record = yield db.getByKeyID(subscriptionUri); equal(record.subscriptionUri, subscriptionUri, diff --git a/dom/push/test/xpcshell/test_register_case.js b/dom/push/test/xpcshell/test_register_case.js index e0ff47b9104..1a922f1487d 100644 --- a/dom/push/test/xpcshell/test_register_case.js +++ b/dom/push/test/xpcshell/test_register_case.js @@ -54,12 +54,8 @@ add_task(function* test_register_case() { ); equal(newRecord.pushEndpoint, 'https://example.com/update/case', 'Wrong push endpoint in registration record'); - equal(newRecord.scope, 'https://example.net/case', - 'Wrong scope in registration record'); - let record = yield db.getByKeyID(newRecord.channelID); - equal(record.pushEndpoint, 'https://example.com/update/case', - 'Wrong push endpoint in database record'); + let record = yield db.getByPushEndpoint('https://example.com/update/case'); equal(record.scope, 'https://example.net/case', 'Wrong scope in database record'); }); diff --git a/dom/push/test/xpcshell/test_register_error_http2.js b/dom/push/test/xpcshell/test_register_error_http2.js index 0b2296e6176..1dbd364ef82 100644 --- a/dom/push/test/xpcshell/test_register_error_http2.js +++ b/dom/push/test/xpcshell/test_register_error_http2.js @@ -49,10 +49,7 @@ add_task(function* test_pushSubscriptionNoConnection() { PushNotificationService.register( 'https://example.net/page/invalid-response', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })), - function(error) { - return error && error.includes("Error"); - }, - 'Wrong error for not being able to establish connecion.' + 'Expected error for not being able to establish connecion.' ); let record = yield db.getAllKeyIDs(); @@ -90,10 +87,7 @@ add_task(function* test_pushSubscriptionMissingLocation() { PushNotificationService.register( 'https://example.net/page/invalid-response', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })), - function(error) { - return error && error.includes("Return code 201, but the answer is bogus"); - }, - 'Wrong error for the missing location header.' + 'Expected error for the missing location header.' ); let record = yield db.getAllKeyIDs(); @@ -117,10 +111,7 @@ add_task(function* test_pushSubscriptionMissingLink() { PushNotificationService.register( 'https://example.net/page/invalid-response', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })), - function(error) { - return error && error.includes("Return code 201, but the answer is bogus"); - }, - 'Wrong error for the missing link header.' + 'Expected error for the missing link header.' ); let record = yield db.getAllKeyIDs(); @@ -144,10 +135,7 @@ add_task(function* test_pushSubscriptionMissingLink1() { PushNotificationService.register( 'https://example.net/page/invalid-response', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })), - function(error) { - return error && error.includes("Return code 201, but the answer is bogus"); - }, - 'Wrong error for the missing push endpoint.' + 'Expected error for the missing push endpoint.' ); let record = yield db.getAllKeyIDs(); @@ -171,10 +159,7 @@ add_task(function* test_pushSubscriptionLocationBogus() { PushNotificationService.register( 'https://example.net/page/invalid-response', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })), - function(error) { - return error && error.includes("Return code 201, but URI is bogus."); - }, - 'Wrong error for the bogus location' + 'Expected error for the bogus location' ); let record = yield db.getAllKeyIDs(); @@ -198,10 +183,7 @@ add_task(function* test_pushSubscriptionNot2xxCode() { PushNotificationService.register( 'https://example.net/page/invalid-response', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })), - function(error) { - return error && error.includes("Error"); - }, - 'Wrong error for not 201 responce code.' + 'Expected error for not 201 responce code.' ); let record = yield db.getAllKeyIDs(); diff --git a/dom/push/test/xpcshell/test_register_flush.js b/dom/push/test/xpcshell/test_register_flush.js index b05775dcc6e..ec6474398a5 100644 --- a/dom/push/test/xpcshell/test_register_flush.js +++ b/dom/push/test/xpcshell/test_register_flush.js @@ -80,8 +80,6 @@ add_task(function* test_register_flush() { 'https://example.com/page/2', ''); equal(newRecord.pushEndpoint, 'https://example.org/update/2', 'Wrong push endpoint in record'); - equal(newRecord.scope, 'https://example.com/page/2', - 'Wrong scope in record'); let {data: scope} = yield waitForPromise(notifyPromise, DEFAULT_TIMEOUT, 'Timed out waiting for notification'); @@ -97,8 +95,6 @@ add_task(function* test_register_flush() { strictEqual(prevRecord.version, 3, 'Should record version updates sent before register responses'); - let registeredRecord = yield db.getByKeyID(newRecord.channelID); - equal(registeredRecord.pushEndpoint, 'https://example.org/update/2', - 'Wrong new push endpoint'); + let registeredRecord = yield db.getByPushEndpoint('https://example.org/update/2'); ok(!registeredRecord.version, 'Should not record premature updates'); }); diff --git a/dom/push/test/xpcshell/test_register_invalid_channel.js b/dom/push/test/xpcshell/test_register_invalid_channel.js index fa1686a643a..88d27284d37 100644 --- a/dom/push/test/xpcshell/test_register_invalid_channel.js +++ b/dom/push/test/xpcshell/test_register_invalid_channel.js @@ -50,10 +50,7 @@ add_task(function* test_register_invalid_channel() { yield rejects( PushNotificationService.register('https://example.com/invalid-channel', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })), - function(error) { - return error == 'Invalid channel ID'; - }, - 'Wrong error for invalid channel ID' + 'Expected error for invalid channel ID' ); let record = yield db.getByKeyID(channelID); diff --git a/dom/push/test/xpcshell/test_register_invalid_endpoint.js b/dom/push/test/xpcshell/test_register_invalid_endpoint.js index fc111e8cb08..85bb46a6e89 100644 --- a/dom/push/test/xpcshell/test_register_invalid_endpoint.js +++ b/dom/push/test/xpcshell/test_register_invalid_endpoint.js @@ -52,10 +52,7 @@ add_task(function* test_register_invalid_endpoint() { PushNotificationService.register( 'https://example.net/page/invalid-endpoint', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })), - function(error) { - return error && error.includes('Invalid pushEndpoint'); - }, - 'Wrong error for invalid endpoint' + 'Expected error for invalid endpoint' ); let record = yield db.getByKeyID(channelID); diff --git a/dom/push/test/xpcshell/test_register_invalid_json.js b/dom/push/test/xpcshell/test_register_invalid_json.js index 6efaa83e31e..febf3ea4940 100644 --- a/dom/push/test/xpcshell/test_register_invalid_json.js +++ b/dom/push/test/xpcshell/test_register_invalid_json.js @@ -51,10 +51,7 @@ add_task(function* test_register_invalid_json() { yield rejects( PushNotificationService.register('https://example.net/page/invalid-json', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })), - function(error) { - return error == 'TimeoutError'; - }, - 'Wrong error for invalid JSON response' + 'Expected error for invalid JSON response' ); yield waitForPromise(helloPromise, DEFAULT_TIMEOUT, diff --git a/dom/push/test/xpcshell/test_register_no_id.js b/dom/push/test/xpcshell/test_register_no_id.js index 7c499df7f09..8ddabbb347e 100644 --- a/dom/push/test/xpcshell/test_register_no_id.js +++ b/dom/push/test/xpcshell/test_register_no_id.js @@ -55,10 +55,7 @@ add_task(function* test_register_no_id() { yield rejects( PushNotificationService.register('https://example.com/incomplete', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })), - function(error) { - return error == 'TimeoutError'; - }, - 'Wrong error for incomplete register response' + 'Expected error for incomplete register response' ); yield waitForPromise(helloPromise, DEFAULT_TIMEOUT, diff --git a/dom/push/test/xpcshell/test_register_request_queue.js b/dom/push/test/xpcshell/test_register_request_queue.js index b61ac73c0d6..7cc25729010 100644 --- a/dom/push/test/xpcshell/test_register_request_queue.js +++ b/dom/push/test/xpcshell/test_register_request_queue.js @@ -55,12 +55,8 @@ add_task(function* test_register_request_queue() { ); yield waitForPromise(Promise.all([ - rejects(firstRegister, function(error) { - return error == 'TimeoutError'; - }, 'Should time out the first request'), - rejects(secondRegister, function(error) { - return error == 'TimeoutError'; - }, 'Should time out the second request') + rejects(firstRegister, 'Should time out the first request'), + rejects(secondRegister, 'Should time out the second request') ]), DEFAULT_TIMEOUT, 'Queued requests did not time out'); yield waitForPromise(helloPromise, DEFAULT_TIMEOUT, diff --git a/dom/push/test/xpcshell/test_register_rollback.js b/dom/push/test/xpcshell/test_register_rollback.js index 567a4c3c723..ddb1eb2d8e1 100644 --- a/dom/push/test/xpcshell/test_register_rollback.js +++ b/dom/push/test/xpcshell/test_register_rollback.js @@ -77,10 +77,7 @@ add_task(function* test_register_rollback() { yield rejects( PushNotificationService.register('https://example.com/storage-error', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })), - function(error) { - return error == 'universe has imploded'; - }, - 'Wrong error for unregister database failure' + 'Expected error for unregister database failure' ); // Should send an out-of-band unregister request. diff --git a/dom/push/test/xpcshell/test_register_success.js b/dom/push/test/xpcshell/test_register_success.js index ce14cffd52c..82c43651886 100644 --- a/dom/push/test/xpcshell/test_register_success.js +++ b/dom/push/test/xpcshell/test_register_success.js @@ -60,22 +60,14 @@ add_task(function* test_register_success() { 'https://example.org/1', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }) ); - equal(newRecord.channelID, channelID, - 'Wrong channel ID in registration record'); equal(newRecord.pushEndpoint, 'https://example.com/update/1', 'Wrong push endpoint in registration record'); - equal(newRecord.scope, 'https://example.org/1', - 'Wrong scope in registration record'); - equal(newRecord.quota, Infinity, - 'Wrong quota in registration record'); let record = yield db.getByKeyID(channelID); equal(record.channelID, channelID, 'Wrong channel ID in database record'); equal(record.pushEndpoint, 'https://example.com/update/1', 'Wrong push endpoint in database record'); - equal(record.scope, 'https://example.org/1', - 'Wrong scope in database record'); equal(record.quota, Infinity, 'Wrong quota in database record'); }); diff --git a/dom/push/test/xpcshell/test_register_success_http2.js b/dom/push/test/xpcshell/test_register_success_http2.js index a993e64e6c5..7930ca7d86c 100644 --- a/dom/push/test/xpcshell/test_register_success_http2.js +++ b/dom/push/test/xpcshell/test_register_success_http2.js @@ -64,15 +64,11 @@ add_task(function* test_pushSubscriptionSuccess() { var subscriptionUri = serverURL + '/pushSubscriptionSuccesss'; var pushEndpoint = serverURL + '/pushEndpointSuccess'; var pushReceiptEndpoint = serverURL + '/receiptPushEndpointSuccess'; - equal(newRecord.subscriptionUri, subscriptionUri, - 'Wrong subscription ID in registration record'); equal(newRecord.pushEndpoint, pushEndpoint, 'Wrong push endpoint in registration record'); equal(newRecord.pushReceiptEndpoint, pushReceiptEndpoint, 'Wrong push endpoint receipt in registration record'); - equal(newRecord.scope, 'https://example.org/1', - 'Wrong scope in registration record'); let record = yield db.getByKeyID(subscriptionUri); equal(record.subscriptionUri, subscriptionUri, @@ -107,15 +103,11 @@ add_task(function* test_pushSubscriptionMissingLink2() { var subscriptionUri = serverURL + '/subscriptionMissingLink2'; var pushEndpoint = serverURL + '/pushEndpointMissingLink2'; var pushReceiptEndpoint = ''; - equal(newRecord.subscriptionUri, subscriptionUri, - 'Wrong subscription ID in registration record'); equal(newRecord.pushEndpoint, pushEndpoint, 'Wrong push endpoint in registration record'); equal(newRecord.pushReceiptEndpoint, pushReceiptEndpoint, 'Wrong push endpoint receipt in registration record'); - equal(newRecord.scope, 'https://example.org/no_receiptEndpoint', - 'Wrong scope in registration record'); let record = yield db.getByKeyID(subscriptionUri); equal(record.subscriptionUri, subscriptionUri, diff --git a/dom/push/test/xpcshell/test_register_timeout.js b/dom/push/test/xpcshell/test_register_timeout.js index 7c558f3cfa2..12e604f6b46 100644 --- a/dom/push/test/xpcshell/test_register_timeout.js +++ b/dom/push/test/xpcshell/test_register_timeout.js @@ -77,10 +77,7 @@ add_task(function* test_register_timeout() { yield rejects( PushNotificationService.register('https://example.net/page/timeout', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })), - function(error) { - return error == 'TimeoutError'; - }, - 'Wrong error for request timeout' + 'Expected error for request timeout' ); let record = yield db.getByKeyID(channelID); diff --git a/dom/push/test/xpcshell/test_register_wrong_id.js b/dom/push/test/xpcshell/test_register_wrong_id.js index 4ba8003e150..7fc47cb9484 100644 --- a/dom/push/test/xpcshell/test_register_wrong_id.js +++ b/dom/push/test/xpcshell/test_register_wrong_id.js @@ -61,10 +61,7 @@ add_task(function* test_register_wrong_id() { yield rejects( PushNotificationService.register('https://example.com/mismatched', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })), - function(error) { - return error == 'TimeoutError'; - }, - 'Wrong error for mismatched register reply' + 'Expected error for mismatched register reply' ); yield waitForPromise(helloPromise, DEFAULT_TIMEOUT, diff --git a/dom/push/test/xpcshell/test_register_wrong_type.js b/dom/push/test/xpcshell/test_register_wrong_type.js index d08996cae52..9793d4f9497 100644 --- a/dom/push/test/xpcshell/test_register_wrong_type.js +++ b/dom/push/test/xpcshell/test_register_wrong_type.js @@ -52,15 +52,10 @@ add_task(function* test_register_wrong_type() { } }); - let promise = - yield rejects( PushNotificationService.register('https://example.com/mistyped', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })), - function(error) { - return error == 'TimeoutError'; - }, - 'Wrong error for non-string channel ID' + 'Expected error for non-string channel ID' ); yield waitForPromise(helloPromise, DEFAULT_TIMEOUT, diff --git a/dom/push/test/xpcshell/test_registration_missing_scope.js b/dom/push/test/xpcshell/test_registration_missing_scope.js index c32955aead1..b1b4a79a027 100644 --- a/dom/push/test/xpcshell/test_registration_missing_scope.js +++ b/dom/push/test/xpcshell/test_registration_missing_scope.js @@ -21,9 +21,6 @@ add_task(function* test_registration_missing_scope() { }); yield rejects( PushNotificationService.registration('', ''), - function(error) { - return error.error == 'NotFoundError'; - }, 'Record missing page and manifest URLs' ); }); diff --git a/dom/push/test/xpcshell/test_unregister_empty_scope.js b/dom/push/test/xpcshell/test_unregister_empty_scope.js index 63846cf7a37..c3760be1218 100644 --- a/dom/push/test/xpcshell/test_unregister_empty_scope.js +++ b/dom/push/test/xpcshell/test_unregister_empty_scope.js @@ -31,9 +31,6 @@ add_task(function* test_unregister_empty_scope() { yield rejects( PushNotificationService.unregister('', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })), - function(error) { - return error.error == 'NotFoundError'; - }, - 'Wrong error for empty endpoint' + 'Expected error for empty endpoint' ); }); diff --git a/dom/push/test/xpcshell/test_updateRecordNoEncryptionKeys_ws.js b/dom/push/test/xpcshell/test_updateRecordNoEncryptionKeys_ws.js index 527de694378..a3b8bf53806 100644 --- a/dom/push/test/xpcshell/test_updateRecordNoEncryptionKeys_ws.js +++ b/dom/push/test/xpcshell/test_updateRecordNoEncryptionKeys_ws.js @@ -77,8 +77,7 @@ add_task(function* test_with_data_enabled() { 'https://example.com/page/3', ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }) ); - ok(newRecord.p256dhPublicKey, 'Should generate public keys for new records'); - ok(newRecord.p256dhPrivateKey, 'Should generate private keys for new records'); + ok(newRecord.p256dhKey, 'Should generate public keys for new records'); let record = yield db.getByKeyID('eb18f12a-cc42-4f14-accb-3bfc1227f1aa'); ok(record.p256dhPublicKey, 'Should add public key to partial record');