Skip to content

Commit

Permalink
Add WPT covering behavior of partitioned cookies in multiple iframes
Browse files Browse the repository at this point in the history
This test shows that if a partitioned cookie is accessible to one
document then it will be accessible to other same site documents.
Regardless of if the document was present before or was added after the cookie was set. Similarly, changes made to the cookie in one
iframe will impact the partitioned cookie in another iframe.

Bug: 384523105
Change-Id: I8abc572904175d43041b1c37426c3e0700c5c0d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6101781
Auto-Submit: Aaron Selya <selya@google.com>
Reviewed-by: Dylan Cutler <dylancutler@google.com>
Commit-Queue: Dylan Cutler <dylancutler@google.com>
Cr-Commit-Position: refs/heads/main@{#1398554}
  • Loading branch information
aselya authored and chromium-wpt-export-bot committed Dec 19, 2024
1 parent e24bf6f commit 180a8a6
Showing 1 changed file with 107 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<!doctype html>
<head>
<meta charset="utf-8"/>
<meta name="timeout" content="long">
<meta name="help" href="https://github.com/WICG/CHIPS#chips-cookies-having-independent-partitioned-state">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/cookies/resources/cookie-helper.sub.js"></script>
<script src="/cookies/partitioned-cookies/resources/test-helpers.js"></script>
<title>Test partitioned cookies behavior in parallel same-site iframes</title>
</head>
<body>
<script>

function waitForIframeToLoad(frame) {
return new Promise((resolve, reject) => {
frame.onload = resolve;
frame.onerror = reject;
});
}

promise_test( async() => {
// Set up document containing two same-site iframes.
const sameSiteIframeUrl = new URL(
"/cookies/partitioned-cookies/resources/" +
"partitioned-cookies-empty-embed.html",
get_host_info().HTTPS_ORIGIN + self.location.pathname);

const iframe = document.createElement("iframe");
const iframe2 = document.createElement("iframe");

iframe.src = sameSiteIframeUrl.href;
iframe2.src = sameSiteIframeUrl.href;

let loadCompleted = Promise.all([waitForIframeToLoad(iframe), waitForIframeToLoad(iframe2)]);

document.body.appendChild(iframe);
document.body.appendChild(iframe2);

await loadCompleted;

// Confirm that partitioned cookies set in iframes are made available to other same-site
// documents that exist before the cookie is set.
const partitionedCookieName = "partitionedCookie";
const partitionedCookie = partitionedCookieName+ "=cookie";
const partitionedCookieAttributes =
";Secure; Path=/; SameSite=None; Partitioned";

iframe.contentWindow.document.cookie = partitionedCookie + partitionedCookieAttributes;

assert_true(document.cookie.includes(partitionedCookie), document.cookie);
assert_true(iframe.contentWindow.document.cookie.includes(partitionedCookie),
iframe.contentWindow.document.cookie);
assert_true(iframe2.contentWindow.document.cookie.includes(partitionedCookie),
iframe2.contentWindow.document.cookie);

// Confirm that partitioned cookies are available to iframes that are added after the
// cookie has been set.
const iframe3 = document.createElement("iframe");
loadCompleted = waitForIframeToLoad(iframe3);

iframe3.src = sameSiteIframeUrl.href;

loadCompleted = waitForIframeToLoad(iframe3);

document.body.appendChild(iframe3);

await loadCompleted;

assert_true(iframe3.contentWindow.document.cookie.includes(partitionedCookie));

// Confirm that a partitioned cookie set in one iframe, is accessible in all other same site
// documents.
const secondPartitionedCookie = "second=cookie";

iframe.contentWindow.document.cookie = secondPartitionedCookie + partitionedCookieAttributes;

assert_true(iframe.contentWindow.document.cookie.includes(secondPartitionedCookie),
iframe.contentWindow.document.cookie);
assert_true(iframe2.contentWindow.document.cookie.includes(secondPartitionedCookie),
iframe2.contentWindow.document.cookie);
assert_true(iframe3.contentWindow.document.cookie.includes(secondPartitionedCookie),
iframe3.contentWindow.document.cookie);
assert_true(document.cookie.includes(secondPartitionedCookie), document.cookie);

// Confirm that changes made to a partitioned cookie in one iframe will impact the cookie
// in other documents.
const changedPartitionedCookie = partitionedCookieName+ "=newValue";

iframe.contentWindow.document.cookie = changedPartitionedCookie + partitionedCookieAttributes;

assert_true(iframe.contentWindow.document.cookie.includes(changedPartitionedCookie),
iframe.contentWindow.document.cookie);
assert_true(iframe2.contentWindow.document.cookie.includes(changedPartitionedCookie),
iframe2.contentWindow.document.cookie);
assert_true(document.cookie.includes(changedPartitionedCookie), document.cookie);

assert_false(document.cookie.includes(partitionedCookie), document.cookie);
assert_false(iframe.contentWindow.document.cookie.includes(partitionedCookie),
iframe.contentWindow.document.cookie);
assert_false(iframe2.contentWindow.document.cookie.includes(partitionedCookie),
iframe2.contentWindow.document.cookie);

}, "Partitioned cookies set in same-site contexts are available in other same-site documents.");
</script>
</body>

0 comments on commit 180a8a6

Please sign in to comment.