tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

response-code-non-successful.https.html (2059B)


      1 <!DOCTYPE html>
      2 <title>Check that non-successful responses result in discarding the prerender</title>
      3 <meta name="variant" content="?code=204">
      4 <meta name="variant" content="?code=205">
      5 <meta name="variant" content="?code=402">
      6 <meta name="variant" content="?code=404">
      7 <meta name="variant" content="?code=500">
      8 <meta name="variant" content="?code=503">
      9 <meta name="timeout" content="long">
     10 <script src="/resources/testharness.js"></script>
     11 <script src="/resources/testharnessreport.js"></script>
     12 <script src="/common/utils.js"></script>
     13 <script src="/common/dispatcher/dispatcher.js"></script>
     14 <script src="../resources/utils.js"></script>
     15 <script src="resources/utils.js"></script>
     16 
     17 <body>
     18 <script>
     19 setup(() => assertSpeculationRulesIsSupported());
     20 
     21 const params = new URLSearchParams(window.location.search);
     22 
     23 promise_test(async t => {
     24  // Pass the `code` search param so that a prerendered page is served with the
     25  // response code.
     26  const {exec, tryToActivate} =
     27      await create_prerendered_page(t, {'prerendering': params});
     28 
     29  // Open new window with url to clear cache data through Clear-Site-Data header.
     30  // Ensure that the cache is cleared before the navigation.
     31  //
     32  // This is a hack for Chromium that may trigger prefetch prior to prerender,
     33  // and serve the same prefetched response multiple times (This is known as
     34  // PrefetchReusable). This breaks the assumption of this test that the first
     35  // prerender request fails for non-OK status code and then the next real
     36  // navigation succeeds with 200. With the PrefetchReusable, the real
     37  // navigation sees the prefetched error response and fails.
     38  const gotMessage = new Promise(resolve => {
     39      window.addEventListener('message', e => {
     40          resolve(e.data);
     41        }, {
     42          once: true
     43      });
     44  });
     45  window.open("/../../clear-site-data/support/clear-site-data-prefetchCache.py");
     46  await gotMessage;
     47 
     48  const result = await tryToActivate();
     49  assert_equals(result, 'discarded');
     50 },`Responses with code ${params.get('code')} should be discarded`);
     51 </script>