Bug 1525941 - Adds ability to change permissions on network/cert error pages. r=johannh,Gijs a=pascalc
authordanielleleb <danielleleb12@gmail.com>
Wed, 03 Apr 2019 15:43:54 +0000
changeset 526210 d49678c63d88b0c19d5168743c16adfe2f6339a5
parent 526209 3772e946500d9b7cd6372f6b27e69208cfd43e98
child 526211 60105c2264a7f0b153c4dc206b1133b10901eea8
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh, Gijs, pascalc
bugs1525941
milestone67.0
Bug 1525941 - Adds ability to change permissions on network/cert error pages. r=johannh,Gijs a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D24052
browser/base/content/pageinfo/pageInfo.js
browser/base/content/test/pageinfo/browser_pageinfo_permissions.js
--- a/browser/base/content/pageinfo/pageInfo.js
+++ b/browser/base/content/pageinfo/pageInfo.js
@@ -351,16 +351,21 @@ function loadPageInfo(frameOuterWindowID
     gImageElement = imageInfo;
     var titleFormat = windowInfo.isTopWindow ? "page-info-page"
                                              : "page-info-frame";
     document.l10n.setAttributes(document.documentElement, titleFormat, {"website": docInfo.location});
 
     document.getElementById("main-window").setAttribute("relatedUrl", docInfo.location);
 
     await makeGeneralTab(pageInfoData.metaViewRows, docInfo);
+    if (uri.spec.startsWith("about:neterror") || uri.spec.startsWith("about:certerror")) {
+      uri = browser.currentURI;
+      principal = Services.scriptSecurityManager
+        .createCodebasePrincipal(uri, browser.contentPrincipal.originAttributes);
+    }
     onLoadPermission(uri, principal);
     securityOnLoad(uri, windowInfo);
   });
 
   // Get the media elements from content script to setup the media tab.
   mm.addMessageListener("PageInfo:mediaData", function onmessage(message) {
     // Page info window was closed.
     if (window.closed) {
--- a/browser/base/content/test/pageinfo/browser_pageinfo_permissions.js
+++ b/browser/base/content/test/pageinfo/browser_pageinfo_permissions.js
@@ -1,11 +1,13 @@
 const {SitePermissions} = ChromeUtils.import("resource:///modules/SitePermissions.jsm");
 
 const TEST_ORIGIN = "https://example.com";
+const TEST_ORIGIN_CERT_ERROR = "https://expired.example.com";
+const LOW_TLS_VERSION = "https://tls1.example.com/";
 
 async function testPermissions(defaultPermission) {
   await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function(browser) {
     let pageInfo = BrowserPageInfo(TEST_ORIGIN, "permTab");
     await BrowserTestUtils.waitForEvent(pageInfo, "load");
 
     let defaultCheckbox = await TestUtils.waitForCondition(() => pageInfo.document.getElementById("geoDef"));
     let radioGroup = pageInfo.document.getElementById("geoRadioGroup");
@@ -45,16 +47,86 @@ async function testPermissions(defaultPe
       "Selecting the default value should reset the permission.");
     ok(defaultCheckbox.checked, "The default checkbox should be checked.");
 
     pageInfo.close();
     SitePermissions.remove(gBrowser.currentURI, "geo");
   });
 }
 
+// Test displaying website permissions on certificate error pages.
+add_task(async function test_CertificateError() {
+  let browser;
+  let pageLoaded;
+  await BrowserTestUtils.openNewForegroundTab(gBrowser, () => {
+    gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, TEST_ORIGIN_CERT_ERROR);
+    browser = gBrowser.selectedBrowser;
+    pageLoaded = BrowserTestUtils.waitForErrorPage(browser);
+  }, false);
+
+  await pageLoaded;
+
+  let pageInfo = BrowserPageInfo(TEST_ORIGIN_CERT_ERROR, "permTab");
+  await BrowserTestUtils.waitForEvent(pageInfo, "load");
+  let permissionTab = pageInfo.document.getElementById("permTab");
+  await TestUtils.waitForCondition(() => BrowserTestUtils.is_visible(permissionTab),
+    "Permission tab should be visible.");
+
+  let hostText = pageInfo.document.getElementById("hostText");
+  let permList = pageInfo.document.getElementById("permList");
+  let permissions = SitePermissions.listPermissions()
+    .filter(p => SitePermissions.getPermissionLabel(p) != null);
+
+  await TestUtils.waitForCondition(() => hostText.value === browser.currentURI.displayPrePath,
+    `Value of owner should be "${browser.currentURI.displayPrePath}" instead got "${hostText.value}".`);
+
+  await TestUtils.waitForCondition(() => permList.childElementCount === permissions.length,
+    `Value of verifier should be ${permissions.length}, instead got ${permList.childElementCount}.`);
+
+  pageInfo.close();
+  BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});
+
+// Test displaying website permissions on network error pages.
+add_task(async function test_NetworkError() {
+  // Setup for TLS error
+  Services.prefs.setIntPref("security.tls.version.max", 3);
+  Services.prefs.setIntPref("security.tls.version.min", 3);
+
+  let browser;
+  let pageLoaded;
+  await BrowserTestUtils.openNewForegroundTab(gBrowser, () => {
+    gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, LOW_TLS_VERSION);
+    browser = gBrowser.selectedBrowser;
+    pageLoaded = BrowserTestUtils.waitForErrorPage(browser);
+  }, false);
+
+  await pageLoaded;
+
+  let pageInfo = BrowserPageInfo(LOW_TLS_VERSION, "permTab");
+  await BrowserTestUtils.waitForEvent(pageInfo, "load");
+  let permissionTab = pageInfo.document.getElementById("permTab");
+  await TestUtils.waitForCondition(() => BrowserTestUtils.is_visible(permissionTab),
+    "Permission tab should be visible.");
+
+  let hostText = pageInfo.document.getElementById("hostText");
+  let permList = pageInfo.document.getElementById("permList");
+  let permissions = SitePermissions.listPermissions()
+    .filter(p => SitePermissions.getPermissionLabel(p) != null);
+
+  await TestUtils.waitForCondition(() => hostText.value === browser.currentURI.displayPrePath,
+    `Value of host should be should be "${browser.currentURI.displayPrePath}" instead got "${hostText.value}".`);
+
+  await TestUtils.waitForCondition(() => permList.childElementCount === permissions.length,
+    `Value of permissions list should be ${permissions.length}, instead got ${permList.childElementCount}.`);
+
+  pageInfo.close();
+  BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});
+
 // Test some standard operations in the permission tab.
 add_task(async function test_geo_permission() {
   await testPermissions(SitePermissions.UNKNOWN);
 });
 
 // Test some standard operations in the permission tab, falling back to a custom
 // default permission instead of UNKNOWN.
 add_task(async function test_default_geo_permission() {