diff --git a/browser/base/content/browser-siteIdentity.js b/browser/base/content/browser-siteIdentity.js index def0375826a3..77b6c61b76fc 100644 --- a/browser/base/content/browser-siteIdentity.js +++ b/browser/base/content/browser-siteIdentity.js @@ -971,7 +971,12 @@ var gIdentityHandler = { "identity-popup-mainView" ); identityPopupPanelView.removeAttribute("footerVisible"); - if (this._uriHasHost && !this._pageExtensionPolicy) { + // Bug 1754172 - Only show the clear site data footer if we're not in private browsing. + if ( + !PrivateBrowsingUtils.isWindowPrivate(window) && + this._uriHasHost && + !this._pageExtensionPolicy + ) { SiteDataManager.hasSiteData(this._uri.asciiHost).then(hasData => { this._clearSiteDataFooter.hidden = !hasData; identityPopupPanelView.setAttribute("footerVisible", hasData); diff --git a/browser/base/content/test/siteIdentity/browser.toml b/browser/base/content/test/siteIdentity/browser.toml index 5a7c083f42d1..dbf7e507a93a 100644 --- a/browser/base/content/test/siteIdentity/browser.toml +++ b/browser/base/content/test/siteIdentity/browser.toml @@ -54,6 +54,9 @@ skip-if = ["os == 'linux' && bits == 64"] # Bug 1577395 ["browser_identityPopup_clearSiteData_extensions.js"] + +["browser_identityPopup_clearSiteData_privateBrowsingMode.js"] + ["browser_identityPopup_custom_roots.js"] https_first_disabled = true diff --git a/browser/base/content/test/siteIdentity/browser_identityPopup_clearSiteData_privateBrowsingMode.js b/browser/base/content/test/siteIdentity/browser_identityPopup_clearSiteData_privateBrowsingMode.js new file mode 100644 index 000000000000..1531d81b2f64 --- /dev/null +++ b/browser/base/content/test/siteIdentity/browser_identityPopup_clearSiteData_privateBrowsingMode.js @@ -0,0 +1,65 @@ +/** + * Test: browser_identityPopup_clearSiteData_privateBrowsingMode.js + * + * This browser-chrome test verifies that the "Clear Site Data" controls + * (button and footer) in the identity popup are correctly hidden in + * private browsing mode. + * + * The test opens a private browsing window, loads a known HTTPS page + * (`https://example.com/`), opens the identity popup via the identity + * icon, and checks for the visibility of: + * + * - `identity-popup-clear-sitedata-footer` + * - `identity-popup-clear-sitedata-button` + * + * Expected behavior: + * These elements should not be visible while in private browsing mode. + * + * The test uses `BrowserTestUtils.withNewTab()` to load the page in a new + * tab within the private window and ensures cleanup of both the tab and + * window after the test completes. + * + */ + +add_task(async function clearSiteDataHidden() { + const TEST_URL = "https://example.com/"; + + // Open a private browsing window + const winPrivate = await BrowserTestUtils.openNewBrowserWindow({ + private: true, + }); + + // Use withNewTab to open a tab in the private window + await BrowserTestUtils.withNewTab( + { + gBrowser: winPrivate.gBrowser, + url: TEST_URL, + }, + async _browser => { + let doc = winPrivate.document; + let { gIdentityHandler } = winPrivate; + + let panelShown = BrowserTestUtils.waitForEvent(doc, "popupshown"); + gIdentityHandler._identityIconBox.click(); + await panelShown; + + let clearFooter = doc.getElementById( + "identity-popup-clear-sitedata-footer" + ); + let clearButton = doc.getElementById( + "identity-popup-clear-sitedata-button" + ); + + Assert.ok( + BrowserTestUtils.isHidden(clearFooter), + "The clear data footer should be hidden in private browsing." + ); + Assert.ok( + BrowserTestUtils.isHidden(clearButton), + "The clear data button should be hidden in private browsing." + ); + } + ); + + await BrowserTestUtils.closeWindow(winPrivate); +});