From 79c583976411ce3c8962429f58cb962c69eefd64 Mon Sep 17 00:00:00 2001 From: Johann Hofmann Date: Tue, 9 Oct 2018 09:11:01 +0000 Subject: [PATCH] Bug 1476220 - Show a "site information" header in the identity popup. r=paolo Differential Revision: https://phabricator.services.mozilla.com/D7090 --HG-- extra : moz-landing-system : lando --- browser/base/content/browser-siteIdentity.js | 38 ++--- .../test/siteIdentity/browser_identity_UI.js | 145 +++++++----------- .../controlcenter/content/panel.inc.xul | 12 +- .../locales/en-US/chrome/browser/browser.dtd | 1 + .../en-US/chrome/browser/browser.properties | 3 + .../themes/shared/controlcenter/panel.inc.css | 37 +++-- 6 files changed, 111 insertions(+), 125 deletions(-) diff --git a/browser/base/content/browser-siteIdentity.js b/browser/base/content/browser-siteIdentity.js index f871f3fbb6f2..820c839bc380 100644 --- a/browser/base/content/browser-siteIdentity.js +++ b/browser/base/content/browser-siteIdentity.js @@ -115,15 +115,14 @@ var gIdentityHandler = { delete this._identityPopupMainView; return this._identityPopupMainView = document.getElementById("identity-popup-mainView"); }, - get _identityPopupContentHosts() { - delete this._identityPopupContentHosts; - return this._identityPopupContentHosts = - [...document.querySelectorAll(".identity-popup-host")]; + get _identityPopupMainViewHeaderLabel() { + delete this._identityPopupMainViewHeaderLabel; + return this._identityPopupMainViewHeaderLabel = + document.querySelector("#identity-popup-mainView-panel-header-span"); }, - get _identityPopupContentHostless() { - delete this._identityPopupContentHostless; - return this._identityPopupContentHostless = - [...document.querySelectorAll(".identity-popup-hostless")]; + get _identityPopupContentHost() { + delete this._identityPopupContentHost; + return this._identityPopupContentHost = document.getElementById("identity-popup-host"); }, get _identityPopupContentOwner() { delete this._identityPopupContentOwner; @@ -703,7 +702,6 @@ var gIdentityHandler = { let verifier = ""; let host = ""; let owner = ""; - let hostless = false; try { host = this.getEffectiveHost(); @@ -711,16 +709,13 @@ var gIdentityHandler = { // Some URIs might have no hosts. } + if (this._pageExtensionPolicy) { + host = this._pageExtensionPolicy.name; + } + // Fallback for special protocols. if (!host) { host = this._uri.specIgnoringRef; - // Special URIs without a host (eg, about:) should crop the end so - // the protocol can be seen. - hostless = true; - } - - if (this._pageExtensionPolicy) { - host = this._pageExtensionPolicy.name; } // Fill in the CA name if we have a valid TLS certificate. @@ -747,14 +742,9 @@ var gIdentityHandler = { } // Push the appropriate strings out to the UI. - this._identityPopupContentHosts.forEach((el) => { - el.textContent = host; - el.hidden = hostless; - }); - this._identityPopupContentHostless.forEach((el) => { - el.setAttribute("value", host); - el.hidden = !hostless; - }); + this._identityPopupMainViewHeaderLabel.textContent = + gNavigatorBundle.getFormattedString("identity.headerWithHost", [host]); + this._identityPopupContentHost.textContent = host; this._identityPopupContentOwner.textContent = owner; this._identityPopupContentSupp.textContent = supplemental; this._identityPopupContentVerif.textContent = verifier; diff --git a/browser/base/content/test/siteIdentity/browser_identity_UI.js b/browser/base/content/test/siteIdentity/browser_identity_UI.js index e5b3862c8f50..05a9da59685f 100644 --- a/browser/base/content/test/siteIdentity/browser_identity_UI.js +++ b/browser/base/content/test/siteIdentity/browser_identity_UI.js @@ -1,16 +1,6 @@ /* Tests for correct behaviour of getEffectiveHost on identity handler */ -function test() { - waitForExplicitFinish(); - requestLongerTimeout(2); - - ok(gIdentityHandler, "gIdentityHandler should exist"); - - BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank", true).then(() => { - BrowserTestUtils.addContentEventListener(gBrowser.selectedBrowser, "load", checkResult, true); - nextTest(); - }); -} +requestLongerTimeout(2); // Greek IDN for 'example.test'. var idnDomain = "\u03C0\u03B1\u03C1\u03AC\u03B4\u03B5\u03B9\u03B3\u03BC\u03B1.\u03B4\u03BF\u03BA\u03B9\u03BC\u03AE"; @@ -29,7 +19,6 @@ var tests = [ name: "normal HTTPS", location: "https://example.com/", effectiveHost: "example.com", - isHTTPS: true, }, { name: "IDN subdomain", @@ -45,13 +34,11 @@ var tests = [ name: "subdomain HTTPS", location: "https://test1.example.com/", effectiveHost: "test1.example.com", - isHTTPS: true, }, { name: "view-source HTTPS", location: "view-source:https://example.com/", effectiveHost: null, - isHTTPS: true, }, { name: "IP address", @@ -60,91 +47,73 @@ var tests = [ }, ]; -var gCurrentTest, gCurrentTestIndex = -1, gTestDesc, gPopupHidden; -// Go through the tests in both directions, to add additional coverage for -// transitions between different states. -var gForward = true; -var gCheckETLD = false; -function nextTest() { - if (!gCheckETLD) { - if (gForward) - gCurrentTestIndex++; - else - gCurrentTestIndex--; +add_task(async function test() { + ok(gIdentityHandler, "gIdentityHandler should exist"); - if (gCurrentTestIndex == tests.length) { - // Went too far, reverse - gCurrentTestIndex--; - gForward = false; - } + await BrowserTestUtils.openNewForegroundTab(gBrowser); - if (gCurrentTestIndex == -1) { - gBrowser.removeCurrentTab(); - finish(); - return; - } - - gCurrentTest = tests[gCurrentTestIndex]; - gTestDesc = "#" + gCurrentTestIndex + " (" + gCurrentTest.name + ")"; - if (!gForward) - gTestDesc += " (second time)"; - if (gCurrentTest.isHTTPS) { - gCheckETLD = true; - } - - // Navigate to the next page, which will cause checkResult to fire. - let spec = gBrowser.selectedBrowser.currentURI.spec; - if (spec == "about:blank" || spec == gCurrentTest.location) { - BrowserTestUtils.loadURI(gBrowser.selectedBrowser, gCurrentTest.location); - } else { - // Open the Control Center and make sure it closes after nav (Bug 1207542). - let popupShown = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown"); - gPopupHidden = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popuphidden"); - gIdentityHandler._identityBox.click(); - info("Waiting for the Control Center to be shown"); - popupShown.then(async () => { - ok(!BrowserTestUtils.is_hidden(gIdentityHandler._identityPopup), "Control Center is visible"); - // Show the subview, which is an easy way in automation to reproduce - // Bug 1207542, where the CC wouldn't close on navigation. - let promiseViewShown = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "ViewShown"); - gBrowser.ownerDocument.querySelector("#identity-popup-security-expander").click(); - await promiseViewShown; - BrowserTestUtils.loadURI(gBrowser.selectedBrowser, gCurrentTest.location); - }); - } - } else { - gCheckETLD = false; - gTestDesc = "#" + gCurrentTestIndex + " (" + gCurrentTest.name + " without eTLD in identity icon label)"; - if (!gForward) - gTestDesc += " (second time)"; - gBrowser.selectedBrowser.reloadWithFlags(Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE | - Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY); + for (let i = 0; i < tests.length; i++) { + await runTest(i, true); } -} -function checkResult() { - if (gBrowser.selectedBrowser.currentURI.spec == "about:blank") - return; + gBrowser.removeCurrentTab(); + await BrowserTestUtils.openNewForegroundTab(gBrowser); + + for (let i = tests.length - 1; i >= 0; i--) { + await runTest(i, false); + } + + gBrowser.removeCurrentTab(); +}); + +async function runTest(i, forward) { + let currentTest = tests[i]; + let testDesc = "#" + i + " (" + currentTest.name + ")"; + if (!forward) { + testDesc += " (second time)"; + } + + info("Running test " + testDesc); + + let popupHidden = null; + if ((forward && i > 0) || (!forward && i < tests.length - 1)) { + popupHidden = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popuphidden"); + } + + let loaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, currentTest.location); + BrowserTestUtils.loadURI(gBrowser.selectedBrowser, currentTest.location); + await loaded; + await popupHidden; + ok(BrowserTestUtils.is_hidden(gIdentityHandler._identityPopup), "Control Center is hidden"); // Sanity check other values, and the value of gIdentityHandler.getEffectiveHost() - is(gIdentityHandler._uri.spec, gCurrentTest.location, "location matches for test " + gTestDesc); + is(gIdentityHandler._uri.spec, currentTest.location, "location matches for test " + testDesc); // getEffectiveHost can't be called for all modes - if (gCurrentTest.effectiveHost === null) { + if (currentTest.effectiveHost === null) { let identityBox = document.getElementById("identity-box"); ok(identityBox.className == "unknownIdentity" || identityBox.className == "chromeUI", "mode matched"); } else { - is(gIdentityHandler.getEffectiveHost(), gCurrentTest.effectiveHost, "effectiveHost matches for test " + gTestDesc); + is(gIdentityHandler.getEffectiveHost(), currentTest.effectiveHost, "effectiveHost matches for test " + testDesc); } - if (gPopupHidden) { - info("Waiting for the Control Center to hide"); - gPopupHidden.then(() => { - gPopupHidden = null; - ok(BrowserTestUtils.is_hidden(gIdentityHandler._identityPopup), "Control Center is hidden"); - executeSoon(nextTest); - }); - } else { - executeSoon(nextTest); - } + // Open the Control Center and make sure it closes after nav (Bug 1207542). + let popupShown = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown"); + gIdentityHandler._identityBox.click(); + info("Waiting for the Control Center to be shown"); + await popupShown; + ok(!BrowserTestUtils.is_hidden(gIdentityHandler._identityPopup), "Control Center is visible"); + let displayedHost = currentTest.effectiveHost || currentTest.location; + ok(gIdentityHandler._identityPopupMainViewHeaderLabel.textContent.includes(displayedHost), + "identity UI header shows the host for test " + testDesc); + + // Show the subview, which is an easy way in automation to reproduce + // Bug 1207542, where the CC wouldn't close on navigation. + let promiseViewShown = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "ViewShown"); + gBrowser.ownerDocument.querySelector("#identity-popup-security-expander").click(); + await promiseViewShown; + + displayedHost = currentTest.effectiveHost || currentTest.location; + ok(gIdentityHandler._identityPopupContentHost.textContent.includes(displayedHost), + "security subview header shows the host for test " + testDesc); } diff --git a/browser/components/controlcenter/content/panel.inc.xul b/browser/components/controlcenter/content/panel.inc.xul index aada8397a1af..d71c1dea6c94 100644 --- a/browser/components/controlcenter/content/panel.inc.xul +++ b/browser/components/controlcenter/content/panel.inc.xul @@ -15,12 +15,17 @@ mainViewId="identity-popup-mainView"> + + + +