blob: df2392558422206fad617a5eec7cc596ed4b4152 [file] [log] [blame]
function waitFor(duration)
{
return new Promise((resolve) => setTimeout(resolve, duration));
}
function withIframe(url) {
return new Promise(function(resolve) {
var frame = document.createElement('iframe');
frame.src = url;
frame.onload = function() { resolve(frame); };
document.body.appendChild(frame);
});
}
function waitForState(worker, state)
{
if (!worker || worker.state == undefined)
return Promise.reject(new Error('wait_for_state must be passed a ServiceWorker'));
if (worker.state === state)
return Promise.resolve(state);
return new Promise(function(resolve) {
worker.addEventListener('statechange', function() {
if (worker.state === state)
resolve(state);
});
});
}