tor-browser

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

test_estimateOrigin.js (2045B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 loadScript("dom/quota/test/xpcshell/common/utils.js");
      7 
      8 async function verifyOriginEstimation(principal, expectedUsage, expectedLimit) {
      9  info("Estimating origin");
     10 
     11  const request = estimateOrigin(principal);
     12  await requestFinished(request);
     13 
     14  is(request.result.usage, expectedUsage, "Correct usage");
     15  is(request.result.limit, expectedLimit, "Correct limit");
     16 }
     17 
     18 async function testSteps() {
     19  // The group limit is calculated as 20% of the global limit and the minimum
     20  // value of the group limit is 10 MB.
     21 
     22  const groupLimitKB = 10 * 1024;
     23  const groupLimitBytes = groupLimitKB * 1024;
     24  const globalLimitKB = groupLimitKB * 5;
     25  const globalLimitBytes = globalLimitKB * 1024;
     26 
     27  info("Setting limits");
     28 
     29  setGlobalLimit(globalLimitKB);
     30 
     31  info("Clearing");
     32 
     33  let request = clear();
     34  await requestFinished(request);
     35 
     36  info("Filling origins");
     37 
     38  await fillOrigin(getPrincipal("https://foo1.example1.com"), 100);
     39  await fillOrigin(getPrincipal("https://foo2.example1.com"), 200);
     40  await fillOrigin(getPrincipal("https://foo1.example2.com"), 300);
     41  await fillOrigin(getPrincipal("https://foo2.example2.com"), 400);
     42 
     43  info("Verifying origin estimations");
     44 
     45  await verifyOriginEstimation(
     46    getPrincipal("https://foo1.example1.com"),
     47    300,
     48    groupLimitBytes
     49  );
     50  await verifyOriginEstimation(
     51    getPrincipal("https://foo2.example1.com"),
     52    300,
     53    groupLimitBytes
     54  );
     55  await verifyOriginEstimation(
     56    getPrincipal("https://foo1.example2.com"),
     57    700,
     58    groupLimitBytes
     59  );
     60  await verifyOriginEstimation(
     61    getPrincipal("https://foo2.example2.com"),
     62    700,
     63    groupLimitBytes
     64  );
     65 
     66  info("Persisting origin");
     67 
     68  request = persist(getPrincipal("https://foo2.example2.com"));
     69  await requestFinished(request);
     70 
     71  info("Verifying origin estimation");
     72 
     73  await verifyOriginEstimation(
     74    getPrincipal("https://foo2.example2.com"),
     75    1000,
     76    globalLimitBytes
     77  );
     78 
     79  finishTest();
     80 }