Skip to content

Commit 4a4084e

Browse files
ArthurSonzognimoz-wptsync-bot
authored andcommitted
Bug 1710016 [wpt PR 28891] - [Credentialless]: WPT vs CacheStorage., a=testonly
Automatic update from web-platform-tests [Credentialless]: WPT vs CacheStorage. Add tentative WPT tests about COEP and CacheStorage. Issues: - COEP:require-corp: w3c/ServiceWorker#1490 - COEP:credentialless: w3c/ServiceWorker#1592 Bug: 1175099 Change-Id: I857adbd134443b17b9689c314307bb1e3888235b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2876191 Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org> Reviewed-by: Antonio Sartori <antoniosartori@chromium.org> Reviewed-by: Camille Lamy <clamy@chromium.org> Cr-Commit-Position: refs/heads/master@{#880447} -- wpt-commits: 6bf109f244a20f48bb8723663c384e1e2220f006 wpt-pr: 28891
1 parent a710e1e commit 4a4084e

2 files changed

Lines changed: 123 additions & 1 deletion

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<meta name="timeout" content="long">
2+
<script src=/resources/testharness.js></script>
3+
<script src=/resources/testharnessreport.js></script>
4+
<script src="/common/get-host-info.sub.js"></script>
5+
<script src="/common/utils.js"></script>
6+
<script src="./resources/common.js"></script>
7+
<script src="./resources/dispatcher.js"></script>
8+
<script>
9+
10+
// Fetch a resource and store it into CacheStorage from |storer| context. Then
11+
// check if it can be retrieved via CacheStorage.match from |retriever| context.
12+
const cacheStorageTest = (
13+
description,
14+
storer,
15+
retriever,
16+
resource_headers,
17+
expectation
18+
) => {
19+
promise_test_parallel(async test => {
20+
const cross_origin = get_host_info().HTTPS_REMOTE_ORIGIN;
21+
const url = cross_origin + "/common/square.png?pipe=" + resource_headers +
22+
`&${token()}`;
23+
const this_token = token();
24+
25+
// Fetch a request from |stored|. Store the opaque response into
26+
// CacheStorage.
27+
send(storer, `
28+
const cache = await caches.open("v1");
29+
const fetch_request = new Request("${url}", {mode: 'no-cors'});
30+
const fetch_response = await fetch(fetch_request);
31+
await cache.put(fetch_request, fetch_response);
32+
send("${this_token}", "stored");
33+
`);
34+
assert_equals(await receive(this_token), "stored");
35+
36+
// Retrieved it from |retriever|.
37+
send(retriever, `
38+
const cache = await caches.open("v1");
39+
try {
40+
const response = await cache.match("${url}");
41+
send("${this_token}", "retrieved");
42+
} catch (error) {
43+
send("${this_token}", "error");
44+
}
45+
`);
46+
assert_equals(await receive(this_token), expectation);
47+
}, description);
48+
};
49+
50+
// Execute the same set of tests for every type of execution contexts:
51+
// Documents, DedicatedWorkers, SharedWorkers, and ServiceWorkers. The results
52+
// should be independent of the context.
53+
Object.entries(environments).forEach(([name, constructor]) => {
54+
const context_none = constructor(coep_none);
55+
const context_credentialless = constructor(coep_credentialless);
56+
const context_require_corp = constructor(coep_require_corp);
57+
58+
cacheStorageTest(`[${name}] unsafe-none => unsafe-none`,
59+
context_none, context_none, "", "retrieved");
60+
cacheStorageTest(`[${name}] unsafe-none => credentialless`,
61+
context_none, context_credentialless, "", "error");
62+
cacheStorageTest(`[${name}] unsafe-none => credentialless + CORP`,
63+
context_none, context_credentialless, corp_cross_origin, "retrieved");
64+
cacheStorageTest(`[${name}] unsafe-none => require-corp`,
65+
context_none, context_require_corp, "", "error");
66+
cacheStorageTest(`[${name}] unsafe-none => require-corp + CORP`,
67+
context_none, context_require_corp, corp_cross_origin, "retrieved");
68+
69+
cacheStorageTest(`[${name}] credentialless => unsafe-none`,
70+
context_credentialless, context_none, "", "retrieved");
71+
cacheStorageTest(`[${name}] credentialless => credentialless`,
72+
context_credentialless, context_credentialless, "", "retrieved");
73+
cacheStorageTest(`[${name}] credentialless => require-corp`,
74+
context_credentialless, context_require_corp, "", "error");
75+
cacheStorageTest(`[${name}] credentialless => require-corp + CORP`,
76+
context_credentialless, context_require_corp, corp_cross_origin, "retrieved");
77+
78+
cacheStorageTest(`[${name}] require_corp => unsafe-none`,
79+
context_require_corp, context_none, corp_cross_origin, "retrieved");
80+
cacheStorageTest(`[${name}] require_corp => credentialless`,
81+
context_require_corp, context_credentialless, corp_cross_origin, "retrieved");
82+
cacheStorageTest(`[${name}] require_corp => require-corp`,
83+
context_require_corp, context_require_corp, corp_cross_origin, "retrieved");
84+
})
85+
86+
</script>

‎testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/resources/common.js‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const newCredentiallessWindow = (origin) => {
7070
const main_document_token = token();
7171
const url = origin + executor_path + coep_credentialless +
7272
`&uuid=${main_document_token}`;
73-
const w = window.open(url);
73+
const context = window.open(url);
7474
add_completion_callback(() => w.close());
7575
return main_document_token;
7676
};
@@ -89,3 +89,39 @@ const newCredentiallessIframe = (parent_token, child_origin) => {
8989
return sub_document_token;
9090
};
9191

92+
const environments = {
93+
document: headers => {
94+
const tok = token();
95+
const url = window.origin + executor_path + headers + `&uuid=${tok}`;
96+
const context = window.open(url);
97+
add_completion_callback(() => context.close());
98+
return tok;
99+
},
100+
101+
dedicated_worker: headers => {
102+
const tok = token();
103+
const url = window.origin + executor_js_path + headers + `&uuid=${tok}`;
104+
const context = new Worker(url);
105+
return tok;
106+
},
107+
108+
shared_worker: headers => {
109+
const tok = token();
110+
const url = window.origin + executor_js_path + headers + `&uuid=${tok}`;
111+
const context = new SharedWorker(url);
112+
return tok;
113+
},
114+
115+
service_worker: headers => {
116+
const tok = token();
117+
const url = window.origin + executor_js_path + headers + `&uuid=${tok}`;
118+
const scope = url; // Generate a one-time scope for service worker.
119+
navigator.serviceWorker.register(url, {scope: scope})
120+
.then(registration => {
121+
add_completion_callback(() => registration.unregister());
122+
});
123+
return tok;
124+
},
125+
};
126+
127+

0 commit comments

Comments
 (0)