Bug 1960668: Make Unified Search Button unavailable if the page was loaded as background r=tabbrowser-reviewers,daleharvey,dao

Differential Revision: https://phabricator.services.mozilla.com/D245714
This commit is contained in:
Daisuke Akatsuka
2025-05-03 22:14:20 +00:00
committed by dakatsuka.birchill@mozilla.com
parent 199ec844a3
commit 3bda5e2fd3
2 changed files with 59 additions and 0 deletions

View File

@@ -275,6 +275,7 @@ export class UrlbarInput {
this.window.addEventListener("unload", this);
this.window.gBrowser.tabContainer.addEventListener("TabSelect", this);
this.window.gBrowser.addTabsProgressListener(this);
this.window.addEventListener("customizationstarting", this);
this.window.addEventListener("aftercustomization", this);
@@ -666,6 +667,29 @@ export class UrlbarInput {
return uri;
}
/**
* Function for tabs progress listener.
*
* @param {nsIBrowser} browser
* @param {nsIWebProgress} webProgress
* The nsIWebProgress instance that fired the notification.
* @param {nsIRequest} request
* The associated nsIRequest. This may be null in some cases.
* @param {nsIURI} location
* The URI of the location that is being loaded.
*/
onLocationChange(browser, webProgress, request, location) {
if (
webProgress.isTopLevel &&
browser != this.window.gBrowser.selectedBrowser &&
!this.window.isBlankPageURL(location.spec)
) {
// If the page is loaded on background tab, make Unified Search Button
// unavailable when back to the tab.
this.getBrowserState(browser).isUnifiedSearchButtonAvailable = false;
}
}
/**
* Passes DOM events to the _on_<event type> methods.
*

View File

@@ -15,6 +15,41 @@ add_setup(async function setup() {
});
});
add_task(async function test_button_visibility_by_loaded_on_background() {
info("Open valid page that loads slow");
let tab1 = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
opening:
getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"https://www.example.com"
) + "slow-page.sjs",
waitForLoad: false,
});
await assertState(true, "invalid");
info("Open a new tab");
let tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser);
await assertState(true, "invalid");
info("Wait until loading the slow page on background");
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
await new Promise(r => setTimeout(r, 5000));
await TestUtils.waitForCondition(
() =>
!gURLBar.getBrowserState(tab1.linkedBrowser)
.isUnifiedSearchButtonAvailable
);
info("Select the previous tab");
gBrowser.selectedTab = tab1;
await assertState(false, "valid");
info("Clean up");
BrowserTestUtils.removeTab(tab2);
BrowserTestUtils.removeTab(tab1);
});
add_task(async function test_button_visibility_by_pageproxystate() {
info("Open pageproxystate valid page");
let tab = await BrowserTestUtils.openNewForegroundTab(