tor-browser

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

browser_hwconcurrency_popups_noopener.js (4298B)


      1 /**
      2 * This test tests values in a popup that is opened with noopener, it does not test them on the page that made the popup
      3 *
      4 * Covers the following cases:
      5 *  - RFP is disabled entirely
      6 *  - RFP is enabled entirely
      7 *  - FPP is enabled entirely
      8 *
      9 *  - (A) RFP is exempted on the maker and popup
     10 *  - (C) RFP is exempted on the maker but not the popup
     11 *  - (E) RFP is not exempted on the maker nor the popup
     12 *  - (G) RFP is not exempted on the maker but is on the popup
     13 *
     14 */
     15 
     16 "use strict";
     17 
     18 const SPOOFED_HW_CONCURRENCY =
     19  SpecialPowers.Services.appinfo.OS == "Darwin" ? 8 : 4;
     20 
     21 const DEFAULT_HARDWARE_CONCURRENCY = navigator.hardwareConcurrency;
     22 
     23 // =============================================================================================
     24 // =============================================================================================
     25 
     26 async function testHWConcurrency(result, expectedResults, extraData) {
     27  let testDesc = extraData.testDesc;
     28 
     29  is(
     30    result.hardwareConcurrency,
     31    expectedResults.hardwareConcurrency,
     32    `Checking ${testDesc} navigator.hardwareConcurrency.`
     33  );
     34 }
     35 
     36 add_setup(async function () {
     37  await SpecialPowers.pushPrefEnv({
     38    set: [
     39      ["privacy.fingerprintingProtection.overrides", "+NavigatorHWConcurrency"],
     40    ],
     41  });
     42  registerCleanupFunction(async function () {
     43    Services.prefs.clearUserPref(
     44      "privacy.trackingprotection.allow_list.hasUserInteractedWithETPSettings"
     45    );
     46  });
     47 });
     48 
     49 // The following are convenience objects that allow you to quickly see what is
     50 //   and is not modified from a logical set of values.
     51 // Be sure to always use `let expectedResults = structuredClone(allNotSpoofed)` to do a
     52 //   deep copy and avoiding corrupting the original 'const' object
     53 const allNotSpoofed = {
     54  hardwareConcurrency: DEFAULT_HARDWARE_CONCURRENCY,
     55 };
     56 const allSpoofed = {
     57  hardwareConcurrency: SPOOFED_HW_CONCURRENCY,
     58 };
     59 
     60 const uri = `https://${FRAMER_DOMAIN}/browser/browser/components/resistfingerprinting/test/browser/file_hwconcurrency_iframer.html?mode=popup&submode=noopener`;
     61 const await_uri = `https://${IFRAME_DOMAIN}/browser/browser/components/resistfingerprinting/test/browser/file_hwconcurrency_iframee.html?mode=popup`;
     62 
     63 requestLongerTimeout(2);
     64 
     65 let extraData = {
     66  noopener: true,
     67  await_uri,
     68 };
     69 
     70 let expectedResults = {};
     71 
     72 expectedResults = structuredClone(allNotSpoofed);
     73 add_task(
     74  defaultsTest.bind(null, uri, testHWConcurrency, expectedResults, extraData)
     75 );
     76 
     77 expectedResults = structuredClone(allSpoofed);
     78 add_task(
     79  simpleRFPTest.bind(null, uri, testHWConcurrency, expectedResults, extraData)
     80 );
     81 
     82 // Test a private window with RFP enabled in PBMode
     83 expectedResults = structuredClone(allSpoofed);
     84 add_task(
     85  simplePBMRFPTest.bind(
     86    null,
     87    uri,
     88    testHWConcurrency,
     89    expectedResults,
     90    extraData
     91  )
     92 );
     93 
     94 expectedResults = structuredClone(allSpoofed);
     95 add_task(
     96  simpleFPPTest.bind(null, uri, testHWConcurrency, expectedResults, extraData)
     97 );
     98 
     99 // Test a Private Window with FPP Enabled in PBM
    100 expectedResults = structuredClone(allSpoofed);
    101 add_task(
    102  simplePBMFPPTest.bind(
    103    null,
    104    uri,
    105    testHWConcurrency,
    106    expectedResults,
    107    extraData
    108  )
    109 );
    110 
    111 // (A) RFP is exempted on the maker and popup
    112 expectedResults = structuredClone(allNotSpoofed);
    113 add_task(testA.bind(null, uri, testHWConcurrency, expectedResults, extraData));
    114 
    115 // (C) RFP is exempted on the maker but not the popup
    116 expectedResults = structuredClone(allSpoofed);
    117 add_task(testC.bind(null, uri, testHWConcurrency, expectedResults, extraData));
    118 
    119 // (E) RFP is not exempted on the maker nor the popup
    120 expectedResults = structuredClone(allSpoofed);
    121 add_task(testE.bind(null, uri, testHWConcurrency, expectedResults, extraData));
    122 
    123 // (G) RFP is not exempted on the maker but is on the popup
    124 //     Ordinarily, RFP would not be exempted, however because the opener relationship is severed
    125 //     it is safe to exempt the popup
    126 expectedResults = structuredClone(allNotSpoofed);
    127 add_task(testG.bind(null, uri, testHWConcurrency, expectedResults, extraData));
    128 
    129 // Test RFP Enabled in PBM and FPP enabled in Normal Browsing Mode
    130 expectedResults = structuredClone(allNotSpoofed);
    131 add_task(
    132  RFPPBMFPP_NormalMode_NoProtectionsTest.bind(
    133    null,
    134    uri,
    135    testHWConcurrency,
    136    expectedResults,
    137    extraData
    138  )
    139 );