Bug 1769585: Introduce a pref that the minimum char length to enable adaptive history autofill. r=adw

Differential Revision: https://phabricator.services.mozilla.com/D146654
This commit is contained in:
Daisuke Akatsuka 2022-05-19 05:57:34 +00:00
Родитель 7e24758b24
Коммит 47b4bdd69c
3 изменённых файлов: 82 добавлений и 1 удалений

Просмотреть файл

@ -50,6 +50,9 @@ const PREF_URLBAR_DEFAULTS = new Map([
// Nimbus variable `autoFillAdaptiveHistoryEnabled`.
["autoFill.adaptiveHistory.enabled", false],
// Minimum char length to enable adaptive history autofill.
["autoFill.adaptiveHistory.minCharsThreshold", 0],
// Threshold for use count of input history that we handle as adaptive history
// autofill. If the use count is this value or more, it will be a candidate.
// Set the threshold to not be candidate the input history passed

Просмотреть файл

@ -752,7 +752,11 @@ class ProviderAutofill extends UrlbarProvider {
}
// We try to autofill with adaptive history first.
if (UrlbarPrefs.get("autoFillAdaptiveHistoryEnabled")) {
if (
UrlbarPrefs.get("autoFillAdaptiveHistoryEnabled") &&
UrlbarPrefs.get("autoFill.adaptiveHistory.minCharsThreshold") <=
queryContext.searchString.length
) {
const [query, params] = this._getAdaptiveHistoryQuery(queryContext);
if (query) {
const resultSet = await conn.executeCached(query, params);

Просмотреть файл

@ -745,6 +745,71 @@ const TEST_DATA = [
],
},
},
{
description: "minCharsThreshold pref equals to the user input length",
pref: true,
minCharsThreshold: 3,
visitHistory: ["http://example.com/test"],
inputHistory: [{ uri: "http://example.com/test", input: "exa" }],
userInput: "exa",
expected: {
autofilled: "example.com/test",
completed: "http://example.com/test",
results: [
context =>
makeVisitResult(context, {
uri: "http://example.com/test",
title: "example.com/test",
heuristic: true,
}),
],
},
},
{
description: "minCharsThreshold pref is smaller than the user input length",
pref: true,
minCharsThreshold: 2,
visitHistory: ["http://example.com/test"],
inputHistory: [{ uri: "http://example.com/test", input: "exa" }],
userInput: "exa",
expected: {
autofilled: "example.com/test",
completed: "http://example.com/test",
results: [
context =>
makeVisitResult(context, {
uri: "http://example.com/test",
title: "example.com/test",
heuristic: true,
}),
],
},
},
{
description: "minCharsThreshold pref is larger than the user input length",
pref: true,
minCharsThreshold: 4,
visitHistory: ["http://example.com/test"],
inputHistory: [{ uri: "http://example.com/test", input: "exa" }],
userInput: "exa",
expected: {
autofilled: "example.com/",
completed: "http://example.com/",
results: [
context =>
makeVisitResult(context, {
uri: "http://example.com/",
title: "example.com",
heuristic: true,
}),
context =>
makeVisitResult(context, {
uri: "http://example.com/test",
title: "test visit for http://example.com/test",
}),
],
},
},
{
description: "Turn the pref off",
pref: false,
@ -775,6 +840,7 @@ add_task(async function inputTest() {
for (const {
description,
pref,
minCharsThreshold,
useCountThreshold,
source,
visitHistory,
@ -787,6 +853,13 @@ add_task(async function inputTest() {
UrlbarPrefs.set("autoFill.adaptiveHistory.enabled", pref);
if (!isNaN(minCharsThreshold)) {
UrlbarPrefs.set(
"autoFill.adaptiveHistory.minCharsThreshold",
minCharsThreshold
);
}
if (!isNaN(useCountThreshold)) {
UrlbarPrefs.set(
"autoFill.adaptiveHistory.useCountThreshold",
@ -825,6 +898,7 @@ add_task(async function inputTest() {
await cleanupPlaces();
UrlbarPrefs.clear("autoFill.adaptiveHistory.enabled");
UrlbarPrefs.clear("autoFill.adaptiveHistory.minCharsThreshold");
UrlbarPrefs.clear("autoFill.adaptiveHistory.useCountThreshold");
}
});