tor-browser

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

cache.https.any.js (1563B)


      1 // META: title=Request signals & the cache API
      2 // META: global=window,worker
      3 
      4 promise_test(async () => {
      5  await caches.delete('test');
      6  const controller = new AbortController();
      7  const signal = controller.signal;
      8  const request = new Request('../resources/data.json', { signal });
      9 
     10  const cache = await caches.open('test');
     11  await cache.put(request, new Response(''));
     12 
     13  const requests = await cache.keys();
     14 
     15  assert_equals(requests.length, 1, 'Ensuring cleanup worked');
     16 
     17  const [cachedRequest] = requests;
     18 
     19  controller.abort();
     20 
     21  assert_false(cachedRequest.signal.aborted, "Request from cache shouldn't be aborted");
     22 
     23  const data = await fetch(cachedRequest).then(r => r.json());
     24  assert_equals(data.key, 'value', 'Fetch fully completes');
     25 }, "Signals are not stored in the cache API");
     26 
     27 promise_test(async () => {
     28  await caches.delete('test');
     29  const controller = new AbortController();
     30  const signal = controller.signal;
     31  const request = new Request('../resources/data.json', { signal });
     32  controller.abort();
     33 
     34  const cache = await caches.open('test');
     35  await cache.put(request, new Response(''));
     36 
     37  const requests = await cache.keys();
     38 
     39  assert_equals(requests.length, 1, 'Ensuring cleanup worked');
     40 
     41  const [cachedRequest] = requests;
     42 
     43  assert_false(cachedRequest.signal.aborted, "Request from cache shouldn't be aborted");
     44 
     45  const data = await fetch(cachedRequest).then(r => r.json());
     46  assert_equals(data.key, 'value', 'Fetch fully completes');
     47 }, "Signals are not stored in the cache API, even if they're already aborted");