Files
sousa-gecko/testing/web-platform/tests/storage-access-api/requestStorageAccess-cross-origin-iframe-navigation.sub.https.window.js
T
Chris Fredrickson 9d543e0f7d Bug 1990311 [wpt PR 55018] - [SAA] Fix test failures due to default cookie availability, a=testonly
Automatic update from web-platform-tests
[SAA] Fix test failures due to default cookie availability

This fixes the tests such that they no longer assume that third-party
cookies are blocked by default (or that test_driver.set_storage_access
does anything; see
https://github.com/privacycg/storage-access/issues/162 for discussion).

Fixed: b:446148374
Change-Id: I11c1e4fee88cbde810d31445357b233fcebc566b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6973284
Commit-Queue: Chris Fredrickson <cfredric@chromium.org>
Auto-Submit: Chris Fredrickson <cfredric@chromium.org>
Reviewed-by: Dylan Cutler <dylancutler@google.com>
Cr-Commit-Position: refs/heads/main@{#1519499}

--
Remove new assertion

--

wpt-commits: c3f887e7f1f9ff410de609304f95e550d4a37570, 8539bf6cb4b87d36ceef4cee1b951f203cfda2e8
wpt-pr: 55018
2025-11-10 09:56:31 +00:00

115 lines
4.7 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
// META: timeout=long
'use strict';
(async function() {
// This is cross-domain 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 altWwwResponder = `${altWww}${responderPath}`;
const altRootResponder = `${altRoot}${responderPath}`;
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 MaybeSetStorageAccess("*", "*", "allowed");
});
const hasStorageAccess = await FrameHasStorageAccess(frame);
if (hasStorageAccess) {
// Nothing to test here, since cookies are not blocked.
// See https://github.com/privacycg/storage-access/issues/162.
return null;
}
assert_false(await HasUnpartitionedCookie(frame), "frame initially does not have access to cookies.");
assert_true(await RequestStorageAccessInFrame(frame), "requestStorageAccess resolves without requiring a gesture.");
assert_true(await FrameHasStorageAccess(frame), "frame has storage access after request.");
assert_true(await HasUnpartitionedCookie(frame), "frame has access to cookies after request.");
return frame;
}
promise_test(async (t) => {
await MaybeSetStorageAccess("*", "*", "blocked");
await SetFirstPartyCookie(altWww);
const frame = await SetUpResponderFrame(t, altWwwResponder);
if (!frame) {
return;
}
await FrameInitiatedReload(frame);
assert_true(await FrameHasStorageAccess(frame), "frame has storage access after refresh.");
assert_true(await HasUnpartitionedCookie(frame), "frame has access to cookies after refresh.");
let cookieOnLoad = await GetHTTPCookiesFromFrame(frame);
assert_true(cookieStringHasCookie("cookie", "unpartitioned", cookieOnLoad), "innermost frame has cookie in initial load");
}, "Self-initiated reloads preserve storage access");
promise_test(async (t) => {
await MaybeSetStorageAccess("*", "*", "blocked");
await SetFirstPartyCookie(altWww);
const frame = await SetUpResponderFrame(t, altWwwResponder);
if (!frame) {
return;
}
await FrameInitiatedNavigation(frame, altWwwResponder);
assert_true(await FrameHasStorageAccess(frame), "frame has storage access after refresh.");
assert_true(await HasUnpartitionedCookie(frame), "frame has access to cookies after refresh.");
let cookieOnLoad = await GetHTTPCookiesFromFrame(frame);
assert_true(cookieStringHasCookie("cookie", "unpartitioned", cookieOnLoad), "innermost frame has cookie in initial load");
}, "Self-initiated same-origin navigations preserve storage access");
promise_test(async (t) => {
await MaybeSetStorageAccess("*", "*", "blocked");
await SetFirstPartyCookie(altWww);
const frame = await SetUpResponderFrame(t, altWwwResponder);
if (!frame) {
return;
}
await new Promise((resolve) => {
frame.addEventListener("load", () => resolve());
frame.src = altWwwResponder;
});
assert_false(await FrameHasStorageAccess(frame), "frame does not have storage access after refresh.");
assert_false(await HasUnpartitionedCookie(frame), "frame has access to cookies after refresh.");
let cookieOnLoad = await GetHTTPCookiesFromFrame(frame);
assert_false(cookieStringHasCookie("cookie", "unpartitioned", cookieOnLoad), "innermost frame has no cookie in initial load");
}, "Non-self-initiated same-origin navigations do not preserve storage access");
promise_test(async (t) => {
await MaybeSetStorageAccess("*", "*", "blocked");
await SetFirstPartyCookie(altWww);
const frame = await SetUpResponderFrame(t, altWwwResponder);
if (!frame) {
return;
}
await FrameInitiatedNavigation(frame, altRootResponder);
assert_false(await FrameHasStorageAccess(frame), "frame does not have storage access after refresh.");
assert_false(await HasUnpartitionedCookie(frame), "frame has access to cookies after refresh.");
let cookieOnLoad = await GetHTTPCookiesFromFrame(frame);
assert_false(cookieStringHasCookie("cookie", "unpartitioned", cookieOnLoad), "innermost frame has no cookie in initial load");
}, "Self-initiated cross-origin navigations do not preserve storage access");
})();