browser_statePartitioning_PBM_strings.js (4278B)
1 "use strict"; 2 3 /* Any copyright is dedicated to the Public Domain. 4 * http://creativecommons.org/publicdomain/zero/1.0/ */ 5 6 const COOKIE_BEHAVIOR_PREF = "network.cookie.cookieBehavior"; 7 const COOKIE_BEHAVIOR_PBM_PREF = "network.cookie.cookieBehavior.pbmode"; 8 9 const CB_STRICT_FEATURES_PREF = "browser.contentblocking.features.strict"; 10 const FPI_PREF = "privacy.firstparty.isolate"; 11 12 async function testCookieBlockingInfoStandard( 13 cookieBehavior, 14 cookieBehaviorPBM, 15 isShown 16 ) { 17 let defaults = Services.prefs.getDefaultBranch(""); 18 defaults.setIntPref(COOKIE_BEHAVIOR_PREF, cookieBehavior); 19 defaults.setIntPref(COOKIE_BEHAVIOR_PBM_PREF, cookieBehaviorPBM); 20 21 await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true }); 22 23 let doc = gBrowser.contentDocument; 24 25 // Select standard mode. 26 let standardRadioOption = doc.getElementById("standardRadio"); 27 standardRadioOption.click(); 28 29 // Check the cookie blocking info for private windows for standard mode. 30 let elts = doc.querySelectorAll( 31 "#contentBlockingOptionStandard .extra-information-label.all-third-party-cookies-private-windows-option" 32 ); 33 for (let elt of elts) { 34 is( 35 elt.hidden, 36 !isShown, 37 `The visibility of cookie blocking info for standard mode is correct` 38 ); 39 } 40 41 gBrowser.removeCurrentTab(); 42 } 43 44 async function testCookieBlockingInfoStrict( 45 contentBlockingStrictFeatures, 46 isShown 47 ) { 48 await SpecialPowers.pushPrefEnv({ 49 set: [ 50 [CB_STRICT_FEATURES_PREF, contentBlockingStrictFeatures], 51 [FPI_PREF, false], 52 ], 53 }); 54 55 await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true }); 56 57 let doc = gBrowser.contentDocument; 58 59 // Select strict mode. 60 let strictRadioOption = doc.getElementById("strictRadio"); 61 strictRadioOption.click(); 62 63 // Check the cookie blocking info for private windows for strict mode. 64 let elts = doc.querySelectorAll( 65 "#contentBlockingOptionStrict .extra-information-label.all-third-party-cookies-private-windows-option" 66 ); 67 for (let elt of elts) { 68 is( 69 elt.hidden, 70 !isShown, 71 `The cookie blocking info is hidden for strict mode` 72 ); 73 } 74 75 gBrowser.removeCurrentTab(); 76 } 77 78 add_task(async function runTests() { 79 await SpecialPowers.pushPrefEnv({ 80 set: [[FPI_PREF, false]], 81 }); 82 83 let defaults = Services.prefs.getDefaultBranch(""); 84 let originalCookieBehavior = defaults.getIntPref(COOKIE_BEHAVIOR_PREF); 85 let originalCookieBehaviorPBM = defaults.getIntPref(COOKIE_BEHAVIOR_PBM_PREF); 86 87 // Test if the cookie blocking info for state partitioning in PBM is 88 // shown in standard mode if the regular cookieBehavior is 89 // BEHAVIOR_REJECT_TRACKER and the private cookieBehavior is 90 // BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN 91 await testCookieBlockingInfoStandard( 92 Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER, 93 Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN, 94 true 95 ); 96 97 // Test if the cookie blocking info is hidden in standard mode if both 98 // cookieBehaviors are the same. 99 await testCookieBlockingInfoStandard( 100 Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN, 101 Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN, 102 false 103 ); 104 105 // Test if the cookie blocking info is hidden for strict mode if 106 // cookieBehaviors both are BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN in 107 // the strict feature value. 108 await testCookieBlockingInfoStrict( 109 "tp,tpPrivate,cookieBehavior5,cookieBehaviorPBM5,cryptoTP,fp,stp,emailTP,emailTPPrivate,-consentmanagerSkip,-consentmanagerSkipPrivate,lvl2,rp,rpTop,ocsp,fpp,fppPrivate,3pcd", 110 false 111 ); 112 113 // Test if the cookie blocking info is shown for strict mode if the regular 114 // cookieBehavior is BEHAVIOR_REJECT_TRACKER and the private cookieBehavior is 115 // BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN 116 await testCookieBlockingInfoStrict( 117 "tp,tpPrivate,cookieBehavior4,cookieBehaviorPBM5,cryptoTP,fp,stp,emailTP,emailTPPrivate,-consentmanagerSkip,-consentmanagerSkipPrivate,lvl2,rp,rpTop,ocsp,fpp,fppPrivate,3pcd", 118 true 119 ); 120 121 defaults.setIntPref(COOKIE_BEHAVIOR_PREF, originalCookieBehavior); 122 defaults.setIntPref(COOKIE_BEHAVIOR_PBM_PREF, originalCookieBehaviorPBM); 123 await SpecialPowers.popPrefEnv(); 124 });