Bug 1139561 - Various small ServiceWorker test fixes. r=baku

Replace setTimeout for test_unregister with detailed checks for active worker before opening iframe
check for null reg in unregister tests
Removed current dir scope so potential fetch event slowdown does not timeout tests
use navigator.serviceWorker to receive messages
Remove leftover getRegistration() test
This commit is contained in:
Nikhil Marathe 2015-03-03 16:00:02 -08:00
parent 00822e89c4
commit e2cfed77bc
7 changed files with 70 additions and 34 deletions

View File

@ -36,15 +36,6 @@
}
});
navigator.serviceWorker.getRegistration('http://mochi.test:8888/with_star/*')
.then(function(a) {
window.parent.postMessage({ type: "check", status: true,
msg: "getRegistration returns a ServiceWorkerRegistration" }, "*");
a.onupdatefound = function(e) {
eventReceived();
}
});
navigator.serviceWorker.getRegistration('http://www.something_else.net/')
.then(function(a) {
window.parent.postMessage({ type: "check", status: false,

View File

@ -16,7 +16,6 @@
<script class="testbody" type="text/javascript">
var scriptsAndScopes = [
[ "worker.js", "." ],
[ "worker.js", "./sub/dir/"],
[ "worker.js", "./sub/dir" ],
[ "worker.js", "./sub/dir.html" ],
@ -53,15 +52,24 @@
return base + s;
}
ok(getScope(p("index.html")) === p(""), "Scope should match");
ok(getScope(p("sua.html")) === p(""), "Scope should match");
function fail(fn) {
try {
getScope(p("index.html"));
ok(false, "No registration");
} catch(e) {
ok(true, "No registration");
}
}
ok(getScope(p("sub.html")) === p("sub"), "Scope should match");
ok(getScope(p("sub/dir.html")) === p("sub/dir.html"), "Scope should match");
ok(getScope(p("sub/dir")) === p("sub/dir"), "Scope should match");
ok(getScope(p("sub/dir/foo")) === p("sub/dir/"), "Scope should match");
ok(getScope(p("sub/dir/afoo")) === p("sub/dir/a"), "Scope should match");
ok(getScope(p("star*wars")) === p("star*"), "Scope should match");
ok(getScope(p("star/a.html")) === p(""), "Scope should match");
fail("index.html");
fail("sua.html");
fail("star/a.html");
resolve();
});
}

View File

@ -16,8 +16,31 @@
<script class="testbody" type="text/javascript">
function simpleRegister() {
info("simpleRegister() just before calling register");
return navigator.serviceWorker.register("worker.js", { scope: "unregister/" });
return navigator.serviceWorker.register("worker.js", { scope: "unregister/" }).then(function(swr) {
if (swr.installing) {
return new Promise(function(resolve, reject) {
swr.installing.onstatechange = function(e) {
if (swr.waiting) {
swr.waiting.onstatechange = function(e) {
if (swr.active) {
resolve();
} else if (swr.waiting && swr.waiting.state == "redundant") {
reject("Should not go into redundant");
}
}
} else {
if (swr.active) {
resolve();
} else {
reject("No waiting and no active!");
}
}
}
});
} else {
return Promise.reject("Installing should be non-null");
}
});
}
function testControlled() {
@ -49,6 +72,11 @@
function unregister() {
return navigator.serviceWorker.getRegistration("unregister/")
.then(function(reg) {
if (!reg) {
info("Registration already removed");
return;
}
info("getRegistration() succeeded " + reg.scope);
return reg.unregister().then(function(v) {
ok(v, "Unregister should resolve to true");

View File

@ -14,7 +14,31 @@
<script class="testbody" type="text/javascript">
function simpleRegister() {
return navigator.serviceWorker.register("worker_unregister.js", { scope: "unregister/" });
return navigator.serviceWorker.register("worker_unregister.js", { scope: "unregister/" }).then(function(swr) {
if (swr.installing) {
return new Promise(function(resolve, reject) {
swr.installing.onstatechange = function(e) {
if (swr.waiting) {
swr.waiting.onstatechange = function(e) {
if (swr.active) {
resolve();
} else if (swr.waiting && swr.waiting.state == "redundant") {
reject("Should not go into redundant");
}
}
} else {
if (swr.active) {
resolve();
} else {
reject("No waiting and no active!");
}
}
}
});
} else {
return Promise.reject("Installing should be non-null");
}
});
}
function waitForMessages(sw) {

View File

@ -19,22 +19,7 @@
info("unregister/index.html should not to be launched directly!");
}
SimpleTest.requestFlakyTimeout("Unfortunately we have no way to test for a page being uncontrolled except waiting for ready to not resolve");
var tId = setTimeout(function() {
parent.postMessage({ controlled: false }, "*");
tId = null;
}, 2000);
navigator.serviceWorker.ready.then(function() {
if (tId == null) {
parent.postMessage("FAIL!!!", "*");
return;
}
clearTimeout(tId);
parent.postMessage({ controlled: true }, "*");
});
parent.postMessage({ controlled: !!navigator.serviceWorker.controller }, "*");
</script>
</pre>
</body>

View File

@ -12,7 +12,7 @@
<body>
<script type="text/javascript">
onmessage = function(e) { parent.postMessage(e.data, "*"); }
navigator.serviceWorker.onmessage = function(e) { parent.postMessage(e.data, "*"); }
navigator.serviceWorker.controller.postMessage("GO");
</script>

View File

@ -12,7 +12,7 @@
<body>
<script type="text/javascript">
onmessage = function(e) { parent.postMessage(e.data, "*"); }
navigator.serviceWorker.onmessage = function(e) { parent.postMessage(e.data, "*"); }
navigator.serviceWorker.ready.then(function() {
navigator.serviceWorker.controller.postMessage("GO");
});