diff --git a/browser/components/newtab/lib/FeatureCalloutBroker.sys.mjs b/browser/components/newtab/lib/FeatureCalloutBroker.sys.mjs index ca2460e8e82b..7bf83d567d89 100644 --- a/browser/components/newtab/lib/FeatureCalloutBroker.sys.mjs +++ b/browser/components/newtab/lib/FeatureCalloutBroker.sys.mjs @@ -84,6 +84,13 @@ export class _FeatureCalloutBroker { return false; } const win = browser.ownerGlobal; + // Avoid showing feature callouts if a dialog or panel is showing. + if ( + win.gDialogBox?.dialog || + [...win.document.querySelectorAll("panel")].some(p => p.state === "open") + ) { + return false; + } const currentCallout = this.#calloutMap.get(win); // If a custom callout was previously showing, but is no longer showing, // tear down the FeatureCallout instance. We avoid tearing them down when diff --git a/browser/components/newtab/test/browser/browser_feature_callout_in_chrome.js b/browser/components/newtab/test/browser/browser_feature_callout_in_chrome.js index 2dd714d648bb..ec9201ecbed0 100644 --- a/browser/components/newtab/test/browser/browser_feature_callout_in_chrome.js +++ b/browser/components/newtab/test/browser/browser_feature_callout_in_chrome.js @@ -1,7 +1,9 @@ /* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ -"use strict"; +const { CustomizableUITestUtils } = ChromeUtils.importESModule( + "resource://testing-common/CustomizableUITestUtils.sys.mjs" +); const PDF_TEST_URL = "https://example.com/browser/browser/components/newtab/test/browser/file_pdf.PDF"; @@ -457,6 +459,42 @@ add_task(async function triggered_feature_tour_with_custom_pref() { ); }); +add_task(async function callout_not_shown_if_dialog_open() { + await SpecialPowers.pushPrefEnv({ + set: [["prompts.windowPromptSubDialog", true]], + }); + + const win = await BrowserTestUtils.openNewBrowserWindow(); + let dialogPromise = BrowserTestUtils.promiseAlertDialogOpen(); + // Avoid blocking the test on the (sync) alert by sticking it in a timeout: + setTimeout(() => Services.prompt.alert(win, "Some title", "some message"), 0); + await dialogPromise; + + let rv = await FeatureCalloutBroker.showFeatureCallout( + win.gBrowser.selectedBrowser, + testMessage.message + ); + ok(!rv, "Feature callout not shown when a dialog is open in the same window"); + + await BrowserTestUtils.closeWindow(win); + await SpecialPowers.popPrefEnv(); +}); + +add_task(async function callout_not_shown_if_panel_open() { + const win = await BrowserTestUtils.openNewBrowserWindow(); + const gCUITestUtils = new CustomizableUITestUtils(win); + await gCUITestUtils.openMainMenu(); + + let rv = await FeatureCalloutBroker.showFeatureCallout( + win.gBrowser.selectedBrowser, + testMessage.message + ); + ok(!rv, "Feature callout not shown when a panel is open in the same window"); + + await gCUITestUtils.hideMainMenu(); + await BrowserTestUtils.closeWindow(win); +}); + add_task(async function feature_callout_renders_in_browser_chrome_for_pdf() { const sandbox = sinon.createSandbox(); const sendTriggerStub = sandbox.stub(ASRouter, "sendTriggerMessage");