Bug 1501955 - Runs securityOnLoad on certificate error pages and adds test. r=johannh
authordanielleleb <danielleleb12@gmail.com>
Sat, 16 Mar 2019 19:53:02 +0000
changeset 464488 355c869b33e3c85d2277c4da98aef846a6f83d4b
parent 464487 55935c0cdcb403767b529b865be953b7bc529157
child 464489 634792168a9dd19482a9538e3ca93e8b6b2ba717
push id35716
push useraciure@mozilla.com
push dateSun, 17 Mar 2019 09:42:17 +0000
treeherdermozilla-central@8ee97c045359 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1501955
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1501955 - Runs securityOnLoad on certificate error pages and adds test. r=johannh Differential Revision: https://phabricator.services.mozilla.com/D21840
browser/base/content/pageinfo/pageInfo.js
browser/base/content/pageinfo/security.js
browser/base/content/test/pageinfo/browser_pageinfo_security.js
--- a/browser/base/content/pageinfo/pageInfo.js
+++ b/browser/base/content/pageinfo/pageInfo.js
@@ -314,16 +314,30 @@ async function onLoadPageInfo() {
 }
 
 function loadPageInfo(frameOuterWindowID, imageElement, browser) {
   browser = browser || window.opener.gBrowser.selectedBrowser;
   let mm = browser.messageManager;
 
   let imageInfo = imageElement;
 
+  // Generate security information if it is a security error page.
+  let documentURI = browser.documentURI.spec;
+  if (documentURI.startsWith("about:certerror")) {
+    let hostName = null;
+    try {
+      hostName = browser.currentURI.displayHost;
+    } catch (exception) { }
+    let info = {
+      isTopWindow: !!frameOuterWindowID,
+      hostName,
+    };
+    securityOnLoad(documentURI, info);
+  }
+
   // Look for pageInfoListener in content.js. Sends message to listener with arguments.
   mm.sendAsyncMessage("PageInfo:getData", {strings: gStrings, frameOuterWindowID});
 
   let pageInfoData;
 
   // Get initial pageInfoData needed to display the general, permission and security tabs.
   mm.addMessageListener("PageInfo:data", async function onmessage(message) {
     mm.removeMessageListener("PageInfo:data", onmessage);
--- a/browser/base/content/pageinfo/security.js
+++ b/browser/base/content/pageinfo/security.js
@@ -185,17 +185,17 @@ var security = {
 
   _cert: null,
 };
 
 function securityOnLoad(uri, windowInfo) {
   security.init(uri, windowInfo);
 
   var info = security._getSecurityInfo();
-  if (!info || uri.scheme === "about") {
+  if (!info || (uri.scheme === "about" && !uri.spec.startsWith("about:certerror"))) {
     document.getElementById("securityTab").hidden = true;
     return;
   }
   document.getElementById("securityTab").hidden = false;
 
   /* Set Identity section text */
   setText("security-identity-domain-value", info.hostName);
 
--- a/browser/base/content/test/pageinfo/browser_pageinfo_security.js
+++ b/browser/base/content/test/pageinfo/browser_pageinfo_security.js
@@ -1,16 +1,43 @@
 ChromeUtils.defineModuleGetter(this, "SiteDataTestUtils",
                                "resource://testing-common/SiteDataTestUtils.jsm");
 ChromeUtils.defineModuleGetter(this, "DownloadUtils",
                                "resource://gre/modules/DownloadUtils.jsm");
 
 const TEST_ORIGIN = "https://example.com";
 const TEST_SUB_ORIGIN = "https://test1.example.com";
 const REMOVE_DIALOG_URL = "chrome://browser/content/preferences/siteDataRemoveSelected.xul";
+const TEST_ORIGIN_CERT_ERROR = "https://expired.example.com";
+
+// Test displaying website identity information on certificate error pages.
+add_task(async function test_CertificateError() {
+  await BrowserTestUtils.withNewTab({gBrowser, url: TEST_ORIGIN_CERT_ERROR, waitForLoad: false}, async function(browser) {
+    let pageInfo = BrowserPageInfo(TEST_ORIGIN_CERT_ERROR, "securityTab");
+    await BrowserTestUtils.waitForEvent(pageInfo, "load");
+    let securityTab = pageInfo.document.getElementById("securityTab");
+    await TestUtils.waitForCondition(() => BrowserTestUtils.is_visible(securityTab),
+      "Security tab should be visible.");
+
+    let owner = pageInfo.document.getElementById("security-identity-owner-value");
+    let verifier = pageInfo.document.getElementById("security-identity-verifier-value");
+    let domain = pageInfo.document.getElementById("security-identity-domain-value");
+
+    await TestUtils.waitForCondition(() => owner.textContent === "This website does not supply ownership information.",
+      `Value of owner should be should be "This website does not supply ownership information." instead got "${verifier.textContent}".`);
+
+    await TestUtils.waitForCondition(() => verifier.textContent === "Not specified",
+      `Value of verifier should be "Not specified", instead got "${verifier.textContent}".`);
+
+    await TestUtils.waitForCondition(() => domain.value === browser.currentURI.displayHost,
+      `Value of domain should be ${browser.currentURI.displayHost}, instead got "${domain.value}".`);
+
+    pageInfo.close();
+  });
+});
 
 // Test displaying and removing quota managed data.
 add_task(async function test_SiteData() {
   await SiteDataTestUtils.addToIndexedDB(TEST_ORIGIN);
 
   await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function(browser) {
     let totalUsage = await SiteDataTestUtils.getQuotaUsage(TEST_ORIGIN);
     Assert.greater(totalUsage, 0, "The total usage should not be 0");