Bug 1425975 P11 Fix test_workerupdatefound.html not to frame loading against SW activation and updatefound events. r=asuth

This commit is contained in:
Ben Kelly 2017-12-22 21:09:19 -05:00
Родитель 171584cc47
Коммит a03dd3c968
2 изменённых файлов: 16 добавлений и 20 удалений

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

@ -13,14 +13,15 @@
<p id="display"></p>
<div id="content"></div>
<pre id="test"></pre>
<script src="utils.js"></script>
<script class="testbody" type="text/javascript">
var registration;
var promise;
function start() {
return navigator.serviceWorker.register("worker_updatefoundevent.js",
{ scope: "./updatefoundevent.html" })
.then((swr) => registration = swr);
async function start() {
registration = await navigator.serviceWorker.register("worker_updatefoundevent.js",
{ scope: "./updatefoundevent.html" })
await waitForState(registration.installing, 'activated');
}
function startWaitForUpdateFound() {

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

@ -3,21 +3,16 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
onactivate = function(e) {
e.waitUntil(new Promise(function(resolve, reject) {
registration.onupdatefound = function(e) {
clients.matchAll().then(function(clients) {
if (!clients.length) {
reject("No clients found");
}
if (registration.scope.match(/updatefoundevent\.html$/)) {
clients[0].postMessage("finish");
resolve();
} else {
dump("Scope did not match");
}
}, reject);
registration.onupdatefound = function(e) {
clients.matchAll().then(function(clients) {
if (!clients.length) {
reject("No clients found");
}
}));
if (registration.scope.match(/updatefoundevent\.html$/)) {
clients[0].postMessage("finish");
} else {
dump("Scope did not match");
}
});
}