mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1210896, Part 2 - Use JS errors to reject internal Push promises. r=mt
This commit is contained in:
parent
e901a1c306
commit
357fec3abc
@ -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",
|
||||
|
@ -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"];
|
||||
|
@ -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() {
|
||||
|
@ -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()");
|
||||
|
||||
|
@ -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);
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -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"));
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -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');
|
||||
});
|
||||
|
@ -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,
|
||||
|
@ -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');
|
||||
});
|
||||
|
@ -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();
|
||||
|
@ -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');
|
||||
});
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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.
|
||||
|
@ -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');
|
||||
});
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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'
|
||||
);
|
||||
});
|
||||
|
@ -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'
|
||||
);
|
||||
});
|
||||
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user