mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 14:52:16 +00:00
Bug 1311739 - PushDB.update
should reject instead of returning undefined
for invalid records. r=dragana
MozReview-Commit-ID: HCLOSz4FHWO --HG-- extra : rebase_source : 57b4e19d3b391e9b0ad96b95d36aee4e3ebcc5a5
This commit is contained in:
parent
ee288ff7bb
commit
d1bf3d09e9
@ -376,11 +376,10 @@ this.PushDB.prototype = {
|
||||
*
|
||||
* @param {String} aKeyID The registration ID.
|
||||
* @param {Function} aUpdateFunc A function that receives the existing
|
||||
* registration record as its argument, and returns a new record. If the
|
||||
* function returns `null` or `undefined`, the record will not be updated.
|
||||
* If the record does not exist, the function will not be called.
|
||||
* @returns {Promise} A promise resolved with either the updated record, or
|
||||
* `undefined` if the record was not updated.
|
||||
* registration record as its argument, and returns a new record.
|
||||
* @returns {Promise} A promise resolved with either the updated record.
|
||||
* Rejects if the record does not exist, or the function returns an invalid
|
||||
* record.
|
||||
*/
|
||||
update: function(aKeyID, aUpdateFunc) {
|
||||
return new Promise((resolve, reject) =>
|
||||
@ -393,14 +392,13 @@ this.PushDB.prototype = {
|
||||
|
||||
let record = aEvent.target.result;
|
||||
if (!record) {
|
||||
console.error("update: Record does not exist", aKeyID);
|
||||
return;
|
||||
throw new Error("Record " + aKeyID + " does not exist");
|
||||
}
|
||||
let newRecord = aUpdateFunc(this.toPushRecord(record));
|
||||
if (!this.isValidRecord(newRecord)) {
|
||||
console.error("update: Ignoring invalid update",
|
||||
aKeyID, newRecord);
|
||||
return;
|
||||
throw new Error("Invalid update for record " + aKeyID);
|
||||
}
|
||||
function putRecord() {
|
||||
let req = aStore.put(newRecord);
|
||||
|
@ -829,9 +829,6 @@ this.PushService = {
|
||||
});
|
||||
});
|
||||
}).then(record => {
|
||||
if (!record) {
|
||||
throw new Error("Ignoring update for key ID " + keyID);
|
||||
}
|
||||
gPushNotifier.notifySubscriptionModified(record.scope,
|
||||
record.principal);
|
||||
return record;
|
||||
@ -880,18 +877,16 @@ this.PushService = {
|
||||
}
|
||||
return record;
|
||||
}).then(record => {
|
||||
if (record) {
|
||||
if (record.isExpired()) {
|
||||
this._recordDidNotNotify(kDROP_NOTIFICATION_REASON_EXPIRED);
|
||||
// Drop the registration in the background. If the user returns to the
|
||||
// site, the service worker will be notified on the next `idle-daily`
|
||||
// event.
|
||||
this._backgroundUnregister(record,
|
||||
Ci.nsIPushErrorReporter.UNSUBSCRIBE_QUOTA_EXCEEDED);
|
||||
} else {
|
||||
gPushNotifier.notifySubscriptionModified(record.scope,
|
||||
record.principal);
|
||||
}
|
||||
if (record.isExpired()) {
|
||||
this._recordDidNotNotify(kDROP_NOTIFICATION_REASON_EXPIRED);
|
||||
// Drop the registration in the background. If the user returns to the
|
||||
// site, the service worker will be notified on the next `idle-daily`
|
||||
// event.
|
||||
this._backgroundUnregister(record,
|
||||
Ci.nsIPushErrorReporter.UNSUBSCRIBE_QUOTA_EXCEEDED);
|
||||
} else {
|
||||
gPushNotifier.notifySubscriptionModified(record.scope,
|
||||
record.principal);
|
||||
}
|
||||
if (this._updateQuotaTestCallback) {
|
||||
// Callback so that test may be notified when the quota update is complete.
|
||||
|
@ -4,15 +4,6 @@
|
||||
'use strict';
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://testing-common/PromiseTestUtils.jsm");
|
||||
|
||||
///////////////////
|
||||
//
|
||||
// Whitelisting this test.
|
||||
// As part of bug 1077403, the leaking uncaught rejection should be fixed.
|
||||
//
|
||||
// Instances of the rejection "record is undefined" may or may not appear.
|
||||
PromiseTestUtils.thisTestLeaksUncaughtRejectionsAndShouldBeFixed();
|
||||
|
||||
const {PushDB, PushService, PushServiceHttp2} = serviceExports;
|
||||
|
||||
|
@ -4,15 +4,6 @@
|
||||
'use strict';
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://testing-common/PromiseTestUtils.jsm");
|
||||
|
||||
///////////////////
|
||||
//
|
||||
// Whitelisting this test.
|
||||
// As part of bug 1077403, the leaking uncaught rejection should be fixed.
|
||||
//
|
||||
// Instances of the rejection "record is undefined" may or may not appear.
|
||||
PromiseTestUtils.thisTestLeaksUncaughtRejectionsAndShouldBeFixed();
|
||||
|
||||
const {PushDB, PushService, PushServiceHttp2} = serviceExports;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user