tor-browser

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

browser_scriptCache_evict_with_non_cacheable.js (2142B)


      1 const TEST_URL =
      2  "https://example.com/browser/dom/tests/browser/page_evict_with_non_cacheable.html";
      3 
      4 const TEST_SCRIPT_URL =
      5  "https://example.com/browser/dom/tests/browser/cacheable_non_cacheable_server.sjs";
      6 
      7 add_task(async function () {
      8  await SpecialPowers.pushPrefEnv({
      9    set: [["dom.script_loader.experimental.navigation_cache", true]],
     10  });
     11  registerCleanupFunction(() => SpecialPowers.popPrefEnv());
     12 
     13  // Set the server to return a cacheable script.
     14  const response1 = await fetch(TEST_SCRIPT_URL + "?use-cacheable");
     15  is(await response1.text(), "ok", "Server state should be set");
     16 
     17  ChromeUtils.clearResourceCache();
     18  Services.cache2.clear();
     19 
     20  const tab = await BrowserTestUtils.openNewForegroundTab({
     21    gBrowser,
     22    url: TEST_URL,
     23  });
     24 
     25  // The server should return a script that sets cacheable attribute to
     26  // true.
     27  let cacheable = await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
     28    return content.document.body.getAttribute("cacheable");
     29  });
     30  is(cacheable, "true");
     31 
     32  // Reloading the page should use the cached script.
     33  await BrowserTestUtils.reloadTab(tab);
     34  cacheable = await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
     35    return content.document.body.getAttribute("cacheable");
     36  });
     37  is(cacheable, "true");
     38 
     39  // Set the server to return a non-cacheable script.
     40  const response2 = await fetch(TEST_SCRIPT_URL + "?use-non-cacheable");
     41  is(await response2.text(), "ok", "Server state should be set");
     42 
     43  // Force-reload should fetch the script from the server
     44  await BrowserTestUtils.reloadTab(tab, { bypassCache: true });
     45 
     46  // The server should return a script that sets cacheable attribute to
     47  // false.
     48  cacheable = await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
     49    return content.document.body.getAttribute("cacheable");
     50  });
     51  is(cacheable, "false");
     52 
     53  // Reloading the page shouldn't use the cached script.
     54  await BrowserTestUtils.reloadTab(tab);
     55  cacheable = await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
     56    return content.document.body.getAttribute("cacheable");
     57  });
     58  is(cacheable, "false");
     59 
     60  BrowserTestUtils.removeTab(tab);
     61 });