browser_privacy_segmentation_pref.js (3824B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Test the privacy segmentation pref and preferences UI. 5 6 "use strict"; 7 8 const PREF = "browser.dataFeatureRecommendations.enabled"; 9 const PREF_VISIBILITY = "browser.privacySegmentation.preferences.show"; 10 11 add_task(async function test_preferences_section() { 12 if (!AppConstants.MOZ_DATA_REPORTING) { 13 ok(true, "Skipping test because data reporting is disabled"); 14 return; 15 } 16 17 await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true }); 18 19 let doc = gBrowser.selectedBrowser.contentDocument; 20 let section = doc.getElementById("privacySegmentationSection"); 21 let sectionHeader = section.querySelector("h2"); 22 let sectionDescription = section.querySelector("label"); 23 let radioGroup = section.querySelector( 24 "#privacyDataFeatureRecommendationRadioGroup" 25 ); 26 let radioEnabled = radioGroup.querySelector( 27 "#privacyDataFeatureRecommendationEnabled" 28 ); 29 let radioDisabled = radioGroup.querySelector( 30 "#privacyDataFeatureRecommendationDisabled" 31 ); 32 33 for (let show of [false, true]) { 34 Services.prefs.setBoolPref(PREF_VISIBILITY, show); 35 let showStr = show ? "visible" : "hidden"; 36 37 is( 38 BrowserTestUtils.isVisible(section), 39 show, 40 `Privacy Segmentation section should be ${showStr}.` 41 ); 42 is( 43 BrowserTestUtils.isVisible(sectionHeader), 44 show, 45 `Privacy Segmentation section header should be ${showStr}.` 46 ); 47 is( 48 BrowserTestUtils.isVisible(sectionDescription), 49 show, 50 `Privacy Segmentation section description should be ${showStr}.` 51 ); 52 is( 53 BrowserTestUtils.isVisible(radioGroup), 54 show, 55 `Privacy Segmentation radio group should be ${showStr}.` 56 ); 57 58 // The section is visible, test radio buttons. 59 if (show) { 60 Services.prefs.setBoolPref(PREF, false); 61 62 is( 63 radioGroup.value, 64 "false", 65 "Radio group should reflect initial pref state of false." 66 ); 67 68 info("Selecting radio on."); 69 radioEnabled.click(); 70 is( 71 Services.prefs.getBoolPref(PREF), 72 true, 73 "Privacy Segmentation should be enabled." 74 ); 75 76 info("Selecting radio off."); 77 radioDisabled.click(); 78 is( 79 Services.prefs.getBoolPref(PREF), 80 false, 81 "Privacy Segmentation should be disabled." 82 ); 83 84 info("Updating pref externally"); 85 is( 86 radioGroup.value, 87 "false", 88 "Radio group should reflect initial pref state of false." 89 ); 90 Services.prefs.setBoolPref(PREF, true); 91 await BrowserTestUtils.waitForMutationCondition( 92 radioGroup, 93 { attributeFilter: ["value"] }, 94 () => radioGroup.value == "true" 95 ); 96 is( 97 radioGroup.value, 98 "true", 99 "Updating Privacy Segmentation pref also updates radio group." 100 ); 101 } 102 } 103 104 BrowserTestUtils.removeTab(gBrowser.selectedTab); 105 Services.prefs.clearUserPref(PREF_VISIBILITY); 106 Services.prefs.clearUserPref(PREF); 107 }); 108 109 add_task(async function test_preferences_section_data_reporting_disabled() { 110 if (AppConstants.MOZ_DATA_REPORTING) { 111 ok(true, "Skipping test because data reporting is enabled"); 112 return; 113 } 114 115 for (let show of [false, true]) { 116 Services.prefs.setBoolPref(PREF_VISIBILITY, show); 117 await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true }); 118 119 let doc = gBrowser.selectedBrowser.contentDocument; 120 let section = doc.getElementById("privacySegmentationSection"); 121 is( 122 !!section, 123 show, 124 "Section should only exist when privacy segmentation section is enabled." 125 ); 126 127 BrowserTestUtils.removeTab(gBrowser.selectedTab); 128 } 129 130 Services.prefs.clearUserPref(PREF_VISIBILITY); 131 });