From f3342fe1486afb0b7e7ecddf47419321494b8bd1 Mon Sep 17 00:00:00 2001 From: Camillia Smith Barnes Date: Tue, 12 Dec 2023 11:18:27 -0800 Subject: [PATCH] Shared Storage: Add test for SSW fetch controlled by service worker We add some web tests to show that `fetch()` requests from windows, with the `sharedStorageWritable` attribute set to true in the `RequestInit` dict, that are intercepted by service workers but fallback to network can write to shared storage via response headers. Bug: 1434529,1218540 Change-Id: Ib6a3c078fa6ae599754bc9ab3d7b3e3300bab2fc Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5112422 Reviewed-by: Yao Xiao Commit-Queue: Cammie Smith Barnes Cr-Commit-Position: refs/heads/main@{#1236475} --- ...uest-fallback-to-network-iframe.https.html | 16 +++ ...vice-worker-fetch.tentative.https.sub.html | 109 ++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 shared-storage/shared-storage-writable-service-worker-fetch.tentative.https.sub.html diff --git a/shared-storage/resources/shared-storage-writable-fetch-request-fallback-to-network-iframe.https.html b/shared-storage/resources/shared-storage-writable-fetch-request-fallback-to-network-iframe.https.html index 2966723ce38669..3451d91477ddc7 100644 --- a/shared-storage/resources/shared-storage-writable-fetch-request-fallback-to-network-iframe.https.html +++ b/shared-storage/resources/shared-storage-writable-fetch-request-fallback-to-network-iframe.https.html @@ -36,5 +36,21 @@ frame.src = url; }); } + + function fetchUrl(url, hasSharedStorageWritableAttribute) { + return new Promise(function(resolve, reject) { + fetch(url, {sharedStorageWritable: + hasSharedStorageWritableAttribute}) + .then(response => { + if (!response.ok) { + throw new Error('Failed to fetch ' + url + '; ' + + String(response.status) + ' ' + response.statusText); + } + resolve(response); + }).catch(error => { + reject(error); + }); + }); + } diff --git a/shared-storage/shared-storage-writable-service-worker-fetch.tentative.https.sub.html b/shared-storage/shared-storage-writable-service-worker-fetch.tentative.https.sub.html new file mode 100644 index 00000000000000..ea7af527b540d3 --- /dev/null +++ b/shared-storage/shared-storage-writable-service-worker-fetch.tentative.https.sub.html @@ -0,0 +1,109 @@ + + + + + + + + + +