partitioned-cookies-parallel-iframes.embed.tentative.https.html (4633B)
1 <!doctype html> 2 <head> 3 <meta charset="utf-8"/> 4 <meta name="timeout" content="long"> 5 <meta name="help" href="https://github.com/WICG/CHIPS#chips-cookies-having-independent-partitioned-state"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="/common/get-host-info.sub.js"></script> 9 <script src="/cookies/resources/cookie-helper.sub.js"></script> 10 <script src="/cookies/partitioned-cookies/resources/test-helpers.js"></script> 11 <title>Test partitioned cookies behavior in parallel same-site iframes</title> 12 </head> 13 <body> 14 <script> 15 16 function waitForIframeToLoad(frame) { 17 return new Promise((resolve, reject) => { 18 frame.onload = resolve; 19 frame.onerror = reject; 20 }); 21 } 22 23 promise_test( async() => { 24 // Set up document containing two same-site iframes. 25 const sameSiteIframeUrl = new URL( 26 "/cookies/partitioned-cookies/resources/" + 27 "partitioned-cookies-empty-embed.html", 28 get_host_info().HTTPS_ORIGIN + self.location.pathname); 29 30 const iframe = document.createElement("iframe"); 31 const iframe2 = document.createElement("iframe"); 32 33 iframe.src = sameSiteIframeUrl.href; 34 iframe2.src = sameSiteIframeUrl.href; 35 36 let loadCompleted = Promise.all([waitForIframeToLoad(iframe), waitForIframeToLoad(iframe2)]); 37 38 document.body.appendChild(iframe); 39 document.body.appendChild(iframe2); 40 41 await loadCompleted; 42 43 // Confirm that partitioned cookies set in iframes are made available to other same-site 44 // documents that exist before the cookie is set. 45 const partitionedCookieName = "partitionedCookie"; 46 const partitionedCookie = partitionedCookieName+ "=cookie"; 47 const partitionedCookieAttributes = 48 ";Secure; Path=/; SameSite=None; Partitioned"; 49 50 iframe.contentWindow.document.cookie = partitionedCookie + partitionedCookieAttributes; 51 52 assert_true(document.cookie.includes(partitionedCookie), document.cookie); 53 assert_true(iframe.contentWindow.document.cookie.includes(partitionedCookie), 54 iframe.contentWindow.document.cookie); 55 assert_true(iframe2.contentWindow.document.cookie.includes(partitionedCookie), 56 iframe2.contentWindow.document.cookie); 57 58 // Confirm that partitioned cookies are available to iframes that are added after the 59 // cookie has been set. 60 const iframe3 = document.createElement("iframe"); 61 loadCompleted = waitForIframeToLoad(iframe3); 62 63 iframe3.src = sameSiteIframeUrl.href; 64 65 loadCompleted = waitForIframeToLoad(iframe3); 66 67 document.body.appendChild(iframe3); 68 69 await loadCompleted; 70 71 assert_true(iframe3.contentWindow.document.cookie.includes(partitionedCookie)); 72 73 // Confirm that a partitioned cookie set in one iframe, is accessible in all other same site 74 // documents. 75 const secondPartitionedCookie = "second=cookie"; 76 77 iframe.contentWindow.document.cookie = secondPartitionedCookie + partitionedCookieAttributes; 78 79 assert_true(iframe.contentWindow.document.cookie.includes(secondPartitionedCookie), 80 iframe.contentWindow.document.cookie); 81 assert_true(iframe2.contentWindow.document.cookie.includes(secondPartitionedCookie), 82 iframe2.contentWindow.document.cookie); 83 assert_true(iframe3.contentWindow.document.cookie.includes(secondPartitionedCookie), 84 iframe3.contentWindow.document.cookie); 85 assert_true(document.cookie.includes(secondPartitionedCookie), document.cookie); 86 87 // Confirm that changes made to a partitioned cookie in one iframe will impact the cookie 88 // in other documents. 89 const changedPartitionedCookie = partitionedCookieName+ "=newValue"; 90 91 iframe.contentWindow.document.cookie = changedPartitionedCookie + partitionedCookieAttributes; 92 93 assert_true(iframe.contentWindow.document.cookie.includes(changedPartitionedCookie), 94 iframe.contentWindow.document.cookie); 95 assert_true(iframe2.contentWindow.document.cookie.includes(changedPartitionedCookie), 96 iframe2.contentWindow.document.cookie); 97 assert_true(document.cookie.includes(changedPartitionedCookie), document.cookie); 98 99 assert_false(document.cookie.includes(partitionedCookie), document.cookie); 100 assert_false(iframe.contentWindow.document.cookie.includes(partitionedCookie), 101 iframe.contentWindow.document.cookie); 102 assert_false(iframe2.contentWindow.document.cookie.includes(partitionedCookie), 103 iframe2.contentWindow.document.cookie); 104 105 erase_cookie_from_js("partitionedCookie", "Secure; Path=/; SameSite=None; Partitioned"); 106 erase_cookie_from_js("second", "Secure; Path=/; SameSite=None; Partitioned"); 107 108 }, "Partitioned cookies set in same-site contexts are available in other same-site documents."); 109 </script> 110 </body>