diff options
Diffstat (limited to 'tests/wpt/tests/storage-access-api/helpers.js')
-rw-r--r-- | tests/wpt/tests/storage-access-api/helpers.js | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/wpt/tests/storage-access-api/helpers.js b/tests/wpt/tests/storage-access-api/helpers.js index 0a89c6d7f99..7d259b21676 100644 --- a/tests/wpt/tests/storage-access-api/helpers.js +++ b/tests/wpt/tests/storage-access-api/helpers.js @@ -150,10 +150,34 @@ async function CanFrameWriteCookies(frame, keep_after_writing = false) { return can_write; } +// Sets a cookie in an unpartitioned context by creating a new frame +// and requesting storage access in the frame. +async function SetFirstPartyCookieAndUnsetStorageAccessPermission(origin) { + let frame = await CreateFrame(`${origin}/storage-access-api/resources/script-with-cookie-header.py?script=embedded_responder.js`); + await SetPermissionInFrame(frame, [{ name: 'storage-access' }, 'granted']); + await RequestStorageAccessInFrame(frame); + await SetDocumentCookieFromFrame(frame, `cookie=unpartitioned;Secure;SameSite=None;Path=/`); + await SetPermissionInFrame(frame, [{ name: 'storage-access' }, 'prompt']); +} + +// Tests for the presence of the unpartitioned cookie set by SetFirstPartyCookieAndUnsetStorageAccessPermission +// in both the `document.cookie` variable and same-origin subresource \ +// Request Headers in the given frame +async function HasUnpartitionedCookie(frame) { + let frameDocumentCookie = await GetJSCookiesFromFrame(frame); + let jsAccess = cookieStringHasCookie("cookie", "unpartitioned", frameDocumentCookie); + const httpCookie = await FetchSubresourceCookiesFromFrame(frame, ""); + let httpAccess = cookieStringHasCookie("cookie", "unpartitioned", httpCookie); + assert_equals(jsAccess, httpAccess, "HTTP and Javascript cookies must be in sync"); + return jsAccess && httpAccess; +} + // Tests whether the current frame can read and write cookies via HTTP headers. // This deletes, writes, reads, then deletes a cookie named "cookie". async function CanAccessCookiesViaHTTP() { - await create_cookie(window.location.origin, "cookie", "1", "samesite=None;Secure"); + // We avoid reusing SetFirstPartyCookieAndUnsetStorageAccessPermission here, since that bypasses the + // cookie-accessibility settings that we want to check here. + await fetch(`${window.location.origin}/storage-access-api/resources/set-cookie-header.py?cookie=1;path=/;SameSite=None;Secure`); const http_cookies = await fetch(`${window.location.origin}/storage-access-api/resources/echo-cookie-header.py`) .then((resp) => resp.text()); const can_access = cookieStringHasCookie("cookie", "1", http_cookies); |