tor-browser

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

prefetch-cache.html (1288B)


      1 <!DOCTYPE html>
      2 <title>Ensures that prefetch respects HTTP cache semantics</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="/common/utils.js"></script>
      6 <script src="resources/prefetch-helper.js"></script>
      7 <body>
      8 <script>
      9 
     10 async function prefetch_and_count(cacheControl, t) {
     11    const {href} = await prefetch({
     12        "cache-control": cacheControl,
     13        "type": "application/javascript",
     14        content: "/**/"}, t);
     15    const script = document.createElement("script");
     16    script.src = href;
     17    t.add_cleanup(() => script.remove());
     18    const loaded = new Promise(resolve => script.addEventListener("load", resolve));
     19    document.body.appendChild(script);
     20    await loaded;
     21    const info = await get_prefetch_info(href);
     22    return info.length;
     23 }
     24 
     25 promise_test(async t => {
     26    const result = await prefetch_and_count("max-age=604800", t);
     27    assert_equals(result, 1);
     28 }, "Prefetch should populate the HTTP cache");
     29 
     30 for (const cacheControl of ["no-cache", "no-store", "max-age=0"]) {
     31    promise_test(async t => {
     32        const result = await prefetch_and_count(cacheControl, t);
     33        assert_equals(result, 2);
     34    }, `Prefetch should respect cache-control: ${cacheControl}`);
     35 }
     36 </script>
     37 </body>