tor-browser

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

test_temporaryStorageRFP.js (1671B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 const { AppConstants } = ChromeUtils.importESModule(
      7  "resource://gre/modules/AppConstants.sys.mjs"
      8 );
      9 
     10 async function testSteps() {
     11  const principal = getPrincipal("http://example.com");
     12  const GiB = 1024 * 1024 * 1024;
     13 
     14  // Set the limit to some random value that is less than 50 GiB.
     15  const globalLimitBytes = 1 * GiB;
     16  const globalLimitKib = globalLimitBytes / 1024;
     17 
     18  setGlobalLimit(globalLimitKib);
     19 
     20  let request = init();
     21  await requestFinished(request);
     22 
     23  request = initTemporaryStorage();
     24  await requestFinished(request);
     25 
     26  request = estimateOrigin(principal);
     27  await requestFinished(request);
     28 
     29  const perGroupPercentage = 0.2;
     30  const expectedGroupLimitBytes = Math.floor(
     31    globalLimitBytes * perGroupPercentage
     32  );
     33  is(expectedGroupLimitBytes, request.result.limit);
     34 
     35  // Verify the RFP override is applied.
     36  request = reset();
     37  await requestFinished(request);
     38 
     39  const spoofedLimitBytes = 50 * GiB;
     40 
     41  Services.prefs.setBoolPref("privacy.resistFingerprinting", true);
     42 
     43  request = init();
     44  await requestFinished(request);
     45 
     46  request = initTemporaryStorage();
     47  await requestFinished(request);
     48 
     49  request = estimateOrigin(principal);
     50  await requestFinished(request);
     51 
     52  const expectedSpoofedGroupLimitBytes = Math.floor(
     53    spoofedLimitBytes * perGroupPercentage
     54  );
     55  is(
     56    expectedSpoofedGroupLimitBytes,
     57    request.result.limit,
     58    "RFP limit should be applied"
     59  );
     60 
     61  Services.prefs.clearUserPref("privacy.resistFingerprinting");
     62 
     63  resetGlobalLimit();
     64 
     65  request = reset();
     66  await requestFinished(request);
     67 }