browser_hwconcurrency_etp_iframes.js (3767B)
1 /** 2 * This test only tests values in the iframe, it does not test them on the framer 3 * 4 * Covers the following cases: 5 * - RFP is disabled entirely 6 * - RFP is enabled entirely in normal and PBM 7 * - FPP is enabled entirely in normal and PBM 8 * 9 */ 10 11 "use strict"; 12 13 const SPOOFED_HW_CONCURRENCY = 14 SpecialPowers.Services.appinfo.OS == "Darwin" ? 8 : 4; 15 16 const DEFAULT_HARDWARE_CONCURRENCY = navigator.hardwareConcurrency; 17 18 // ============================================================================================= 19 // ============================================================================================= 20 21 async function testHWConcurrency(result, expectedResults, extraData) { 22 let testDesc = extraData.testDesc; 23 24 is( 25 result.hardwareConcurrency, 26 expectedResults.hardwareConcurrency, 27 `Checking ${testDesc} navigator.hardwareConcurrency.` 28 ); 29 } 30 31 add_setup(async function () { 32 await SpecialPowers.pushPrefEnv({ 33 set: [ 34 ["privacy.fingerprintingProtection.overrides", "+NavigatorHWConcurrency"], 35 ], 36 }); 37 registerCleanupFunction(async function () { 38 Services.prefs.clearUserPref( 39 "privacy.trackingprotection.allow_list.hasUserInteractedWithETPSettings" 40 ); 41 }); 42 }); 43 44 // The following are convenience objects that allow you to quickly see what is 45 // and is not modified from a logical set of values. 46 // Be sure to always use `let expectedResults = structuredClone(allNotSpoofed)` to do a 47 // deep copy and avoiding corrupting the original 'const' object 48 const allNotSpoofed = { 49 hardwareConcurrency: DEFAULT_HARDWARE_CONCURRENCY, 50 }; 51 const allSpoofed = { 52 hardwareConcurrency: SPOOFED_HW_CONCURRENCY, 53 }; 54 55 const uri = `https://${FRAMER_DOMAIN}/browser/browser/components/resistfingerprinting/test/browser/file_hwconcurrency_iframer.html?mode=iframe`; 56 57 requestLongerTimeout(2); 58 59 let extraData = { 60 etp_reload: true, 61 }; 62 63 let expectedResults = {}; 64 65 expectedResults = structuredClone(allNotSpoofed); 66 add_task( 67 defaultsTest.bind(null, uri, testHWConcurrency, expectedResults, extraData) 68 ); 69 70 // The ETP toggle _does not_ override RFP, only FPP. 71 expectedResults = structuredClone(allSpoofed); 72 add_task( 73 simpleRFPTest.bind(null, uri, testHWConcurrency, expectedResults, extraData) 74 ); 75 76 expectedResults = structuredClone(allSpoofed); 77 add_task( 78 simplePBMRFPTest.bind( 79 null, 80 uri, 81 testHWConcurrency, 82 expectedResults, 83 extraData 84 ) 85 ); 86 87 expectedResults = structuredClone(allNotSpoofed); 88 add_task( 89 simpleFPPTest.bind(null, uri, testHWConcurrency, expectedResults, extraData) 90 ); 91 92 expectedResults = structuredClone(allNotSpoofed); 93 add_task( 94 simplePBMFPPTest.bind( 95 null, 96 uri, 97 testHWConcurrency, 98 expectedResults, 99 extraData 100 ) 101 ); 102 103 // These test cases exercise the unusual configuration of RFP enabled in PBM and FPP enabled 104 // in normal browsing mode. 105 let extraPrefs = [ 106 ["privacy.resistFingerprinting.pbmode", true], 107 ["privacy.fingerprintingProtection", true], 108 ["privacy.fingerprintingProtection.overrides", "+NavigatorHWConcurrency"], 109 ]; 110 111 let this_extraData = structuredClone(extraData); 112 this_extraData.testDesc = 113 "RFP enabled in PBM, FPP enabled globally, testing in normal browsing mode"; 114 expectedResults = allNotSpoofed; 115 add_task( 116 defaultsTest.bind( 117 null, 118 uri, 119 testHWConcurrency, 120 structuredClone(expectedResults), 121 this_extraData, 122 structuredClone(extraPrefs) 123 ) 124 ); 125 126 this_extraData = structuredClone(extraData); 127 this_extraData.testDesc = 128 "RFP enabled in PBM, FPP enabled globally, testing in PBM"; 129 this_extraData.private_window = true; 130 expectedResults = allSpoofed; 131 add_task( 132 defaultsTest.bind( 133 null, 134 uri, 135 testHWConcurrency, 136 structuredClone(expectedResults), 137 this_extraData, 138 structuredClone(extraPrefs) 139 ) 140 );