browser_security-3.js (3627B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 add_setup(async function () { 7 await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true }); 8 registerCleanupFunction(async function () { 9 Services.prefs.unlockPref("browser.safebrowsing.phishing.enabled"); 10 Services.prefs.unlockPref("browser.safebrowsing.malware.enabled"); 11 Services.prefs.unlockPref("browser.safebrowsing.downloads.enabled"); 12 Services.prefs.unlockPref( 13 "browser.safebrowsing.downloads.remote.block_potentially_unwanted" 14 ); 15 Services.prefs.unlockPref( 16 "browser.safebrowsing.downloads.remote.block_uncommon" 17 ); 18 BrowserTestUtils.removeTab(gBrowser.selectedTab); 19 }); 20 }); 21 22 // This test just reloads the preferences page for the various tests. 23 add_task(async function () { 24 Services.prefs.lockPref("browser.safebrowsing.phishing.enabled"); 25 Services.prefs.lockPref("browser.safebrowsing.malware.enabled"); 26 Services.prefs.lockPref("browser.safebrowsing.downloads.enabled"); 27 Services.prefs.lockPref( 28 "browser.safebrowsing.downloads.remote.block_potentially_unwanted" 29 ); 30 Services.prefs.lockPref( 31 "browser.safebrowsing.downloads.remote.block_uncommon" 32 ); 33 34 gBrowser.reload(); 35 await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); 36 37 let doc = gBrowser.selectedBrowser.contentDocument; 38 is( 39 doc.getElementById("enableSafeBrowsing").disabled, 40 true, 41 "Safe browsing should be disabled" 42 ); 43 is( 44 doc.getElementById("blockDownloads").disabled, 45 true, 46 "Block downloads should be disabled" 47 ); 48 is( 49 doc.getElementById("blockUncommonUnwanted").disabled, 50 true, 51 "Block common unwanted should be disabled" 52 ); 53 54 Services.prefs.unlockPref("browser.safebrowsing.phishing.enabled"); 55 Services.prefs.unlockPref("browser.safebrowsing.malware.enabled"); 56 57 gBrowser.reload(); 58 await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); 59 60 doc = gBrowser.selectedBrowser.contentDocument; 61 62 let checkbox = doc.getElementById("enableSafeBrowsing"); 63 checkbox.scrollIntoView(); 64 EventUtils.synthesizeMouseAtCenter( 65 checkbox.inputEl, 66 {}, 67 gBrowser.selectedBrowser.contentWindow 68 ); 69 70 is( 71 doc.getElementById("blockDownloads").disabled, 72 true, 73 "Block downloads should be disabled" 74 ); 75 is( 76 doc.getElementById("blockUncommonUnwanted").disabled, 77 true, 78 "Block common unwanted should be disabled" 79 ); 80 81 EventUtils.synthesizeMouseAtCenter( 82 checkbox.inputEl, 83 {}, 84 gBrowser.selectedBrowser.contentWindow 85 ); 86 87 is( 88 doc.getElementById("blockDownloads").disabled, 89 true, 90 "Block downloads should be disabled" 91 ); 92 is( 93 doc.getElementById("blockUncommonUnwanted").disabled, 94 true, 95 "Block common unwanted should be disabled" 96 ); 97 98 Services.prefs.unlockPref("browser.safebrowsing.downloads.enabled"); 99 100 gBrowser.reload(); 101 await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); 102 103 doc = gBrowser.selectedBrowser.contentDocument; 104 105 checkbox = doc.getElementById("blockDownloads"); 106 checkbox.scrollIntoView(); 107 EventUtils.synthesizeMouseAtCenter( 108 checkbox.inputEl, 109 {}, 110 gBrowser.selectedBrowser.contentWindow 111 ); 112 113 is( 114 doc.getElementById("blockUncommonUnwanted").disabled, 115 true, 116 "Block common unwanted should be disabled" 117 ); 118 119 EventUtils.synthesizeMouseAtCenter( 120 checkbox.inputEl, 121 {}, 122 gBrowser.selectedBrowser.contentWindow 123 ); 124 125 is( 126 doc.getElementById("blockUncommonUnwanted").disabled, 127 true, 128 "Block common unwanted should be disabled" 129 ); 130 });