diff options
Diffstat (limited to 'devtools/client/application/test/browser/resources/service-workers/controlled-install-sw.js')
-rw-r--r-- | devtools/client/application/test/browser/resources/service-workers/controlled-install-sw.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/devtools/client/application/test/browser/resources/service-workers/controlled-install-sw.js b/devtools/client/application/test/browser/resources/service-workers/controlled-install-sw.js new file mode 100644 index 0000000000..d0a70a5312 --- /dev/null +++ b/devtools/client/application/test/browser/resources/service-workers/controlled-install-sw.js @@ -0,0 +1,29 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Copied from shared-head.js +function waitUntil(predicate, interval = 10) { + if (predicate()) { + return Promise.resolve(true); + } + return new Promise(resolve => { + setTimeout(function () { + waitUntil(predicate, interval).then(() => resolve(true)); + }, interval); + }); +} + +// this flag will be flipped externally from controlled-install.html +// by sending a message event to the worker +let canInstall = false; +self.addEventListener("message", event => { + if (event.data === "install-service-worker") { + canInstall = true; + } +}); + +self.addEventListener("install", event => { + event.waitUntil(waitUntil(() => canInstall)); +}); |