mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 21:05:36 +00:00
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 --HG-- extra : transplant_source : %F39R%DA2%D5%12%0A%AB%01%9B%BF%BD%5Cy%B3%C3%5C%12%05
This commit is contained in:
parent
04f049b692
commit
0fe8699ff2
@ -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,
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
@ -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");
|
||||
|
@ -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) {
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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");
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user