Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

/* Any copyright is dedicated to the Public Domain.
/**
* Test TrustPanel on pages with certificate override.
*/
"use strict";
async function loadBadCertPage(url) {
const loaded = BrowserTestUtils.waitForErrorPage(gBrowser.selectedBrowser);
const loadFlagsSkipCache =
Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY |
Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
BrowserTestUtils.startLoadingURIString(
gBrowser.selectedBrowser,
url,
loadFlagsSkipCache
);
await loaded;
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async () => {
const netErrorCard =
content.document.querySelector("net-error-card").wrappedJSObject;
await netErrorCard.getUpdateComplete();
EventUtils.synthesizeMouseAtCenter(
netErrorCard.advancedButton,
{},
content
);
await ContentTaskUtils.waitForCondition(() => {
return (
netErrorCard.exceptionButton && !netErrorCard.exceptionButton.disabled
);
}, "Waiting for exception button");
netErrorCard.exceptionButton.scrollIntoView(true);
EventUtils.synthesizeMouseAtCenter(
netErrorCard.exceptionButton,
{},
content
);
});
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
}
function fetchIconUrl(doc, id) {
let icon = doc.defaultView.getComputedStyle(
doc.getElementById(id)
).listStyleImage;
return icon.match(/url\("([^"]+)"\)/)?.[1] ?? null;
}
add_task(async () => {
registerCleanupFunction(() => {
// Remove Exception
let certOverrideService = Cc[
"@mozilla.org/security/certoverride;1"
].getService(Ci.nsICertOverrideService);
certOverrideService.clearValidityOverride(
"self-signed.example.com",
-1,
{}
);
});
await loadBadCertPage("https://self-signed.example.com");
Assert.equal(
fetchIconUrl(window.document, "trust-icon"),
"chrome://browser/skin/trust-icon-warning.svg",
"Trustpanel urlbar icon shows insecure"
);
await UrlbarTestUtils.openTrustPanel(window);
Assert.ok(
!BrowserTestUtils.isVisible(
document.getElementById("trustpanel-insecure-section")
),
"Don't show unencryped warning on self signed certs"
);
await UrlbarTestUtils.openTrustPanelSubview(
window,
"trustpanel-securityInformationView"
);
Assert.ok(
BrowserTestUtils.isVisible(
document.getElementById(
"identity-popup-content-cert-exception-overridden"
)
),
"Show user-added certificate error exception text"
);
await UrlbarTestUtils.closeTrustPanel(window);
});