Bug 1060517 - dom/workers/test/serviceworkers/test_unregister.html must use 'ready', r=nsm

This commit is contained in:
Andrea Marchesini 2014-09-03 16:47:49 +01:00
Родитель 636b4bc534
Коммит 7a610a3d17
2 изменённых файлов: 48 добавлений и 50 удалений

Просмотреть файл

@ -22,27 +22,27 @@
function testControlled() {
var testPromise = new Promise(function(res, rej) {
window.onmessage = function(e) {
if (e.data === "READY") {
w.postMessage({ "controlled": true }, "*");
} else if (e.data === "SUCCESS") {
ok(true, "New window should be controlled.");
res();
} else if (e.data === "FAIL") {
ok(false, "New window should be controlled");
if (!("controlled" in e.data)) {
ok(false, "Something went wrong.");
rej();
return;
}
ok(e.data.controlled, "New window should be controlled.");
res();
}
}
})
var div = document.getElementById("content");
ok(div, "Parent exists");
var ifr = document.createElement("iframe");
ifr.setAttribute('src', "unregister/index.html");
div.appendChild(ifr);
return testPromise.then(function() {
div.removeChild(ifr);
});
// This setTimeout is temporary to allow the ServiceWorker to get
// activated. Once Bug 1025077 is implemented, this can be replaced to use
// ready().
var w;
setTimeout(function() {
w = window.open("unregister/index.html", "_blank", "width=700, height=400");
}, 150);
return testPromise.then(() => w.close());
}
function unregister() {
@ -59,23 +59,27 @@
function testUncontrolled() {
var testPromise = new Promise(function(res, rej) {
window.onmessage = function(e) {
if (e.data === "READY") {
w.postMessage({ "controlled": false }, "*");
} else if (e.data === "SUCCESS") {
ok(true, "New window should not be controlled.");
res();
} else if (e.data === "FAIL") {
ok(false, "New window should not be controlled");
res();
if (!("controlled" in e.data)) {
ok(false, "Something went wrong.");
rej();
return;
}
ok(!e.data.controlled, "New window should not be controlled.");
res();
}
});
var w;
setTimeout(function() {
w = window.open("unregister/index.html", "_blank", "width=700, height=400");
}, 150);
return testPromise.then(() => w.close());
var div = document.getElementById("content");
ok(div, "Parent exists");
var ifr = document.createElement("iframe");
ifr.setAttribute('src', "unregister/index.html");
div.appendChild(ifr);
return testPromise.then(function() {
div.removeChild(ifr);
});
}
function runTest() {

Просмотреть файл

@ -14,32 +14,26 @@
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<script class="testbody" type="text/javascript">
function fail(msg) {
info("unregister/index.html: " + msg);
opener.postMessage("FAIL", "*");
}
if (!opener) {
if (!parent) {
info("unregister/index.html should not to be launched directly!");
}
window.addEventListener("message", function(e) {
if (!e.data) {
return fail("Message had no data!");
var tId = setTimeout(function() {
parent.postMessage({ controlled: false }, "*");
tId = null;
}, 2000);
navigator.serviceWorker.ready.then(function() {
if (tId == null) {
parent.postMessage("FAIL!!!", "*");
return;
}
if (e.data.controlled === true && !navigator.serviceWorker.controller) {
return fail("Not controlled!");
} else if (e.data.controlled === false && navigator.serviceWorker.controller) {
return fail("Controlled when it shouldn't be!");
}
clearTimeout(tId);
parent.postMessage({ controlled: true }, "*");
});
opener.postMessage("SUCCESS", "*");
}, false);
window.onload = function() {
opener.postMessage("READY", "*");
}
</script>
</pre>
</body>