summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:53:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:53:14 +0000
commit7300995d7647085f97dc32643f1eefd0c33c6050 (patch)
tree2b891915a578113eb0f08fa04125fa2844c94c12 /browser/components/urlbar
parentAdding upstream version 125.0.2. (diff)
downloadfirefox-7300995d7647085f97dc32643f1eefd0c33c6050.tar.xz
firefox-7300995d7647085f97dc32643f1eefd0c33c6050.zip
Adding upstream version 125.0.3.upstream/125.0.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/urlbar')
-rw-r--r--browser/components/urlbar/UrlbarInput.sys.mjs16
-rw-r--r--browser/components/urlbar/tests/browser/browser_result_menu_general.js117
2 files changed, 91 insertions, 42 deletions
diff --git a/browser/components/urlbar/UrlbarInput.sys.mjs b/browser/components/urlbar/UrlbarInput.sys.mjs
index 6aefd18f9c..96fc7b9301 100644
--- a/browser/components/urlbar/UrlbarInput.sys.mjs
+++ b/browser/components/urlbar/UrlbarInput.sys.mjs
@@ -2766,20 +2766,18 @@ export class UrlbarInput {
return;
}
- let url =
- element.dataset.command == "help"
- ? result.payload.helpUrl
- : element.dataset.url;
+ let url;
+ if (element.dataset.command == "help") {
+ url = result.payload.helpUrl;
+ }
+ url ||= element.dataset.url;
+
if (!url) {
return;
}
let where = this._whereToOpen(event);
- if (
- url &&
- result.type != lazy.UrlbarUtils.RESULT_TYPE.TIP &&
- where == "current"
- ) {
+ if (result.type != lazy.UrlbarUtils.RESULT_TYPE.TIP && where == "current") {
// Open non-tip help links in a new tab unless the user held a modifier.
// TODO (bug 1696232): Do this for tip help links, too.
where = "tab";
diff --git a/browser/components/urlbar/tests/browser/browser_result_menu_general.js b/browser/components/urlbar/tests/browser/browser_result_menu_general.js
index ece48de20a..397ffe0e94 100644
--- a/browser/components/urlbar/tests/browser/browser_result_menu_general.js
+++ b/browser/components/urlbar/tests/browser/browser_result_menu_general.js
@@ -9,6 +9,9 @@
const MAX_RESULTS = UrlbarPrefs.get("maxRichResults");
const RESULT_URL = "https://example.com/test";
const RESULT_HELP_URL = "https://example.com/help";
+const DEFAULT_HELP_URL =
+ Services.urlFormatter.formatURLPref("app.support.baseURL") +
+ "awesome-bar-result-menu";
add_setup(async function () {
// Add enough results to fill up the view.
@@ -21,25 +24,60 @@ add_setup(async function () {
});
});
-// Sets `helpUrl` on a result payload and makes sure the result menu ends up
-// with a help command.
-add_task(async function help() {
- let provider = registerTestProvider(1);
+// Creates a provider that sets `helpUrl` on its result payload. The specified
+// `helpUrl` should be loaded when the result's help menu item is clicked.
+add_task(async function help_resultHelpUrl() {
+ await doHelpTest({
+ provider: registerTestProvider({
+ resultHelpUrl: RESULT_HELP_URL,
+ }),
+ expectedHelpUrl: RESULT_HELP_URL,
+ expectedHelpL10n: { id: "urlbar-result-menu-tip-get-help", args: null },
+ });
+});
+
+// Creates a provider that does not set `helpUrl` on its result payload but
+// instead implements `getResultCommands()` and returns a "help" command. The
+// default help URL should be loaded when the result's help menu item is
+// clicked.
+add_task(async function help_getResultCommands() {
+ let provider = registerTestProvider({
+ resultHelpUrl: null,
+ });
+ let l10n = { id: "urlbar-result-menu-learn-more", args: null };
+ provider.getResultCommands = () => [{ l10n, name: "help" }];
+
+ await doHelpTest({
+ provider,
+ expectedHelpUrl: DEFAULT_HELP_URL,
+ expectedHelpL10n: l10n,
+ });
+});
+
+async function doHelpTest({
+ provider,
+ expectedHelpUrl,
+ expectedHelpL10n,
+ expectedResultIndex = 1,
+}) {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
value: "example",
window,
});
- await assertIsTestResult(1);
+ await assertIsTestResult(expectedResultIndex);
- let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
+ let result = await UrlbarTestUtils.getDetailsOfResultAt(
+ window,
+ expectedResultIndex
+ );
let menuButton = result.element.row._buttons.get("menu");
Assert.ok(menuButton, "Sanity check: menu button should exist");
let menuitem = await UrlbarTestUtils.openResultMenuAndGetItem({
window,
command: "help",
- resultIndex: 1,
+ resultIndex: expectedResultIndex,
openByMouse: true,
});
Assert.ok(menuitem, "Help menu item should exist");
@@ -47,7 +85,7 @@ add_task(async function help() {
let l10nAttrs = document.l10n.getAttributes(menuitem);
Assert.deepEqual(
l10nAttrs,
- { id: "urlbar-result-menu-tip-get-help", args: null },
+ expectedHelpL10n,
"The l10n ID attribute was correctly set"
);
@@ -60,7 +98,7 @@ add_task(async function help() {
let loadPromise = BrowserTestUtils.waitForNewTab(gBrowser);
await UrlbarTestUtils.openResultMenuAndClickItem(window, "help", {
- resultIndex: 1,
+ resultIndex: expectedResultIndex,
openByMouse: true,
});
@@ -69,18 +107,18 @@ add_task(async function help() {
await TestUtils.waitForTick();
Assert.equal(
gBrowser.currentURI.spec,
- RESULT_HELP_URL,
+ expectedHelpUrl,
"The load URL should be the help URL"
);
BrowserTestUtils.removeTab(gBrowser.selectedTab);
UrlbarProvidersManager.unregisterProvider(provider);
-});
+}
// (SHIFT+)TABs through a result with a menu button. The result is the second
// result and has other results after it.
add_task(async function keyboardSelection_secondResult() {
- let provider = registerTestProvider(1);
+ let provider = registerTestProvider();
await UrlbarTestUtils.promiseAutocompleteResultPopup({
value: "example",
window,
@@ -130,7 +168,7 @@ add_task(async function keyboardSelection_secondResult() {
// (SHIFT+)TABs through a result with a help button. The result is the
// last result.
add_task(async function keyboardSelection_lastResult() {
- let provider = registerTestProvider(MAX_RESULTS - 1);
+ let provider = registerTestProvider({ suggestedIndex: MAX_RESULTS - 1 });
await UrlbarTestUtils.promiseAutocompleteResultPopup({
value: "example",
window,
@@ -221,7 +259,7 @@ add_task(async function pick_help_mouse() {
async function doPickTest({ pickHelp, useKeyboard }) {
await BrowserTestUtils.withNewTab("about:blank", async () => {
let index = 1;
- let provider = registerTestProvider(index);
+ let provider = registerTestProvider({ suggestedIndex: index });
await UrlbarTestUtils.promiseAutocompleteResultPopup({
value: "example",
window,
@@ -281,31 +319,44 @@ async function doPickTest({ pickHelp, useKeyboard }) {
}
/**
- * Registers a provider that creates a result with a help URL.
+ * Registers a provider that creates a result optionally with a help URL.
*
- * @param {number} suggestedIndex
+ * @param {object} options
+ * Options object
+ * @param {number} options.suggestedIndex
* The result's suggestedIndex.
+ * @param {string} options.resultHelpUrl
+ * The result's helpUrl. Pass a falsey value to prevent setting a helpUrl.
* @returns {UrlbarProvider}
* The new provider.
*/
-function registerTestProvider(suggestedIndex) {
- let results = [
- Object.assign(
- new UrlbarResult(
- UrlbarUtils.RESULT_TYPE.URL,
- UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
- {
- url: RESULT_URL,
- helpUrl: RESULT_HELP_URL,
- helpL10n: {
- id: "urlbar-result-menu-tip-get-help",
- },
- }
+function registerTestProvider({
+ suggestedIndex = 1,
+ resultHelpUrl = RESULT_HELP_URL,
+} = {}) {
+ let payload = { url: RESULT_URL };
+ if (resultHelpUrl) {
+ payload = {
+ ...payload,
+ helpUrl: resultHelpUrl,
+ helpL10n: {
+ id: "urlbar-result-menu-tip-get-help",
+ },
+ };
+ }
+
+ let provider = new UrlbarTestUtils.TestProvider({
+ results: [
+ Object.assign(
+ new UrlbarResult(
+ UrlbarUtils.RESULT_TYPE.URL,
+ UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
+ payload
+ ),
+ { suggestedIndex }
),
- { suggestedIndex }
- ),
- ];
- let provider = new UrlbarTestUtils.TestProvider({ results });
+ ],
+ });
UrlbarProvidersManager.registerProvider(provider);
return provider;
}