Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 3c6a79f

Browse files
author
Daisuke Akatsuka
committed
Bug 1925988: Use bookmark title if no visit_date r=urlbar-reviewers,mak
Differential Revision: https://phabricator.services.mozilla.com/D226829
1 parent 0252976 commit 3c6a79f

File tree

2 files changed

+64
-9
lines changed

2 files changed

+64
-9
lines changed

browser/components/urlbar/UrlbarProviderHistoryUrlHeuristic.sys.mjs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ class ProviderHistoryUrlHeuristic extends UrlbarProvider {
9090
const connection = await lazy.PlacesUtils.promiseLargeCacheDBConnection();
9191
const resultSet = await connection.executeCached(
9292
`
93-
SELECT url, title, frecency
94-
FROM moz_places
93+
SELECT url, IIF(last_visit_date NOTNULL, h.title, b.title) AS _title, frecency
94+
FROM moz_places h
95+
LEFT JOIN moz_bookmarks b ON b.fk = h.id
9596
WHERE
9697
url_hash IN (
9798
hash('https://' || :strippedURL),
@@ -101,11 +102,11 @@ class ProviderHistoryUrlHeuristic extends UrlbarProvider {
101102
)
102103
AND frecency <> 0
103104
ORDER BY
104-
title IS NOT NULL DESC,
105-
title || '/' <> :strippedURL DESC,
106-
url = :inputedURL DESC,
107-
frecency DESC,
108-
id DESC
105+
_title NOTNULL DESC,
106+
_title || '/' <> :strippedURL DESC,
107+
h.url = :inputedURL DESC,
108+
h.frecency DESC,
109+
h.id DESC
109110
LIMIT 1
110111
`,
111112
{ inputedURL, strippedURL }
@@ -115,7 +116,7 @@ class ProviderHistoryUrlHeuristic extends UrlbarProvider {
115116
return null;
116117
}
117118

118-
const title = resultSet[0].getResultByName("title");
119+
const title = resultSet[0].getResultByName("_title");
119120
if (!title) {
120121
return null;
121122
}

browser/components/urlbar/tests/unit/test_providerHistoryUrlHeuristic.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,68 @@
66
// Test for the behavior of UrlbarProviderHistoryUrlHeuristic.
77

88
add_setup(async function () {
9+
Services.prefs.setBoolPref("browser.search.suggest.enabled", false);
910
Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
1011
Services.prefs.setBoolPref("browser.urlbar.suggest.quickactions", false);
11-
registerCleanupFunction(() => {
12+
registerCleanupFunction(async () => {
13+
Services.prefs.clearUserPref("browser.search.suggest.enabled");
1214
Services.prefs.clearUserPref("browser.urlbar.autoFill");
1315
Services.prefs.clearUserPref("browser.urlbar.suggest.quickactions");
16+
await PlacesUtils.history.clear();
17+
await PlacesUtils.bookmarks.eraseEverything();
1418
});
1519
});
1620

21+
add_task(async function test_after_clear_history() {
22+
await PlacesTestUtils.addVisits([
23+
{ uri: "https://example.com/", title: "VISIT" },
24+
]);
25+
await PlacesTestUtils.addBookmarkWithDetails({
26+
uri: "https://example.com/",
27+
title: "BOOKMARK",
28+
});
29+
30+
const before = createContext("example.com", { isPrivate: false });
31+
await check_results({
32+
context: before,
33+
matches: [
34+
makeVisitResult(before, {
35+
uri: "http://example.com/",
36+
title: "VISIT",
37+
iconUri: "page-icon:https://example.com/",
38+
heuristic: true,
39+
providerName: "HistoryUrlHeuristic",
40+
}),
41+
makeBookmarkResult(before, {
42+
uri: "https://example.com/",
43+
title: "BOOKMARK",
44+
}),
45+
],
46+
});
47+
48+
await PlacesUtils.history.clear();
49+
50+
const after = createContext("example.com", { isPrivate: false });
51+
await check_results({
52+
context: after,
53+
matches: [
54+
makeVisitResult(after, {
55+
uri: "http://example.com/",
56+
title: "BOOKMARK",
57+
iconUri: "page-icon:https://example.com/",
58+
heuristic: true,
59+
providerName: "HistoryUrlHeuristic",
60+
}),
61+
makeBookmarkResult(after, {
62+
uri: "https://example.com/",
63+
title: "BOOKMARK",
64+
}),
65+
],
66+
});
67+
68+
await PlacesUtils.bookmarks.eraseEverything();
69+
});
70+
1771
add_task(async function test_basic() {
1872
await PlacesTestUtils.addVisits([
1973
{ uri: "https://example.com/", title: "Example COM" },

0 commit comments

Comments
 (0)