cookie-indices.https.html (7557B)
1 <!DOCTYPE html> 2 <meta name="timeout" content="long"> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="/resources/testdriver.js"></script> 6 <script src='/resources/testdriver-vendor.js'></script> 7 <script src="/common/dispatcher/dispatcher.js"></script> 8 <script src="/common/subset-tests-by-key.js"></script> 9 <script src="/common/utils.js"></script> 10 <script src="../../resources/utils.js"></script> 11 <script src="../resources/utils.sub.js"></script> 12 <meta name="variant" content="?include=unchanged"> 13 <meta name="variant" content="?include=changed"> 14 <meta name="variant" content="?include=unchangedWithRedirect"> 15 <meta name="variant" content="?include=changedWithRedirect"> 16 <meta name="variant" content="?include=changedWithRedirect2"> 17 <meta name="variant" content="?include=changedWithRedirect3"> 18 19 <!-- 20 This is a test for the integration of 21 https://mnot.github.io/I-D/draft-nottingham-http-availability-hints.html 22 with prefetch. Chromium has an implementation of such integration 23 behind a flag; see https://issues.chromium.org/issues/328628231. 24 --> 25 26 <script> 27 setup(() => assertSpeculationRulesIsSupported()); 28 29 subsetTestByKey("unchanged", promise_test, async t => { 30 await test_driver.delete_all_cookies(); 31 document.cookie = 'vary1=hello'; 32 33 let agent = await spawnWindow(t); 34 35 let nextUrl = agent.getExecutorURL({ executor: "cookies.py", cookieindices: "1" }); 36 await agent.forceSinglePrefetch(nextUrl); 37 await agent.navigate(nextUrl); 38 39 assert_prefetched(await agent.getRequestHeaders()); 40 let request_cookies = await agent.getRequestCookies(); 41 let response_cookies = await agent.getResponseCookies(); 42 assert_equals(request_cookies.vary1, "hello"); 43 assert_equals(request_cookies.vary2, undefined); 44 assert_equals(response_cookies.vary1, "hello"); 45 assert_equals(response_cookies.vary2, undefined); 46 }, "Cookie-Indices should not prevent a prefetch from succeeding if the cookie has not changed."); 47 48 subsetTestByKey("changed", promise_test, async t => { 49 await test_driver.delete_all_cookies(); 50 document.cookie = 'vary1=hello'; 51 52 let agent = await spawnWindow(t); 53 54 let nextUrl = agent.getExecutorURL({ executor: "cookies.py", cookieindices: "1" }); 55 await agent.forceSinglePrefetch(nextUrl); 56 document.cookie = 'vary1=two'; 57 await agent.navigate(nextUrl); 58 59 assert_not_prefetched(await agent.getRequestHeaders()); 60 let request_cookies = await agent.getRequestCookies(); 61 let response_cookies = await agent.getResponseCookies(); 62 assert_equals(request_cookies.vary1, "two"); 63 assert_equals(request_cookies.vary2, undefined); 64 assert_equals(response_cookies.vary1, "two"); 65 assert_equals(response_cookies.vary2, undefined); 66 }, "Cookie-Indices should prevent a prefetch from being used if the cookie has changed."); 67 68 subsetTestByKey("unchangedWithRedirect", promise_test, async t => { 69 await test_driver.delete_all_cookies(); 70 71 document.cookie = 'vary1=hello'; 72 73 let agent = await spawnWindow(t); 74 75 let finalUrl = agent.getExecutorURL({ executor: "cookies.py", cookieindices: "1" }); 76 let nextUrl = new URL("/common/redirect.py?location=" + encodeURIComponent(finalUrl), document.baseURI); 77 await agent.forceSinglePrefetch(nextUrl); 78 await agent.navigate(nextUrl, {expectedDestinationUrl: finalUrl}); 79 80 assert_prefetched(await agent.getRequestHeaders()); 81 let request_cookies = await agent.getRequestCookies(); 82 let response_cookies = await agent.getResponseCookies(); 83 assert_equals(request_cookies.vary1, "hello"); 84 assert_equals(request_cookies.vary2, undefined); 85 assert_equals(response_cookies.vary1, "hello"); 86 assert_equals(response_cookies.vary2, undefined); 87 }, "Cookie-Indices should not prevent a prefetch from succeeding with unchanged cookies, even with redirect"); 88 89 subsetTestByKey("changedWithRedirect", promise_test, async t => { 90 await test_driver.delete_all_cookies(); 91 92 document.cookie = 'vary1=hello'; 93 94 let agent = await spawnWindow(t); 95 96 let finalUrl = agent.getExecutorURL({ executor: "cookies.py", cookieindices: "1" }); 97 let nextUrl = new URL("/common/redirect.py?location=" + encodeURIComponent(finalUrl), document.baseURI); 98 await agent.forceSinglePrefetch(nextUrl); 99 document.cookie = 'vary1=two'; 100 await agent.navigate(nextUrl, {expectedDestinationUrl: finalUrl}); 101 102 assert_not_prefetched(await agent.getRequestHeaders()); 103 let request_cookies = await agent.getRequestCookies(); 104 let response_cookies = await agent.getResponseCookies(); 105 assert_equals(request_cookies.vary1, "two"); 106 assert_equals(request_cookies.vary2, undefined); 107 assert_equals(response_cookies.vary1, "two"); 108 assert_equals(response_cookies.vary2, undefined); 109 }, "Cookie-Indices should prevent a prefetch from succeeding if the cookie changed, with a redirect"); 110 111 subsetTestByKey("changedWithRedirect2", promise_test, async t => { 112 await test_driver.delete_all_cookies(); 113 114 document.cookie = 'vary1=hello'; 115 116 let agent = await spawnWindow(t); 117 118 // One subtlety here: the wptserve pipe parser doesn't allow commas inside 119 // the header value (since that delimits the pipe arguments). 120 // There is currently no way around this, so we simply don't use a value with a comma. 121 let finalUrl = agent.getExecutorURL({ executor: "cookies.py" }); 122 let pipe = "header(Cache-Control,no-store)|header(Vary,Cookie)|header(Cookie-Indices,\"vary1\")"; 123 let nextUrl = new URL(`/common/redirect.py?location=${encodeURIComponent(finalUrl)}&pipe=${encodeURIComponent(pipe)}`, document.baseURI); 124 await agent.forceSinglePrefetch(nextUrl); 125 document.cookie = 'vary1=two'; 126 await agent.navigate(nextUrl, {expectedDestinationUrl: finalUrl}); 127 128 assert_prefetched(await agent.getRequestHeaders()); 129 let request_cookies = await agent.getRequestCookies(); 130 let response_cookies = await agent.getResponseCookies(); 131 assert_equals(request_cookies.vary1, "hello"); 132 assert_equals(request_cookies.vary2, undefined); 133 assert_equals(response_cookies.vary1, "two"); 134 assert_equals(response_cookies.vary2, undefined); 135 }, "If the redirect needs to be rerequested but goes to the same place and that one doesn't vary, we actually can use the prefetched final response."); 136 137 subsetTestByKey("changedWithRedirect3", promise_test, async t => { 138 await test_driver.delete_all_cookies(); 139 140 document.cookie = 'vary1=hello'; 141 142 let agent = await spawnWindow(t); 143 144 // One subtlety here: the wptserve pipe parser doesn't allow commas inside 145 // the header value (since that delimits the pipe arguments). 146 // There is currently no way around this, so we simply don't use a value with a comma. 147 let finalUrl = agent.getExecutorURL({ executor: "cookies.py" }); 148 let pipe = "header(Cache-Control,no-store)|header(Vary,Cookie)|header(Cookie-Indices,\"vary1\")"; 149 let nextUrl = new URL(`resources/random_redirect.py?location=${encodeURIComponent(finalUrl)}&pipe=${encodeURIComponent(pipe)}`, document.baseURI); 150 await agent.forceSinglePrefetch(nextUrl); 151 document.cookie = 'vary1=two'; 152 await agent.navigate(nextUrl, {expectedDestinationUrl: null}); 153 154 assert_not_prefetched(await agent.getRequestHeaders()); 155 let request_cookies = await agent.getRequestCookies(); 156 let response_cookies = await agent.getResponseCookies(); 157 assert_equals(request_cookies.vary1, "two"); 158 assert_equals(request_cookies.vary2, undefined); 159 assert_equals(response_cookies.vary1, "two"); 160 assert_equals(response_cookies.vary2, undefined); 161 }, "If the redirect needs to be rerequested and goes elsewhere, we cannot can use the prefetched final response."); 162 </script>