tor-browser

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

fetch.any.js (1042B)


      1 // META: global=window,worker
      2 // META: title=Tests Stale While Revalidate is executed for fetch API
      3 // META: script=/common/utils.js
      4 
      5 function wait25ms(test) {
      6  return new Promise(resolve => {
      7    test.step_timeout(() => {
      8      resolve();
      9    }, 25);
     10  });
     11 }
     12 
     13 promise_test(async (test) => {
     14  var request_token = token();
     15 
     16  const response = await fetch(`resources/stale-script.py?token=` + request_token);
     17  // Wait until resource is completely fetched to allow caching before next fetch.
     18  const body = await response.text();
     19  const response2 = await fetch(`resources/stale-script.py?token=` + request_token);
     20 
     21  assert_equals(response.headers.get('Unique-Id'), response2.headers.get('Unique-Id'));
     22  const body2 = await response2.text();
     23  assert_equals(body, body2);
     24 
     25  while(true) {
     26    const revalidation_check = await fetch(`resources/stale-script.py?query&token=` + request_token);
     27    if (revalidation_check.headers.get('Count') == '2') {
     28      break;
     29    }
     30    await wait25ms(test);
     31  }
     32 }, 'Second fetch returns same response');