summaryrefslogtreecommitdiffstats
path: root/mobile/android/geckoview/src/androidTest/assets/www/push
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /mobile/android/geckoview/src/androidTest/assets/www/push
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mobile/android/geckoview/src/androidTest/assets/www/push')
-rw-r--r--mobile/android/geckoview/src/androidTest/assets/www/push/push.html10
-rw-r--r--mobile/android/geckoview/src/androidTest/assets/www/push/push.js44
-rw-r--r--mobile/android/geckoview/src/androidTest/assets/www/push/sw.js30
3 files changed, 84 insertions, 0 deletions
diff --git a/mobile/android/geckoview/src/androidTest/assets/www/push/push.html b/mobile/android/geckoview/src/androidTest/assets/www/push/push.html
new file mode 100644
index 0000000000..ccd091eaea
--- /dev/null
+++ b/mobile/android/geckoview/src/androidTest/assets/www/push/push.html
@@ -0,0 +1,10 @@
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>Push API test</title>
+ </head>
+ <body>
+ <p>Hello, world!</p>
+ <script src="push.js"></script>
+ </body>
+</html>
diff --git a/mobile/android/geckoview/src/androidTest/assets/www/push/push.js b/mobile/android/geckoview/src/androidTest/assets/www/push/push.js
new file mode 100644
index 0000000000..d9322d11cc
--- /dev/null
+++ b/mobile/android/geckoview/src/androidTest/assets/www/push/push.js
@@ -0,0 +1,44 @@
+window.doSubscribe = async function (applicationServerKey) {
+ const registration = await navigator.serviceWorker.register("./sw.js");
+ const sub = await registration.pushManager.subscribe({
+ applicationServerKey,
+ });
+ return sub.toJSON();
+};
+
+window.doGetSubscription = async function () {
+ const registration = await navigator.serviceWorker.register("./sw.js");
+ const sub = await registration.pushManager.getSubscription();
+ if (sub) {
+ return sub.toJSON();
+ }
+
+ return null;
+};
+
+window.doUnsubscribe = async function () {
+ const registration = await navigator.serviceWorker.register("./sw.js");
+ const sub = await registration.pushManager.getSubscription();
+ sub.unsubscribe();
+ return {};
+};
+
+window.doWaitForPushEvent = function () {
+ return new Promise(resolve => {
+ navigator.serviceWorker.addEventListener("message", function (e) {
+ if (e.data.type === "push") {
+ resolve(e.data.payload);
+ }
+ });
+ });
+};
+
+window.doWaitForSubscriptionChange = function () {
+ return new Promise(resolve => {
+ navigator.serviceWorker.addEventListener("message", function (e) {
+ if (e.data.type === "pushsubscriptionchange") {
+ resolve(e.data.type);
+ }
+ });
+ });
+};
diff --git a/mobile/android/geckoview/src/androidTest/assets/www/push/sw.js b/mobile/android/geckoview/src/androidTest/assets/www/push/sw.js
new file mode 100644
index 0000000000..2e51383205
--- /dev/null
+++ b/mobile/android/geckoview/src/androidTest/assets/www/push/sw.js
@@ -0,0 +1,30 @@
+self.addEventListener("install", function () {
+ self.skipWaiting();
+});
+
+self.addEventListener("activate", function (e) {
+ e.waitUntil(self.clients.claim());
+});
+
+self.addEventListener("push", async function (e) {
+ const clients = await self.clients.matchAll();
+ let text = "";
+ if (e.data) {
+ text = e.data.text();
+ }
+ clients.forEach(function (client) {
+ client.postMessage({ type: "push", payload: text });
+ });
+
+ try {
+ const { title, body } = e.data.json();
+ self.registration.showNotification(title, { body });
+ } catch (e) {}
+});
+
+self.addEventListener("pushsubscriptionchange", async function (e) {
+ const clients = await self.clients.matchAll();
+ clients.forEach(function (client) {
+ client.postMessage({ type: "pushsubscriptionchange" });
+ });
+});