blob: 63de9a3636e7fc8050344bb4a2eccdc3844e2957 [file] [log] [blame]
function checkRegistration(registration, expected, name)
{
if (registration === expected) {
log("PASS: " + name + " is as expected");
return;
}
if (registration === null) {
log("FAIL: " + name + " is null");
return;
}
if (expected === null) {
log("FAIL: " + name + " is not null");
return;
}
log("FAIL: " + name + " is not as expected. Its scope is " + registration.scope + " expected scope is " + expected.scope);
}
async function test()
{
try {
log("Registering service worker 0");
var newRegistration0 = await navigator.serviceWorker.register("resources/service-worker-getRegistration-worker.js", { scope: "/workers/service/resources/test1" });
log("Service worker 0 registered with scope " + newRegistration0.scope);
var registration0 = await navigator.serviceWorker.getRegistration();
checkRegistration(registration0, undefined, "registration0");
var registration1 = await navigator.serviceWorker.getRegistration("/workers/service/resources/test1");
checkRegistration(registration1, newRegistration0, "registration1");
var registration2 = await navigator.serviceWorker.getRegistration("/workers/service/resources/test");
checkRegistration(registration2, undefined, "registration2");
var registration3 = await navigator.serviceWorker.getRegistration("/workers/service/resources/test1/test2/test3");
checkRegistration(registration3, newRegistration0, "registration3");
log("Registering service worker 1");
var newRegistration1 = await navigator.serviceWorker.register("resources/service-worker-getRegistration-worker.js", { scope: "/workers/service/resources/test1/test2" });
log("Service worker 1 registered with scope " + newRegistration1.scope);
log("Registering service worker 2");
var newRegistration2 = await navigator.serviceWorker.register("resources/service-worker-getRegistration-worker.js", { scope: "/workers/service/resources/" });
log("Service worker 2 registered with scope " + newRegistration2.scope);
var registration4 = await navigator.serviceWorker.getRegistration("/workers/service/resources/test1/test2");
checkRegistration(registration4, newRegistration1, "registration4");
var registration5 = await navigator.serviceWorker.getRegistration("/workers/service/resources/test1/test2-test3");
checkRegistration(registration5, newRegistration1, "registration5");
var registration6 = await navigator.serviceWorker.getRegistration("/workers/service/resources/");
checkRegistration(registration6, newRegistration2, "registration6");
var registration7 = await navigator.serviceWorker.getRegistration("/workers/service/resources/");
checkRegistration(registration7, newRegistration2, "registration7");
var registration8 = await navigator.serviceWorker.getRegistration("/workers/service/resources/foo");
checkRegistration(registration8, newRegistration2, "registration8");
await newRegistration1.unregister();
var registration9 = await navigator.serviceWorker.getRegistration("/workers/service/resources/test1/test2");
checkRegistration(registration9, newRegistration0, "registration9");
} catch(e) {
log("Got exception: " + e);
}
finishSWTest();
}
test();