Bug 1717507 - Convert test_special_search.js. r=adw

Apologies in advance for this review. It's the test I've had to rewrite the most. This is because the unifiedcomplete tests did not care about sorting, and urlbar tests do. Since this test does some complicated stuff with frecency, many of the expected matches had to be reordered in the test. The old test just listed all the uris in descending order in `matches`, paying no mind to frecency. As I've been doing with other tests, I reversed the order which with they are added to history/bookmarks, to reduce the number of changes required in the sets of expected matches.
That yielded this order, in descending order of frecency:
uri11
uri1
uri4
uri6
uri5
uri7
uri8
uri9
uri10
uri12
uri2
uri3

Differential Revision: https://phabricator.services.mozilla.com/D119113
This commit is contained in:
Harry Twyford 2021-07-09 14:23:47 +00:00
Родитель e44cbd69d2
Коммит 90d4eb0eb0
4 изменённых файлов: 540 добавлений и 540 удалений

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

@ -0,0 +1,539 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test for bug 395161 that allows special searches that restrict results to
* history/bookmark/tagged items and title/url matches.
*
* Test 485122 by making sure results don't have tags when restricting result
* to just history either by default behavior or dynamic query restrict.
*/
testEngine_setup();
function setSuggestPrefsToFalse() {
Services.prefs.setBoolPref("browser.urlbar.suggest.history", false);
Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
}
const TRANSITION_TYPED = PlacesUtils.history.TRANSITION_TYPED;
add_task(async function test_special_searches() {
let uri1 = Services.io.newURI("http://url/");
let uri2 = Services.io.newURI("http://url/2");
let uri3 = Services.io.newURI("http://foo.bar/");
let uri4 = Services.io.newURI("http://foo.bar/2");
let uri5 = Services.io.newURI("http://url/star");
let uri6 = Services.io.newURI("http://url/star/2");
let uri7 = Services.io.newURI("http://foo.bar/star");
let uri8 = Services.io.newURI("http://foo.bar/star/2");
let uri9 = Services.io.newURI("http://url/tag");
let uri10 = Services.io.newURI("http://url/tag/2");
let uri11 = Services.io.newURI("http://foo.bar/tag");
let uri12 = Services.io.newURI("http://foo.bar/tag/2");
await PlacesTestUtils.addVisits([
{ uri: uri11, title: "title", transition: TRANSITION_TYPED },
{ uri: uri6, title: "foo.bar" },
{ uri: uri4, title: "foo.bar", transition: TRANSITION_TYPED },
{ uri: uri3, title: "title" },
{ uri: uri2, title: "foo.bar" },
{ uri: uri1, title: "title", transition: TRANSITION_TYPED },
]);
await PlacesTestUtils.addBookmarkWithDetails({
uri: uri12,
title: "foo.bar",
tags: ["foo.bar"],
});
await PlacesTestUtils.addBookmarkWithDetails({
uri: uri11,
title: "title",
tags: ["foo.bar"],
});
await PlacesTestUtils.addBookmarkWithDetails({
uri: uri10,
title: "foo.bar",
tags: ["foo.bar"],
});
await PlacesTestUtils.addBookmarkWithDetails({
uri: uri9,
title: "title",
tags: ["foo.bar"],
});
await PlacesTestUtils.addBookmarkWithDetails({ uri: uri8, title: "foo.bar" });
await PlacesTestUtils.addBookmarkWithDetails({ uri: uri7, title: "title" });
await PlacesTestUtils.addBookmarkWithDetails({ uri: uri6, title: "foo.bar" });
await PlacesTestUtils.addBookmarkWithDetails({ uri: uri5, title: "title" });
// Order of frecency when not restricting, descending:
// uri11
// uri1
// uri4
// uri6
// uri5
// uri7
// uri8
// uri9
// uri10
// uri12
// uri2
// uri3
// Test restricting searches.
info("History restrict");
let context = createContext(UrlbarTokenizer.RESTRICT.HISTORY, {
isPrivate: false,
});
await check_results({
context,
matches: [
makeSearchResult(context, {
engineName: SUGGESTIONS_ENGINE_NAME,
heuristic: true,
}),
makeVisitResult(context, { uri: uri11.spec, title: "title" }),
makeVisitResult(context, { uri: uri1.spec, title: "title" }),
makeVisitResult(context, { uri: uri4.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri6.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri2.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri3.spec, title: "title" }),
],
});
info("Star restrict");
context = createContext(UrlbarTokenizer.RESTRICT.BOOKMARK, {
isPrivate: false,
});
await check_results({
context,
matches: [
makeSearchResult(context, {
engineName: SUGGESTIONS_ENGINE_NAME,
heuristic: true,
}),
makeBookmarkResult(context, {
uri: uri11.spec,
title: "title",
}),
makeBookmarkResult(context, { uri: uri6.spec, title: "foo.bar" }),
makeBookmarkResult(context, { uri: uri5.spec, title: "title" }),
makeBookmarkResult(context, { uri: uri7.spec, title: "title" }),
makeBookmarkResult(context, { uri: uri8.spec, title: "foo.bar" }),
makeBookmarkResult(context, {
uri: uri9.spec,
title: "title",
}),
makeBookmarkResult(context, {
uri: uri10.spec,
title: "foo.bar",
}),
makeBookmarkResult(context, {
uri: uri12.spec,
title: "foo.bar",
}),
],
});
info("Tag restrict");
context = createContext(UrlbarTokenizer.RESTRICT.TAG, { isPrivate: false });
await check_results({
context,
matches: [
makeSearchResult(context, {
engineName: SUGGESTIONS_ENGINE_NAME,
heuristic: true,
}),
makeBookmarkResult(context, {
uri: uri11.spec,
title: "title",
}),
makeBookmarkResult(context, {
uri: uri9.spec,
title: "title",
}),
makeBookmarkResult(context, {
uri: uri10.spec,
title: "foo.bar",
}),
makeBookmarkResult(context, {
uri: uri12.spec,
title: "foo.bar",
}),
],
});
info("Special as first word");
context = createContext(`${UrlbarTokenizer.RESTRICT.HISTORY} foo bar`, {
isPrivate: false,
});
await check_results({
context,
matches: [
makeSearchResult(context, {
query: "foo bar",
alias: UrlbarTokenizer.RESTRICT.HISTORY,
source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
heuristic: true,
}),
makeVisitResult(context, { uri: uri11.spec, title: "title" }),
makeVisitResult(context, { uri: uri4.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri6.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri2.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri3.spec, title: "title" }),
],
});
info("Special as last word");
context = createContext(`foo bar ${UrlbarTokenizer.RESTRICT.HISTORY}`, {
isPrivate: false,
});
await check_results({
context,
matches: [
makeSearchResult(context, {
engineName: SUGGESTIONS_ENGINE_NAME,
heuristic: true,
}),
makeVisitResult(context, { uri: uri11.spec, title: "title" }),
makeVisitResult(context, { uri: uri4.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri6.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri2.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri3.spec, title: "title" }),
],
});
// Test restricting and matching searches with a term.
info(`foo ${UrlbarTokenizer.RESTRICT.HISTORY} -> history`);
context = createContext(`foo ${UrlbarTokenizer.RESTRICT.HISTORY}`, {
isPrivate: false,
});
await check_results({
context,
matches: [
makeSearchResult(context, {
engineName: SUGGESTIONS_ENGINE_NAME,
heuristic: true,
}),
makeVisitResult(context, { uri: uri11.spec, title: "title" }),
makeVisitResult(context, { uri: uri4.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri6.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri2.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri3.spec, title: "title" }),
],
});
info(`foo ${UrlbarTokenizer.RESTRICT.BOOKMARK} -> is star`);
context = createContext(`foo ${UrlbarTokenizer.RESTRICT.BOOKMARK}`, {
isPrivate: false,
});
await check_results({
context,
matches: [
makeSearchResult(context, {
engineName: SUGGESTIONS_ENGINE_NAME,
heuristic: true,
}),
makeBookmarkResult(context, {
uri: uri11.spec,
title: "title",
tags: ["foo.bar"],
}),
makeBookmarkResult(context, { uri: uri6.spec, title: "foo.bar" }),
makeBookmarkResult(context, { uri: uri7.spec, title: "title" }),
makeBookmarkResult(context, { uri: uri8.spec, title: "foo.bar" }),
makeBookmarkResult(context, {
uri: uri9.spec,
title: "title",
tags: ["foo.bar"],
}),
makeBookmarkResult(context, {
uri: uri10.spec,
title: "foo.bar",
tags: ["foo.bar"],
}),
makeBookmarkResult(context, {
uri: uri12.spec,
title: "foo.bar",
tags: ["foo.bar"],
}),
],
});
info(`foo ${UrlbarTokenizer.RESTRICT.TITLE} -> in title`);
context = createContext(`foo ${UrlbarTokenizer.RESTRICT.TITLE}`, {
isPrivate: false,
});
await check_results({
context,
matches: [
makeSearchResult(context, {
engineName: SUGGESTIONS_ENGINE_NAME,
heuristic: true,
}),
makeVisitResult(context, { uri: uri11.spec, title: "title" }),
makeVisitResult(context, { uri: uri4.spec, title: "foo.bar" }),
makeBookmarkResult(context, { uri: uri6.spec, title: "foo.bar" }),
makeBookmarkResult(context, { uri: uri8.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri9.spec, title: "title" }),
makeVisitResult(context, { uri: uri10.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri12.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri2.spec, title: "foo.bar" }),
],
});
info(`foo ${UrlbarTokenizer.RESTRICT.URL} -> in url`);
context = createContext(`foo ${UrlbarTokenizer.RESTRICT.URL}`, {
isPrivate: false,
});
await check_results({
context,
matches: [
makeSearchResult(context, {
engineName: SUGGESTIONS_ENGINE_NAME,
heuristic: true,
}),
makeVisitResult(context, { uri: uri11.spec, title: "title" }),
makeVisitResult(context, { uri: uri4.spec, title: "foo.bar" }),
makeBookmarkResult(context, { uri: uri7.spec, title: "title" }),
makeBookmarkResult(context, { uri: uri8.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri12.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri3.spec, title: "title" }),
],
});
info(`foo ${UrlbarTokenizer.RESTRICT.TAG} -> is tag`);
context = createContext(`foo ${UrlbarTokenizer.RESTRICT.TAG}`, {
isPrivate: false,
});
await check_results({
context,
matches: [
makeSearchResult(context, {
engineName: SUGGESTIONS_ENGINE_NAME,
heuristic: true,
}),
makeBookmarkResult(context, {
uri: uri11.spec,
title: "title",
tags: ["foo.bar"],
}),
makeBookmarkResult(context, {
uri: uri9.spec,
title: "title",
tags: ["foo.bar"],
}),
makeBookmarkResult(context, {
uri: uri10.spec,
title: "foo.bar",
tags: ["foo.bar"],
}),
makeBookmarkResult(context, {
uri: uri12.spec,
title: "foo.bar",
tags: ["foo.bar"],
}),
],
});
// Test conflicting restrictions.
info(
`conflict ${UrlbarTokenizer.RESTRICT.TITLE} ${UrlbarTokenizer.RESTRICT.URL} -> url wins`
);
await PlacesTestUtils.addVisits([
{
uri: `http://conflict.com/${UrlbarTokenizer.RESTRICT.TITLE}`,
title: "test",
},
{
uri: "http://conflict.com/",
title: `test${UrlbarTokenizer.RESTRICT.TITLE}`,
},
]);
context = createContext(
`conflict ${UrlbarTokenizer.RESTRICT.TITLE} ${UrlbarTokenizer.RESTRICT.URL}`,
{ isPrivate: false }
);
await check_results({
context,
matches: [
makeSearchResult(context, {
engineName: SUGGESTIONS_ENGINE_NAME,
heuristic: true,
}),
makeVisitResult(context, {
uri: `http://conflict.com/${UrlbarTokenizer.RESTRICT.TITLE}`,
title: "test",
}),
],
});
info(
`conflict ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.BOOKMARK} -> bookmark wins`
);
await PlacesTestUtils.addBookmarkWithDetails({
uri: "http://bookmark.conflict.com/",
title: `conflict ${UrlbarTokenizer.RESTRICT.HISTORY}`,
});
context = createContext(
`conflict ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.BOOKMARK}`,
{ isPrivate: false }
);
await check_results({
context,
matches: [
makeSearchResult(context, {
engineName: SUGGESTIONS_ENGINE_NAME,
heuristic: true,
}),
makeBookmarkResult(context, {
uri: "http://bookmark.conflict.com/",
title: `conflict ${UrlbarTokenizer.RESTRICT.HISTORY}`,
}),
],
});
info(
`conflict ${UrlbarTokenizer.RESTRICT.BOOKMARK} ${UrlbarTokenizer.RESTRICT.TAG} -> tag wins`
);
await PlacesTestUtils.addBookmarkWithDetails({
uri: "http://tag.conflict.com/",
title: `conflict ${UrlbarTokenizer.RESTRICT.BOOKMARK}`,
tags: ["one"],
});
await PlacesTestUtils.addBookmarkWithDetails({
uri: "http://nontag.conflict.com/",
title: `conflict ${UrlbarTokenizer.RESTRICT.BOOKMARK}`,
});
context = createContext(
`conflict ${UrlbarTokenizer.RESTRICT.BOOKMARK} ${UrlbarTokenizer.RESTRICT.TAG}`,
{ isPrivate: false }
);
await check_results({
context,
matches: [
makeSearchResult(context, {
engineName: SUGGESTIONS_ENGINE_NAME,
heuristic: true,
}),
makeBookmarkResult(context, {
uri: "http://tag.conflict.com/",
title: `conflict ${UrlbarTokenizer.RESTRICT.BOOKMARK}`,
}),
],
});
// Disable autoFill for the next tests, see test_autoFill_default_behavior.js
// for specific tests.
Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
// Test default usage by setting certain browser.urlbar.suggest.* prefs
info("foo -> default history");
setSuggestPrefsToFalse();
Services.prefs.setBoolPref("browser.urlbar.suggest.history", true);
context = createContext("foo", { isPrivate: false });
await check_results({
context,
matches: [
makeSearchResult(context, {
engineName: SUGGESTIONS_ENGINE_NAME,
heuristic: true,
}),
makeVisitResult(context, { uri: uri11.spec, title: "title" }),
makeVisitResult(context, { uri: uri4.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri6.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri2.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri3.spec, title: "title" }),
],
});
info("foo -> default history, is star");
setSuggestPrefsToFalse();
Services.prefs.setBoolPref("browser.urlbar.suggest.history", true);
Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", true);
// The purpose of this test is to verify what is being sent by UnifiedComplete.
// It will send 10 results, but the heuristic result pushes the last result
// out of the panel. We set maxRichResults to a high value to test the full
// output of UnifiedComplete.
Services.prefs.setIntPref("browser.urlbar.maxRichResults", 20);
context = createContext("foo", { isPrivate: false });
await check_results({
context,
matches: [
makeSearchResult(context, {
engineName: SUGGESTIONS_ENGINE_NAME,
heuristic: true,
}),
makeBookmarkResult(context, {
uri: uri11.spec,
title: "title",
tags: ["foo.bar"],
}),
makeVisitResult(context, { uri: uri4.spec, title: "foo.bar" }),
makeBookmarkResult(context, { uri: uri6.spec, title: "foo.bar" }),
makeBookmarkResult(context, { uri: uri7.spec, title: "title" }),
makeBookmarkResult(context, { uri: uri8.spec, title: "foo.bar" }),
makeBookmarkResult(context, {
uri: uri9.spec,
title: "title",
tags: ["foo.bar"],
}),
makeBookmarkResult(context, {
uri: uri10.spec,
title: "foo.bar",
tags: ["foo.bar"],
}),
makeBookmarkResult(context, {
uri: uri12.spec,
title: "foo.bar",
tags: ["foo.bar"],
}),
makeVisitResult(context, { uri: uri2.spec, title: "foo.bar" }),
makeVisitResult(context, { uri: uri3.spec, title: "title" }),
],
});
Services.prefs.clearUserPref("browser.urlbar.maxRichResults");
info("foo -> is star");
setSuggestPrefsToFalse();
Services.prefs.setBoolPref("browser.urlbar.suggest.history", false);
Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", true);
context = createContext("foo", { isPrivate: false });
await check_results({
context,
matches: [
makeSearchResult(context, {
engineName: SUGGESTIONS_ENGINE_NAME,
heuristic: true,
}),
makeBookmarkResult(context, {
uri: uri11.spec,
title: "title",
tags: ["foo.bar"],
}),
makeBookmarkResult(context, { uri: uri6.spec, title: "foo.bar" }),
makeBookmarkResult(context, { uri: uri7.spec, title: "title" }),
makeBookmarkResult(context, { uri: uri8.spec, title: "foo.bar" }),
makeBookmarkResult(context, {
uri: uri9.spec,
title: "title",
tags: ["foo.bar"],
}),
makeBookmarkResult(context, {
uri: uri10.spec,
title: "foo.bar",
tags: ["foo.bar"],
}),
makeBookmarkResult(context, {
uri: uri12.spec,
title: "foo.bar",
tags: ["foo.bar"],
}),
],
});
await cleanupPlaces();
});

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

@ -56,6 +56,7 @@ skip-if = !sync
[test_search_suggestions.js]
[test_search_suggestions_aliases.js]
[test_search_suggestions_tail.js]
[test_special_search.js]
[test_suggestedIndex.js]
[test_tab_matches.js]
[test_tags_extendedUnicode.js]

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

@ -1,539 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test for bug 395161 that allows special searches that restrict results to
* history/bookmark/tagged items and title/url matches.
*
* Test 485122 by making sure results don't have tags when restricting result
* to just history either by default behavior or dynamic query restrict.
*/
function setSuggestPrefsToFalse() {
Services.prefs.setBoolPref("browser.urlbar.suggest.history", false);
Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
}
add_task(async function test_special_searches() {
let uri1 = NetUtil.newURI("http://url/");
let uri2 = NetUtil.newURI("http://url/2");
let uri3 = NetUtil.newURI("http://foo.bar/");
let uri4 = NetUtil.newURI("http://foo.bar/2");
let uri5 = NetUtil.newURI("http://url/star");
let uri6 = NetUtil.newURI("http://url/star/2");
let uri7 = NetUtil.newURI("http://foo.bar/star");
let uri8 = NetUtil.newURI("http://foo.bar/star/2");
let uri9 = NetUtil.newURI("http://url/tag");
let uri10 = NetUtil.newURI("http://url/tag/2");
let uri11 = NetUtil.newURI("http://foo.bar/tag");
let uri12 = NetUtil.newURI("http://foo.bar/tag/2");
await PlacesTestUtils.addVisits([
{ uri: uri1, title: "title", transition: TRANSITION_TYPED },
{ uri: uri2, title: "foo.bar" },
{ uri: uri3, title: "title" },
{ uri: uri4, title: "foo.bar", transition: TRANSITION_TYPED },
{ uri: uri6, title: "foo.bar" },
{ uri: uri11, title: "title", transition: TRANSITION_TYPED },
]);
await PlacesTestUtils.addBookmarkWithDetails({ uri: uri5, title: "title" });
await PlacesTestUtils.addBookmarkWithDetails({ uri: uri6, title: "foo.bar" });
await PlacesTestUtils.addBookmarkWithDetails({ uri: uri7, title: "title" });
await PlacesTestUtils.addBookmarkWithDetails({ uri: uri8, title: "foo.bar" });
await PlacesTestUtils.addBookmarkWithDetails({
uri: uri9,
title: "title",
tags: ["foo.bar"],
});
await PlacesTestUtils.addBookmarkWithDetails({
uri: uri10,
title: "foo.bar",
tags: ["foo.bar"],
});
await PlacesTestUtils.addBookmarkWithDetails({
uri: uri11,
title: "title",
tags: ["foo.bar"],
});
await PlacesTestUtils.addBookmarkWithDetails({
uri: uri12,
title: "foo.bar",
tags: ["foo.bar"],
});
// Test restricting searches.
info("History restrict");
await check_autocomplete({
search: UrlbarTokenizer.RESTRICT.HISTORY,
matches: [
{ uri: uri1, title: "title" },
{ uri: uri2, title: "foo.bar" },
{ uri: uri3, title: "title" },
{ uri: uri4, title: "foo.bar" },
{ uri: uri6, title: "foo.bar" },
{ uri: uri11, title: "title", tags: ["foo.bar"], style: ["tag"] },
],
});
info("Star restrict");
await check_autocomplete({
search: UrlbarTokenizer.RESTRICT.BOOKMARK,
matches: [
{ uri: uri5, title: "title", style: ["bookmark"] },
{ uri: uri6, title: "foo.bar", style: ["bookmark"] },
{ uri: uri7, title: "title", style: ["bookmark"] },
{ uri: uri8, title: "foo.bar", style: ["bookmark"] },
{ uri: uri9, title: "title", tags: ["foo.bar"], style: ["bookmark-tag"] },
{
uri: uri10,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri11,
title: "title",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri12,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
],
});
info("Tag restrict");
await check_autocomplete({
search: UrlbarTokenizer.RESTRICT.TAG,
matches: [
{ uri: uri9, title: "title", tags: ["foo.bar"], style: ["bookmark-tag"] },
{
uri: uri10,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri11,
title: "title",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri12,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
],
});
info("Special as first word");
await check_autocomplete({
search: `${UrlbarTokenizer.RESTRICT.HISTORY} foo bar`,
matches: [
{ uri: uri2, title: "foo.bar" },
{ uri: uri3, title: "title" },
{ uri: uri4, title: "foo.bar" },
{ uri: uri6, title: "foo.bar" },
{ uri: uri11, title: "title", tags: ["foo.bar"], style: ["tag"] },
],
});
info("Special as last word");
await check_autocomplete({
search: `foo bar ${UrlbarTokenizer.RESTRICT.HISTORY}`,
matches: [
{ uri: uri2, title: "foo.bar" },
{ uri: uri3, title: "title" },
{ uri: uri4, title: "foo.bar" },
{ uri: uri6, title: "foo.bar" },
{ uri: uri11, title: "title", tags: ["foo.bar"], style: ["tag"] },
],
});
// Test restricting and matching searches with a term.
info(`foo ${UrlbarTokenizer.RESTRICT.HISTORY} -> history`);
await check_autocomplete({
search: `foo ${UrlbarTokenizer.RESTRICT.HISTORY}`,
matches: [
{ uri: uri2, title: "foo.bar" },
{ uri: uri3, title: "title" },
{ uri: uri4, title: "foo.bar" },
{ uri: uri6, title: "foo.bar" },
{ uri: uri11, title: "title", tags: ["foo.bar"], style: ["tag"] },
],
});
info(`foo ${UrlbarTokenizer.RESTRICT.BOOKMARK} -> is star`);
await check_autocomplete({
search: `foo ${UrlbarTokenizer.RESTRICT.BOOKMARK}`,
matches: [
{ uri: uri6, title: "foo.bar", style: ["bookmark"] },
{ uri: uri7, title: "title", style: ["bookmark"] },
{ uri: uri8, title: "foo.bar", style: ["bookmark"] },
{ uri: uri9, title: "title", tags: ["foo.bar"], style: ["bookmark-tag"] },
{
uri: uri10,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri11,
title: "title",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri12,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
],
});
info(`foo ${UrlbarTokenizer.RESTRICT.TITLE} -> in title`);
await check_autocomplete({
search: `foo ${UrlbarTokenizer.RESTRICT.TITLE}`,
matches: [
{ uri: uri2, title: "foo.bar" },
{ uri: uri4, title: "foo.bar" },
{ uri: uri6, title: "foo.bar", style: ["bookmark"] },
{ uri: uri8, title: "foo.bar", style: ["bookmark"] },
{ uri: uri9, title: "title", tags: ["foo.bar"], style: ["tag"] },
{ uri: uri10, title: "foo.bar", tags: ["foo.bar"], style: ["tag"] },
{ uri: uri11, title: "title", tags: ["foo.bar"], style: ["tag"] },
{ uri: uri12, title: "foo.bar", tags: ["foo.bar"], style: ["tag"] },
],
});
info(`foo ${UrlbarTokenizer.RESTRICT.URL} -> in url`);
await check_autocomplete({
search: `foo ${UrlbarTokenizer.RESTRICT.URL}`,
matches: [
{ uri: uri3, title: "title" },
{ uri: uri4, title: "foo.bar" },
{ uri: uri7, title: "title", style: ["bookmark"] },
{ uri: uri8, title: "foo.bar", style: ["bookmark"] },
{ uri: uri11, title: "title", tags: ["foo.bar"], style: ["tag"] },
{ uri: uri12, title: "foo.bar", tags: ["foo.bar"], style: ["tag"] },
],
});
info(`foo ${UrlbarTokenizer.RESTRICT.TAG} -> is tag`);
await check_autocomplete({
search: `foo ${UrlbarTokenizer.RESTRICT.TAG}`,
matches: [
{ uri: uri9, title: "title", tags: ["foo.bar"], style: ["bookmark-tag"] },
{
uri: uri10,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri11,
title: "title",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri12,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
],
});
// Test various pairs of special searches
info(
`foo ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.TITLE} -> history, in title`
);
await check_autocomplete({
search: `foo ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.TITLE}`,
matches: [
{ uri: uri2, title: "foo.bar" },
{ uri: uri4, title: "foo.bar" },
{ uri: uri6, title: "foo.bar" },
{ uri: uri11, title: "title", tags: ["foo.bar"], style: ["tag"] },
],
});
info(
`foo ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.URL} -> history, in url`
);
await check_autocomplete({
search: `foo ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.URL}`,
matches: [
{ uri: uri3, title: "title" },
{ uri: uri4, title: "foo.bar" },
{ uri: uri11, title: "title", tags: ["foo.bar"], style: ["tag"] },
],
});
info(
`foo ${UrlbarTokenizer.RESTRICT.BOOKMARK} ${UrlbarTokenizer.RESTRICT.TITLE} -> is star, in title`
);
await check_autocomplete({
search: `foo ${UrlbarTokenizer.RESTRICT.BOOKMARK} ${UrlbarTokenizer.RESTRICT.TITLE}`,
matches: [
{ uri: uri6, title: "foo.bar", style: ["bookmark"] },
{ uri: uri8, title: "foo.bar", style: ["bookmark"] },
{ uri: uri9, title: "title", tags: ["foo.bar"], style: ["bookmark-tag"] },
{
uri: uri10,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri11,
title: "title",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri12,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
],
});
info(
`foo ${UrlbarTokenizer.RESTRICT.BOOKMARK} ${UrlbarTokenizer.RESTRICT.URL} -> is star, in url`
);
await check_autocomplete({
search: `foo ${UrlbarTokenizer.RESTRICT.BOOKMARK} ${UrlbarTokenizer.RESTRICT.URL}`,
matches: [
{ uri: uri7, title: "title", style: ["bookmark"] },
{ uri: uri8, title: "foo.bar", style: ["bookmark"] },
{
uri: uri11,
title: "title",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri12,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
],
});
info(
`foo ${UrlbarTokenizer.RESTRICT.TITLE} ${UrlbarTokenizer.RESTRICT.TAG} -> in title, is tag`
);
await check_autocomplete({
search: `foo ${UrlbarTokenizer.RESTRICT.TITLE} ${UrlbarTokenizer.RESTRICT.TAG}`,
matches: [
{ uri: uri9, title: "title", tags: ["foo.bar"], style: ["bookmark-tag"] },
{
uri: uri10,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri11,
title: "title",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri12,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
],
});
info(
`foo ${UrlbarTokenizer.RESTRICT.URL} ${UrlbarTokenizer.RESTRICT.TAG} -> in url, is tag`
);
await check_autocomplete({
search: `foo ${UrlbarTokenizer.RESTRICT.URL} ${UrlbarTokenizer.RESTRICT.TAG}`,
matches: [
{
uri: uri11,
title: "title",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri12,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
],
});
// Test conflicting restrictions.
info(
`conflict ${UrlbarTokenizer.RESTRICT.TITLE} ${UrlbarTokenizer.RESTRICT.URL} -> url wins`
);
await PlacesTestUtils.addVisits([
{
uri: `http://conflict.com/${UrlbarTokenizer.RESTRICT.TITLE}`,
title: "test",
},
{
uri: "http://conflict.com/",
title: `test${UrlbarTokenizer.RESTRICT.TITLE}`,
},
]);
await check_autocomplete({
search: `conflict ${UrlbarTokenizer.RESTRICT.TITLE} ${UrlbarTokenizer.RESTRICT.URL}`,
matches: [
{
uri: `http://conflict.com/${UrlbarTokenizer.RESTRICT.TITLE}`,
title: "test",
},
],
});
info(
`conflict ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.BOOKMARK} -> bookmark wins`
);
await PlacesTestUtils.addBookmarkWithDetails({
uri: "http://bookmark.conflict.com/",
title: `conflict ${UrlbarTokenizer.RESTRICT.HISTORY}`,
});
await check_autocomplete({
search: `conflict ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.BOOKMARK}`,
matches: [
{
uri: "http://bookmark.conflict.com/",
title: `conflict ${UrlbarTokenizer.RESTRICT.HISTORY}`,
style: ["bookmark"],
},
],
});
info(
`conflict ${UrlbarTokenizer.RESTRICT.BOOKMARK} ${UrlbarTokenizer.RESTRICT.TAG} -> tag wins`
);
await PlacesTestUtils.addBookmarkWithDetails({
uri: "http://tag.conflict.com/",
title: `conflict ${UrlbarTokenizer.RESTRICT.BOOKMARK}`,
tags: ["one"],
});
await PlacesTestUtils.addBookmarkWithDetails({
uri: "http://nontag.conflict.com/",
title: `conflict ${UrlbarTokenizer.RESTRICT.BOOKMARK}`,
});
await check_autocomplete({
search: `conflict ${UrlbarTokenizer.RESTRICT.BOOKMARK} ${UrlbarTokenizer.RESTRICT.TAG}`,
matches: [
{
uri: "http://tag.conflict.com/",
title: `conflict ${UrlbarTokenizer.RESTRICT.BOOKMARK}`,
tags: ["one"],
style: ["bookmark-tag"],
},
],
});
// Disable autoFill for the next tests, see test_autoFill_default_behavior.js
// for specific tests.
Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
// Test default usage by setting certain browser.urlbar.suggest.* prefs
info("foo -> default history");
setSuggestPrefsToFalse();
Services.prefs.setBoolPref("browser.urlbar.suggest.history", true);
await check_autocomplete({
search: "foo",
matches: [
{ uri: uri2, title: "foo.bar" },
{ uri: uri3, title: "title" },
{ uri: uri4, title: "foo.bar" },
{ uri: uri6, title: "foo.bar" },
{ uri: uri11, title: "title", tags: ["foo.bar"], style: ["tag"] },
],
});
info("foo -> default history, is star");
setSuggestPrefsToFalse();
Services.prefs.setBoolPref("browser.urlbar.suggest.history", true);
Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", true);
await check_autocomplete({
search: "foo",
matches: [
{ uri: uri2, title: "foo.bar" },
{ uri: uri3, title: "title" },
{ uri: uri4, title: "foo.bar" },
{ uri: uri6, title: "foo.bar", style: ["bookmark"] },
{ uri: uri7, title: "title", style: ["bookmark"] },
{ uri: uri8, title: "foo.bar", style: ["bookmark"] },
{ uri: uri9, title: "title", tags: ["foo.bar"], style: ["bookmark-tag"] },
{
uri: uri10,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri11,
title: "title",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri12,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
],
});
info("foo -> is star");
setSuggestPrefsToFalse();
Services.prefs.setBoolPref("browser.urlbar.suggest.history", false);
Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", true);
await check_autocomplete({
search: "foo",
matches: [
{ uri: uri6, title: "foo.bar", style: ["bookmark"] },
{ uri: uri7, title: "title", style: ["bookmark"] },
{ uri: uri8, title: "foo.bar", style: ["bookmark"] },
{ uri: uri9, title: "title", tags: ["foo.bar"], style: ["bookmark-tag"] },
{
uri: uri10,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri11,
title: "title",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
{
uri: uri12,
title: "foo.bar",
tags: ["foo.bar"],
style: ["bookmark-tag"],
},
],
});
await cleanup();
});

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

@ -8,4 +8,3 @@ support-files =
!/toolkit/components/places/tests/favicons/favicon-normal16.png
[test_autocomplete_stopSearch_no_throw.js]
[test_special_search.js]