cookie-store.tentative.https.window.js (3274B)
1 // META: timeout=long 2 // META: script=/common/get-host-info.sub.js 3 // META: script=/common/utils.js 4 // META: script=/common/dispatcher/dispatcher.js 5 // META: script=/html/cross-origin-embedder-policy/credentialless/resources/common.js 6 // META: script=./resources/common.js 7 8 // A set of tests, checking cookies defined from within a credentialless iframe 9 // continue to work. 10 11 const same_origin = get_host_info().HTTPS_ORIGIN; 12 const cross_origin = get_host_info().HTTPS_REMOTE_ORIGIN; 13 const cookie_key = token() 14 15 const credentialless_iframe = newIframeCredentialless(cross_origin); 16 17 // Install some helper functions in the child to observe Cookies: 18 promise_setup(async () => { 19 await send(credentialless_iframe, ` 20 window.getMyCookie = () => { 21 const value = "; " + document.cookie; 22 const parts = value.split("; ${cookie_key}="); 23 if (parts.length !== 2) 24 return undefined 25 return parts.pop().split(';').shift(); 26 }; 27 28 window.nextCookieValue = () => { 29 return new Promise(resolve => { 30 const old_cookie = getMyCookie(); 31 let timeToLive = 40; // 40 iterations of 100ms = 4s; 32 const interval = setInterval(() => { 33 const next_cookie_value = getMyCookie(); 34 timeToLive--; 35 if (old_cookie !== next_cookie_value || timeToLive <= 0) { 36 clearInterval(interval); 37 resolve(next_cookie_value) 38 } 39 }, 100) 40 }); 41 }; 42 `); 43 }, "Setup"); 44 45 promise_test(async test => { 46 const this_token = token(); 47 send(credentialless_iframe, ` 48 document.cookie = "${cookie_key}=cookie_value_1"; 49 send("${this_token}", getMyCookie()); 50 `); 51 52 assert_equals(await receive(this_token), "cookie_value_1"); 53 }, "Set/Get cookie via JS API"); 54 55 promise_test(async test => { 56 const resource_token = token(); 57 send(credentialless_iframe, ` 58 fetch("${showRequestHeaders(cross_origin, resource_token)}"); 59 `); 60 61 const request_headers = JSON.parse(await receive(resource_token)); 62 const cookie_value = parseCookies(request_headers)[cookie_key]; 63 assert_equals(cookie_value, "cookie_value_1"); 64 }, "Get Cookie via subresource requests"); 65 66 promise_test(async test => { 67 const resource_token = token(); 68 const resource_url = cross_origin + "/common/blank.html?pipe=" + 69 `|header(Set-Cookie,${cookie_key}=cookie_value_2;Path=/common/dispatcher)`; 70 const this_token = token(); 71 send(credentialless_iframe, ` 72 const next_cookie_value = nextCookieValue(); 73 fetch("${resource_url}"); 74 send("${this_token}", await next_cookie_value); 75 `); 76 77 assert_equals(await receive(this_token), "cookie_value_2"); 78 }, "Set Cookie via subresource requests"); 79 80 promise_test(async test => { 81 const resource_token = token(); 82 const resource_url = cross_origin + "/common/blank.html?pipe=" + 83 `|header(Set-Cookie,${cookie_key}=cookie_value_3;Path=/common/dispatcher)`; 84 const this_token = token(); 85 send(credentialless_iframe, ` 86 const next_cookie_value = nextCookieValue(); 87 const iframe = document.createElement("iframe"); 88 iframe.src = "${resource_url}"; 89 document.body.appendChild(iframe); 90 send("${this_token}", await next_cookie_value); 91 `); 92 93 assert_equals(await receive(this_token), "cookie_value_3"); 94 }, "Set Cookie via navigation requests");