1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 // This test makes sure that adding certificate exceptions behaves correctly
8 // when done from the prefs window
10 ChromeUtils.defineESModuleGetters(this, {
11 BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs",
15 const EXCEPTIONS_DLG_URL = "chrome://pippki/content/exceptionDialog.xhtml";
16 const EXCEPTIONS_DLG_FEATURES = "chrome,centerscreen";
17 const INVALID_CERT_DOMAIN = "self-signed.example.com";
18 const INVALID_CERT_LOCATION = "https://" + INVALID_CERT_DOMAIN + "/";
19 waitForExplicitFinish();
21 function testAddCertificate() {
22 win.removeEventListener("load", testAddCertificate);
23 Services.obs.addObserver(async function onCertUI() {
24 Services.obs.removeObserver(onCertUI, "cert-exception-ui-ready");
25 ok(win.gCert, "The certificate information should be available now");
27 let dialog = win.document.getElementById("exceptiondialog");
28 let confirmButton = dialog.getButton("extra1");
29 confirmButton.click();
31 params.exceptionAdded,
32 "The certificate exception should have been added"
35 registerCleanupFunction(() => {
36 let certOverrideService = Cc[
37 "@mozilla.org/security/certoverride;1"
38 ].getService(Ci.nsICertOverrideService);
39 certOverrideService.clearValidityOverride(INVALID_CERT_DOMAIN, -1, {});
42 BrowserTestUtils.startLoadingURIString(gBrowser, INVALID_CERT_LOCATION);
43 let loaded = await BrowserTestUtils.browserLoaded(
46 INVALID_CERT_LOCATION,
49 ok(loaded, "The certificate exception should allow the page to load");
52 }, "cert-exception-ui-ready");
55 let bWin = BrowserWindowTracker.getTopWindow();
57 exceptionAdded: false,
58 location: INVALID_CERT_LOCATION,
62 let win = bWin.openDialog(
65 EXCEPTIONS_DLG_FEATURES,
68 win.addEventListener("load", testAddCertificate);