Files
firefox/testing/web-platform/tests/storage-access-api/requestStorageAccess-cross-origin-fetch.sub.https.window.js
T
Charlie Wolfe 593aa2bf2f Bug 1983619 [wpt PR 54330] - WebKit export of https://bugs.webkit.org/show_bug.cgi?id=297352, a=testonly
Automatic update from web-platform-tests
WebKit export: Storage Access API tests should set a cookie from a first-party context before setting cross-site cookies (#54330)

https://bugs.webkit.org/show_bug.cgi?id=297352
--

wpt-commits: d26b8d3c95004258b41e6c9b8932f1ca136059fb
wpt-pr: 54330
2025-08-25 08:46:12 +00:00

83 lines
3.9 KiB
JavaScript

// META: script=helpers.js
// META: script=/cookies/resources/cookie-helper.sub.js
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js
'use strict';
(async function() {
// These are cross-site from the current document.
const altWww = "https://{{hosts[alt][www]}}:{{ports[https][0]}}";
const altRoot = "https://{{hosts[alt][]}}:{{ports[https][0]}}";
const responderPath = "/storage-access-api/resources/script-with-cookie-header.py?script=embedded_responder.js";
const altRootResponder = `${altRoot}${responderPath}`;
const domainCookieString = "cookie=unpartitioned;Secure;SameSite=None;Path=/;Domain={{hosts[alt][]}}";
async function SetUpResponderFrame(t, url) {
const frame = await CreateFrame(url);
await SetPermissionInFrame(frame, [{ name: 'storage-access' }, 'granted']);
t.add_cleanup(async () => {
await test_driver.delete_all_cookies();
await SetPermissionInFrame(frame, [{ name: 'storage-access' }, 'prompt']);
await DeleteCookieInFrame(frame, "cookie", "Secure;SameSite=None;Path=/;Domain={{hosts[alt][]}}");
});
return frame;
}
promise_test(async (t) => {
await SetFirstPartyCookie(altRoot, "initial-cookie=unpartitioned;Secure;SameSite=None;Path=/");
const frame = await SetUpResponderFrame(t, altRootResponder);
await SetDocumentCookieFromFrame(frame, domainCookieString);
const initiallyHasCookieAccess =
cookieStringHasCookie("cookie", "unpartitioned",
await FetchSubresourceCookiesFromFrame(frame, altWww));
if (initiallyHasCookieAccess) {
// Nothing to test here; third-party cookies are already accessible.
return;
}
assert_true(await RequestStorageAccessInFrame(frame), "requestStorageAccess resolves without requiring a gesture.");
assert_true(await FrameHasStorageAccess(frame), "frame has storage access after request.");
await SetDocumentCookieFromFrame(frame, domainCookieString);
assert_true(await HasUnpartitionedCookie(frame), "frame has access to cookies after request.");
// The frame's origin is hosts[alt][], so hosts[alt][www] is same-site but
// cross-origin to it.
assert_false(
cookieStringHasCookie("cookie", "unpartitioned",
await FetchSubresourceCookiesFromFrame(frame, altWww)),
"same-site cross-origin fetch is not credentialed");
}, "Cross-origin fetches from a frame with storage-access are not credentialed by default");
promise_test(async (t) => {
await SetFirstPartyCookie(altRoot, "initial-cookie=unpartitioned;Secure;SameSite=None;Path=/");
const frame = await SetUpResponderFrame(t, altRootResponder);
await SetDocumentCookieFromFrame(frame, domainCookieString);
const initiallyHasCookieAccess =
cookieStringHasCookie("cookie", "unpartitioned",
await FetchSubresourceCookiesFromFrame(frame, altWww));
if (initiallyHasCookieAccess) {
// Nothing to test here; third-party cookies are already accessible.
return;
}
assert_true(await RequestStorageAccessInFrame(frame), "requestStorageAccess resolves without requiring a gesture.");
assert_true(await FrameHasStorageAccess(frame), "frame has storage access after request.");
await SetDocumentCookieFromFrame(frame, domainCookieString);
assert_true(await HasUnpartitionedCookie(frame), "frame has access to cookies after request.");
// The frame's origin is hosts[alt][], so hosts[alt][www] is same-site but
// cross-origin to it.
const cross_origin_redirect = `${altRoot}/common/redirect.py?location=${altWww}/storage-access-api/resources/echo-cookie-header.py`;
assert_false(
cookieStringHasCookie("cookie", "unpartitioned",
await FetchFromFrame(frame, cross_origin_redirect)),
"fetch is not credentialed after a cross-origin redirect");
}, "Cross-origin HTTP redirects from a frame with storage-access are not credentialed by default");
})();