Skip to content

Commit

Permalink
WPT: Update unrecognized-member tests to make them all promotable
Browse files Browse the repository at this point in the history
This CL updates all wpt/appmanifest/unrecognized-member tests.
Now they can be installed.

Bug: 1247435
Change-Id: Ic7e541d32df0ebe00167380093ff37f9530b0e03
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3226003
Auto-Submit: Fangzhen Song <songfangzhen@bytedance.com>
Reviewed-by: Phillis Tang <phillis@chromium.org>
Commit-Queue: Fangzhen Song <songfangzhen@bytedance.com>
Cr-Commit-Position: refs/heads/main@{#932812}
  • Loading branch information
song-fangzhen authored and Chromium LUCI CQ committed Oct 19, 2021
1 parent d1dff8e commit 928c65a
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 8 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register(
'unrecognized-member-service-worker.js');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"this member name is not expected to be recognized": "ok",
"this object is not expected to be recognized": {
"this sub-field is not expected to be recognized": []
},
"short_name": "pass",
"icons": [
{
"src": "icon.png",
"sizes": "192x192"
}
],
"start_url": "../unrecognized-member-manual.html",
"display": "fullscreen"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<!DOCTYPE html>
<title>Test that an unrecognized member is ignored</title>
<link rel="help" href="https://www.w3.org/TR/appmanifest/#processing" />
<link rel="manifest" href="unrecognized-member.webmanifest" />
<link rel="manifest" href="resources/unrecognized-member.webmanifest" />
<script src="resources/unrecognized-member-manual.js"></script>
<h1>Testing support for ignoring an unrecognized member</h1>
<p>
To pass, the application name must be "pass". Parsing must not fail due to the
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = [
"unrecognized-member-manual.html",
"unrecognized-member-service-worker.js",
"resources/unrecognized-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));
});

This file was deleted.

0 comments on commit 928c65a

Please sign in to comment.