Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android'
- Manifest: browser/components/urlbar/tests/unit/xpcshell.toml
/* Any copyright is dedicated to the Public Domain.
"use strict";
// Test for the behavior of UrlbarProviderHistoryUrlHeuristic.
add_setup(async function () {
Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
Services.prefs.setBoolPref("browser.urlbar.suggest.quickactions", false);
registerCleanupFunction(() => {
Services.prefs.clearUserPref("browser.urlbar.autoFill");
Services.prefs.clearUserPref("browser.urlbar.suggest.quickactions");
});
});
add_task(async function test_basic() {
await PlacesTestUtils.addVisits([
]);
const testCases = [
{
expected: context => [
makeVisitResult(context, {
title: "Example COM",
heuristic: true,
providerName: "HistoryUrlHeuristic",
}),
],
},
{
expected: context => [
makeVisitResult(context, {
title: "Example COM",
heuristic: true,
providerName: "HistoryUrlHeuristic",
}),
],
},
{
expected: context => [
makeVisitResult(context, {
title: "Example COM",
heuristic: true,
providerName: "HistoryUrlHeuristic",
}),
makeVisitResult(context, {
title: "Example COM",
providerName: "Places",
}),
],
},
{
input: "example.com",
expected: context => [
makeVisitResult(context, {
title: "Example COM",
heuristic: true,
providerName: "HistoryUrlHeuristic",
}),
makeVisitResult(context, {
title: "Example COM",
providerName: "Places",
}),
],
},
{
input: "www.example.com",
expected: context => [
makeVisitResult(context, {
title: "Example COM",
heuristic: true,
providerName: "HistoryUrlHeuristic",
}),
],
},
{
input: "htp:example.com",
expected: context => [
makeVisitResult(context, {
title: "Example COM",
heuristic: true,
providerName: "HistoryUrlHeuristic",
}),
],
},
];
for (const { input, expected } of testCases) {
info(`Test with "${input}"`);
const context = createContext(input, { isPrivate: false });
await check_results({
context,
matches: expected(context),
});
}
await PlacesUtils.history.clear();
});
add_task(async function test_null_title() {
await check_results({
context,
matches: [
makeVisitResult(context, {
source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
heuristic: true,
providerName: "HeuristicFallback",
}),
],
});
await PlacesUtils.history.clear();
});
add_task(async function test_over_max_length_text() {
for (; uri.length < UrlbarUtils.MAX_TEXT_LENGTH; ) {
uri += "0123456789";
}
await PlacesTestUtils.addVisits([{ uri, title: "Example MAX" }]);
const context = createContext(uri, { isPrivate: false });
await check_results({
context,
matches: [
makeVisitResult(context, {
source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
uri,
fallbackTitle: uri,
heuristic: true,
providerName: "HeuristicFallback",
}),
],
});
await PlacesUtils.history.clear();
});
add_task(async function test_unsupported_protocol() {
await PlacesTestUtils.addBookmarkWithDetails({
uri: "about:robots",
title: "Robots!",
});
const context = createContext("about:robots", { isPrivate: false });
await check_results({
context,
matches: [
makeVisitResult(context, {
source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
uri: "about:robots",
fallbackTitle: "about:robots",
heuristic: true,
providerName: "HeuristicFallback",
}),
makeBookmarkResult(context, {
uri: "about:robots",
title: "Robots!",
}),
makeVisitResult(context, {
source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
uri: "about:robots",
title: "about:robots",
iconUri: "page-icon:about:robots",
tags: null,
providerName: "AboutPages",
}),
],
});
await PlacesUtils.bookmarks.eraseEverything();
});