1 // META: script=/resources/testdriver.js
2 // META: script=/resources/testdriver-vendor.js
6 // Here's the set-up for this test:
7 // Step 1 (top-frame) Set up fallback failure listener for if the handle cannot be used.
8 // Step 2 (top-frame) Set up relay worker to expect "Same-origin handle access".
9 // Step 3 (top-frame) Set cookies and embed an iframe that's cross-site with top-frame.
10 // Step 4 (sub-frame) Try to use storage access API to access shared worker.
11 // Step 5 (sub-frame) Embed an iframe that's same-origin with top-frame.
12 // Step 6 (sub-sub-frame) Try to use storage access API to access first-party shared worker.
13 // Step 7 (sub-sub-frame) Send "HasAccess for SharedWorker" message to top-frame.
14 // Step 8 (top-frame) Set up cookie worker to expect it's already opened.
15 // TODO(crbug.com/1484966): Verify access to cookies in shared workers.
19 window.addEventListener("message", t.step_func(e => {
20 assert_equals(e.data, "HasAccess for SharedWorker", "Storage Access API should be accessible and return first-party data");
24 const id = Date.now();
25 const relay_worker = new SharedWorker("/storage-access-api/resources/shared-worker-relay.js", {name: id, sameSiteCookies: 'none'});
26 relay_worker.port.onmessage = t.step_func(e => {
27 assert_equals(e.data, "Same-origin handle access", "Relay worker should divert messages here");
29 const cookie_worker = new SharedWorker("/storage-access-api/resources/shared-worker-cookies.py", {name: id, sameSiteCookies: 'none'});
30 cookie_worker.port.onmessage = t.step_func(e => {
31 assert_equals(e.data, "ReadOnLoad:None,ReadOnFetch:None,ConnectionsMade:2", "Worker should already have been opened and only see SameSite=None cookies");
37 const cookie_set_window = window.open("/storage-access-api/resources/set_cookies.py");
38 cookie_set_window.onload = t.step_func(_ => {
39 let iframe = document.createElement("iframe");
40 iframe.src = "https://{{hosts[alt][]}}:{{ports[https][0]}}/storage-access-api/resources/storage-access-beyond-cookies-iframe.sub.html?type=SharedWorker&id="+id;
41 document.body.appendChild(iframe);
43 }, "Verify StorageAccessAPIBeyondCookies for Shared Worker");