function nextRegister(reg) {
ok(reg instanceof ServiceWorkerRegistration, "reg should be a ServiceWorkerRegistration"); varp = navigator.serviceWorker.register("install_event_worker.js", { scope: "./install_event" });
return p.then(function(swr) {
ok(reg === swr, "register should resolve to the same registration object"); var update_found_promise = new Promise(function(resolve, reject) {
swr.addEventListener('updatefound', function(e) {
ok(true, "Received onupdatefound");
resolve();
});
});
var worker_activating = new Promise(function(res, reject) {
ok(swr.installing instanceof ServiceWorker, "There should be an installing worker if promise resolves.");
ok(swr.installing.state == "installing", "Installing worker's state should be 'installing'");
swr.installing.onstatechange = function(e) {
if (e.target.state == "activating") {
e.target.onstatechange = null;
res();
}
}
});
function installError() {
// Silence worker errors so they don't cause the test to fail.
window.onerror = function(e) {}
return navigator.serviceWorker.register("install_event_error_worker.js", { scope: "./install_event" })
.then(function(swr) {
ok(swr.installing instanceof ServiceWorker, "There should be an installing worker if promise resolves.");
ok(swr.installing.state == "installing", "Installing worker's state should be 'installing'");
return new Promise(function(resolve, reject) {
swr.installing.onstatechange = function(e) {
ok(e.target.state == "redundant", "Installation of worker with error should fail.");
resolve();
}
});
}).then(function() {
return navigator.serviceWorker.getRegistration("./install_event").then(function(swr) { var newest = swr.waiting || swr.active;
ok(newest, "Waiting or active worker should still exist");
ok(newest.scriptURL.match(/install_event_worker.js$/), "Previous worker should remain the newest worker");
});
});
}
function testActive(worker) {
is(worker.state, "activating", "Should be activating");
return new Promise(function(resolve, reject) {
worker.onstatechange = function(e) {
e.target.onstatechange = null;
is(e.target.state, "activated", "Activation of worker with error in activate event handler should still succeed.");
resolve();
}
});
}
function activateErrorShouldSucceed() {
// Silence worker errors so they don't cause the test to fail.
window.onerror = function() { }
return navigator.serviceWorker.register("activate_event_error_worker.js", { scope: "./activate_error" })
.then(function(swr) { varp = new Promise(function(resolve, reject) {
ok(swr.installing.state == "installing", "activateErrorShouldSucceed(): Installing worker's state should be 'installing'");
swr.installing.onstatechange = function(e) {
e.target.onstatechange = null;
if (swr.waiting) {
swr.waiting.onstatechange = function(event) {
event.target.onstatechange = null;
testActive(swr.active).then(resolve, reject);
}
} else {
testActive(swr.active).then(resolve, reject);
}
}
});
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.