From f7475b059ca3221f71a33259cdd365a2d7c86340 Mon Sep 17 00:00:00 2001 From: William Durand Date: Thu, 1 Jun 2023 11:27:43 +0000 Subject: [PATCH] Bug 1836224 - A click on the "learn more" link in the panel should close it. r=zombie Differential Revision: https://phabricator.services.mozilla.com/D179649 --- browser/base/content/browser-addons.js | 5 ++ .../browser_unified_extensions_messages.js | 87 +++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/browser/base/content/browser-addons.js b/browser/base/content/browser-addons.js index 2ccc1dc471a12..40033cfe03148 100644 --- a/browser/base/content/browser-addons.js +++ b/browser/base/content/browser-addons.js @@ -1361,6 +1361,11 @@ var gUnifiedExtensions = { supportPage: "quarantined-domains", dismissable: false, }); + this._messageBarQuarantinedDomain + .querySelector("a") + .addEventListener("click", () => { + this.togglePanel(); + }); } container.appendChild(this._messageBarQuarantinedDomain); diff --git a/browser/components/extensions/test/browser/browser_unified_extensions_messages.js b/browser/components/extensions/test/browser/browser_unified_extensions_messages.js index 991247d4d4674..131e20c98192b 100644 --- a/browser/components/extensions/test/browser/browser_unified_extensions_messages.js +++ b/browser/components/extensions/test/browser/browser_unified_extensions_messages.js @@ -128,3 +128,90 @@ add_task(async function test_quarantined_domain_message() { await extension.unload(); await SpecialPowers.popPrefEnv(); }); + +add_task(async function test_quarantined_domain_message_learn_more_link() { + const quarantinedDomain = "example.org"; + await SpecialPowers.pushPrefEnv({ + set: [ + ["extensions.quarantinedDomains.enabled", true], + ["extensions.quarantinedDomains.list", quarantinedDomain], + ], + }); + + // Load an extension that will have access to all domains, including the + // quarantined domain. + const extension = ExtensionTestUtils.loadExtension({ + manifest: { + permissions: ["activeTab"], + browser_action: {}, + }, + }); + await extension.startup(); + + const expectedSupportURL = + Services.urlFormatter.formatURLPref("app.support.baseURL") + + "quarantined-domains"; + + // We expect the SUMO page to be open in a new tab and the panel to be closed + // when the user clicks on the "learn more" link. + await BrowserTestUtils.withNewTab( + { gBrowser, url: `https://${quarantinedDomain}/` }, + async () => { + await openExtensionsPanel(); + const messages = getMessageBars(); + Assert.equal(messages.length, 1, "expected a message"); + + const [message] = messages; + verifyMessageBar(message); + + const tabPromise = BrowserTestUtils.waitForNewTab( + gBrowser, + expectedSupportURL + ); + const hidden = BrowserTestUtils.waitForEvent( + gUnifiedExtensions.panel, + "popuphidden", + true + ); + message.querySelector("a").click(); + const [tab] = await Promise.all([tabPromise, hidden]); + BrowserTestUtils.removeTab(tab); + } + ); + + // Same as above but with keyboard navigation. + await BrowserTestUtils.withNewTab( + { gBrowser, url: `https://${quarantinedDomain}/` }, + async () => { + await openExtensionsPanel(); + const messages = getMessageBars(); + Assert.equal(messages.length, 1, "expected a message"); + + const [message] = messages; + verifyMessageBar(message); + + const supportLink = message.querySelector("a"); + + // Focus the "learn more" (support) link. + const focused = BrowserTestUtils.waitForEvent(supportLink, "focus"); + EventUtils.synthesizeKey("VK_TAB", {}); + await focused; + + const tabPromise = BrowserTestUtils.waitForNewTab( + gBrowser, + expectedSupportURL + ); + const hidden = BrowserTestUtils.waitForEvent( + gUnifiedExtensions.panel, + "popuphidden", + true + ); + EventUtils.synthesizeKey("KEY_Enter", {}); + const [tab] = await Promise.all([tabPromise, hidden]); + BrowserTestUtils.removeTab(tab); + } + ); + + await extension.unload(); + await SpecialPowers.popPrefEnv(); +});