summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/cross-origin-embedder-policy/resources/cache-storage-reporting.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/html/cross-origin-embedder-policy/resources/cache-storage-reporting.js')
-rw-r--r--testing/web-platform/tests/html/cross-origin-embedder-policy/resources/cache-storage-reporting.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/cross-origin-embedder-policy/resources/cache-storage-reporting.js b/testing/web-platform/tests/html/cross-origin-embedder-policy/resources/cache-storage-reporting.js
new file mode 100644
index 0000000000..86dff9c845
--- /dev/null
+++ b/testing/web-platform/tests/html/cross-origin-embedder-policy/resources/cache-storage-reporting.js
@@ -0,0 +1,63 @@
+function remote(path) {
+ const REMOTE_ORIGIN = get_host_info().HTTPS_REMOTE_ORIGIN;
+ return new URL(path, REMOTE_ORIGIN).href;
+}
+
+function local(path) {
+ return new URL(path, location.origin).href;
+}
+
+function encode(url) {
+ return encodeURI(url).replace(/\;/g, '%3B');
+}
+
+const resource_path = (new URL('./resources', location)).pathname;
+const header_coep = '|header(Cross-Origin-Embedder-Policy,require-corp)';
+const header_coep_report_only =
+ '|header(Cross-Origin-Embedder-Policy-Report-Only,require-corp)';
+
+const iframe_path = resource_path + '/iframe.html?pipe=';
+const worker_path = resource_path + '/reporting-worker.js?pipe=';
+const image_url = remote('/images/blue.png');
+
+// This script attempt to load a COEP:require-corp CORP:undefined response from
+// the CacheStorage.
+//
+// Executed from different context:
+// - A Document
+// - A ServiceWorker
+// - A DedicatedWorker
+// - A SharedWorker
+//
+// The context has either COEP or COEP-Report-Only defined.
+const eval_script = `
+ (async function() {
+ try {
+ const cache = await caches.open('v1');
+ const request = new Request('${image_url}', { mode: 'no-cors' });
+ const response = await cache.match(request);
+ } catch(e) {
+ }
+ })()
+`;
+
+promise_setup(async (t) => {
+ const cache = await caches.open('v1');
+ const request = new Request(image_url, {mode: 'no-cors'});
+ const response = await fetch(request);
+ await cache.put(request, response);
+}, 'Setup: store a CORS:cross-origin COEP:none response into CacheStorage')
+
+async function makeIframe(test, iframe_url) {
+ const iframe = document.createElement('iframe');
+ test.add_cleanup(() => iframe.remove());
+ iframe.src = iframe_url;
+ const iframe_loaded = new Promise(resolve => iframe.onload = resolve);
+ document.body.appendChild(iframe);
+ await iframe_loaded;
+ return iframe;
+}
+
+function wait(ms) {
+ return new Promise(resolve => step_timeout(resolve, ms));
+}