function observeMessage() {
ok(false, "Should not deliver malformed updates");
}
registerCleanupFunction(() =>
Services.obs.removeObserver(observeMessage, PushServiceComponent.pushTopic)
);
Services.obs.addObserver(observeMessage, PushServiceComponent.pushTopic);
let notificationDone;
let notificationPromise = new Promise(
resolve => (notificationDone = after(2, resolve))
);
let prevHandler = PushServiceWebSocket._handleNotificationReply;
PushServiceWebSocket._handleNotificationReply = function _handleNotificationReply() {
notificationDone(); return prevHandler.apply(this, arguments);
};
PushService.init({
serverURI: "wss://push.example.org/",
db,
makeWebSocket(uri) { returnnew MockWebSocket(uri, {
onHello() { this.serverSendMsg(
JSON.stringify({
messageType: "hello",
status: 200,
uaid: userAgentID,
})
); 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");
},
});
},
});
await notificationPromise;
let storeRecords = await db.getAllKeyIDs();
storeRecords.sort(({ pushEndpoint: a }, { pushEndpoint: b }) =>
compareAscending(a, b)
);
recordsAreEqual(records, storeRecords);
});
function recordIsEqual(a, b) {
strictEqual(a.channelID, b.channelID, "Wrong channel ID in record");
strictEqual(a.pushEndpoint, b.pushEndpoint, "Wrong push endpoint in record");
strictEqual(a.scope, b.scope, "Wrong scope in record");
strictEqual(a.version, b.version, "Wrong version in record");
}
function recordsAreEqual(a, b) {
equal(a.length, b.length, "Mismatched record count"); for (let i = 0; i < a.length; i++) {
recordIsEqual(a[i], b[i]);
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.0 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.