// Tests a _registered_ ServiceWorker whose script evaluation results in an
// "abrupt completion", e.g. threw an uncaught exception. Such a ServiceWorker's
// first script evaluation must result in a "normal completion", however, for
// the Update algorithm to not abort in its step 18 when registering:
//
// 18. If runResult is failure or an abrupt completion, then: [...]
// Should only be called once registration.active is non-null. Uses
// implementation details by zero-ing the "idle timeout"s and then sending an
// event to the ServiceWorker, which should immediately cause its termination.
// The idle timeouts are restored after the ServiceWorker is terminated.
async function startAndStopServiceWorker() {
SpecialPowers.registerObservers("service-worker-shutdown");
ok(registration.active instanceof ServiceWorker, "ServiceWorker is activated");
});
// We expect that the restarted SW that experiences an abrupt completion at
// startup after adding its message handler 1) will be active in order to
// respond to our postMessage and 2) will respond with the global value set
// prior to the importScripts call that throws (and not the global value that
// would have been assigned after the importScripts call if it didn't throw).
add_task(async function testMessageHandler() {
await startAndStopServiceWorker();
await new Promise(resolve => {
navigator.serviceWorker.onmessage = e => {
is(e.data, expectedMessage, "Correct message handler");
resolve();
};
registration.active.postMessage("");
});
});
// We expect that the restarted SW that experiences an abrupt completion at
// startup before adding its "fetch" listener will 1) successfully dispatch the
// event and 2) it will not be handled (respondWith() will not be called) so
// interception will be reset and the response will contain the contents of
// empty.html. Before the fix in bug 1603484 the SW would fail to properly start
// up and the fetch event would result in a NetworkError, breaking the
// controlled page.
add_task(async function testFetchHandler() {
await startAndStopServiceWorker();
// NetworkError will have a status of 0, which is not "ok", and this is
// a stronger guarantee that should be true instead of just checking if there
// isn't a NetworkError.
ok(response.ok, "Fetch succeeded and didn't result in a NetworkError");
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.