зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1559686 - Reimplement the inputHistory feature in the Quantum Bar. r=adw
Differential Revision: https://phabricator.services.mozilla.com/D35364 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
fea8493145
Коммит
8c35f37875
|
@ -524,6 +524,13 @@ class UrlbarInput {
|
|||
if (!url) {
|
||||
throw new Error(`Invalid url for result ${JSON.stringify(result)}`);
|
||||
}
|
||||
|
||||
if (!this.isPrivate && !result.heuristic) {
|
||||
// This should not interrupt the load anyway.
|
||||
UrlbarUtils.addToInputHistory(url, this._lastSearchString)
|
||||
.catch(Cu.reportError);
|
||||
}
|
||||
|
||||
this._loadURL(url, where, openParams, {
|
||||
source: result.source,
|
||||
type: result.type,
|
||||
|
|
|
@ -372,6 +372,19 @@ var UrlbarUtils = {
|
|||
}
|
||||
return pasteData;
|
||||
},
|
||||
|
||||
async addToInputHistory(url, input) {
|
||||
await PlacesUtils.withConnectionWrapper("addToInputHistory", db => {
|
||||
// use_count will asymptotically approach the max of 10.
|
||||
return db.executeCached(`
|
||||
INSERT OR REPLACE INTO moz_inputhistory
|
||||
SELECT h.id, IFNULL(i.input, :input), IFNULL(i.use_count, 0) * .9 + 1
|
||||
FROM moz_places h
|
||||
LEFT JOIN moz_inputhistory i ON i.place_id = h.id AND i.input = :input
|
||||
WHERE url_hash = hash(:url) AND url = :url
|
||||
`, {url, input});
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
XPCOMUtils.defineLazyGetter(UrlbarUtils.ICON, "DEFAULT", () => {
|
||||
|
|
|
@ -47,6 +47,7 @@ support-files =
|
|||
[browser_dragdropURL.js]
|
||||
[browser_dropmarker.js]
|
||||
[browser_ime_composition.js]
|
||||
[browser_inputHistory.js]
|
||||
[browser_keepStateAcrossTabSwitches.js]
|
||||
[browser_keywordBookmarklets.js]
|
||||
[browser_keyword_override.js]
|
||||
|
|
|
@ -0,0 +1,307 @@
|
|||
/* eslint-disable mozilla/no-arbitrary-setTimeout */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/**
|
||||
* This tests the urlbar adaptive behavior powered by input history.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
async function bumpScore(uri, searchString, counts, useMouseClick = false) {
|
||||
if (counts.visits) {
|
||||
let visits = new Array(counts.visits).fill(uri);
|
||||
await PlacesTestUtils.addVisits(visits);
|
||||
}
|
||||
if (counts.picks) {
|
||||
for (let i = 0; i < counts.picks; ++i) {
|
||||
await promiseAutocompleteResultPopup(searchString);
|
||||
let promise = BrowserTestUtils.waitForDocLoadAndStopIt(uri, gBrowser.selectedBrowser);
|
||||
// Look for the expected uri.
|
||||
while (gURLBar.value != uri) {
|
||||
EventUtils.synthesizeKey("KEY_ArrowDown");
|
||||
}
|
||||
if (useMouseClick) {
|
||||
let element = UrlbarTestUtils.getSelectedElement(window);
|
||||
EventUtils.synthesizeMouseAtCenter(element, {});
|
||||
} else {
|
||||
EventUtils.synthesizeKey("KEY_Enter");
|
||||
}
|
||||
await promise;
|
||||
}
|
||||
}
|
||||
await PlacesTestUtils.promiseAsyncUpdates();
|
||||
}
|
||||
|
||||
async function decayInputHistory() {
|
||||
PlacesUtils.history.decayFrecency();
|
||||
await PlacesTestUtils.promiseAsyncUpdates();
|
||||
}
|
||||
|
||||
add_task(async function setup() {
|
||||
await SpecialPowers.pushPrefEnv({set: [
|
||||
// We don't want autofill to influence this test.
|
||||
["browser.urlbar.autoFill", false],
|
||||
]});
|
||||
registerCleanupFunction(async () => {
|
||||
await PlacesUtils.history.clear();
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function test_adaptive_no_search_terms() {
|
||||
let url1 = "http://site.tld/1";
|
||||
let url2 = "http://site.tld/2";
|
||||
|
||||
info("Same visit count, different picks");
|
||||
await PlacesUtils.history.clear();
|
||||
await bumpScore(url1, "site", {visits: 3, picks: 3});
|
||||
await bumpScore(url2, "site", {visits: 3, picks: 1});
|
||||
await promiseAutocompleteResultPopup("");
|
||||
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
|
||||
Assert.equal(result.url, url1, "Check first result");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result.url, url2, "Check second result");
|
||||
|
||||
info("Same visit count, different picks, invert");
|
||||
await PlacesUtils.history.clear();
|
||||
await bumpScore(url1, "site", {visits: 3, picks: 1});
|
||||
await bumpScore(url2, "site", {visits: 3, picks: 3});
|
||||
await promiseAutocompleteResultPopup("");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
|
||||
Assert.equal(result.url, url2, "Check first result");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result.url, url1, "Check second result");
|
||||
|
||||
info("Different visit count, same picks");
|
||||
await PlacesUtils.history.clear();
|
||||
await bumpScore(url1, "site", {visits: 3, picks: 3});
|
||||
await bumpScore(url2, "site", {visits: 1, picks: 3});
|
||||
await promiseAutocompleteResultPopup("");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
|
||||
Assert.equal(result.url, url1, "Check first result");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result.url, url2, "Check second result");
|
||||
|
||||
info("Different visit count, same picks, invert");
|
||||
await PlacesUtils.history.clear();
|
||||
await bumpScore(url1, "site", {visits: 1, picks: 3});
|
||||
await bumpScore(url2, "site", {visits: 3, picks: 3});
|
||||
await promiseAutocompleteResultPopup("");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
|
||||
Assert.equal(result.url, url2, "Check first result");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result.url, url1, "Check second result");
|
||||
});
|
||||
|
||||
add_task(async function test_adaptive_with_search_terms() {
|
||||
let url1 = "http://site.tld/1";
|
||||
let url2 = "http://site.tld/2";
|
||||
|
||||
info("Same visit count, same picks, one partial match, one exact match");
|
||||
await PlacesUtils.history.clear();
|
||||
await bumpScore(url1, "si", {visits: 3, picks: 3});
|
||||
await bumpScore(url2, "site", {visits: 3, picks: 3});
|
||||
await promiseAutocompleteResultPopup("si");
|
||||
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result.url, url1, "Check first result");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 2);
|
||||
Assert.equal(result.url, url2, "Check second result");
|
||||
|
||||
info("Same visit count, same picks, one partial match, one exact match, invert");
|
||||
await PlacesUtils.history.clear();
|
||||
await bumpScore(url1, "site", {visits: 3, picks: 3});
|
||||
await bumpScore(url2, "si", {visits: 3, picks: 3});
|
||||
await promiseAutocompleteResultPopup("si");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result.url, url2, "Check first result");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 2);
|
||||
Assert.equal(result.url, url1, "Check second result");
|
||||
|
||||
info("Same visit count, different picks, both exact match");
|
||||
await PlacesUtils.history.clear();
|
||||
await bumpScore(url1, "si", {visits: 3, picks: 3});
|
||||
await bumpScore(url2, "si", {visits: 3, picks: 1});
|
||||
await promiseAutocompleteResultPopup("si");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result.url, url1, "Check first result");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 2);
|
||||
Assert.equal(result.url, url2, "Check second result");
|
||||
|
||||
info("Same visit count, different picks, both exact match, invert");
|
||||
await PlacesUtils.history.clear();
|
||||
await bumpScore(url1, "si", {visits: 3, picks: 1});
|
||||
await bumpScore(url2, "si", {visits: 3, picks: 3});
|
||||
await promiseAutocompleteResultPopup("si");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result.url, url2, "Check first result");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 2);
|
||||
Assert.equal(result.url, url1, "Check second result");
|
||||
|
||||
info("Same visit count, different picks, both partial match");
|
||||
await PlacesUtils.history.clear();
|
||||
await bumpScore(url1, "site", {visits: 3, picks: 3});
|
||||
await bumpScore(url2, "site", {visits: 3, picks: 1});
|
||||
await promiseAutocompleteResultPopup("si");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result.url, url1, "Check first result");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 2);
|
||||
Assert.equal(result.url, url2, "Check second result");
|
||||
|
||||
info("Same visit count, different picks, both partial match, invert");
|
||||
await PlacesUtils.history.clear();
|
||||
await bumpScore(url1, "site", {visits: 3, picks: 1});
|
||||
await bumpScore(url2, "site", {visits: 3, picks: 3});
|
||||
await promiseAutocompleteResultPopup("si");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result.url, url2, "Check first result");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 2);
|
||||
Assert.equal(result.url, url1, "Check second result");
|
||||
});
|
||||
|
||||
add_task(async function test_adaptive_with_decay() {
|
||||
let url1 = "http://site.tld/1";
|
||||
let url2 = "http://site.tld/2";
|
||||
|
||||
info("Same visit count, same picks, both exact match, decay first");
|
||||
await PlacesUtils.history.clear();
|
||||
await bumpScore(url1, "si", {visits: 3, picks: 3});
|
||||
await decayInputHistory();
|
||||
await bumpScore(url2, "si", {visits: 3, picks: 3});
|
||||
await promiseAutocompleteResultPopup("si");
|
||||
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result.url, url2, "Check first result");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 2);
|
||||
Assert.equal(result.url, url1, "Check second result");
|
||||
|
||||
info("Same visit count, same picks, both exact match, decay second");
|
||||
await PlacesUtils.history.clear();
|
||||
await bumpScore(url2, "si", {visits: 3, picks: 3});
|
||||
await decayInputHistory();
|
||||
await bumpScore(url1, "si", {visits: 3, picks: 3});
|
||||
await promiseAutocompleteResultPopup("si");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result.url, url1, "Check first result");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 2);
|
||||
Assert.equal(result.url, url2, "Check second result");
|
||||
});
|
||||
|
||||
|
||||
add_task(async function test_adaptive_limited() {
|
||||
let url1 = "http://site.tld/1";
|
||||
let url2 = "http://site.tld/2";
|
||||
|
||||
info("Same visit count, same picks, both exact match, decay first");
|
||||
await PlacesUtils.history.clear();
|
||||
await bumpScore(url1, "si", {visits: 3, picks: 3});
|
||||
await decayInputHistory();
|
||||
await bumpScore(url2, "si", {visits: 3, picks: 3});
|
||||
await promiseAutocompleteResultPopup("si");
|
||||
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result.url, url2, "Check first result");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 2);
|
||||
Assert.equal(result.url, url1, "Check second result");
|
||||
|
||||
info("Same visit count, same picks, both exact match, decay second");
|
||||
await PlacesUtils.history.clear();
|
||||
await bumpScore(url2, "si", {visits: 3, picks: 3});
|
||||
await decayInputHistory();
|
||||
await bumpScore(url1, "si", {visits: 3, picks: 3});
|
||||
await promiseAutocompleteResultPopup("si");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result.url, url1, "Check first result");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 2);
|
||||
Assert.equal(result.url, url2, "Check second result");
|
||||
});
|
||||
|
||||
add_task(async function test_adaptive_limited() {
|
||||
info("Adaptive results should be added at the top up to maxRichResults / 4, then enqueued");
|
||||
await PlacesUtils.history.clear();
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
|
||||
// Add as many adaptive results as maxRichResults.
|
||||
let n = UrlbarPrefs.get("maxRichResults");
|
||||
let urls = Array(n).fill(0).map((e, i) => "http://site.tld/" + i);
|
||||
for (let url of urls) {
|
||||
await bumpScore(url, "site", {visits: 1, picks: 1});
|
||||
}
|
||||
|
||||
// Add a matching bookmark with an higher frecency.
|
||||
let url = "http://site.bookmark.tld/";
|
||||
await PlacesTestUtils.addVisits(url);
|
||||
let bm = await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
title: "test_site_book",
|
||||
url,
|
||||
});
|
||||
|
||||
let expectedBookmarkIndex = Math.floor(n / 4) + 2;
|
||||
await promiseAutocompleteResultPopup("site");
|
||||
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, expectedBookmarkIndex);
|
||||
Assert.equal(result.url, url, "Check bookmarked result");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, n - 1);
|
||||
Assert.equal(UrlbarTestUtils.getResultCount(window), n,
|
||||
"Check all the results are filled");
|
||||
Assert.ok(result.url.startsWith("http://site.tld"),
|
||||
"Check last adaptive result");
|
||||
await PlacesUtils.bookmarks.remove(bm);
|
||||
});
|
||||
|
||||
add_task(async function test_adaptive_behaviors() {
|
||||
info("Check adaptive results are not provided regardless of the requested behavior");
|
||||
await PlacesUtils.history.clear();
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
|
||||
// Add an adaptive entry.
|
||||
await bumpScore("http://site.tld/1", "site", {visits: 1, picks: 1});
|
||||
|
||||
let url = "http://bookmarked.site.tld/1";
|
||||
let bm = await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
title: "test_book",
|
||||
url,
|
||||
});
|
||||
|
||||
await SpecialPowers.pushPrefEnv({set: [
|
||||
// Search only bookmarks.
|
||||
["browser.urlbar.suggest.bookmarks", true],
|
||||
["browser.urlbar.suggest.history", false],
|
||||
]});
|
||||
await promiseAutocompleteResultPopup("site");
|
||||
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result.url, url, "Check bookmarked result");
|
||||
|
||||
Assert.equal(UrlbarTestUtils.getResultCount(window), 2,
|
||||
"Check there are no unexpected results");
|
||||
|
||||
await PlacesUtils.bookmarks.remove(bm);
|
||||
await SpecialPowers.popPrefEnv();
|
||||
});
|
||||
|
||||
add_task(async function test_adaptive_mouse() {
|
||||
info("Check adaptive results are updated on mouse picks");
|
||||
await PlacesUtils.history.clear();
|
||||
|
||||
let url1 = "http://site.tld/1";
|
||||
let url2 = "http://site.tld/2";
|
||||
|
||||
info("Same visit count, different picks");
|
||||
await PlacesUtils.history.clear();
|
||||
await bumpScore(url1, "site", {visits: 3, picks: 3}, true);
|
||||
await bumpScore(url2, "site", {visits: 3, picks: 1}, true);
|
||||
await promiseAutocompleteResultPopup("");
|
||||
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
|
||||
Assert.equal(result.url, url1, "Check first result");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result.url, url2, "Check second result");
|
||||
|
||||
info("Same visit count, different picks, invert");
|
||||
await PlacesUtils.history.clear();
|
||||
await bumpScore(url1, "site", {visits: 3, picks: 1}, true);
|
||||
await bumpScore(url2, "site", {visits: 3, picks: 3}, true);
|
||||
await promiseAutocompleteResultPopup("");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
|
||||
Assert.equal(result.url, url2, "Check first result");
|
||||
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result.url, url1, "Check second result");
|
||||
});
|
|
@ -57,6 +57,7 @@ skip-if = os != "mac" # Mac only feature
|
|||
[../browser/browser_canonizeURL.js]
|
||||
[../browser/browser_dragdropURL.js]
|
||||
[../browser/browser_ime_composition.js]
|
||||
[../browser/browser_inputHistory.js]
|
||||
[../browser/browser_keywordBookmarklets.js]
|
||||
[../browser/browser_keepStateAcrossTabSwitches.js]
|
||||
[../browser/browser_keyword_override.js]
|
||||
|
|
|
@ -1324,4 +1324,10 @@ interface nsINavHistoryService : nsISupports
|
|||
* May be null if it's too late to get one.
|
||||
*/
|
||||
readonly attribute nsIAsyncShutdownClient connectionShutdownClient;
|
||||
|
||||
/**
|
||||
* Asynchronously recalculates frecency for all pages where frecency < 0, then
|
||||
* decays frecency and inputhistory values.
|
||||
*/
|
||||
void decayFrecency();
|
||||
};
|
||||
|
|
|
@ -2301,13 +2301,14 @@ nsNavHistory::Observe(nsISupports* aSubject, const char* aTopic,
|
|||
}
|
||||
|
||||
else if (strcmp(aTopic, TOPIC_IDLE_DAILY) == 0) {
|
||||
(void)FixAndDecayFrecency();
|
||||
(void)DecayFrecency();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsNavHistory::FixAndDecayFrecency() {
|
||||
NS_IMETHODIMP
|
||||
nsNavHistory::DecayFrecency() {
|
||||
float decayRate =
|
||||
Preferences::GetFloat(PREF_FREC_DECAY_RATE, PREF_FREC_DECAY_RATE_DEF);
|
||||
if (decayRate > 1.0f) {
|
||||
|
|
|
@ -438,16 +438,6 @@ class nsNavHistory final : public nsSupportsWeakReference,
|
|||
// Database handle.
|
||||
RefPtr<mozilla::places::Database> mDB;
|
||||
|
||||
/**
|
||||
* Recalculates frecency for all pages where frecency < 0, then decays
|
||||
* frecency and inputhistory values. Pages can invalidate frecencies:
|
||||
* * After a "clear private data"
|
||||
* * After removing visits
|
||||
* * After migrating from older versions
|
||||
* This method runs on idle-daily.
|
||||
*/
|
||||
nsresult FixAndDecayFrecency();
|
||||
|
||||
/**
|
||||
* Loads all of the preferences that we use into member variables.
|
||||
*
|
||||
|
|
|
@ -1,370 +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 395739 to make sure the feedback to the search results in those
|
||||
* entries getting better ranks. Additionally, exact matches should be ranked
|
||||
* higher. Because the interactions among adaptive rank and visit counts is not
|
||||
* well defined, this test holds one of the two values constant when modifying
|
||||
* the other.
|
||||
*
|
||||
* This also tests bug 395735 for the instrumentation feedback mechanism.
|
||||
*
|
||||
* Bug 411293 is tested to make sure the drop down strongly prefers previously
|
||||
* typed pages that have been selected and are moved to the top with adaptive
|
||||
* learning.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks that autocomplete results are ordered correctly.
|
||||
*/
|
||||
function ensure_results(expected, searchTerm, callback) {
|
||||
let controller = Cc["@mozilla.org/autocomplete/controller;1"].
|
||||
getService(Ci.nsIAutoCompleteController);
|
||||
|
||||
// Make an AutoCompleteInput that uses our searches
|
||||
// and confirms results on search complete.
|
||||
let input = new AutoCompleteInput(["unifiedcomplete"]);
|
||||
|
||||
controller.input = input;
|
||||
|
||||
input.onSearchComplete = function() {
|
||||
Assert.equal(controller.searchStatus,
|
||||
Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH,
|
||||
"The search should be complete");
|
||||
Assert.equal(controller.matchCount, expected.length,
|
||||
"All the expected results should have been found");
|
||||
for (let i = 0; i < controller.matchCount; i++) {
|
||||
print("Testing for '" + expected[i].uri.spec + "' got '" + controller.getValueAt(i) + "'");
|
||||
Assert.equal(controller.getValueAt(i), expected[i].uri.spec);
|
||||
Assert.equal(controller.getStyleAt(i), expected[i].style);
|
||||
}
|
||||
|
||||
callback();
|
||||
};
|
||||
|
||||
controller.startSearch(searchTerm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronous task that bumps up the rank for an uri.
|
||||
*/
|
||||
async function task_setCountRank(aURI, aCount, aRank, aSearch, aBookmark) {
|
||||
// Bump up the visit count for the uri.
|
||||
let visits = [];
|
||||
for (let i = 0; i < aCount; i++) {
|
||||
visits.push({ uri: aURI, visitDate: d1, transition: TRANSITION_TYPED });
|
||||
}
|
||||
await PlacesTestUtils.addVisits(visits);
|
||||
|
||||
// Make a nsIAutoCompleteController and friends for instrumentation feedback.
|
||||
let thing = {
|
||||
QueryInterface: ChromeUtils.generateQI([Ci.nsIAutoCompleteInput,
|
||||
Ci.nsIAutoCompletePopup,
|
||||
Ci.nsIAutoCompleteController]),
|
||||
get popup() {
|
||||
return thing;
|
||||
},
|
||||
get controller() {
|
||||
return thing;
|
||||
},
|
||||
popupOpen: true,
|
||||
selectedIndex: 0,
|
||||
getValueAt() {
|
||||
return aURI.spec;
|
||||
},
|
||||
searchString: aSearch,
|
||||
};
|
||||
|
||||
// Bump up the instrumentation feedback.
|
||||
for (let i = 0; i < aRank; i++) {
|
||||
Services.obs.notifyObservers(thing, "autocomplete-will-enter-text");
|
||||
}
|
||||
|
||||
// If this is supposed to be a bookmark, add it.
|
||||
if (aBookmark) {
|
||||
await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
title: "test_book",
|
||||
url: aURI,
|
||||
});
|
||||
|
||||
// And add the tag if we need to.
|
||||
if (aBookmark == "tag") {
|
||||
PlacesUtils.tagging.tagURI(aURI, ["test_tag"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decay the adaptive entries by sending the daily idle topic.
|
||||
*/
|
||||
function doAdaptiveDecay() {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
PlacesUtils.history.QueryInterface(Ci.nsIObserver)
|
||||
.observe(null, "idle-daily", null);
|
||||
}
|
||||
}
|
||||
|
||||
var uri1 = uri("http://site.tld/1");
|
||||
var uri2 = uri("http://site.tld/2");
|
||||
|
||||
// d1 is some date for the page visit
|
||||
var d1 = new Date(Date.now() - 1000 * 60 * 60) * 1000;
|
||||
// c1 is larger (should show up higher) than c2
|
||||
var c1 = 10;
|
||||
var c2 = 1;
|
||||
// s1 is a partial match of s2
|
||||
var s0 = "";
|
||||
var s1 = "si";
|
||||
var s2 = "site";
|
||||
|
||||
var observer;
|
||||
|
||||
function promiseResultsCompleted() {
|
||||
return new Promise(resolve => {
|
||||
observer = {
|
||||
results: null,
|
||||
search: null,
|
||||
runCount: -1,
|
||||
observe(aSubject, aTopic, aData) {
|
||||
if (--this.runCount > 0)
|
||||
return;
|
||||
ensure_results(this.results, this.search, resolve);
|
||||
Services.obs.removeObserver(observer, PlacesUtils.TOPIC_FEEDBACK_UPDATED);
|
||||
},
|
||||
};
|
||||
Services.obs.addObserver(observer, PlacesUtils.TOPIC_FEEDBACK_UPDATED);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the result object for a given URI that will be passed to ensure_results.
|
||||
*/
|
||||
function makeResult(aURI, aStyle = "favicon") {
|
||||
return {
|
||||
uri: aURI,
|
||||
style: aStyle,
|
||||
};
|
||||
}
|
||||
|
||||
var tests = [
|
||||
// Test things without a search term.
|
||||
async function() {
|
||||
print("Test 0 same count, diff rank, same term; no search");
|
||||
observer.results = [
|
||||
makeResult(uri1),
|
||||
makeResult(uri2),
|
||||
];
|
||||
observer.search = s0;
|
||||
observer.runCount = c1 + c2;
|
||||
await task_setCountRank(uri1, c1, c1, s2);
|
||||
await task_setCountRank(uri2, c1, c2, s2);
|
||||
},
|
||||
async function() {
|
||||
print("Test 1 same count, diff rank, same term; no search");
|
||||
observer.results = [
|
||||
makeResult(uri2),
|
||||
makeResult(uri1),
|
||||
];
|
||||
observer.search = s0;
|
||||
observer.runCount = c1 + c2;
|
||||
await task_setCountRank(uri1, c1, c2, s2);
|
||||
await task_setCountRank(uri2, c1, c1, s2);
|
||||
},
|
||||
async function() {
|
||||
print("Test 2 diff count, same rank, same term; no search");
|
||||
observer.results = [
|
||||
makeResult(uri1),
|
||||
makeResult(uri2),
|
||||
];
|
||||
observer.search = s0;
|
||||
observer.runCount = c1 + c1;
|
||||
await task_setCountRank(uri1, c1, c1, s2);
|
||||
await task_setCountRank(uri2, c2, c1, s2);
|
||||
},
|
||||
async function() {
|
||||
print("Test 3 diff count, same rank, same term; no search");
|
||||
observer.results = [
|
||||
makeResult(uri2),
|
||||
makeResult(uri1),
|
||||
];
|
||||
observer.search = s0;
|
||||
observer.runCount = c1 + c1;
|
||||
await task_setCountRank(uri1, c2, c1, s2);
|
||||
await task_setCountRank(uri2, c1, c1, s2);
|
||||
},
|
||||
|
||||
// Test things with a search term (exact match one, partial other).
|
||||
async function() {
|
||||
print("Test 4 same count, same rank, diff term; one exact/one partial search");
|
||||
observer.results = [
|
||||
makeResult(uri1),
|
||||
makeResult(uri2),
|
||||
];
|
||||
observer.search = s1;
|
||||
observer.runCount = c1 + c1;
|
||||
await task_setCountRank(uri1, c1, c1, s1);
|
||||
await task_setCountRank(uri2, c1, c1, s2);
|
||||
},
|
||||
async function() {
|
||||
print("Test 5 same count, same rank, diff term; one exact/one partial search");
|
||||
observer.results = [
|
||||
makeResult(uri2),
|
||||
makeResult(uri1),
|
||||
];
|
||||
observer.search = s1;
|
||||
observer.runCount = c1 + c1;
|
||||
await task_setCountRank(uri1, c1, c1, s2);
|
||||
await task_setCountRank(uri2, c1, c1, s1);
|
||||
},
|
||||
|
||||
// Test things with a search term (exact match both).
|
||||
async function() {
|
||||
print("Test 6 same count, diff rank, same term; both exact search");
|
||||
observer.results = [
|
||||
makeResult(uri1),
|
||||
makeResult(uri2),
|
||||
];
|
||||
observer.search = s1;
|
||||
observer.runCount = c1 + c2;
|
||||
await task_setCountRank(uri1, c1, c1, s1);
|
||||
await task_setCountRank(uri2, c1, c2, s1);
|
||||
},
|
||||
async function() {
|
||||
print("Test 7 same count, diff rank, same term; both exact search");
|
||||
observer.results = [
|
||||
makeResult(uri2),
|
||||
makeResult(uri1),
|
||||
];
|
||||
observer.search = s1;
|
||||
observer.runCount = c1 + c2;
|
||||
await task_setCountRank(uri1, c1, c2, s1);
|
||||
await task_setCountRank(uri2, c1, c1, s1);
|
||||
},
|
||||
|
||||
// Test things with a search term (partial match both).
|
||||
async function() {
|
||||
print("Test 8 same count, diff rank, same term; both partial search");
|
||||
observer.results = [
|
||||
makeResult(uri1),
|
||||
makeResult(uri2),
|
||||
];
|
||||
observer.search = s1;
|
||||
observer.runCount = c1 + c2;
|
||||
await task_setCountRank(uri1, c1, c1, s2);
|
||||
await task_setCountRank(uri2, c1, c2, s2);
|
||||
},
|
||||
async function() {
|
||||
print("Test 9 same count, diff rank, same term; both partial search");
|
||||
observer.results = [
|
||||
makeResult(uri2),
|
||||
makeResult(uri1),
|
||||
];
|
||||
observer.search = s1;
|
||||
observer.runCount = c1 + c2;
|
||||
await task_setCountRank(uri1, c1, c2, s2);
|
||||
await task_setCountRank(uri2, c1, c1, s2);
|
||||
},
|
||||
async function() {
|
||||
print("Test 10 same count, same rank, same term, decay first; exact match");
|
||||
observer.results = [
|
||||
makeResult(uri2),
|
||||
makeResult(uri1),
|
||||
];
|
||||
observer.search = s1;
|
||||
observer.runCount = c1 + c1;
|
||||
await task_setCountRank(uri1, c1, c1, s1);
|
||||
doAdaptiveDecay();
|
||||
await task_setCountRank(uri2, c1, c1, s1);
|
||||
},
|
||||
async function() {
|
||||
print("Test 11 same count, same rank, same term, decay second; exact match");
|
||||
observer.results = [
|
||||
makeResult(uri1),
|
||||
makeResult(uri2),
|
||||
];
|
||||
observer.search = s1;
|
||||
observer.runCount = c1 + c1;
|
||||
await task_setCountRank(uri2, c1, c1, s1);
|
||||
doAdaptiveDecay();
|
||||
await task_setCountRank(uri1, c1, c1, s1);
|
||||
},
|
||||
// Test that bookmarks are hidden if the preferences are set right.
|
||||
async function() {
|
||||
print("Test 12 same count, diff rank, same term; no search; history only");
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.history", true);
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.openpage", false);
|
||||
observer.results = [
|
||||
makeResult(uri1),
|
||||
makeResult(uri2),
|
||||
];
|
||||
observer.search = s0;
|
||||
observer.runCount = c1 + c2;
|
||||
await task_setCountRank(uri1, c1, c1, s2, "bookmark");
|
||||
await task_setCountRank(uri2, c1, c2, s2);
|
||||
},
|
||||
// Test that tags are shown if the preferences are set right.
|
||||
async function() {
|
||||
print("Test 13 same count, diff rank, same term; no search; history only with tag");
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.history", true);
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.openpage", false);
|
||||
observer.results = [
|
||||
makeResult(uri1, "tag"),
|
||||
makeResult(uri2),
|
||||
];
|
||||
observer.search = s0;
|
||||
observer.runCount = c1 + c2;
|
||||
await task_setCountRank(uri1, c1, c1, s2, "tag");
|
||||
await task_setCountRank(uri2, c1, c2, s2);
|
||||
},
|
||||
// Test that many results are all shown if no other results are available.
|
||||
async function() {
|
||||
print("Test 14 - many results");
|
||||
let n = 10;
|
||||
observer.results = Array(n).fill(0).map(
|
||||
(e, i) => makeResult(Services.io.newURI("http://site.tld/" + i))
|
||||
);
|
||||
observer.search = s2;
|
||||
observer.runCount = n * (n + 1) / 2;
|
||||
let c = n;
|
||||
for (let result of observer.results) {
|
||||
task_setCountRank(result.uri, c, c, s2);
|
||||
c--;
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Test adaptive autocomplete.
|
||||
*/
|
||||
add_task(async function test_adaptive() {
|
||||
// Disable autoFill for this test.
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
|
||||
|
||||
registerCleanupFunction(async function() {
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
await PlacesUtils.history.clear();
|
||||
});
|
||||
|
||||
for (let test of tests) {
|
||||
// Cleanup.
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
|
||||
let types = ["history", "bookmark", "openpage"];
|
||||
for (let type of types) {
|
||||
Services.prefs.clearUserPref("browser.urlbar.suggest." + type);
|
||||
}
|
||||
|
||||
await PlacesUtils.history.clear();
|
||||
|
||||
let resultsCompletedPromise = promiseResultsCompleted();
|
||||
await test();
|
||||
await resultsCompletedPromise;
|
||||
}
|
||||
});
|
|
@ -1,40 +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 527311
|
||||
// Addressbar suggests adaptive results regardless of the requested behavior.
|
||||
|
||||
const TEST_URL = "http://adapt.mozilla.org/";
|
||||
const SEARCH_STRING = "adapt";
|
||||
const SUGGEST_TYPES = ["history", "bookmark", "openpage"];
|
||||
|
||||
add_task(async function test_adaptive_search_specific() {
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
|
||||
|
||||
// Add a bookmark to our url.
|
||||
await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
title: "test_book",
|
||||
url: TEST_URL,
|
||||
});
|
||||
registerCleanupFunction(async function() {
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
});
|
||||
|
||||
// We want to search only history.
|
||||
for (let type of SUGGEST_TYPES) {
|
||||
type == "history" ? Services.prefs.setBoolPref("browser.urlbar.suggest." + type, true)
|
||||
: Services.prefs.setBoolPref("browser.urlbar.suggest." + type, false);
|
||||
}
|
||||
|
||||
// Add an adaptive entry.
|
||||
await addAdaptiveFeedback(TEST_URL, SEARCH_STRING);
|
||||
|
||||
await check_autocomplete({
|
||||
search: SEARCH_STRING,
|
||||
matches: [],
|
||||
});
|
||||
});
|
|
@ -1,41 +0,0 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// Test that top adaptive results are limited, remaining ones are enqueued.
|
||||
|
||||
add_task(async function() {
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
|
||||
|
||||
let n = 10;
|
||||
let uris = Array(n).fill(0).map((e, i) => "http://site.tld/" + i);
|
||||
|
||||
// Add a bookmark to one url.
|
||||
let bm = await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
title: "test_book",
|
||||
url: uris.shift(),
|
||||
});
|
||||
|
||||
// Make remaining ones adaptive results.
|
||||
for (let uri of uris) {
|
||||
await PlacesTestUtils.addVisits(uri);
|
||||
await addAdaptiveFeedback(uri, "book");
|
||||
}
|
||||
|
||||
registerCleanupFunction(async function() {
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
await PlacesUtils.history.clear();
|
||||
});
|
||||
|
||||
let matches = uris.map(uri => ({ uri: Services.io.newURI(uri),
|
||||
title: "test visit for " + uri }));
|
||||
let book_index = Math.ceil(Services.prefs.getIntPref("browser.urlbar.maxRichResults", 10) / 4);
|
||||
matches.splice(book_index, 0, { uri: Services.io.newURI(bm.url.href),
|
||||
title: "test_book", "style": ["bookmark"] });
|
||||
|
||||
await check_autocomplete({
|
||||
search: "book",
|
||||
matches,
|
||||
checkSorting: true,
|
||||
});
|
||||
});
|
|
@ -14,9 +14,6 @@ support-files =
|
|||
[test_417798.js]
|
||||
[test_418257.js]
|
||||
[test_422277.js]
|
||||
[test_adaptive.js]
|
||||
[test_adaptive_behaviors.js]
|
||||
[test_adaptive_limited.js]
|
||||
[test_autocomplete_functional.js]
|
||||
[test_autocomplete_stopSearch_no_throw.js]
|
||||
[test_autofill_about_urls.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче