blob: def3c96cfd77f90766f2d1e61d936b77ace74679 [file] [log] [blame]
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
function testServiceWorker() {
navigator.serviceWorker.addEventListener("message", function(event) {
alert("Message from worker: " + event.data);
if (window.testRunner)
testRunner.notifyDone();
});
try {
navigator.serviceWorker.register('resources/fetch-worker.js').then(function(reg) {
worker = reg.installing ? reg.installing : reg.active;
worker.postMessage("Hello from the web page");
}).catch(function(error) {
alert("Registration failed with: " + error);
if (window.testRunner)
testRunner.notifyDone();
});
} catch(e) {
alert("Exception: " + e);
if (window.testRunner)
testRunner.notifyDone();
}
}
function test() {
fetch("/resources/dummy.js").then(() => {
alert("FAIL - should have blocked request to dummy.js");
if (window.testRunner)
testRunner.notifyDone();
}).catch(() => {
alert("PASS - blocked request to dummy.js");
fetch("/resources/dummy.css").then(() => {
testServiceWorker();
}).catch(() => {
alert("FAIL - should have allowed request to dummy.css");
if (window.testRunner)
testRunner.notifyDone();
});
});
}