diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /devtools/client/application/test/browser/resources/service-workers | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/application/test/browser/resources/service-workers')
10 files changed, 199 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)); +}); diff --git a/devtools/client/application/test/browser/resources/service-workers/controlled-install.html b/devtools/client/application/test/browser/resources/service-workers/controlled-install.html new file mode 100644 index 0000000000..300ee1fde7 --- /dev/null +++ b/devtools/client/application/test/browser/resources/service-workers/controlled-install.html @@ -0,0 +1,27 @@ +<!-- Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ --> +<!DOCTYPE HTML> +<html> +<head> + <meta charset="UTF-8"> + <title>Service worker test</title> +</head> +<body> +<script type="text/javascript"> +"use strict"; + +let registration; + +window.registerServiceWorker = async function() { + registration = await navigator.serviceWorker.register( + "controlled-install-sw.js" + ); + window.sw = registration; +}; + +window.installServiceWorker = function() { + registration.installing.postMessage("install-service-worker"); +}; +</script> +</body> +</html> diff --git a/devtools/client/application/test/browser/resources/service-workers/debug-sw.js b/devtools/client/application/test/browser/resources/service-workers/debug-sw.js new file mode 100644 index 0000000000..31f0b1bdd2 --- /dev/null +++ b/devtools/client/application/test/browser/resources/service-workers/debug-sw.js @@ -0,0 +1,18 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +self.addEventListener("activate", event => { + event.waitUntil(self.clients.claim()); +}); + +self.onfetch = function (event) { + const url = event.request.url; + + const response = url.endsWith("test") + ? new Response("lorem ipsum", { statusText: "OK" }) + : fetch(event.request); + + event.respondWith(response); +}; diff --git a/devtools/client/application/test/browser/resources/service-workers/debug.html b/devtools/client/application/test/browser/resources/service-workers/debug.html new file mode 100644 index 0000000000..f0f16858fd --- /dev/null +++ b/devtools/client/application/test/browser/resources/service-workers/debug.html @@ -0,0 +1,25 @@ +<!-- Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ --> + +<!DOCTYPE HTML> +<html> +<head> + <meta charset="UTF-8"> + <title>Service worker test</title> +</head> +<body> +<script type="text/javascript"> +"use strict"; +window.sw = navigator.serviceWorker.register("debug-sw.js"); + +/* exported fetchFromWorker */ +async function fetchFromWorker() { + const response = await fetch("test"); + const text = await response.text(); + console.log(`Response from worker: ${text}`); +} +</script> + +<p>This page has a <code>fetchFromWorker()</code> function.</p> +</body> +</html> diff --git a/devtools/client/application/test/browser/resources/service-workers/dynamic-registration.html b/devtools/client/application/test/browser/resources/service-workers/dynamic-registration.html new file mode 100644 index 0000000000..def300da65 --- /dev/null +++ b/devtools/client/application/test/browser/resources/service-workers/dynamic-registration.html @@ -0,0 +1,19 @@ +<!-- Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ --> +<!DOCTYPE HTML> +<html> +<head> + <meta charset="UTF-8"> + <title>Service worker test</title> +</head> +<body> +<script type="text/javascript"> +"use strict"; + +window.registerServiceWorker = function() { + window.sw = navigator.serviceWorker.register("empty-sw.js"); +}; + +</script> +</body> +</html> diff --git a/devtools/client/application/test/browser/resources/service-workers/empty-sw.js b/devtools/client/application/test/browser/resources/service-workers/empty-sw.js new file mode 100644 index 0000000000..5d33297056 --- /dev/null +++ b/devtools/client/application/test/browser/resources/service-workers/empty-sw.js @@ -0,0 +1,4 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Empty, just test registering. diff --git a/devtools/client/application/test/browser/resources/service-workers/empty.html b/devtools/client/application/test/browser/resources/service-workers/empty.html new file mode 100644 index 0000000000..02373ca02e --- /dev/null +++ b/devtools/client/application/test/browser/resources/service-workers/empty.html @@ -0,0 +1,11 @@ +<!-- Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ --> + +<!DOCTYPE HTML> +<html> +<head> + <meta charset="UTF-8"> + <title>Service worker test (no worker, empty page)</title> +</head> +<body></body> +</html> diff --git a/devtools/client/application/test/browser/resources/service-workers/scope-page.html b/devtools/client/application/test/browser/resources/service-workers/scope-page.html new file mode 100644 index 0000000000..eed5bc82ed --- /dev/null +++ b/devtools/client/application/test/browser/resources/service-workers/scope-page.html @@ -0,0 +1,19 @@ +<!-- Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ --> +<!DOCTYPE HTML> +<html> +<head> + <meta charset="UTF-8"> + <title>Service worker test</title> +</head> +<body> +<script type="text/javascript"> +"use strict"; + +window.sw = navigator.serviceWorker.register("empty-sw.js", { + scope: "./scope-page.html", +}); + +</script> +</body> +</html> diff --git a/devtools/client/application/test/browser/resources/service-workers/simple-unicode.html b/devtools/client/application/test/browser/resources/service-workers/simple-unicode.html new file mode 100644 index 0000000000..51e17b7fec --- /dev/null +++ b/devtools/client/application/test/browser/resources/service-workers/simple-unicode.html @@ -0,0 +1,15 @@ +<!-- Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ --> +<!DOCTYPE HTML> +<html> +<head> + <meta charset="UTF-8"> + <title>Service worker test</title> +</head> +<body> +<script type="text/javascript"> +"use strict"; +window.sw = navigator.serviceWorker.register("empty-sw.js?q=日本"); +</script> +</body> +</html> diff --git a/devtools/client/application/test/browser/resources/service-workers/simple.html b/devtools/client/application/test/browser/resources/service-workers/simple.html new file mode 100644 index 0000000000..88dc00aff0 --- /dev/null +++ b/devtools/client/application/test/browser/resources/service-workers/simple.html @@ -0,0 +1,32 @@ +<!-- Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ --> +<!DOCTYPE HTML> +<html> +<head> + <meta charset="UTF-8"> + <title>Service worker test</title> +</head> +<body> +<script type="text/javascript"> +"use strict"; + +let registration; + +const registerServiceWorker = async function() { + try { + registration = await navigator.serviceWorker.register("empty-sw.js"); + dump("Empty service worker registered\n"); + } catch (e) { + dump("Empty service worker not registered: " + e + "\n"); + } +}; + +// Helper called from head.js to unregister the service worker. +window.getRegistration = function() { + return registration; +}; +// Register the service worker. +registerServiceWorker(); +</script> +</body> +</html> |