browser_addCertException.js (3392B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 // Test adding a certificate exception by attempting to browse to a site with 8 // a bad certificate, being redirected to the internal about:certerror page, 9 // using the button contained therein to load the certificate exception 10 // dialog, using that to add an exception, and finally successfully visiting 11 // the site, including showing the right identity box and control center icons. 12 add_setup(async function () { 13 await SpecialPowers.pushPrefEnv({ 14 set: [["browser.urlbar.trustPanel.featureGate", false]], 15 }); 16 }); 17 18 add_task(async function () { 19 for (let feltPrivacyEnabled of [true, false]) { 20 await SpecialPowers.pushPrefEnv({ 21 set: [["security.certerrors.felt-privacy-v1", feltPrivacyEnabled]], 22 }); 23 24 await BrowserTestUtils.openNewForegroundTab(gBrowser); 25 await loadBadCertPage("https://expired.example.com", feltPrivacyEnabled); 26 27 let { gIdentityHandler } = gBrowser.ownerGlobal; 28 let promisePanelOpen = BrowserTestUtils.waitForEvent( 29 gBrowser.ownerGlobal, 30 "popupshown", 31 true, 32 event => event.target == gIdentityHandler._identityPopup 33 ); 34 gIdentityHandler._identityIconBox.click(); 35 await promisePanelOpen; 36 37 let promiseViewShown = BrowserTestUtils.waitForEvent( 38 gIdentityHandler._identityPopup, 39 "ViewShown" 40 ); 41 document.getElementById("identity-popup-security-button").click(); 42 await promiseViewShown; 43 44 is_element_visible( 45 document.getElementById("identity-icon"), 46 "Should see identity icon" 47 ); 48 let identityIconImage = gBrowser.ownerGlobal 49 .getComputedStyle(document.getElementById("identity-icon")) 50 .getPropertyValue("list-style-image"); 51 let securityViewBG = gBrowser.ownerGlobal 52 .getComputedStyle( 53 document 54 .getElementById("identity-popup-securityView") 55 .getElementsByClassName("identity-popup-security-connection")[0] 56 ) 57 .getPropertyValue("list-style-image"); 58 let securityContentBG = gBrowser.ownerGlobal 59 .getComputedStyle( 60 document 61 .getElementById("identity-popup-mainView") 62 .getElementsByClassName("identity-popup-security-connection")[0] 63 ) 64 .getPropertyValue("list-style-image"); 65 is( 66 identityIconImage, 67 'url("chrome://global/skin/icons/security-warning.svg")', 68 "Using expected icon image in the identity block" 69 ); 70 is( 71 securityViewBG, 72 'url("chrome://global/skin/icons/security-warning.svg")', 73 "Using expected icon image in the Control Center main view" 74 ); 75 is( 76 securityContentBG, 77 'url("chrome://global/skin/icons/security-warning.svg")', 78 "Using expected icon image in the Control Center subview" 79 ); 80 81 gIdentityHandler._identityPopup.hidePopup(); 82 83 let certOverrideService = Cc[ 84 "@mozilla.org/security/certoverride;1" 85 ].getService(Ci.nsICertOverrideService); 86 certOverrideService.clearValidityOverride("expired.example.com", -1, {}); 87 BrowserTestUtils.removeTab(gBrowser.selectedTab); 88 89 await SpecialPowers.popPrefEnv(); 90 } 91 });