tor-browser

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

test_persist_eviction.js (2829B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 /**
      7 * This test is mainly to verify that normally the oldest origin will be
      8 * evicted if the global limit is reached, but if the oldest origin is
      9 * persisted or is an extension origin, then it won't be evicted.
     10 */
     11 
     12 loadScript("dom/quota/test/xpcshell/common/utils.js");
     13 
     14 async function testSteps() {
     15  // The group limit is calculated as 20% of the global limit and the minimum
     16  // value of the group limit is 10 MB.
     17 
     18  const groupLimitKB = 10 * 1024;
     19  const globalLimitKB = groupLimitKB * 5;
     20 
     21  setGlobalLimit(globalLimitKB);
     22 
     23  let request = clear();
     24  await requestFinished(request);
     25 
     26  for (let persistOldestOrigin of [false, true]) {
     27    info(
     28      "Testing " +
     29        (persistOldestOrigin ? "with" : "without") +
     30        " persisting the oldest origin"
     31    );
     32 
     33    info(
     34      "Step 0: Filling a moz-extension origin as the oldest origin with non-persisted data"
     35    );
     36 
     37    // Just a fake moz-extension origin to mock an extension origin.
     38    let extUUID = "20445ca5-75f9-420e-a1d4-9cccccb5e891";
     39    let spec = `moz-extension://${extUUID}`;
     40    await fillOrigin(getPrincipal(spec), groupLimitKB * 1024);
     41 
     42    info(
     43      "Step 1: Filling five separate web origins to reach the global limit " +
     44        "and trigger eviction"
     45    );
     46 
     47    for (let index = 1; index <= 5; index++) {
     48      let spec = "http://example" + index + ".com";
     49      if (index == 1 && persistOldestOrigin) {
     50        request = persist(getPrincipal(spec));
     51        await requestFinished(request);
     52      }
     53      await fillOrigin(getPrincipal(spec), groupLimitKB * 1024);
     54    }
     55 
     56    info("Step 2: Verifying origin directories");
     57 
     58    for (let index = 1; index <= 5; index++) {
     59      let path = "storage/default/http+++example" + index + ".com";
     60      let file = getRelativeFile(path);
     61      if (index == (persistOldestOrigin ? 2 : 1)) {
     62        ok(!file.exists(), "The origin directory " + path + " doesn't exist");
     63 
     64        let spec = "http://example" + index + ".com";
     65        request = initTemporaryOrigin("default", getPrincipal(spec));
     66        await requestFinished(request);
     67 
     68        ok(file.exists(), "The origin directory " + path + " does exist");
     69      } else {
     70        ok(file.exists(), "The origin directory " + path + " does exist");
     71      }
     72    }
     73 
     74    // Verify that the extension storage data has not been evicted (even if it wasn't marked as
     75    // persisted and it was the less recently used origin).
     76    let path = `storage/default/moz-extension+++${extUUID}`;
     77    let file = getRelativeFile(path);
     78    ok(file.exists(), "The origin directory " + path + "does exist");
     79 
     80    request = clear();
     81    await requestFinished(request);
     82  }
     83 
     84  resetGlobalLimit();
     85 
     86  request = reset();
     87  await requestFinished(request);
     88 }