summaryrefslogtreecommitdiffstats
path: root/dom/serviceworkers/test/thirdparty
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /dom/serviceworkers/test/thirdparty
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--dom/serviceworkers/test/thirdparty/iframe1.html42
-rw-r--r--dom/serviceworkers/test/thirdparty/iframe2.html14
-rw-r--r--dom/serviceworkers/test/thirdparty/register.html29
-rw-r--r--dom/serviceworkers/test/thirdparty/sw.js33
-rw-r--r--dom/serviceworkers/test/thirdparty/unregister.html19
-rw-r--r--dom/serviceworkers/test/thirdparty/worker.js1
6 files changed, 138 insertions, 0 deletions
diff --git a/dom/serviceworkers/test/thirdparty/iframe1.html b/dom/serviceworkers/test/thirdparty/iframe1.html
new file mode 100644
index 0000000000..e8982d306a
--- /dev/null
+++ b/dom/serviceworkers/test/thirdparty/iframe1.html
@@ -0,0 +1,42 @@
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html>
+<head>
+ <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
+ <title>SW third party iframe test</title>
+
+ <script type="text/javascript">
+ function messageListener(event) {
+ let message = event.data;
+
+ dump("got message " + JSON.stringify(message) + "\n");
+ if (message.source == "parent") {
+ document.getElementById("iframe2").src = message.href;
+ }
+ else if (message.source == "iframe") {
+ parent.postMessage(event.data, "*");
+ } else if (message.source == "worker") {
+ parent.postMessage(event.data, "*");
+ }
+ }
+ </script>
+
+</head>
+
+<body>
+ <script>
+ onload = function() {
+ window.addEventListener('message', messageListener);
+ let message = {
+ source: "iframe",
+ status: "iframeloaded",
+ }
+ parent.postMessage(message, "*");
+ }
+ </script>
+ <iframe id="iframe2"></iframe>
+</body>
+
+</html>
diff --git a/dom/serviceworkers/test/thirdparty/iframe2.html b/dom/serviceworkers/test/thirdparty/iframe2.html
new file mode 100644
index 0000000000..8013899195
--- /dev/null
+++ b/dom/serviceworkers/test/thirdparty/iframe2.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<script>
+ window.parent.postMessage({
+ source: "iframe",
+ status: "networkresponse"
+ }, "*");
+ var w = new Worker('worker.js');
+ w.onmessage = function(evt) {
+ window.parent.postMessage({
+ source: 'worker',
+ status: evt.data,
+ }, '*');
+ };
+</script>
diff --git a/dom/serviceworkers/test/thirdparty/register.html b/dom/serviceworkers/test/thirdparty/register.html
new file mode 100644
index 0000000000..b166acb8a4
--- /dev/null
+++ b/dom/serviceworkers/test/thirdparty/register.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<script>
+ function ok(v, msg) {
+ window.parent.postMessage({status: "ok", result: !!v, message: msg}, "*");
+ }
+
+ var isDone = false;
+ function done(reg) {
+ if (!isDone) {
+ ok(reg.waiting || reg.active,
+ "Either active or waiting worker should be available.");
+ window.parent.postMessage({status: "registrationdone"}, "*");
+ isDone = true;
+ }
+ }
+
+ navigator.serviceWorker.register("sw.js", {scope: "."})
+ .then(function(registration) {
+ if (registration.installing) {
+ registration.installing.onstatechange = function(e) {
+ done(registration);
+ };
+ } else {
+ done(registration);
+ }
+ }).catch(function(e) {
+ window.parent.postMessage({status: "registrationfailed"}, "*");
+ });
+</script>
diff --git a/dom/serviceworkers/test/thirdparty/sw.js b/dom/serviceworkers/test/thirdparty/sw.js
new file mode 100644
index 0000000000..ea844e8f2b
--- /dev/null
+++ b/dom/serviceworkers/test/thirdparty/sw.js
@@ -0,0 +1,33 @@
+self.addEventListener("fetch", function(event) {
+ dump("fetch " + event.request.url + "\n");
+ if (event.request.url.includes("iframe2.html")) {
+ var body =
+ "<script>" +
+ "window.parent.postMessage({" +
+ "source: 'iframe', status: 'swresponse'" +
+ "}, '*');" +
+ "var w = new Worker('worker.js');" +
+ "w.onmessage = function(evt) {" +
+ "window.parent.postMessage({" +
+ "source: 'worker'," +
+ "status: evt.data," +
+ "}, '*');" +
+ "};" +
+ "</script>";
+ event.respondWith(
+ new Response(body, {
+ headers: { "Content-Type": "text/html" },
+ })
+ );
+ return;
+ }
+ if (event.request.url.includes("worker.js")) {
+ var body = "self.postMessage('worker-swresponse');";
+ event.respondWith(
+ new Response(body, {
+ headers: { "Content-Type": "application/javascript" },
+ })
+ );
+ return;
+ }
+});
diff --git a/dom/serviceworkers/test/thirdparty/unregister.html b/dom/serviceworkers/test/thirdparty/unregister.html
new file mode 100644
index 0000000000..65b29d5648
--- /dev/null
+++ b/dom/serviceworkers/test/thirdparty/unregister.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<script>
+ if (navigator.serviceWorker.controller) {
+ window.parent.postMessage({status: "controlled"}, "*");
+ } else {
+ window.parent.postMessage({status: "uncontrolled"}, "*");
+ }
+
+ navigator.serviceWorker.getRegistration(".").then(function(registration) {
+ if(!registration) {
+ return;
+ }
+ registration.unregister().then(() => {
+ window.parent.postMessage({status: "unregistrationdone"}, "*");
+ });
+ }).catch(function(e) {
+ window.parent.postMessage({status: "getregistrationfailed"}, "*");
+ });
+</script>
diff --git a/dom/serviceworkers/test/thirdparty/worker.js b/dom/serviceworkers/test/thirdparty/worker.js
new file mode 100644
index 0000000000..bbdc608cde
--- /dev/null
+++ b/dom/serviceworkers/test/thirdparty/worker.js
@@ -0,0 +1 @@
+self.postMessage("worker-networkresponse");