commit 6845ecc07ce88c673f7efaeefbf6ab6555488d15
parent 96eb60d7079bcf61327083f398c06a28de07b013
Author: Tooru Fujisawa <arai_a@mac.com>
Date: Tue, 28 Oct 2025 15:36:47 +0000
Bug 1996056 - Properly handle not-yet-loaded tab in the "Ask an AI Chatbot" menu handling. r=Mardak,firefox-ai-ml-reviewers,yjamora
Differential Revision: https://phabricator.services.mozilla.com/D270196
Diffstat:
2 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/browser/components/genai/GenAI.sys.mjs b/browser/components/genai/GenAI.sys.mjs
@@ -673,8 +673,8 @@ export const GenAI = {
} = contextMenu;
// DO NOT show menu when inside an extension panel
- const uri = browser.browsingContext.currentURI.spec;
- if (uri.startsWith("moz-extension:")) {
+ const uri = browser.browsingContext?.currentURI.spec;
+ if (uri?.startsWith("moz-extension:")) {
showItem(menu, false);
return;
}
diff --git a/browser/components/genai/tests/browser/browser_chat_page.js b/browser/components/genai/tests/browser/browser_chat_page.js
@@ -69,6 +69,7 @@ async function runContextMenuTest({
menuId,
targetId,
expectedLabel,
+ expectedDisabled = false,
expectedDescription,
stub,
browser,
@@ -84,14 +85,17 @@ async function runContextMenuTest({
return menuItems[0]?.label === expectedLabel;
}, expectedDescription);
- menuItems[0].click();
+ if (expectedDisabled) {
+ Assert.ok(menuItems[0].disabled, "Menu item is disabled");
+ } else {
+ menuItems[0].click();
+ }
await hideContextMenu(menuId);
if (stub) {
assertContextMenuStubResult(stub);
+ stub.resetHistory();
}
-
- stub.resetHistory();
}
function assertContextMenuStubResult(stub) {
@@ -658,3 +662,36 @@ add_task(async function test_show_warning_when_text_is_long() {
}
);
});
+
+add_task(async function test_tab_menu_on_unloaded() {
+ const sandbox = sinon.createSandbox();
+ await SpecialPowers.pushPrefEnv({
+ set: [["browser.ml.chat.provider", "http://localhost:8080"]],
+ });
+
+ const tab1 = await BrowserTestUtils.openNewForegroundTab(
+ gBrowser,
+ "https://example.com"
+ );
+
+ const tab2 = await BrowserTestUtils.openNewForegroundTab(
+ gBrowser,
+ "https://example.com"
+ );
+
+ await gBrowser.explicitUnloadTabs([tab1]);
+
+ await runContextMenuTest({
+ menuId: TAB_CONTEXT_MENU,
+ targetId: "context_askChat",
+ expectedLabel: "Summarize Page",
+ expectedDescription: "Page prompt added",
+ expectedDisabled: true,
+ browser: tab1.linkedBrowser,
+ });
+
+ BrowserTestUtils.removeTab(tab1);
+ BrowserTestUtils.removeTab(tab2);
+
+ sandbox.restore();
+});