зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1717507 - Convert tag tests from unifiedcomplete to urlbar. r=adw
The last few subtests in test_tags_returnedInSearches.js got substantive changes. This is because urlbar tests reflect the results actually shown in the Urlbar and unifiedcomplete tests just tested what came out of UnifiedComplete. Those last few subtests tested that we show non-matching tags. While UnifiedComplete returns those non-matching tags, UrlbarProviderUnifiedComplete has filtered them out since bug 1522226. Differential Revision: https://phabricator.services.mozilla.com/D118635
This commit is contained in:
Родитель
364d97cbe8
Коммит
2897122d92
|
@ -14,12 +14,18 @@
|
|||
* - make sure the url is decoded
|
||||
*/
|
||||
|
||||
testEngine_setup();
|
||||
|
||||
add_task(async function test_tag_match_url() {
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
|
||||
registerCleanupFunction(() => {
|
||||
Services.prefs.clearUserPref("browser.urlbar.suggest.searches");
|
||||
});
|
||||
info(
|
||||
"Make sure tag matches return the right url as well as '+' remain escaped"
|
||||
);
|
||||
let uri1 = NetUtil.newURI("http://escaped/ユニコード");
|
||||
let uri2 = NetUtil.newURI("http://asciiescaped/blocking-firefox3%2B");
|
||||
let uri1 = Services.io.newURI("http://escaped/ユニコード");
|
||||
let uri2 = Services.io.newURI("http://asciiescaped/blocking-firefox3%2B");
|
||||
await PlacesTestUtils.addVisits([
|
||||
{ uri: uri1, title: "title" },
|
||||
{ uri: uri2, title: "title" },
|
||||
|
@ -36,22 +42,25 @@ add_task(async function test_tag_match_url() {
|
|||
tags: ["superTag"],
|
||||
style: ["bookmark-tag"],
|
||||
});
|
||||
await check_autocomplete({
|
||||
search: "superTag",
|
||||
let context = createContext("superTag", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
{
|
||||
uri: uri1,
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
makeBookmarkResult(context, {
|
||||
uri: uri2.spec,
|
||||
title: "title",
|
||||
tags: ["superTag"],
|
||||
style: ["bookmark-tag"],
|
||||
},
|
||||
{
|
||||
uri: uri2,
|
||||
}),
|
||||
makeBookmarkResult(context, {
|
||||
uri: uri1.spec,
|
||||
title: "title",
|
||||
tags: ["superTag"],
|
||||
style: ["bookmark-tag"],
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
await cleanup();
|
||||
await cleanupPlaces();
|
||||
});
|
|
@ -0,0 +1,205 @@
|
|||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||
/* 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/. */
|
||||
|
||||
testEngine_setup();
|
||||
|
||||
/**
|
||||
* Checks the results of a search for `searchTerm`.
|
||||
* @param {array} uris
|
||||
* A 2-element array containing [{string} uri, {array} tags}], where `tags`
|
||||
* is a comma-separated list of the tags expected to appear in the search.
|
||||
* @param {string} searchTerm
|
||||
*/
|
||||
async function ensure_tag_results(uris, searchTerm) {
|
||||
print("Searching for '" + searchTerm + "'");
|
||||
let context = createContext(searchTerm, { isPrivate: false });
|
||||
let urlbarResults = [];
|
||||
for (let [uri, tags] of uris) {
|
||||
urlbarResults.push(
|
||||
makeBookmarkResult(context, {
|
||||
uri,
|
||||
title: "A title",
|
||||
tags,
|
||||
})
|
||||
);
|
||||
}
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
...urlbarResults,
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
var uri1 = "http://site.tld/1/aaa";
|
||||
var uri2 = "http://site.tld/2/bbb";
|
||||
var uri3 = "http://site.tld/3/aaa";
|
||||
var uri4 = "http://site.tld/4/bbb";
|
||||
var uri5 = "http://site.tld/5/aaa";
|
||||
var uri6 = "http://site.tld/6/bbb";
|
||||
|
||||
var tests = [
|
||||
() =>
|
||||
ensure_tag_results(
|
||||
[
|
||||
[uri1, ["foo"]],
|
||||
[uri4, ["foo bar"]],
|
||||
[uri6, ["foo bar cheese"]],
|
||||
],
|
||||
"foo"
|
||||
),
|
||||
() => ensure_tag_results([[uri1, ["foo"]]], "foo aaa"),
|
||||
() =>
|
||||
ensure_tag_results(
|
||||
[
|
||||
[uri4, ["foo bar"]],
|
||||
[uri6, ["foo bar cheese"]],
|
||||
],
|
||||
"foo bbb"
|
||||
),
|
||||
() =>
|
||||
ensure_tag_results(
|
||||
[
|
||||
[uri2, ["bar"]],
|
||||
[uri4, ["foo bar"]],
|
||||
[uri5, ["bar cheese"]],
|
||||
[uri6, ["foo bar cheese"]],
|
||||
],
|
||||
"bar"
|
||||
),
|
||||
() => ensure_tag_results([[uri5, ["bar cheese"]]], "bar aaa"),
|
||||
() =>
|
||||
ensure_tag_results(
|
||||
[
|
||||
[uri2, ["bar"]],
|
||||
[uri4, ["foo bar"]],
|
||||
[uri6, ["foo bar cheese"]],
|
||||
],
|
||||
"bar bbb"
|
||||
),
|
||||
() =>
|
||||
ensure_tag_results(
|
||||
[
|
||||
[uri3, ["cheese"]],
|
||||
[uri5, ["bar cheese"]],
|
||||
[uri6, ["foo bar cheese"]],
|
||||
],
|
||||
"cheese"
|
||||
),
|
||||
() =>
|
||||
ensure_tag_results(
|
||||
[
|
||||
[uri3, ["cheese"]],
|
||||
[uri5, ["bar cheese"]],
|
||||
],
|
||||
"chees aaa"
|
||||
),
|
||||
() => ensure_tag_results([[uri6, ["foo bar cheese"]]], "chees bbb"),
|
||||
() =>
|
||||
ensure_tag_results(
|
||||
[
|
||||
[uri4, ["foo bar"]],
|
||||
[uri6, ["foo bar cheese"]],
|
||||
],
|
||||
"fo bar"
|
||||
),
|
||||
() => ensure_tag_results([], "fo bar aaa"),
|
||||
() =>
|
||||
ensure_tag_results(
|
||||
[
|
||||
[uri4, ["foo bar"]],
|
||||
[uri6, ["foo bar cheese"]],
|
||||
],
|
||||
"fo bar bbb"
|
||||
),
|
||||
() =>
|
||||
ensure_tag_results(
|
||||
[
|
||||
[uri4, ["foo bar"]],
|
||||
[uri6, ["foo bar cheese"]],
|
||||
],
|
||||
"ba foo"
|
||||
),
|
||||
() => ensure_tag_results([], "ba foo aaa"),
|
||||
() =>
|
||||
ensure_tag_results(
|
||||
[
|
||||
[uri4, ["foo bar"]],
|
||||
[uri6, ["foo bar cheese"]],
|
||||
],
|
||||
"ba foo bbb"
|
||||
),
|
||||
() =>
|
||||
ensure_tag_results(
|
||||
[
|
||||
[uri5, ["bar cheese"]],
|
||||
[uri6, ["foo bar cheese"]],
|
||||
],
|
||||
"ba chee"
|
||||
),
|
||||
() => ensure_tag_results([[uri5, ["bar cheese"]]], "ba chee aaa"),
|
||||
() => ensure_tag_results([[uri6, ["foo bar cheese"]]], "ba chee bbb"),
|
||||
() =>
|
||||
ensure_tag_results(
|
||||
[
|
||||
[uri5, ["bar cheese"]],
|
||||
[uri6, ["foo bar cheese"]],
|
||||
],
|
||||
"cheese bar"
|
||||
),
|
||||
() => ensure_tag_results([[uri5, ["bar cheese"]]], "cheese bar aaa"),
|
||||
() => ensure_tag_results([[uri6, ["foo bar cheese"]]], "chees bar bbb"),
|
||||
() => ensure_tag_results([[uri6, ["foo bar cheese"]]], "cheese bar foo"),
|
||||
() => ensure_tag_results([], "foo bar cheese aaa"),
|
||||
() => ensure_tag_results([[uri6, ["foo bar cheese"]]], "foo bar cheese bbb"),
|
||||
];
|
||||
|
||||
/**
|
||||
* Properly tags a uri adding it to bookmarks.
|
||||
*
|
||||
* @param {string} url
|
||||
* The URI to tag.
|
||||
* @param {array} tags
|
||||
* The tags to add.
|
||||
*/
|
||||
async function tagURI(url, tags) {
|
||||
await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
url,
|
||||
title: "A title",
|
||||
});
|
||||
PlacesUtils.tagging.tagURI(Services.io.newURI(url), tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test history autocomplete
|
||||
*/
|
||||
add_task(async function test_history_autocomplete_tags() {
|
||||
// always search in history + bookmarks, no matter what the default is
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.history", true);
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.bookmarks", true);
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
|
||||
registerCleanupFunction(() => {
|
||||
Services.prefs.clearUserPref("browser.urlbar.suggest.history");
|
||||
Services.prefs.clearUserPref("browser.urlbar.suggest.bookmarks");
|
||||
Services.prefs.clearUserPref("browser.urlbar.suggest.searches");
|
||||
});
|
||||
|
||||
await tagURI(uri6, ["foo bar cheese"]);
|
||||
await tagURI(uri5, ["bar cheese"]);
|
||||
await tagURI(uri4, ["foo bar"]);
|
||||
await tagURI(uri3, ["cheese"]);
|
||||
await tagURI(uri2, ["bar"]);
|
||||
await tagURI(uri1, ["foo"]);
|
||||
|
||||
for (let tagTest of tests) {
|
||||
await tagTest();
|
||||
}
|
||||
});
|
|
@ -7,25 +7,36 @@
|
|||
* title instead of the page title.
|
||||
*/
|
||||
|
||||
testEngine_setup();
|
||||
|
||||
add_task(async function test_tag_match_has_bookmark_title() {
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
|
||||
registerCleanupFunction(() => {
|
||||
Services.prefs.clearUserPref("browser.urlbar.suggest.searches");
|
||||
});
|
||||
|
||||
info("Make sure the tag match gives the bookmark title");
|
||||
let uri = NetUtil.newURI("http://theuri/");
|
||||
let uri = Services.io.newURI("http://theuri/");
|
||||
await PlacesTestUtils.addVisits({ uri, title: "Page title" });
|
||||
await PlacesTestUtils.addBookmarkWithDetails({
|
||||
uri,
|
||||
title: "Bookmark title",
|
||||
tags: ["superTag"],
|
||||
});
|
||||
await check_autocomplete({
|
||||
search: "superTag",
|
||||
let context = createContext("superTag", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
{
|
||||
uri,
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
makeBookmarkResult(context, {
|
||||
uri: uri.spec,
|
||||
title: "Bookmark title",
|
||||
tags: ["superTag"],
|
||||
style: ["bookmark-tag"],
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
await cleanup();
|
||||
await cleanupPlaces();
|
||||
});
|
|
@ -0,0 +1,125 @@
|
|||
/* 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 bug 418257 by making sure tags are returned with the title as part of
|
||||
* the "comment" if there are tags even if we didn't match in the tags. They
|
||||
* are separated from the title by a endash.
|
||||
*/
|
||||
|
||||
testEngine_setup();
|
||||
|
||||
add_task(async function test() {
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
|
||||
registerCleanupFunction(() => {
|
||||
Services.prefs.clearUserPref("browser.urlbar.suggest.searches");
|
||||
Services.prefs.clearUserPref("browser.urlbar.autoFill");
|
||||
});
|
||||
|
||||
let uri1 = Services.io.newURI("http://page1");
|
||||
let uri2 = Services.io.newURI("http://page2");
|
||||
let uri3 = Services.io.newURI("http://page3");
|
||||
let uri4 = Services.io.newURI("http://page4");
|
||||
await PlacesTestUtils.addVisits([
|
||||
{ uri: uri1, title: "tagged" },
|
||||
{ uri: uri2, title: "tagged" },
|
||||
{ uri: uri3, title: "tagged" },
|
||||
{ uri: uri4, title: "tagged" },
|
||||
]);
|
||||
await PlacesTestUtils.addBookmarkWithDetails({
|
||||
uri: uri1,
|
||||
title: "tagged",
|
||||
tags: ["tag1"],
|
||||
});
|
||||
await PlacesTestUtils.addBookmarkWithDetails({
|
||||
uri: uri2,
|
||||
title: "tagged",
|
||||
tags: ["tag1", "tag2"],
|
||||
});
|
||||
await PlacesTestUtils.addBookmarkWithDetails({
|
||||
uri: uri3,
|
||||
title: "tagged",
|
||||
tags: ["tag1", "tag3"],
|
||||
});
|
||||
await PlacesTestUtils.addBookmarkWithDetails({
|
||||
uri: uri4,
|
||||
title: "tagged",
|
||||
tags: ["tag1", "tag2", "tag3"],
|
||||
});
|
||||
info("Make sure tags come back in the title when matching tags");
|
||||
let context = createContext("page1 tag", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
makeBookmarkResult(context, {
|
||||
uri: uri1.spec,
|
||||
title: "tagged",
|
||||
tags: ["tag1"],
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
info("Check tags in title for page2");
|
||||
context = createContext("page2 tag", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
makeBookmarkResult(context, {
|
||||
uri: uri2.spec,
|
||||
title: "tagged",
|
||||
tags: ["tag1", "tag2"],
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
info("Tags do not appear when not matching the tag");
|
||||
context = createContext("page3", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
makeBookmarkResult(context, {
|
||||
uri: uri3.spec,
|
||||
title: "tagged",
|
||||
tags: [],
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
info("Extra test just to make sure we match the title");
|
||||
context = createContext("tag2", { isPrivate: true });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
makeBookmarkResult(context, {
|
||||
uri: uri4.spec,
|
||||
title: "tagged",
|
||||
tags: ["tag2"],
|
||||
}),
|
||||
makeBookmarkResult(context, {
|
||||
uri: uri2.spec,
|
||||
title: "tagged",
|
||||
tags: ["tag2"],
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
await cleanupPlaces();
|
||||
});
|
|
@ -47,6 +47,10 @@ skip-if = !sync
|
|||
[test_search_suggestions_aliases.js]
|
||||
[test_search_suggestions_tail.js]
|
||||
[test_suggestedIndex.js]
|
||||
[test_tags_extendedUnicode.js]
|
||||
[test_tags_general.js]
|
||||
[test_tags_matchBookmarkTitles.js]
|
||||
[test_tags_returnedInSearches.js]
|
||||
[test_quicksuggest_keywordtree.js]
|
||||
[test_tokenizer.js]
|
||||
[test_trimming.js]
|
||||
|
|
|
@ -1,112 +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 bug 418257 by making sure tags are returned with the title as part of
|
||||
* the "comment" if there are tags even if we didn't match in the tags. They
|
||||
* are separated from the title by a endash.
|
||||
*/
|
||||
|
||||
add_task(async function test() {
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
|
||||
|
||||
let uri1 = NetUtil.newURI("http://page1");
|
||||
let uri2 = NetUtil.newURI("http://page2");
|
||||
let uri3 = NetUtil.newURI("http://page3");
|
||||
let uri4 = NetUtil.newURI("http://page4");
|
||||
await PlacesTestUtils.addVisits([
|
||||
{ uri: uri1, title: "tagged" },
|
||||
{ uri: uri2, title: "tagged" },
|
||||
{ uri: uri3, title: "tagged" },
|
||||
{ uri: uri4, title: "tagged" },
|
||||
]);
|
||||
await PlacesTestUtils.addBookmarkWithDetails({
|
||||
uri: uri1,
|
||||
title: "tagged",
|
||||
tags: ["tag1"],
|
||||
});
|
||||
await PlacesTestUtils.addBookmarkWithDetails({
|
||||
uri: uri2,
|
||||
title: "tagged",
|
||||
tags: ["tag1", "tag2"],
|
||||
});
|
||||
await PlacesTestUtils.addBookmarkWithDetails({
|
||||
uri: uri3,
|
||||
title: "tagged",
|
||||
tags: ["tag1", "tag3"],
|
||||
});
|
||||
await PlacesTestUtils.addBookmarkWithDetails({
|
||||
uri: uri4,
|
||||
title: "tagged",
|
||||
tags: ["tag1", "tag2", "tag3"],
|
||||
});
|
||||
|
||||
info("Make sure tags come back in the title when matching tags");
|
||||
await check_autocomplete({
|
||||
search: "page1 tag",
|
||||
matches: [
|
||||
{ uri: uri1, title: "tagged", tags: ["tag1"], style: ["bookmark-tag"] },
|
||||
],
|
||||
});
|
||||
|
||||
info("Check tags in title for page2");
|
||||
await check_autocomplete({
|
||||
search: "page2 tag",
|
||||
matches: [
|
||||
{
|
||||
uri: uri2,
|
||||
title: "tagged",
|
||||
tags: ["tag1", "tag2"],
|
||||
style: ["bookmark-tag"],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
info("Make sure tags appear even when not matching the tag");
|
||||
await check_autocomplete({
|
||||
search: "page3",
|
||||
matches: [
|
||||
{
|
||||
uri: uri3,
|
||||
title: "tagged",
|
||||
tags: ["tag1", "tag3"],
|
||||
style: ["bookmark-tag"],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
info("Multiple tags come in commas for page4");
|
||||
await check_autocomplete({
|
||||
search: "page4",
|
||||
matches: [
|
||||
{
|
||||
uri: uri4,
|
||||
title: "tagged",
|
||||
tags: ["tag1", "tag2", "tag3"],
|
||||
style: ["bookmark-tag"],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
info("Extra test just to make sure we match the title");
|
||||
await check_autocomplete({
|
||||
search: "tag2",
|
||||
matches: [
|
||||
{
|
||||
uri: uri2,
|
||||
title: "tagged",
|
||||
tags: ["tag1", "tag2"],
|
||||
style: ["bookmark-tag"],
|
||||
},
|
||||
{
|
||||
uri: uri4,
|
||||
title: "tagged",
|
||||
tags: ["tag1", "tag2", "tag3"],
|
||||
style: ["bookmark-tag"],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await cleanup();
|
||||
});
|
|
@ -1,162 +0,0 @@
|
|||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||
/* 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/. */
|
||||
|
||||
var current_test = 0;
|
||||
|
||||
function AutoCompleteInput(aSearches) {
|
||||
this.searches = aSearches;
|
||||
}
|
||||
AutoCompleteInput.prototype = {
|
||||
constructor: AutoCompleteInput,
|
||||
|
||||
searches: null,
|
||||
|
||||
minResultsForPopup: 0,
|
||||
timeout: 10,
|
||||
searchParam: "",
|
||||
textValue: "",
|
||||
disableAutoComplete: false,
|
||||
completeDefaultIndex: false,
|
||||
|
||||
get searchCount() {
|
||||
return this.searches.length;
|
||||
},
|
||||
|
||||
getSearchAt(aIndex) {
|
||||
return this.searches[aIndex];
|
||||
},
|
||||
|
||||
onSearchBegin() {},
|
||||
onSearchComplete() {},
|
||||
|
||||
popupOpen: false,
|
||||
|
||||
popup: {
|
||||
setSelectedIndex(aIndex) {},
|
||||
invalidate() {},
|
||||
|
||||
// nsISupports implementation
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIAutoCompletePopup"]),
|
||||
},
|
||||
|
||||
// nsISupports implementation
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIAutoCompleteInput"]),
|
||||
};
|
||||
|
||||
async function ensure_tag_results(uris, searchTerm) {
|
||||
print("Searching for '" + searchTerm + "'");
|
||||
var controller = Cc["@mozilla.org/autocomplete/controller;1"].getService(
|
||||
Ci.nsIAutoCompleteController
|
||||
);
|
||||
|
||||
// Make an AutoCompleteInput that uses our searches
|
||||
// and confirms results on search complete
|
||||
var input = new AutoCompleteInput(["unifiedcomplete"]);
|
||||
|
||||
controller.input = input;
|
||||
|
||||
return new Promise(resolve => {
|
||||
var numSearchesStarted = 0;
|
||||
input.onSearchBegin = function() {
|
||||
numSearchesStarted++;
|
||||
Assert.equal(numSearchesStarted, 1);
|
||||
};
|
||||
|
||||
input.onSearchComplete = function() {
|
||||
Assert.equal(numSearchesStarted, 1);
|
||||
Assert.equal(
|
||||
controller.searchStatus,
|
||||
uris.length
|
||||
? Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH
|
||||
: Ci.nsIAutoCompleteController.STATUS_COMPLETE_NO_MATCH
|
||||
);
|
||||
Assert.equal(controller.matchCount, uris.length);
|
||||
let vals = [];
|
||||
for (let i = 0; i < controller.matchCount; i++) {
|
||||
// Keep the URL for later because order of tag results is undefined
|
||||
vals.push(controller.getValueAt(i));
|
||||
Assert.equal(controller.getStyleAt(i), "bookmark-tag");
|
||||
}
|
||||
// Sort the results then check if we have the right items
|
||||
vals.sort().forEach((val, i) => Assert.equal(val, uris[i]));
|
||||
|
||||
resolve();
|
||||
};
|
||||
|
||||
controller.startSearch(searchTerm);
|
||||
});
|
||||
}
|
||||
|
||||
var uri1 = "http://site.tld/1/aaa";
|
||||
var uri2 = "http://site.tld/2/bbb";
|
||||
var uri3 = "http://site.tld/3/aaa";
|
||||
var uri4 = "http://site.tld/4/bbb";
|
||||
var uri5 = "http://site.tld/5/aaa";
|
||||
var uri6 = "http://site.tld/6/bbb";
|
||||
|
||||
var tests = [
|
||||
() => ensure_tag_results([uri1, uri4, uri6], "foo"),
|
||||
() => ensure_tag_results([uri1], "foo aaa"),
|
||||
() => ensure_tag_results([uri4, uri6], "foo bbb"),
|
||||
() => ensure_tag_results([uri2, uri4, uri5, uri6], "bar"),
|
||||
() => ensure_tag_results([uri5], "bar aaa"),
|
||||
() => ensure_tag_results([uri2, uri4, uri6], "bar bbb"),
|
||||
() => ensure_tag_results([uri3, uri5, uri6], "cheese"),
|
||||
() => ensure_tag_results([uri3, uri5], "chees aaa"),
|
||||
() => ensure_tag_results([uri6], "chees bbb"),
|
||||
() => ensure_tag_results([uri4, uri6], "fo bar"),
|
||||
() => ensure_tag_results([], "fo bar aaa"),
|
||||
() => ensure_tag_results([uri4, uri6], "fo bar bbb"),
|
||||
() => ensure_tag_results([uri4, uri6], "ba foo"),
|
||||
() => ensure_tag_results([], "ba foo aaa"),
|
||||
() => ensure_tag_results([uri4, uri6], "ba foo bbb"),
|
||||
() => ensure_tag_results([uri5, uri6], "ba chee"),
|
||||
() => ensure_tag_results([uri5], "ba chee aaa"),
|
||||
() => ensure_tag_results([uri6], "ba chee bbb"),
|
||||
() => ensure_tag_results([uri5, uri6], "cheese bar"),
|
||||
() => ensure_tag_results([uri5], "cheese bar aaa"),
|
||||
() => ensure_tag_results([uri6], "chees bar bbb"),
|
||||
() => ensure_tag_results([uri6], "cheese bar foo"),
|
||||
() => ensure_tag_results([], "foo bar cheese aaa"),
|
||||
() => ensure_tag_results([uri6], "foo bar cheese bbb"),
|
||||
];
|
||||
|
||||
/**
|
||||
* Properly tags a uri adding it to bookmarks.
|
||||
*
|
||||
* @param url
|
||||
* The nsIURI to tag.
|
||||
* @param tags
|
||||
* The tags to add.
|
||||
*/
|
||||
async function tagURI(url, tags) {
|
||||
await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
url,
|
||||
title: "A title",
|
||||
});
|
||||
PlacesUtils.tagging.tagURI(uri(url), tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test history autocomplete
|
||||
*/
|
||||
add_task(async function test_history_autocomplete_tags() {
|
||||
// always search in history + bookmarks, no matter what the default is
|
||||
Services.prefs.setIntPref("browser.urlbar.search.sources", 3);
|
||||
Services.prefs.setIntPref("browser.urlbar.default.behavior", 0);
|
||||
|
||||
await tagURI(uri1, ["foo"]);
|
||||
await tagURI(uri2, ["bar"]);
|
||||
await tagURI(uri3, ["cheese"]);
|
||||
await tagURI(uri4, ["foo bar"]);
|
||||
await tagURI(uri5, ["bar cheese"]);
|
||||
await tagURI(uri6, ["foo bar cheese"]);
|
||||
|
||||
for (let tagTest of tests) {
|
||||
await tagTest();
|
||||
}
|
||||
});
|
|
@ -7,17 +7,13 @@ support-files =
|
|||
data/engine-suggestions.xml
|
||||
!/toolkit/components/places/tests/favicons/favicon-normal16.png
|
||||
|
||||
[test_416211.js]
|
||||
[test_416214.js]
|
||||
[test_417798.js]
|
||||
[test_418257.js]
|
||||
[test_422277.js]
|
||||
[test_autocomplete_stopSearch_no_throw.js]
|
||||
[test_do_not_trim.js]
|
||||
[test_download_embed_bookmarks.js]
|
||||
[test_empty_search.js]
|
||||
[test_escape_self.js]
|
||||
[test_history_autocomplete_tags.js]
|
||||
[test_ignore_protocol.js]
|
||||
[test_multi_word_search.js]
|
||||
[test_search_engine_restyle.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче