tor-browser

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

cache-storage.tentative.https.window.js (2397B)


      1 // META: script=/common/get-host-info.sub.js
      2 // META: script=/common/utils.js
      3 // META: script=/common/dispatcher/dispatcher.js
      4 // META: script=/html/cross-origin-embedder-policy/credentialless/resources/common.js
      5 // META: script=./resources/common.js
      6 
      7 // A script storing a value into the CacheStorage.
      8 const store_script = (key, value, done) =>  `
      9  const request = new Request("/${key}.txt");
     10  const response = new Response("${value}", {
     11    headers: { "content-type": "plain/txt" }
     12  });
     13  const cache = await caches.open("v1");
     14  const value = await cache.put(request, response.clone());
     15  send("${done}", "stored");
     16 `;
     17 
     18 // A script loading a value from the CacheStorage.
     19 const load_script = (key, done) => `
     20  const cache = await caches.open("v1");
     21  const request = new Request("/${key}.txt");
     22  try {
     23    const response = await cache.match(request);
     24    const value = await response.text();
     25    send("${done}", value);
     26  } catch (error) {
     27    send("${done}", "not found");
     28  }
     29 `;
     30 
     31 promise_test(async test => {
     32  const origin = get_host_info().HTTPS_REMOTE_ORIGIN;
     33  const key_1 = token();
     34  const key_2 = token();
     35 
     36  // 2 actors: A credentialless iframe and a normal one.
     37  const iframe_credentialless = newIframeCredentialless(origin);
     38  const iframe_normal = newIframe(origin);
     39  const response_queue_1 = token();
     40  const response_queue_2 = token();
     41 
     42  // 1. Each of them store a value in CacheStorage with different keys.
     43  send(iframe_credentialless , store_script(key_1, "value_1", response_queue_1));
     44  send(iframe_normal, store_script(key_2, "value_2", response_queue_2));
     45  assert_equals(await receive(response_queue_1), "stored");
     46  assert_equals(await receive(response_queue_2), "stored");
     47 
     48  // 2. Each of them tries to retrieve the value from opposite side, without
     49  //    success.
     50  send(iframe_credentialless , load_script(key_2, response_queue_1));
     51  send(iframe_normal, load_script(key_1, response_queue_2));
     52  assert_equals(await receive(response_queue_1), "not found");
     53  assert_equals(await receive(response_queue_2), "not found");
     54 
     55  // 3. Each of them tries to retrieve the value from their side, with success:
     56  send(iframe_credentialless , load_script(key_1, response_queue_1));
     57  send(iframe_normal, load_script(key_2, response_queue_2));
     58  assert_equals(await receive(response_queue_1), "value_1");
     59  assert_equals(await receive(response_queue_2), "value_2");
     60 })