Skip to content

Commit

Permalink
Bug 1737629 [wpt PR 31374] - Add Partitioned cookie support to Cookie…
Browse files Browse the repository at this point in the history
…Store API, a=testonly

Automatic update from web-platform-tests
Add Partitioned cookie support to CookieStore API

This CL adds support for Partitioned cookies* to the CookieStore API.
It implements the changes proposed in
WICG/cookie-store#206 in Chromium.

Cookie partitioning will only be active and the `partitioned` field
is only considered by `CookieStore.set` or `CookieStore.delete` when
the --partitioned-cookies flag is set.

*: see https://github.com/WICG/CHIPS

Bug: 1225444
Change-Id: I4bdde833c28fa192bb0b5e011a6005a45029b481
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3212611
Commit-Queue: Dylan Cutler <dylancutler@google.com>
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Reviewed-by: Charlie Harrison <csharrison@chromium.org>
Reviewed-by: Emily Stark <estark@chromium.org>
Reviewed-by: Maksim Orlovich <morlovich@chromium.org>
Cr-Commit-Position: refs/heads/main@{#937656}

--

wpt-commits: bb30d118adc1c7154c548a28e81d30723e0aaaa8
wpt-pr: 31374
  • Loading branch information
DCtheTall authored and moz-wptsync-bot committed Nov 9, 2021
1 parent 9373985 commit b48fba8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,30 @@
const domCookieName = '__Host-pcdom';
document.cookie = `${domCookieName}=foobar;${attributes}`;

// Set another partitioned cookie using the CookieStore API.
const cookieStoreCookieName = '__Host-pccookistore';
await cookieStore.set({
name: cookieStoreCookieName,
value: 'foobar',
path: '/',
sameSite: 'none',
partitioned: true,
});

// Verify that the cookies are sent in requests from this top-level site.
testHttpPartitionedCookies({
origin: self.origin,
cookieNames: [httpCookieName, domCookieName],
cookieNames: [httpCookieName, domCookieName, cookieStoreCookieName],
expectsCookie: true,
});

// Verify that the cookies are exposed to the DOM on this top-level site.
testDomPartitionedCookies({
cookieNames: [httpCookieName, domCookieName],
cookieNames: [httpCookieName, domCookieName, cookieStoreCookieName],
expectsCookie: true,
});
testCookieStorePartitionedCookies({
cookieNames: [httpCookieName, domCookieName, cookieStoreCookieName],
expectsCookie: true,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@
<body>
<script>

const cookieNames = ['__Host-pchttp', '__Host-pcdom', '__Host-pccookiestore'];

testDomPartitionedCookies({
cookieNames: ['__Host-pchttp', '__Host-pcdom'],
cookieNames,
expectsCookie: false,
});

testCookieStorePartitionedCookies({
cookieNames,
expectsCookie: false,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,14 @@ function testDomPartitionedCookies({cookieNames, expectsCookie}) {
}
}, getPartitionedCookieTestName(expectsCookie, 'DOM'));
}

function testCookieStorePartitionedCookies({cookieNames, expectsCookie}) {
promise_test(async () => {
const cookies = await cookieStore.getAll({partitioned: true});
for (const cookieName of cookieNames) {
assert_equals(
!!cookies.find(c => c.name === cookieName), expectsCookie,
getPartitionedCookieAssertDesc(expectsCookie, cookieName));
}
}, getPartitionedCookieTestName(expectsCookie, 'CookieStore'));
}

0 comments on commit b48fba8

Please sign in to comment.