summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/appmanifest/user_preferences-member
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 /testing/web-platform/tests/appmanifest/user_preferences-member
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 'testing/web-platform/tests/appmanifest/user_preferences-member')
-rw-r--r--testing/web-platform/tests/appmanifest/user_preferences-member/resources/icon.pngbin0 -> 104 bytes
-rw-r--r--testing/web-platform/tests/appmanifest/user_preferences-member/resources/user_preferences-member-manual.js4
-rw-r--r--testing/web-platform/tests/appmanifest/user_preferences-member/resources/user_preferences-member.webmanifest22
-rw-r--r--testing/web-platform/tests/appmanifest/user_preferences-member/resources/user_preferences-member.webmanifest.headers1
-rw-r--r--testing/web-platform/tests/appmanifest/user_preferences-member/user_preferences-member-manual.html13
-rw-r--r--testing/web-platform/tests/appmanifest/user_preferences-member/user_preferences-member-service-worker.js52
6 files changed, 92 insertions, 0 deletions
diff --git a/testing/web-platform/tests/appmanifest/user_preferences-member/resources/icon.png b/testing/web-platform/tests/appmanifest/user_preferences-member/resources/icon.png
new file mode 100644
index 0000000000..d6dd4860ae
--- /dev/null
+++ b/testing/web-platform/tests/appmanifest/user_preferences-member/resources/icon.png
Binary files differ
diff --git a/testing/web-platform/tests/appmanifest/user_preferences-member/resources/user_preferences-member-manual.js b/testing/web-platform/tests/appmanifest/user_preferences-member/resources/user_preferences-member-manual.js
new file mode 100644
index 0000000000..bf1bc8d24c
--- /dev/null
+++ b/testing/web-platform/tests/appmanifest/user_preferences-member/resources/user_preferences-member-manual.js
@@ -0,0 +1,4 @@
+if ('serviceWorker' in navigator) {
+ navigator.serviceWorker.register(
+ 'user_preferences-member-service-worker.js');
+}
diff --git a/testing/web-platform/tests/appmanifest/user_preferences-member/resources/user_preferences-member.webmanifest b/testing/web-platform/tests/appmanifest/user_preferences-member/resources/user_preferences-member.webmanifest
new file mode 100644
index 0000000000..3d92202bf7
--- /dev/null
+++ b/testing/web-platform/tests/appmanifest/user_preferences-member/resources/user_preferences-member.webmanifest
@@ -0,0 +1,22 @@
+{
+ "name": "user_preferences member WPT",
+ "icons": [
+ {
+ "src": "icon.png",
+ "sizes": "144x144"
+ }
+ ],
+ "start_url": "../user_preferences-member-manual.html",
+ "display": "fullscreen",
+ "user_preferences": {
+ "color_scheme": {
+ "dark": {
+ "theme_color": "green"
+ },
+ "light": {
+ "theme_color": "green"
+ }
+ }
+ },
+ "theme_color": "red"
+} \ No newline at end of file
diff --git a/testing/web-platform/tests/appmanifest/user_preferences-member/resources/user_preferences-member.webmanifest.headers b/testing/web-platform/tests/appmanifest/user_preferences-member/resources/user_preferences-member.webmanifest.headers
new file mode 100644
index 0000000000..23f36ea27c
--- /dev/null
+++ b/testing/web-platform/tests/appmanifest/user_preferences-member/resources/user_preferences-member.webmanifest.headers
@@ -0,0 +1 @@
+Content-Type: application/manifest+json; charset=utf-8 \ No newline at end of file
diff --git a/testing/web-platform/tests/appmanifest/user_preferences-member/user_preferences-member-manual.html b/testing/web-platform/tests/appmanifest/user_preferences-member/user_preferences-member-manual.html
new file mode 100644
index 0000000000..c864d3dfd5
--- /dev/null
+++ b/testing/web-platform/tests/appmanifest/user_preferences-member/user_preferences-member-manual.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<title>Test that user_preferences member is supported</title>
+<link rel="manifest" href="resources/user_preferences-member.webmanifest" />
+<script src="resources/user_preferences-member-manual.js"></script>
+<h1>Testing support for user_preferences member</h1>
+<ol>
+ <li>Install this site as a PWA</li>
+ <li>Enable the OS dark mode setting</li>
+ <li>To pass, the theme_color must be green. This can be observed by looking
+ at the top of the window. On failure, this will be red.
+ </li>
+</ol>
+
diff --git a/testing/web-platform/tests/appmanifest/user_preferences-member/user_preferences-member-service-worker.js b/testing/web-platform/tests/appmanifest/user_preferences-member/user_preferences-member-service-worker.js
new file mode 100644
index 0000000000..24d575a917
--- /dev/null
+++ b/testing/web-platform/tests/appmanifest/user_preferences-member/user_preferences-member-service-worker.js
@@ -0,0 +1,52 @@
+// Some user agents only offer app installation if there is a SW and it handles
+// offline requests.
+
+const cacheVersion = "1.2";
+const CACHE_NAME = `cache-v${cacheVersion}`;
+
+// The resources cached by this service worker.
+const resources = [
+ "user_preferences-member-manual.html",
+ "user_preferences-member-service-worker.js",
+ "resources/user_preferences-member-manual.js",
+ "resources/icon.png"
+];
+
+// Load all resources for this service worker.
+const precache = async () => {
+ const cache = await caches.open(CACHE_NAME);
+ await cache.addAll(resources);
+};
+
+// Get a resource from the cache.
+const fromCache = async request => {
+ const cache = await caches.open(CACHE_NAME);
+ return await cache.match(request.url);
+};
+
+// Attempt to get resources from the network first, fallback to the cache if we're
+// offline.
+const networkFallbackToCache = async request => {
+ try {
+ const response = await fetch(request);
+ if (response.ok) return response;
+ } catch (err) {}
+ return await fromCache(request);
+};
+
+// When we have a new service worker, update the caches and swap immediately.
+self.addEventListener("install", e => {
+ e.waitUntil(precache().then(() => self.skipWaiting()));
+});
+
+// Claim existing clients.
+self.addEventListener("activate", e => {
+ e.waitUntil(self.clients.claim());
+});
+
+// When a resource need to be fetched, check whether it is
+// contained in the cache and return the cached version, otherwise
+// get it from the network.
+self.addEventListener("fetch", e => {
+ e.respondWith(networkFallbackToCache(e.request));
+});