зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1717507 - Convert tests bound to a legacy instance of unifiedcomplete. r=adw
Differential Revision: https://phabricator.services.mozilla.com/D119429
This commit is contained in:
Родитель
90d4eb0eb0
Коммит
199dfc1b74
|
@ -1,5 +1,3 @@
|
|||
/* -*- 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/. */
|
||||
|
@ -15,6 +13,8 @@ Autocomplete Frecency Tests
|
|||
|
||||
*/
|
||||
|
||||
testEngine_setup();
|
||||
|
||||
try {
|
||||
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(
|
||||
Ci.nsINavHistoryService
|
||||
|
@ -32,15 +32,15 @@ var bucketPrefs = [
|
|||
];
|
||||
|
||||
var bonusPrefs = {
|
||||
embedVisitBonus: Ci.nsINavHistoryService.TRANSITION_EMBED,
|
||||
framedLinkVisitBonus: Ci.nsINavHistoryService.TRANSITION_FRAMED_LINK,
|
||||
linkVisitBonus: Ci.nsINavHistoryService.TRANSITION_LINK,
|
||||
typedVisitBonus: Ci.nsINavHistoryService.TRANSITION_TYPED,
|
||||
bookmarkVisitBonus: Ci.nsINavHistoryService.TRANSITION_BOOKMARK,
|
||||
downloadVisitBonus: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD,
|
||||
permRedirectVisitBonus: Ci.nsINavHistoryService.TRANSITION_REDIRECT_PERMANENT,
|
||||
tempRedirectVisitBonus: Ci.nsINavHistoryService.TRANSITION_REDIRECT_TEMPORARY,
|
||||
reloadVisitBonus: Ci.nsINavHistoryService.TRANSITION_RELOAD,
|
||||
embedVisitBonus: PlacesUtils.history.TRANSITION_EMBED,
|
||||
framedLinkVisitBonus: PlacesUtils.history.TRANSITION_FRAMED_LINK,
|
||||
linkVisitBonus: PlacesUtils.history.TRANSITION_LINK,
|
||||
typedVisitBonus: PlacesUtils.history.TRANSITION_TYPED,
|
||||
bookmarkVisitBonus: PlacesUtils.history.TRANSITION_BOOKMARK,
|
||||
downloadVisitBonus: PlacesUtils.history.TRANSITION_DOWNLOAD,
|
||||
permRedirectVisitBonus: PlacesUtils.history.TRANSITION_REDIRECT_PERMANENT,
|
||||
tempRedirectVisitBonus: PlacesUtils.history.TRANSITION_REDIRECT_TEMPORARY,
|
||||
reloadVisitBonus: PlacesUtils.history.TRANSITION_RELOAD,
|
||||
};
|
||||
|
||||
// create test data
|
||||
|
@ -52,20 +52,20 @@ var prefPrefix = "places.frecency.";
|
|||
async function task_initializeBucket(bucket) {
|
||||
let [cutoffName, weightName] = bucket;
|
||||
// get pref values
|
||||
var weight = Services.prefs.getIntPref(prefPrefix + weightName, 0);
|
||||
var cutoff = Services.prefs.getIntPref(prefPrefix + cutoffName, 0);
|
||||
let weight = Services.prefs.getIntPref(prefPrefix + weightName, 0);
|
||||
let cutoff = Services.prefs.getIntPref(prefPrefix + cutoffName, 0);
|
||||
if (cutoff < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// generate a date within the cutoff period
|
||||
var dateInPeriod = (now - (cutoff - 1) * 86400 * 1000) * 1000;
|
||||
let dateInPeriod = (now - (cutoff - 1) * 86400 * 1000) * 1000;
|
||||
|
||||
for (let [bonusName, visitType] of Object.entries(bonusPrefs)) {
|
||||
var frecency = -1;
|
||||
var calculatedURI = null;
|
||||
var matchTitle = "";
|
||||
var bonusValue = Services.prefs.getIntPref(prefPrefix + bonusName);
|
||||
let frecency = -1;
|
||||
let calculatedURI = null;
|
||||
let matchTitle = "";
|
||||
let bonusValue = Services.prefs.getIntPref(prefPrefix + bonusName);
|
||||
// unvisited (only for first cutoff date bucket)
|
||||
if (
|
||||
bonusName == "unvisitedBookmarkBonus" ||
|
||||
|
@ -73,9 +73,9 @@ async function task_initializeBucket(bucket) {
|
|||
) {
|
||||
if (cutoffName == "firstBucketCutoff") {
|
||||
let points = Math.ceil((bonusValue / parseFloat(100.0)) * weight);
|
||||
var visitCount = 1; // bonusName == "unvisitedBookmarkBonus" ? 1 : 0;
|
||||
let visitCount = 1; // bonusName == "unvisitedBookmarkBonus" ? 1 : 0;
|
||||
frecency = Math.ceil(visitCount * points);
|
||||
calculatedURI = uri(
|
||||
calculatedURI = Services.io.newURI(
|
||||
"http://" +
|
||||
searchTerm +
|
||||
".com/" +
|
||||
|
@ -132,7 +132,7 @@ async function task_initializeBucket(bucket) {
|
|||
} else {
|
||||
frecency = points;
|
||||
}
|
||||
calculatedURI = uri(
|
||||
calculatedURI = Services.io.newURI(
|
||||
"http://" +
|
||||
searchTerm +
|
||||
".com/" +
|
||||
|
@ -177,123 +177,69 @@ async function task_initializeBucket(bucket) {
|
|||
}
|
||||
}
|
||||
|
||||
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"]),
|
||||
};
|
||||
|
||||
add_task(async function test_frecency() {
|
||||
// Disable autoFill for this test.
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
|
||||
registerCleanupFunction(() =>
|
||||
Services.prefs.clearUserPref("browser.urlbar.autoFill")
|
||||
);
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
|
||||
// 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);
|
||||
registerCleanupFunction(() => {
|
||||
Services.prefs.clearUserPref("browser.urlbar.suggest.history");
|
||||
Services.prefs.clearUserPref("browser.urlbar.suggest.bookmarks");
|
||||
Services.prefs.clearUserPref("browser.urlbar.autoFill");
|
||||
Services.prefs.clearUserPref("browser.urlbar.suggest.searches");
|
||||
});
|
||||
for (let bucket of bucketPrefs) {
|
||||
await task_initializeBucket(bucket);
|
||||
}
|
||||
|
||||
// sort results by frecency
|
||||
results.sort((a, b) => b[1] - a[1]);
|
||||
// Sort results by frecency. Break ties by alphabetical URL.
|
||||
results.sort((a, b) => {
|
||||
let frecencyDiff = b[1] - a[1];
|
||||
if (frecencyDiff == 0) {
|
||||
return a[0].spec.localeCompare(b[0].spec);
|
||||
}
|
||||
return frecencyDiff;
|
||||
});
|
||||
|
||||
// Make sure there's enough results returned
|
||||
Services.prefs.setIntPref("browser.urlbar.maxRichResults", results.length);
|
||||
|
||||
// DEBUG
|
||||
// results.every(function(el) { dump("result: " + el[1] + ": " + el[0].spec + " (" + el[2] + ")\n"); return true; })
|
||||
|
||||
await PlacesTestUtils.promiseAsyncUpdates();
|
||||
|
||||
var controller = Cc["@mozilla.org/autocomplete/controller;1"].getService(
|
||||
Ci.nsIAutoCompleteController
|
||||
Services.prefs.setIntPref(
|
||||
"browser.urlbar.maxRichResults",
|
||||
// +1 for the heuristic search result.
|
||||
results.length + 1
|
||||
);
|
||||
|
||||
// Make an AutoCompleteInput that uses our searches
|
||||
// and confirms results on search complete
|
||||
var input = new AutoCompleteInput(["unifiedcomplete"]);
|
||||
|
||||
controller.input = input;
|
||||
|
||||
// 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);
|
||||
|
||||
var numSearchesStarted = 0;
|
||||
input.onSearchBegin = function() {
|
||||
numSearchesStarted++;
|
||||
Assert.equal(numSearchesStarted, 1);
|
||||
};
|
||||
|
||||
await new Promise(resolve => {
|
||||
input.onSearchComplete = function() {
|
||||
Assert.equal(numSearchesStarted, 1);
|
||||
Assert.equal(
|
||||
controller.searchStatus,
|
||||
Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH
|
||||
await PlacesTestUtils.promiseAsyncUpdates();
|
||||
let context = createContext(searchTerm, { isPrivate: false });
|
||||
let urlbarResults = [];
|
||||
for (let result of results) {
|
||||
let url = result[0].spec;
|
||||
if (url.toLowerCase().includes("bookmark")) {
|
||||
urlbarResults.push(
|
||||
makeBookmarkResult(context, {
|
||||
uri: url,
|
||||
title: result[2],
|
||||
})
|
||||
);
|
||||
} else {
|
||||
urlbarResults.push(
|
||||
makeVisitResult(context, {
|
||||
uri: url,
|
||||
title: result[2],
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// test that all records with non-zero frecency were matched
|
||||
Assert.equal(controller.matchCount, results.length);
|
||||
|
||||
// test that matches are sorted by frecency
|
||||
for (var i = 0; i < controller.matchCount; i++) {
|
||||
let searchURL = controller.getValueAt(i);
|
||||
let expectURL = results[i][0].spec;
|
||||
if (searchURL == expectURL) {
|
||||
Assert.equal(controller.getValueAt(i), results[i][0].spec);
|
||||
Assert.equal(controller.getCommentAt(i), results[i][2]);
|
||||
} else {
|
||||
// If the results didn't match exactly, perhaps it's still the right
|
||||
// frecency just in the wrong "order" (order of same frecency is
|
||||
// undefined), so check if frecency matches. This is okay because we
|
||||
// can still ensure the correct number of expected frecencies.
|
||||
let getFrecency = aURL => aURL.match(/frecency:(-?\d+)$/)[1];
|
||||
print(
|
||||
"### checking for same frecency between '" +
|
||||
searchURL +
|
||||
"' and '" +
|
||||
expectURL +
|
||||
"'"
|
||||
);
|
||||
Assert.equal(getFrecency(searchURL), getFrecency(expectURL));
|
||||
}
|
||||
}
|
||||
resolve();
|
||||
};
|
||||
|
||||
controller.startSearch(searchTerm);
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
...urlbarResults,
|
||||
],
|
||||
});
|
||||
});
|
|
@ -0,0 +1,401 @@
|
|||
/* 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 406358 to make sure frecency works for empty input/search, but
|
||||
* this also tests for non-empty inputs as well. Because the interactions among
|
||||
* *DIFFERENT* visit counts and visit dates is not well defined, this test
|
||||
* holds one of the two values constant when modifying the other.
|
||||
*
|
||||
* Also test bug 419068 to make sure tagged pages don't necessarily have to be
|
||||
* first in the results.
|
||||
*
|
||||
* Also test bug 426166 to make sure that the results of autocomplete searches
|
||||
* are stable. Note that failures of this test will be intermittent by nature
|
||||
* since we are testing to make sure that the unstable sort algorithm used
|
||||
* by SQLite is not changing the order of the results on us.
|
||||
*/
|
||||
|
||||
testEngine_setup();
|
||||
|
||||
async function task_setCountDate(uri, count, date) {
|
||||
// We need visits so that frecency can be computed over multiple visits
|
||||
let visits = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
visits.push({
|
||||
uri,
|
||||
visitDate: date,
|
||||
transition: PlacesUtils.history.TRANSITION_TYPED,
|
||||
});
|
||||
}
|
||||
await PlacesTestUtils.addVisits(visits);
|
||||
}
|
||||
|
||||
async function setBookmark(uri) {
|
||||
await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
url: uri,
|
||||
title: "bleh",
|
||||
});
|
||||
}
|
||||
|
||||
async function tagURI(uri, tags) {
|
||||
await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
url: uri,
|
||||
title: "bleh",
|
||||
});
|
||||
PlacesUtils.tagging.tagURI(uri, tags);
|
||||
}
|
||||
|
||||
async function preSearch() {
|
||||
await PlacesTestUtils.promiseAsyncUpdates();
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
await PlacesUtils.history.clear();
|
||||
}
|
||||
|
||||
var uri1 = Services.io.newURI("http://site.tld/1");
|
||||
var uri2 = Services.io.newURI("http://site.tld/2");
|
||||
var uri3 = Services.io.newURI("http://aaaaaaaaaa/1");
|
||||
var uri4 = Services.io.newURI("http://aaaaaaaaaa/2");
|
||||
|
||||
// d1 is younger (should show up higher) than d2 (PRTime is in usecs not msec)
|
||||
// Make sure the dates fall into different frecency buckets
|
||||
var d1 = new Date(Date.now() - 1000 * 60 * 60) * 1000;
|
||||
var d2 = new Date(Date.now() - 1000 * 60 * 60 * 24 * 10) * 1000;
|
||||
// c1 is larger (should show up higher) than c2
|
||||
var c1 = 10;
|
||||
var c2 = 1;
|
||||
|
||||
var tests = [
|
||||
// test things without a search term
|
||||
async function() {
|
||||
info("Test 0: same count, different date");
|
||||
await task_setCountDate(uri1, c1, d1);
|
||||
await task_setCountDate(uri2, c1, d2);
|
||||
await tagURI(uri1, ["site"]);
|
||||
let context = createContext(" ", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
query: " ",
|
||||
}),
|
||||
// uri1 is a visit result despite being a tagged bookmark because we
|
||||
// are searching for the empty string. By default, the empty string
|
||||
// filters to history. uri1 will be displayed as a bookmark later in the
|
||||
// test when we are searching with a non-empty string.
|
||||
makeVisitResult(context, {
|
||||
uri: uri1.spec,
|
||||
title: "bleh",
|
||||
}),
|
||||
makeVisitResult(context, {
|
||||
uri: uri2.spec,
|
||||
title: `test visit for ${uri2.spec}`,
|
||||
}),
|
||||
],
|
||||
});
|
||||
},
|
||||
async function() {
|
||||
info("Test 1: same count, different date");
|
||||
await task_setCountDate(uri1, c1, d2);
|
||||
await task_setCountDate(uri2, c1, d1);
|
||||
await tagURI(uri1, ["site"]);
|
||||
let context = createContext(" ", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
query: " ",
|
||||
}),
|
||||
makeVisitResult(context, {
|
||||
uri: uri2.spec,
|
||||
title: `test visit for ${uri2.spec}`,
|
||||
}),
|
||||
makeVisitResult(context, {
|
||||
uri: uri1.spec,
|
||||
title: "bleh",
|
||||
}),
|
||||
],
|
||||
});
|
||||
},
|
||||
async function() {
|
||||
info("Test 2: different count, same date");
|
||||
await task_setCountDate(uri1, c1, d1);
|
||||
await task_setCountDate(uri2, c2, d1);
|
||||
await tagURI(uri1, ["site"]);
|
||||
let context = createContext(" ", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
query: " ",
|
||||
}),
|
||||
makeVisitResult(context, {
|
||||
uri: uri1.spec,
|
||||
title: "bleh",
|
||||
}),
|
||||
makeVisitResult(context, {
|
||||
uri: uri2.spec,
|
||||
title: `test visit for ${uri2.spec}`,
|
||||
}),
|
||||
],
|
||||
});
|
||||
},
|
||||
async function() {
|
||||
info("Test 3: different count, same date");
|
||||
await task_setCountDate(uri1, c2, d1);
|
||||
await task_setCountDate(uri2, c1, d1);
|
||||
await tagURI(uri1, ["site"]);
|
||||
let context = createContext(" ", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
query: " ",
|
||||
}),
|
||||
makeVisitResult(context, {
|
||||
uri: uri2.spec,
|
||||
title: `test visit for ${uri2.spec}`,
|
||||
}),
|
||||
makeVisitResult(context, {
|
||||
uri: uri1.spec,
|
||||
title: "bleh",
|
||||
}),
|
||||
],
|
||||
});
|
||||
},
|
||||
|
||||
// test things with a search term
|
||||
async function() {
|
||||
info("Test 4: same count, different date");
|
||||
await task_setCountDate(uri1, c1, d1);
|
||||
await task_setCountDate(uri2, c1, d2);
|
||||
await tagURI(uri1, ["site"]);
|
||||
let context = createContext("site", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
makeBookmarkResult(context, {
|
||||
uri: uri1.spec,
|
||||
title: "bleh",
|
||||
tags: ["site"],
|
||||
}),
|
||||
makeVisitResult(context, {
|
||||
uri: uri2.spec,
|
||||
title: `test visit for ${uri2.spec}`,
|
||||
}),
|
||||
],
|
||||
});
|
||||
},
|
||||
async function() {
|
||||
info("Test 5: same count, different date");
|
||||
await task_setCountDate(uri1, c1, d2);
|
||||
await task_setCountDate(uri2, c1, d1);
|
||||
await tagURI(uri1, ["site"]);
|
||||
let context = createContext("site", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
makeVisitResult(context, {
|
||||
uri: uri2.spec,
|
||||
title: `test visit for ${uri2.spec}`,
|
||||
}),
|
||||
makeBookmarkResult(context, {
|
||||
uri: uri1.spec,
|
||||
title: "bleh",
|
||||
tags: ["site"],
|
||||
}),
|
||||
],
|
||||
});
|
||||
},
|
||||
async function() {
|
||||
info("Test 6: different count, same date");
|
||||
await task_setCountDate(uri1, c1, d1);
|
||||
await task_setCountDate(uri2, c2, d1);
|
||||
await tagURI(uri1, ["site"]);
|
||||
let context = createContext("site", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
makeBookmarkResult(context, {
|
||||
uri: uri1.spec,
|
||||
title: "bleh",
|
||||
tags: ["site"],
|
||||
}),
|
||||
makeVisitResult(context, {
|
||||
uri: uri2.spec,
|
||||
title: `test visit for ${uri2.spec}`,
|
||||
}),
|
||||
],
|
||||
});
|
||||
},
|
||||
async function() {
|
||||
info("Test 7: different count, same date");
|
||||
await task_setCountDate(uri1, c2, d1);
|
||||
await task_setCountDate(uri2, c1, d1);
|
||||
await tagURI(uri1, ["site"]);
|
||||
let context = createContext("site", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
makeVisitResult(context, {
|
||||
uri: uri2.spec,
|
||||
title: `test visit for ${uri2.spec}`,
|
||||
}),
|
||||
makeBookmarkResult(context, {
|
||||
uri: uri1.spec,
|
||||
title: "bleh",
|
||||
tags: ["site"],
|
||||
}),
|
||||
],
|
||||
});
|
||||
},
|
||||
// There are multiple tests for 8, hence the multiple functions
|
||||
// Bug 426166 section
|
||||
async function() {
|
||||
info("Test 8.1a: same count, same date");
|
||||
await setBookmark(uri3);
|
||||
await setBookmark(uri4);
|
||||
let context = createContext("a", { isPrivate: false });
|
||||
let bookmarkResults = [
|
||||
makeBookmarkResult(context, {
|
||||
uri: uri4.spec,
|
||||
title: "bleh",
|
||||
}),
|
||||
makeBookmarkResult(context, {
|
||||
uri: uri3.spec,
|
||||
title: "bleh",
|
||||
}),
|
||||
];
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
...bookmarkResults,
|
||||
],
|
||||
});
|
||||
|
||||
context = createContext("aa", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
// We need to continuously redefine the heuristic search result because it
|
||||
// is the only one that changes with the search string.
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
...bookmarkResults,
|
||||
],
|
||||
});
|
||||
|
||||
context = createContext("aaa", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
...bookmarkResults,
|
||||
],
|
||||
});
|
||||
|
||||
context = createContext("aaaa", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
...bookmarkResults,
|
||||
],
|
||||
});
|
||||
|
||||
context = createContext("aaa", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
...bookmarkResults,
|
||||
],
|
||||
});
|
||||
|
||||
context = createContext("aa", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
...bookmarkResults,
|
||||
],
|
||||
});
|
||||
|
||||
context = createContext("a", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
...bookmarkResults,
|
||||
],
|
||||
});
|
||||
},
|
||||
];
|
||||
|
||||
add_task(async function test_frecency() {
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
|
||||
// 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.bookmark", true);
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.openpage", false);
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.engines", false);
|
||||
for (let test of tests) {
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
await PlacesUtils.history.clear();
|
||||
|
||||
await test();
|
||||
}
|
||||
for (let type of ["history", "bookmark", "openpage", "searches", "engines"]) {
|
||||
Services.prefs.clearUserPref("browser.urlbar.suggest." + type);
|
||||
Services.prefs.clearUserPref("browser.urlbar.autoFill");
|
||||
}
|
||||
});
|
|
@ -0,0 +1,43 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
/*
|
||||
|
||||
Test autocomplete for non-English URLs
|
||||
|
||||
- add a visit for a page with a non-English URL
|
||||
- search
|
||||
- test number of matches (should be exactly one)
|
||||
|
||||
*/
|
||||
|
||||
testEngine_setup();
|
||||
|
||||
add_task(async function test_autocomplete_non_english() {
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
|
||||
registerCleanupFunction(() => {
|
||||
Services.prefs.clearUserPref("browser.urlbar.suggest.searches");
|
||||
});
|
||||
|
||||
let searchTerm = "ユニコード";
|
||||
let unescaped = "http://www.foobar.com/" + searchTerm + "/";
|
||||
let uri = Services.io.newURI(unescaped);
|
||||
await PlacesTestUtils.addVisits(uri);
|
||||
let context = createContext(searchTerm, { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeSearchResult(context, {
|
||||
engineName: SUGGESTIONS_ENGINE_NAME,
|
||||
heuristic: true,
|
||||
}),
|
||||
makeVisitResult(context, {
|
||||
uri: uri.spec,
|
||||
title: `test visit for ${uri.spec}`,
|
||||
}),
|
||||
],
|
||||
});
|
||||
});
|
|
@ -0,0 +1,135 @@
|
|||
/* 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,
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
const uri1 = "http://site.tld/1";
|
||||
const uri2 = "http://site.tld/2";
|
||||
const uri3 = "http://site.tld/3";
|
||||
const uri4 = "http://site.tld/4";
|
||||
const uri5 = "http://site.tld/5";
|
||||
const uri6 = "http://site.tld/6";
|
||||
|
||||
/**
|
||||
* 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 bug #408221
|
||||
*/
|
||||
add_task(async function test_tags_search_case_insensitivity() {
|
||||
// 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, ["muD"]);
|
||||
await tagURI(uri6, ["baR"]);
|
||||
await tagURI(uri5, ["mud"]);
|
||||
await tagURI(uri5, ["bar"]);
|
||||
await tagURI(uri4, ["MUD"]);
|
||||
await tagURI(uri4, ["BAR"]);
|
||||
await tagURI(uri3, ["foO"]);
|
||||
await tagURI(uri2, ["FOO"]);
|
||||
await tagURI(uri1, ["Foo"]);
|
||||
|
||||
await ensure_tag_results(
|
||||
[
|
||||
[uri1, ["Foo"]],
|
||||
[uri2, ["Foo"]],
|
||||
[uri3, ["Foo"]],
|
||||
],
|
||||
"foo"
|
||||
);
|
||||
await ensure_tag_results(
|
||||
[
|
||||
[uri1, ["Foo"]],
|
||||
[uri2, ["Foo"]],
|
||||
[uri3, ["Foo"]],
|
||||
],
|
||||
"Foo"
|
||||
);
|
||||
await ensure_tag_results(
|
||||
[
|
||||
[uri1, ["Foo"]],
|
||||
[uri2, ["Foo"]],
|
||||
[uri3, ["Foo"]],
|
||||
],
|
||||
"foO"
|
||||
);
|
||||
await ensure_tag_results(
|
||||
[
|
||||
[uri4, ["BAR", "MUD"]],
|
||||
[uri5, ["BAR", "MUD"]],
|
||||
[uri6, ["BAR", "MUD"]],
|
||||
],
|
||||
"bar mud"
|
||||
);
|
||||
await ensure_tag_results(
|
||||
[
|
||||
[uri4, ["BAR", "MUD"]],
|
||||
[uri5, ["BAR", "MUD"]],
|
||||
[uri6, ["BAR", "MUD"]],
|
||||
],
|
||||
"BAR MUD"
|
||||
);
|
||||
await ensure_tag_results(
|
||||
[
|
||||
[uri4, ["BAR", "MUD"]],
|
||||
[uri5, ["BAR", "MUD"]],
|
||||
[uri6, ["BAR", "MUD"]],
|
||||
],
|
||||
"Bar Mud"
|
||||
);
|
||||
});
|
|
@ -4,6 +4,7 @@ firefox-appdir = browser
|
|||
support-files =
|
||||
data/engine.xml
|
||||
|
||||
[test_000_frecency.js]
|
||||
[test_about_urls.js]
|
||||
[test_autofill_bookmarked.js]
|
||||
[test_autofill_do_not_trim.js]
|
||||
|
@ -25,6 +26,7 @@ support-files =
|
|||
[test_encoded_urls.js]
|
||||
[test_escaping_badEscapedURI.js]
|
||||
[test_escaping_escapeSelf.js]
|
||||
[test_frecency.js]
|
||||
[test_heuristic_cancel.js]
|
||||
[test_keywords.js]
|
||||
skip-if = os == 'linux' # bug 1474616
|
||||
|
@ -38,6 +40,7 @@ skip-if = os == 'linux' # bug 1474616
|
|||
[test_providerKeywords.js]
|
||||
[test_providerOmnibox.js]
|
||||
[test_providerOpenTabs.js]
|
||||
[test_providerPlaces_nonEnglish.js]
|
||||
[test_providerPreloaded.js]
|
||||
[test_providersManager.js]
|
||||
[test_providersManager_filtering.js]
|
||||
|
@ -59,6 +62,7 @@ skip-if = !sync
|
|||
[test_special_search.js]
|
||||
[test_suggestedIndex.js]
|
||||
[test_tab_matches.js]
|
||||
[test_tags_caseInsensitivity.js]
|
||||
[test_tags_extendedUnicode.js]
|
||||
[test_tags_general.js]
|
||||
[test_tags_matchBookmarkTitles.js]
|
||||
|
|
|
@ -1,146 +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/. */
|
||||
|
||||
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"]),
|
||||
};
|
||||
|
||||
// Get tagging service
|
||||
try {
|
||||
var tagssvc = Cc["@mozilla.org/browser/tagging-service;1"].getService(
|
||||
Ci.nsITaggingService
|
||||
);
|
||||
} catch (ex) {
|
||||
do_throw("Could not get tagging service\n");
|
||||
}
|
||||
|
||||
function ensure_tag_results(uris, 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,
|
||||
Ci.nsIAutoCompleteController.STATUS_COMPLETE_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);
|
||||
});
|
||||
}
|
||||
|
||||
const uri1 = "http://site.tld/1";
|
||||
const uri2 = "http://site.tld/2";
|
||||
const uri3 = "http://site.tld/3";
|
||||
const uri4 = "http://site.tld/4";
|
||||
const uri5 = "http://site.tld/5";
|
||||
const uri6 = "http://site.tld/6";
|
||||
|
||||
/**
|
||||
* Properly tags a uri adding it to bookmarks.
|
||||
*
|
||||
* @param aURI
|
||||
* The nsIURI to tag.
|
||||
* @param aTags
|
||||
* The tags to add.
|
||||
*/
|
||||
async function tagURI(url, aTags) {
|
||||
await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
title: "A title",
|
||||
url,
|
||||
});
|
||||
|
||||
tagssvc.tagURI(uri(url), aTags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test bug #408221
|
||||
*/
|
||||
add_task(async function test_tags_search_case_insensitivity() {
|
||||
// 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, ["FOO"]);
|
||||
await tagURI(uri3, ["foO"]);
|
||||
await tagURI(uri4, ["BAR"]);
|
||||
await tagURI(uri4, ["MUD"]);
|
||||
await tagURI(uri5, ["bar"]);
|
||||
await tagURI(uri5, ["mud"]);
|
||||
await tagURI(uri6, ["baR"]);
|
||||
await tagURI(uri6, ["muD"]);
|
||||
|
||||
await ensure_tag_results([uri1, uri2, uri3], "foo");
|
||||
await ensure_tag_results([uri1, uri2, uri3], "Foo");
|
||||
await ensure_tag_results([uri1, uri2, uri3], "foO");
|
||||
await ensure_tag_results([uri4, uri5, uri6], "bar mud");
|
||||
await ensure_tag_results([uri4, uri5, uri6], "BAR MUD");
|
||||
await ensure_tag_results([uri4, uri5, uri6], "Bar Mud");
|
||||
});
|
|
@ -1,101 +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/. */
|
||||
|
||||
/*
|
||||
|
||||
Test autocomplete for non-English URLs
|
||||
|
||||
- add a visit for a page with a non-English URL
|
||||
- search
|
||||
- test number of matches (should be exactly one)
|
||||
|
||||
*/
|
||||
|
||||
// create test data
|
||||
var searchTerm = "ユニコード";
|
||||
var decoded = "http://www.foobar.com/" + searchTerm + "/";
|
||||
var url = uri(decoded);
|
||||
|
||||
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"]),
|
||||
};
|
||||
|
||||
add_task(async function test_autocomplete_non_english() {
|
||||
await PlacesTestUtils.addVisits(url);
|
||||
|
||||
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,
|
||||
Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH
|
||||
);
|
||||
|
||||
// test that we found the entry we added
|
||||
Assert.equal(controller.matchCount, 1);
|
||||
|
||||
// Make sure the url is the same according to spec, so it can be deleted
|
||||
Assert.equal(controller.getValueAt(0), url.spec);
|
||||
|
||||
resolve();
|
||||
};
|
||||
|
||||
controller.startSearch(searchTerm);
|
||||
});
|
||||
});
|
|
@ -1,277 +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/. */
|
||||
|
||||
/**
|
||||
* Test for bug 406358 to make sure frecency works for empty input/search, but
|
||||
* this also tests for non-empty inputs as well. Because the interactions among
|
||||
* *DIFFERENT* visit counts and visit dates is not well defined, this test
|
||||
* holds one of the two values constant when modifying the other.
|
||||
*
|
||||
* Also test bug 419068 to make sure tagged pages don't necessarily have to be
|
||||
* first in the results.
|
||||
*
|
||||
* Also test bug 426166 to make sure that the results of autocomplete searches
|
||||
* are stable. Note that failures of this test will be intermittent by nature
|
||||
* since we are testing to make sure that the unstable sort algorithm used
|
||||
* by SQLite is not changing the order of the results on us.
|
||||
*/
|
||||
|
||||
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_results(uris, searchTerm) {
|
||||
await PlacesTestUtils.promiseAsyncUpdates();
|
||||
await ensure_results_internal(uris, searchTerm);
|
||||
}
|
||||
|
||||
async function ensure_results_internal(uris, 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;
|
||||
|
||||
var numSearchesStarted = 0;
|
||||
input.onSearchBegin = function() {
|
||||
numSearchesStarted++;
|
||||
Assert.equal(numSearchesStarted, 1);
|
||||
};
|
||||
|
||||
let promise = new Promise(resolve => {
|
||||
input.onSearchComplete = function() {
|
||||
Assert.equal(numSearchesStarted, 1);
|
||||
Assert.equal(
|
||||
controller.searchStatus,
|
||||
Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH
|
||||
);
|
||||
Assert.equal(controller.matchCount, uris.length);
|
||||
for (var i = 0; i < controller.matchCount; i++) {
|
||||
Assert.equal(controller.getValueAt(i), uris[i].spec);
|
||||
}
|
||||
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
|
||||
controller.startSearch(searchTerm);
|
||||
await promise;
|
||||
}
|
||||
|
||||
// Get history service
|
||||
try {
|
||||
var tagssvc = Cc["@mozilla.org/browser/tagging-service;1"].getService(
|
||||
Ci.nsITaggingService
|
||||
);
|
||||
} catch (ex) {
|
||||
do_throw("Could not get history service\n");
|
||||
}
|
||||
|
||||
async function task_setCountDate(aURI, aCount, aDate) {
|
||||
// We need visits so that frecency can be computed over multiple visits
|
||||
let visits = [];
|
||||
for (let i = 0; i < aCount; i++) {
|
||||
visits.push({ uri: aURI, visitDate: aDate, transition: TRANSITION_TYPED });
|
||||
}
|
||||
await PlacesTestUtils.addVisits(visits);
|
||||
}
|
||||
|
||||
async function setBookmark(aURI) {
|
||||
await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
url: aURI,
|
||||
title: "bleh",
|
||||
});
|
||||
}
|
||||
|
||||
async function tagURI(aURI, aTags) {
|
||||
await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
url: aURI,
|
||||
title: "bleh",
|
||||
});
|
||||
tagssvc.tagURI(aURI, aTags);
|
||||
}
|
||||
|
||||
var uri1 = uri("http://site.tld/1");
|
||||
var uri2 = uri("http://site.tld/2");
|
||||
var uri3 = uri("http://aaaaaaaaaa/1");
|
||||
var uri4 = uri("http://aaaaaaaaaa/2");
|
||||
|
||||
// d1 is younger (should show up higher) than d2 (PRTime is in usecs not msec)
|
||||
// Make sure the dates fall into different frecency buckets
|
||||
var d1 = new Date(Date.now() - 1000 * 60 * 60) * 1000;
|
||||
var d2 = new Date(Date.now() - 1000 * 60 * 60 * 24 * 10) * 1000;
|
||||
// c1 is larger (should show up higher) than c2
|
||||
var c1 = 10;
|
||||
var c2 = 1;
|
||||
|
||||
var tests = [
|
||||
// test things without a search term
|
||||
async function() {
|
||||
print("TEST-INFO | Test 0: same count, different date");
|
||||
await task_setCountDate(uri1, c1, d1);
|
||||
await task_setCountDate(uri2, c1, d2);
|
||||
await tagURI(uri1, ["site"]);
|
||||
await ensure_results([uri1, uri2], "");
|
||||
},
|
||||
async function() {
|
||||
print("TEST-INFO | Test 1: same count, different date");
|
||||
await task_setCountDate(uri1, c1, d2);
|
||||
await task_setCountDate(uri2, c1, d1);
|
||||
await tagURI(uri1, ["site"]);
|
||||
await ensure_results([uri2, uri1], "");
|
||||
},
|
||||
async function() {
|
||||
print("TEST-INFO | Test 2: different count, same date");
|
||||
await task_setCountDate(uri1, c1, d1);
|
||||
await task_setCountDate(uri2, c2, d1);
|
||||
await tagURI(uri1, ["site"]);
|
||||
await ensure_results([uri1, uri2], "");
|
||||
},
|
||||
async function() {
|
||||
print("TEST-INFO | Test 3: different count, same date");
|
||||
await task_setCountDate(uri1, c2, d1);
|
||||
await task_setCountDate(uri2, c1, d1);
|
||||
await tagURI(uri1, ["site"]);
|
||||
await ensure_results([uri2, uri1], "");
|
||||
},
|
||||
|
||||
// test things with a search term
|
||||
async function() {
|
||||
print("TEST-INFO | Test 4: same count, different date");
|
||||
await task_setCountDate(uri1, c1, d1);
|
||||
await task_setCountDate(uri2, c1, d2);
|
||||
await tagURI(uri1, ["site"]);
|
||||
await ensure_results([uri1, uri2], "site");
|
||||
},
|
||||
async function() {
|
||||
print("TEST-INFO | Test 5: same count, different date");
|
||||
await task_setCountDate(uri1, c1, d2);
|
||||
await task_setCountDate(uri2, c1, d1);
|
||||
await tagURI(uri1, ["site"]);
|
||||
await ensure_results([uri2, uri1], "site");
|
||||
},
|
||||
async function() {
|
||||
print("TEST-INFO | Test 6: different count, same date");
|
||||
await task_setCountDate(uri1, c1, d1);
|
||||
await task_setCountDate(uri2, c2, d1);
|
||||
await tagURI(uri1, ["site"]);
|
||||
await ensure_results([uri1, uri2], "site");
|
||||
},
|
||||
async function() {
|
||||
print("TEST-INFO | Test 7: different count, same date");
|
||||
await task_setCountDate(uri1, c2, d1);
|
||||
await task_setCountDate(uri2, c1, d1);
|
||||
await tagURI(uri1, ["site"]);
|
||||
await ensure_results([uri2, uri1], "site");
|
||||
},
|
||||
// There are multiple tests for 8, hence the multiple functions
|
||||
// Bug 426166 section
|
||||
async function() {
|
||||
print("TEST-INFO | Test 8.1a: same count, same date");
|
||||
await setBookmark(uri3);
|
||||
await setBookmark(uri4);
|
||||
await ensure_results([uri4, uri3], "a");
|
||||
},
|
||||
async function() {
|
||||
print("TEST-INFO | Test 8.1b: same count, same date");
|
||||
await setBookmark(uri3);
|
||||
await setBookmark(uri4);
|
||||
await ensure_results([uri4, uri3], "aa");
|
||||
},
|
||||
async function() {
|
||||
print("TEST-INFO | Test 8.2: same count, same date");
|
||||
await setBookmark(uri3);
|
||||
await setBookmark(uri4);
|
||||
await ensure_results([uri4, uri3], "aaa");
|
||||
},
|
||||
async function() {
|
||||
print("TEST-INFO | Test 8.3: same count, same date");
|
||||
await setBookmark(uri3);
|
||||
await setBookmark(uri4);
|
||||
await ensure_results([uri4, uri3], "aaaa");
|
||||
},
|
||||
async function() {
|
||||
print("TEST-INFO | Test 8.4: same count, same date");
|
||||
await setBookmark(uri3);
|
||||
await setBookmark(uri4);
|
||||
await ensure_results([uri4, uri3], "aaa");
|
||||
},
|
||||
async function() {
|
||||
print("TEST-INFO | Test 8.5: same count, same date");
|
||||
await setBookmark(uri3);
|
||||
await setBookmark(uri4);
|
||||
await ensure_results([uri4, uri3], "aa");
|
||||
},
|
||||
async function() {
|
||||
print("TEST-INFO | Test 8.6: same count, same date");
|
||||
await setBookmark(uri3);
|
||||
await setBookmark(uri4);
|
||||
await ensure_results([uri4, uri3], "a");
|
||||
},
|
||||
];
|
||||
|
||||
add_task(async function test_frecency() {
|
||||
// Disable autoFill for this test.
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
|
||||
registerCleanupFunction(() =>
|
||||
Services.prefs.clearUserPref("browser.urlbar.autoFill")
|
||||
);
|
||||
// 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.bookmark", true);
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.openpage", false);
|
||||
for (let test of tests) {
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
await PlacesUtils.history.clear();
|
||||
|
||||
await test();
|
||||
}
|
||||
for (let type of ["history", "bookmark", "openpage"]) {
|
||||
Services.prefs.clearUserPref("browser.urlbar.suggest." + type);
|
||||
}
|
||||
});
|
|
@ -14,19 +14,13 @@ support-files =
|
|||
mobile_bookmarks_root_merge.json
|
||||
places.sparse.sqlite
|
||||
|
||||
[test_000_frecency.js]
|
||||
skip-if = appname == "thunderbird"
|
||||
[test_331487.js]
|
||||
[test_384370.js]
|
||||
[test_385397.js]
|
||||
[test_399266.js]
|
||||
skip-if = os == "linux" # Bug 821781
|
||||
[test_402799.js]
|
||||
[test_408221.js]
|
||||
skip-if = appname == "thunderbird"
|
||||
[test_412132.js]
|
||||
[test_413784.js]
|
||||
skip-if = appname == "thunderbird"
|
||||
[test_415460.js]
|
||||
[test_415757.js]
|
||||
[test_419792_node_tags_property.js]
|
||||
|
@ -56,8 +50,6 @@ skip-if = appname == "thunderbird"
|
|||
[test_broken_folderShortcut_result.js]
|
||||
[test_browserhistory.js]
|
||||
[test_childlessTags.js]
|
||||
[test_frecency.js]
|
||||
skip-if = appname == "thunderbird"
|
||||
[test_frecency_decay.js]
|
||||
[test_frecency_zero_updated.js]
|
||||
[test_getChildIndex.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче