browser_security-1.js (3436B)
1 const PREFS = [ 2 "browser.safebrowsing.phishing.enabled", 3 "browser.safebrowsing.malware.enabled", 4 5 "browser.safebrowsing.downloads.enabled", 6 7 "browser.safebrowsing.downloads.remote.block_potentially_unwanted", 8 "browser.safebrowsing.downloads.remote.block_uncommon", 9 ]; 10 11 let originals = PREFS.map(pref => [pref, Services.prefs.getBoolPref(pref)]); 12 let originalMalwareTable = Services.prefs.getCharPref( 13 "urlclassifier.malwareTable" 14 ); 15 registerCleanupFunction(function () { 16 originals.forEach(([pref, val]) => Services.prefs.setBoolPref(pref, val)); 17 Services.prefs.setCharPref( 18 "urlclassifier.malwareTable", 19 originalMalwareTable 20 ); 21 }); 22 23 // This test only opens the Preferences once, and then reloads the page 24 // each time that it wants to test various preference combinations. We 25 // only use one tab (instead of opening/closing for each test) for all 26 // to help improve test times on debug builds. 27 add_setup(async function () { 28 await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true }); 29 registerCleanupFunction(async function () { 30 BrowserTestUtils.removeTab(gBrowser.selectedTab); 31 }); 32 }); 33 34 // test the safebrowsing preference 35 add_task(async function () { 36 async function checkPrefSwitch(val1, val2) { 37 Services.prefs.setBoolPref("browser.safebrowsing.phishing.enabled", val1); 38 Services.prefs.setBoolPref("browser.safebrowsing.malware.enabled", val2); 39 40 gBrowser.reload(); 41 await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); 42 43 let doc = gBrowser.selectedBrowser.contentDocument; 44 let checkbox = doc.getElementById("enableSafeBrowsing"); 45 let blockDownloads = doc.getElementById("blockDownloads"); 46 let blockUncommon = doc.getElementById("blockUncommonUnwanted"); 47 let checked = checkbox.checked; 48 is( 49 blockDownloads.hasAttribute("disabled"), 50 !checked, 51 "block downloads checkbox is set correctly" 52 ); 53 54 is( 55 checked, 56 val1 && val2, 57 "safebrowsing preference is initialized correctly" 58 ); 59 // should be disabled when checked is false (= pref is turned off) 60 is( 61 blockUncommon.hasAttribute("disabled"), 62 !checked, 63 "block uncommon checkbox is set correctly" 64 ); 65 66 // scroll the checkbox into the viewport and click checkbox 67 checkbox.scrollIntoView(); 68 let update = waitForSettingControlChange(checkbox.control); 69 EventUtils.synthesizeMouseAtCenter( 70 checkbox.inputEl, 71 {}, 72 gBrowser.selectedBrowser.contentWindow 73 ); 74 await update; 75 // check that both settings are now turned on or off 76 is( 77 Services.prefs.getBoolPref("browser.safebrowsing.phishing.enabled"), 78 !checked, 79 "safebrowsing.enabled is set correctly" 80 ); 81 is( 82 Services.prefs.getBoolPref("browser.safebrowsing.malware.enabled"), 83 !checked, 84 "safebrowsing.malware.enabled is set correctly" 85 ); 86 87 // check if the other checkboxes have updated 88 checked = checkbox.checked; 89 if (blockDownloads) { 90 is( 91 blockDownloads.disabled, 92 !checked, 93 "block downloads checkbox is set correctly" 94 ); 95 is( 96 blockUncommon.disabled, 97 !checked || !blockDownloads.checked, 98 "block uncommon checkbox is set correctly" 99 ); 100 } 101 } 102 103 await checkPrefSwitch(true, true); 104 await checkPrefSwitch(false, true); 105 await checkPrefSwitch(true, false); 106 await checkPrefSwitch(false, false); 107 });