diff --git a/src/browser/components/urlbar/UrlbarProviderPlaces-sys-mjs.patch b/src/browser/components/urlbar/UrlbarProviderPlaces-sys-mjs.patch new file mode 100644 index 000000000..089a06c19 --- /dev/null +++ b/src/browser/components/urlbar/UrlbarProviderPlaces-sys-mjs.patch @@ -0,0 +1,56 @@ +diff --git a/browser/components/urlbar/UrlbarProviderPlaces.sys.mjs b/browser/components/urlbar/UrlbarProviderPlaces.sys.mjs +index b1481a11ef..925f0dc34b 100644 +--- a/browser/components/urlbar/UrlbarProviderPlaces.sys.mjs ++++ b/browser/components/urlbar/UrlbarProviderPlaces.sys.mjs +@@ -35,6 +35,8 @@ const QUERYINDEX_SWITCHTAB = 9; + const QUERYINDEX_FRECENCY = 10; + const QUERYINDEX_USERCONTEXTID = 11; + const QUERYINDEX_LASTVIST = 12; ++const QUERYINDEX_PINNEDTITLE = 13; ++const QUERYINDEX_PINNEDURL = 14; + + // Constants to support an alternative frecency algorithm. + const PAGES_USE_ALT_FRECENCY = Services.prefs.getBoolPref( +@@ -65,11 +67,14 @@ const SQL_BOOKMARK_TAGS_FRAGMENT = `EXISTS(SELECT 1 FROM moz_bookmarks WHERE fk + // condition once, and avoid evaluating "btitle" and "tags" when it is false. + function defaultQuery(conditions = "") { + let query = `SELECT :query_type, h.url, h.title, ${SQL_BOOKMARK_TAGS_FRAGMENT}, +- h.visit_count, h.typed, h.id, t.open_count, ${PAGES_FRECENCY_FIELD}, t.userContextId, h.last_visit_date ++ h.visit_count, h.typed, h.id, t.open_count, ${PAGES_FRECENCY_FIELD}, t.userContextId, h.last_visit_date, ++ zp.title AS pinned_title, zp.url AS pinned_url + FROM moz_places h + LEFT JOIN moz_openpages_temp t + ON t.url = h.url + AND (t.userContextId = :userContextId OR (t.userContextId <> -1 AND :userContextId IS NULL)) ++ LEFT JOIN zen_pins zp ++ ON zp.url = h.url + WHERE ( + (:switchTabsEnabled AND t.open_count > 0) OR + ${PAGES_FRECENCY_FIELD} <> 0 +@@ -83,7 +88,7 @@ function defaultQuery(conditions = "") { + :matchBehavior, :searchBehavior, NULL) + ELSE + AUTOCOMPLETE_MATCH(:searchString, h.url, +- h.title, '', ++ IFNULL(zp.title, h.title), '', + h.visit_count, h.typed, + 0, t.open_count, + :matchBehavior, :searchBehavior, NULL) +@@ -1132,11 +1137,14 @@ Search.prototype = { + let lastVisit = lastVisitPRTime + ? lazy.PlacesUtils.toDate(lastVisitPRTime).getTime() + : undefined; +- ++ let pinnedTitle = row.getResultByIndex(QUERYINDEX_PINNEDTITLE); ++ let pinnedUrl = row.getResultByIndex(QUERYINDEX_PINNEDURL); ++ ++ + let match = { + placeId, +- value: url, +- comment: bookmarkTitle || historyTitle, ++ value: pinnedUrl || url, ++ comment: pinnedTitle || bookmarkTitle || historyTitle, + icon: UrlbarUtils.getIconForUrl(url), + frecency: frecency || FRECENCY_DEFAULT, + userContextId, diff --git a/src/zen/tests/pinned/browser.toml b/src/zen/tests/pinned/browser.toml index f07d4f83c..399c32ce0 100644 --- a/src/zen/tests/pinned/browser.toml +++ b/src/zen/tests/pinned/browser.toml @@ -4,3 +4,5 @@ ["browser_pinned_removed.js"] ["browser_pinned_reorder_changed_label.js"] ["browser_pinned_reordered.js"] + +["browser_issue_7654.js"] diff --git a/src/zen/tests/pinned/browser_issue_7654.js b/src/zen/tests/pinned/browser_issue_7654.js new file mode 100644 index 000000000..5ac6d2df0 --- /dev/null +++ b/src/zen/tests/pinned/browser_issue_7654.js @@ -0,0 +1,60 @@ +/* Any copyright is dedicated to the Public Domain. + https://creativecommons.org/publicdomain/zero/1.0/ */ + +'use strict'; + +ChromeUtils.defineESModuleGetters(this, { + UrlbarTestUtils: 'resource://testing-common/UrlbarTestUtils.sys.mjs', +}); + +add_task(async function test_Create_Pinned() { + let resolvePromise; + const promise = new Promise((resolve) => { + resolvePromise = resolve; + }); + + const customLabel = 'ZEN ROCKS'; + + await BrowserTestUtils.withNewTab({ gBrowser, url: 'https://example.com/1' }, async (browser) => { + const tab = gBrowser.getTabForBrowser(browser); + tab.addEventListener( + 'ZenPinnedTabCreated', + async function () { + const pinTabID = tab.getAttribute('zen-pin-id'); + ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); + + await gZenPinnedTabManager.updatePinTitle(tab, customLabel, true); + + const pinnedTabs = await ZenPinnedTabsStorage.getPins(); + const pinObject = pinnedTabs.find((pin) => pin.uuid === pinTabID); + Assert.equal(pinObject.title, customLabel, 'The pin object should have the correct title'); + + await BrowserTestUtils.openNewForegroundTab(window.gBrowser, 'https://example.com/2', true); + + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + value: customLabel, + waitForFocus: SimpleTest.waitForFocus, + }); + + const total = UrlbarTestUtils.getResultCount(window); + info(`Found ${total} matches`); + + const result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1); + + const url = result?.url; + Assert.equal( + url, + 'https://example.com/1', + `Should have the found result '${url}' in the expected list of entries` + ); + + BrowserTestUtils.removeTab(gBrowser.selectedTab); + resolvePromise(); + }, + { once: true } + ); + gBrowser.pinTab(tab); + await promise; + }); +});