From 64e47ffd900e2d9b5b6ad308e42e090c66a6d2fc Mon Sep 17 00:00:00 2001 From: Mike Jackson Date: Fri, 24 Sep 2021 11:52:05 -0700 Subject: [PATCH] dwpas: Add tentative WPT test for protocol_handler Adding manual WPT test for new protocol_handler field. https://github.com/w3c/manifest/issues/846 Bug: 1019239 Change-Id: I49bbcae9ff1925fb2799d1462fca936147f2e118 --- ...ocol_handlers-member-manual.tentative.html | 34 ++++++++++++ ...protocol_handlers-member-service-worker.js | 52 ++++++++++++++++++ .../resources/icon.png | Bin 0 -> 1520 bytes .../protocol_handlers-member.webmanifest | 18 ++++++ ...otocol_handlers-member.webmanifest.headers | 1 + .../resources/protocol_handlers_entry.html | 19 +++++++ 6 files changed, 124 insertions(+) create mode 100644 appmanifest/protocol_handlers-member/protocol_handlers-member-manual.tentative.html create mode 100644 appmanifest/protocol_handlers-member/protocol_handlers-member-service-worker.js create mode 100644 appmanifest/protocol_handlers-member/resources/icon.png create mode 100644 appmanifest/protocol_handlers-member/resources/protocol_handlers-member.webmanifest create mode 100644 appmanifest/protocol_handlers-member/resources/protocol_handlers-member.webmanifest.headers create mode 100644 appmanifest/protocol_handlers-member/resources/protocol_handlers_entry.html diff --git a/appmanifest/protocol_handlers-member/protocol_handlers-member-manual.tentative.html b/appmanifest/protocol_handlers-member/protocol_handlers-member-manual.tentative.html new file mode 100644 index 000000000000000..fa9c958e0e4ba03 --- /dev/null +++ b/appmanifest/protocol_handlers-member/protocol_handlers-member-manual.tentative.html @@ -0,0 +1,34 @@ + + + + + + Protocol Handling Web Platform Test + + + +

Protocol Handling Web Platform Test

+

This test validates that an install application can register URL protocol + handlers via a property in the web app manifest. The app should open + directly when the 'web+testing' custom-scheme URL is visited. +

+

Manual Test Steps:

+

+

    +
  1. Install this app.
  2. +
  3. Launch 'web+testing://test-url/'. Instructions will vary by OS. +
      +
    • On Windows - open a command prompt, and run "start web+testing://test-url/".
    • +
    • On MacOS - open a terminal, and "open web+testing://test-url/".
    • +
    • On Linux - open a terminal, and "xgd-open web+testing://test-url/".
    • +
    +
  4. +
  5. If your browser prompts you, allow the app to open.
  6. +
  7. The app window that opens should indicate success of this test.
  8. +
+

+ + \ No newline at end of file diff --git a/appmanifest/protocol_handlers-member/protocol_handlers-member-service-worker.js b/appmanifest/protocol_handlers-member/protocol_handlers-member-service-worker.js new file mode 100644 index 000000000000000..e502e2a9859f6df --- /dev/null +++ b/appmanifest/protocol_handlers-member/protocol_handlers-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.1"; +const CACHE_NAME = `cache-v${cacheVersion}`; + +// The resources cached by this service worker. +const resources = [ + "protocol_handlers-member-service-worker.js", + "protocol_handlers-member-manual.tentative.html", + "resources/icon.png", + "resources/protocol_handlers_entry.html", +]; + +// 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)); +}); diff --git a/appmanifest/protocol_handlers-member/resources/icon.png b/appmanifest/protocol_handlers-member/resources/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..9255547fae08775cce76b769ad4c6d13cc9b241a GIT binary patch literal 1520 zcmeAS@N?(olHy`uVBq!ia0vp^6F``Q2}owBl)eX2jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$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dI0*@`9?jhl})ViH3;+W6;N$Dw7 zjV+Bj=l9j5N>~{Gjbl9>zM!qn=}>^rlAxnb+&7La;ySkMyoW@OZ}#(|XpIHR<)I&9 zj>zV`P*>qOR`&d9gH}Lsm4dvQ3eWLnTPqs^H($5!kGP{`6C1P5n# zfOmEySIT_eWsT-vgoVVCp4&_8X?2=5Y1PcSoov4jb8bGR{5Dl4n8|7G#qtlfhmKsv ilOGA@qOSP;|5@|r?+sAVZ*&Ki(hQ!ielF{r5}E*{Y^Tov literal 0 HcmV?d00001 diff --git a/appmanifest/protocol_handlers-member/resources/protocol_handlers-member.webmanifest b/appmanifest/protocol_handlers-member/resources/protocol_handlers-member.webmanifest new file mode 100644 index 000000000000000..cce6ae1e22b7813 --- /dev/null +++ b/appmanifest/protocol_handlers-member/resources/protocol_handlers-member.webmanifest @@ -0,0 +1,18 @@ +{ + "name": "Protocol_handlers test", + "icons": [ + { + "src": "icon.png", + "sizes": "144x144" + } + ], + "start_url": "../protocol_handlers-member-manual.tentative.html", + "display": "standalone", + "scope": "../../protocol_handlers-member/", + "protocol_handlers": [ + { + "protocol": "web+testing", + "url": "protocol_handlers_entry.html?value=%s" + } + ] +} \ No newline at end of file diff --git a/appmanifest/protocol_handlers-member/resources/protocol_handlers-member.webmanifest.headers b/appmanifest/protocol_handlers-member/resources/protocol_handlers-member.webmanifest.headers new file mode 100644 index 000000000000000..2bab061d43ab9e5 --- /dev/null +++ b/appmanifest/protocol_handlers-member/resources/protocol_handlers-member.webmanifest.headers @@ -0,0 +1 @@ +Content-Type: application/manifest+json; charset=utf-8 diff --git a/appmanifest/protocol_handlers-member/resources/protocol_handlers_entry.html b/appmanifest/protocol_handlers-member/resources/protocol_handlers_entry.html new file mode 100644 index 000000000000000..c5fa629f22bfdab --- /dev/null +++ b/appmanifest/protocol_handlers-member/resources/protocol_handlers_entry.html @@ -0,0 +1,19 @@ + + + + + Protocol Handling Web Platform Test - Pass + + + + + +

Protocol Handling Page

+

This test validates that the app was launched with the web+testing://test-url/ URL.

+ + \ No newline at end of file