chromium/third_party/blink/web_tests/http/tests/cookies/partitioned-cookies/ancestor-chain-same-site-subresource-to-cross-site.https.html

<!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="/cookies/resources/testharness-helpers.js"></script>
<title>Test partitioned cookies are not sent in embedded same-site to cross-site redirects</title>
</head>
<body>
<script>

promise_test(async () => {
  //Add partitioned cookie to top-level site.
  assert_equals(document.cookie, "");
  const partitionedCookie = "ancestor=chain";
  const partitionedCookieAttributes =
      "; Secure; Path=/; SameSite=None; Partitioned";
  const partitionedCookieLine =
      partitionedCookie + partitionedCookieAttributes;

  document.cookie = partitionedCookieLine;

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

  const resourceDir = "/cookies/partitioned-cookies/resources/";
  const embedUrl = new URL(resourceDir +
    "ancestor-chain-same-site-to-cross-site-embed.html",
    `https://${TEST_HOST}:${window.location.port}`);
  const redirectUrl = new URL(resourceDir +
    "redirect-and-append-cookie-header.php?" + "location=" + embedUrl,
    `https://${TEST_HOST}:${window.location.port}`);

  const iframe = document.createElement("iframe");
  iframe.src = resourceDir + "ancestor-chain-empty-embed.html";
  document.body.appendChild(iframe);
  await new Promise(r => iframe.onload = r);

  // Confirm that the iframe is same-site to the top-level site.
  var iframeUrl = new URL(iframe.src);
  var iframeHost = iframeUrl.hostname;
  assert_equals(window.location.hostname, iframeHost);

  iframe.src = redirectUrl;
  await new Promise(r => iframe.onload = r);

  fetch_tests_from_window(iframe.contentWindow);

  // Confirm that the iframe is cross-site to the top-level site.
  iframeUrl = new URL(iframe.src);
  iframeHost = iframeUrl.hostname;
  assert_not_equals(window.location.hostname, iframeHost);

}, "Partitioned cookies are not sent in embedded same-site to cross-site redirects");

</script>
</body>