Skip to content

Commit

Permalink
Add Partitioned cookie support to CookieStore API
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DCtheTall authored and chromium-wpt-export-bot committed Oct 26, 2021
1 parent 4d23eaf commit ca15ba5
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
11 changes: 11 additions & 0 deletions cookies/partitioned-cookies/resources/test-helpers.js
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 ca15ba5

Please sign in to comment.