summaryrefslogtreecommitdiffstats
path: root/security/manager/ssl/tests/mochitest/browser/browser_add_exception_dialog.js
blob: d04af61036323266ad77a254d23bf0a0cfb5cb61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

// This test makes sure that adding certificate exceptions behaves correctly
// when done from the prefs window

XPCOMUtils.defineLazyModuleGetters(this, {
  BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
});

function test() {
  const EXCEPTIONS_DLG_URL = "chrome://pippki/content/exceptionDialog.xhtml";
  const EXCEPTIONS_DLG_FEATURES = "chrome,centerscreen";
  const INVALID_CERT_DOMAIN = "self-signed.example.com";
  const INVALID_CERT_LOCATION = "https://" + INVALID_CERT_DOMAIN + "/";
  waitForExplicitFinish();

  function testAddCertificate() {
    win.removeEventListener("load", testAddCertificate);
    Services.obs.addObserver(async function onCertUI(aSubject, aTopic, aData) {
      Services.obs.removeObserver(onCertUI, "cert-exception-ui-ready");
      ok(win.gCert, "The certificate information should be available now");

      let dialog = win.document.getElementById("exceptiondialog");
      let confirmButton = dialog.getButton("extra1");
      confirmButton.click();
      ok(
        params.exceptionAdded,
        "The certificate exception should have been added"
      );

      registerCleanupFunction(() => {
        let certOverrideService = Cc[
          "@mozilla.org/security/certoverride;1"
        ].getService(Ci.nsICertOverrideService);
        certOverrideService.clearValidityOverride(INVALID_CERT_DOMAIN, -1, {});
      });

      BrowserTestUtils.loadURIString(gBrowser, INVALID_CERT_LOCATION);
      let loaded = await BrowserTestUtils.browserLoaded(
        gBrowser,
        false,
        INVALID_CERT_LOCATION,
        true
      );
      ok(loaded, "The certificate exception should allow the page to load");

      finish();
    }, "cert-exception-ui-ready");
  }

  let bWin = BrowserWindowTracker.getTopWindow();
  let params = {
    exceptionAdded: false,
    location: INVALID_CERT_LOCATION,
    prefetchCert: true,
  };

  let win = bWin.openDialog(
    EXCEPTIONS_DLG_URL,
    "",
    EXCEPTIONS_DLG_FEATURES,
    params
  );
  win.addEventListener("load", testAddCertificate);
}