Bug 993372 - Part 1 - Port inline tests to unified autocomplete. r=mano

--HG--
rename : toolkit/components/places/tests/inline/head_autocomplete.js => toolkit/components/places/tests/unifiedcomplete/head_autocomplete.js
rename : toolkit/components/places/tests/inline/test_autocomplete_functional.js => toolkit/components/places/tests/unifiedcomplete/test_autocomplete_functional.js
rename : toolkit/components/places/tests/inline/test_casing.js => toolkit/components/places/tests/unifiedcomplete/test_casing.js
rename : toolkit/components/places/tests/inline/test_do_not_trim.js => toolkit/components/places/tests/unifiedcomplete/test_do_not_trim.js
rename : toolkit/components/places/tests/inline/test_keywords.js => toolkit/components/places/tests/unifiedcomplete/test_keywords.js
rename : toolkit/components/places/tests/inline/test_queryurl.js => toolkit/components/places/tests/unifiedcomplete/test_queryurl.js
rename : toolkit/components/places/tests/inline/test_trimming.js => toolkit/components/places/tests/unifiedcomplete/test_trimming.js
rename : toolkit/components/places/tests/inline/test_typed.js => toolkit/components/places/tests/unifiedcomplete/test_typed.js
rename : toolkit/components/places/tests/inline/test_zero_frecency.js => toolkit/components/places/tests/unifiedcomplete/test_zero_frecency.js
rename : toolkit/components/places/tests/inline/xpcshell.ini => toolkit/components/places/tests/unifiedcomplete/xpcshell.ini
This commit is contained in:
Marco Bonardo 2014-07-18 09:42:31 +02:00
parent 4a29cdabe1
commit 12bdbecad7
12 changed files with 1091 additions and 27 deletions

View File

@ -19,7 +19,7 @@ const TOPIC_PREFCHANGED = "nsPref:changed";
const DEFAULT_BEHAVIOR = 0;
const PREF_BRANCH = "browser.urlbar";
const PREF_BRANCH = "browser.urlbar.";
// Prefs are defined as [pref name, default value].
const PREF_ENABLED = [ "autocomplete.enabled", true ];
@ -187,7 +187,7 @@ const SQL_KEYWORD_QUERY = sql(
const SQL_HOST_QUERY = sql(
"/* do not warn (bug NA): not worth to index on (typed, frecency) */",
"SELECT :query_type, host || '/', prefix || host || '/',",
"SELECT :query_type, host || '/', IFNULL(prefix, '') || host || '/',",
"NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, frecency",
"FROM moz_hosts",
"WHERE host BETWEEN :searchString AND :searchString || X'FFFF'",
@ -200,7 +200,7 @@ const SQL_TYPED_HOST_QUERY = SQL_HOST_QUERY.replace("/*CONDITIONS*/",
"AND typed = 1");
const SQL_URL_QUERY = sql(
"/* do not warn (bug no): cannot use an index */",
"SELECT :query_type, h.url,",
"SELECT :query_type, h.url, NULL,",
"NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, h.frecency",
"FROM moz_places h",
"WHERE h.frecency <> 0",
@ -440,24 +440,24 @@ function stripPrefix(spec)
function Search(searchString, searchParam, autocompleteListener,
resultListener, autocompleteSearch) {
// We want to store the original string with no leading or trailing
// whitespace for case sensitive searches.
this._originalSearchString = searchString.trim();
this._searchString = fixupSearchText(this._originalSearchString.toLowerCase());
// We want to store the original string for case sensitive searches.
this._originalSearchString = searchString;
this._trimmedOriginalSearchString = searchString.trim();
this._searchString = fixupSearchText(this._trimmedOriginalSearchString.toLowerCase());
this._searchTokens =
this.filterTokens(getUnfilteredSearchTokens(this._searchString));
// The protocol and the host are lowercased by nsIURI, so it's fine to
// lowercase the typed prefix, to add it back to the results later.
this._strippedPrefix = this._originalSearchString.slice(
0, this._originalSearchString.length - this._searchString.length
this._strippedPrefix = this._trimmedOriginalSearchString.slice(
0, this._trimmedOriginalSearchString.length - this._searchString.length
).toLowerCase();
// The URIs in the database are fixed-up, so we can match on a lowercased
// host, but the path must be matched in a case sensitive way.
let pathIndex =
this._originalSearchString.indexOf("/", this._strippedPrefix.length);
this._trimmedOriginalSearchString.indexOf("/", this._strippedPrefix.length);
this._autofillUrlSearchString = fixupSearchText(
this._originalSearchString.slice(0, pathIndex).toLowerCase() +
this._originalSearchString.slice(pathIndex)
this._trimmedOriginalSearchString.slice(0, pathIndex).toLowerCase() +
this._trimmedOriginalSearchString.slice(pathIndex)
);
this._enableActions = searchParam.split(" ").indexOf("enable-actions") != -1;
@ -756,7 +756,7 @@ Search.prototype = {
// If the untrimmed value doesn't preserve the user's input just
// ignore it and complete to the found host.
if (untrimmedHost &&
!untrimmedHost.toLowerCase().contains(this._originalSearchString.toLowerCase())) {
!untrimmedHost.toLowerCase().contains(this._trimmedOriginalSearchString.toLowerCase())) {
// THIS CAUSES null TO BE SHOWN AS TITLE.
untrimmedHost = null;
}
@ -791,7 +791,7 @@ Search.prototype = {
// ignore it and complete to the found url.
let untrimmedURL = prefix + url;
if (untrimmedURL &&
!untrimmedURL.toLowerCase().contains(this._originalSearchString.toLowerCase())) {
!untrimmedURL.toLowerCase().contains(this._trimmedOriginalSearchString.toLowerCase())) {
// THIS CAUSES null TO BE SHOWN AS TITLE.
untrimmedURL = null;
}
@ -927,7 +927,7 @@ Search.prototype = {
get _keywordQuery() {
// The keyword is the first word in the search string, with the parameters
// following it.
let searchString = this._originalSearchString;
let searchString = this._trimmedOriginalSearchString;
let queryString = "";
let queryIndex = searchString.indexOf(" ");
if (queryIndex != -1) {
@ -999,6 +999,14 @@ Search.prototype = {
if (Prefs.defaultBehavior != DEFAULT_BEHAVIOR)
return false;
// Don't try to autofill if the search term includes any whitespace.
// This may confuse completeDefaultIndex cause the AUTOCOMPLETE_MATCH
// tokenizer ends up trimming the search string and returning a value
// that doesn't match it, or is even shorter.
if (/\s/.test(this._originalSearchString)) {
return false;
}
// Don't autoFill if the search term is recognized as a keyword, otherwise
// it will override default keywords behavior. Note that keywords are
// hashed on first use, so while the first query may delay a little bit,
@ -1008,14 +1016,6 @@ Search.prototype = {
return false;
}
// Don't try to autofill if the search term includes any whitespace.
// This may confuse completeDefaultIndex cause the AUTOCOMPLETE_MATCH
// tokenizer ends up trimming the search string and returning a value
// that doesn't match it, or is even shorter.
if (/\s/.test(this._searchString)) {
return false;
}
return true;
},
@ -1026,7 +1026,7 @@ Search.prototype = {
* database with and an object containing the params to bound.
*/
get _hostQuery() [
Prefs.autofillTyped ? SQL_TYPED_HOST_QUERY : SQL_TYPED_QUERY,
Prefs.autofillTyped ? SQL_TYPED_HOST_QUERY : SQL_HOST_QUERY,
{
query_type: QUERYTYPE_AUTOFILL_HOST,
searchString: this._searchString.toLowerCase()
@ -1040,7 +1040,7 @@ Search.prototype = {
* database with and an object containing the params to bound.
*/
get _urlQuery() [
Prefs.autofillTyped ? SQL_TYPED_HOST_QUERY : SQL_TYPED_QUERY,
Prefs.autofillTyped ? SQL_TYPED_URL_QUERY : SQL_URL_QUERY,
{
query_type: QUERYTYPE_AUTOFILL_URL,
searchString: this._autofillUrlSearchString,
@ -1117,7 +1117,8 @@ UnifiedComplete.prototype = {
yield SwitchToTabStorage.initDatabase(conn);
return conn;
}.bind(this)).then(null, Cu.reportError);
}.bind(this)).then(null, ex => { dump("Couldn't get database handle: " + ex + "\n");
Cu.reportError(ex); });
}
return this._promiseDatabase;
},
@ -1175,7 +1176,8 @@ UnifiedComplete.prototype = {
if (search == this._currentSearch) {
this.finishSearch(true);
}
}, Cu.reportError);
}, ex => { dump("Query failed: " + ex + "\n");
Cu.reportError(ex); });
},
stopSearch: function () {

View File

@ -15,6 +15,7 @@ XPCSHELL_TESTS_MANIFESTS += [
'migration/xpcshell.ini',
'network/xpcshell.ini',
'queries/xpcshell.ini',
'unifiedcomplete/xpcshell.ini',
'unit/xpcshell.ini',
'xpcshell.ini',
]

View File

@ -0,0 +1,156 @@
/* 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/. */
const Ci = Components.interfaces;
const Cc = Components.classes;
const Cr = Components.results;
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
// Import common head.
let (commonFile = do_get_file("../head_common.js", false)) {
let uri = Services.io.newFileURI(commonFile);
Services.scriptloader.loadSubScript(uri.spec, this);
}
// Put any other stuff relative to this test folder below.
function run_test() {
run_next_test();
}
function* cleanup() {
Services.prefs.clearUserPref("browser.urlbar.autocomplete.enabled");
Services.prefs.clearUserPref("browser.urlbar.autoFill");
Services.prefs.clearUserPref("browser.urlbar.autoFill.typed");
remove_all_bookmarks();
yield promiseClearHistory();
}
do_register_cleanup(cleanup);
/**
* @param aSearches
* Array of AutoCompleteSearch names.
*/
function AutoCompleteInput(aSearches) {
this.searches = aSearches;
}
AutoCompleteInput.prototype = {
popup: {
selectedIndex: -1,
invalidate: function () {},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompletePopup])
},
popupOpen: false,
disableAutoComplete: false,
completeDefaultIndex: true,
completeSelectedIndex: true,
forceComplete: false,
minResultsForPopup: 0,
maxRows: 0,
showCommentColumn: false,
showImageColumn: false,
timeout: 10,
searchParam: "",
get searchCount() {
return this.searches.length;
},
getSearchAt: function(aIndex) {
return this.searches[aIndex];
},
textValue: "",
// Text selection range
_selStart: 0,
_selEnd: 0,
get selectionStart() {
return this._selStart;
},
get selectionEnd() {
return this._selEnd;
},
selectTextRange: function(aStart, aEnd) {
this._selStart = aStart;
this._selEnd = aEnd;
},
onSearchBegin: function () {},
onSearchComplete: function () {},
onTextEntered: function() false,
onTextReverted: function() false,
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteInput])
}
function* check_autocomplete(test) {
// At this point frecency could still be updating due to latest pages
// updates.
// This is not a problem in real life, but autocomplete tests should
// return reliable resultsets, thus we have to wait.
yield promiseAsyncUpdates();
// Make an AutoCompleteInput that uses our searches and confirms results.
let input = new AutoCompleteInput(["unifiedcomplete"]);
input.textValue = test.search;
// Caret must be at the end for autoFill to happen.
let strLen = test.search.length;
input.selectTextRange(strLen, strLen);
Assert.equal(input.selectionStart, strLen, "Selection starts at end");
Assert.equal(input.selectionEnd, strLen, "Selection ends at the end");
let controller = Cc["@mozilla.org/autocomplete/controller;1"]
.getService(Ci.nsIAutoCompleteController);
controller.input = input;
let numSearchesStarted = 0;
input.onSearchBegin = () => {
do_log_info("onSearchBegin received");
numSearchesStarted++;
};
let deferred = Promise.defer();
input.onSearchComplete = () => {
do_log_info("onSearchComplete received");
deferred.resolve();
}
do_log_info("Searching for: '" + test.search + "'");
controller.startSearch(test.search);
yield deferred.promise;
// We should be running only one query.
Assert.equal(numSearchesStarted, 1, "Only one search started");
// Check the autoFilled result.
Assert.equal(input.textValue, test.autofilled,
"Autofilled value is correct");
// Now force completion and check correct casing of the result.
// This ensures the controller is able to do its magic case-preserving
// stuff and correct replacement of the user's casing with result's one.
controller.handleEnter(false);
Assert.equal(input.textValue, test.completed,
"Completed value is correct");
}
function addBookmark(aBookmarkObj) {
Assert.ok(!!aBookmarkObj.url, "Bookmark object contains an url");
let parentId = aBookmarkObj.parentId ? aBookmarkObj.parentId
: PlacesUtils.unfiledBookmarksFolderId;
let itemId = PlacesUtils.bookmarks
.insertBookmark(parentId,
NetUtil.newURI(aBookmarkObj.url),
PlacesUtils.bookmarks.DEFAULT_INDEX,
"A bookmark");
if (aBookmarkObj.keyword) {
PlacesUtils.bookmarks.setKeywordForBookmark(itemId, aBookmarkObj.keyword);
}
}

View File

@ -0,0 +1,147 @@
/* 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/. */
// Functional tests for inline autocomplete
add_task(function* test_disabling_autocomplete() {
do_log_info("Check disabling autocomplete disables autofill");
Services.prefs.setBoolPref("browser.urlbar.autocomplete.enabled", false);
yield promiseAddVisits({ uri: NetUtil.newURI("http://visit.mozilla.org"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "vis",
autofilled: "vis",
completed: "vis"
});
yield cleanup();
});
add_task(function* test_urls_order() {
do_log_info("Add urls, check for correct order");
let places = [{ uri: NetUtil.newURI("http://visit1.mozilla.org") },
{ uri: NetUtil.newURI("http://visit2.mozilla.org"),
transition: TRANSITION_TYPED }];
yield promiseAddVisits(places);
yield check_autocomplete({
search: "vis",
autofilled: "visit2.mozilla.org/",
completed: "visit2.mozilla.org/"
});
yield cleanup();
});
add_task(function* test_ignore_prefix() {
do_log_info("Add urls, make sure www and http are ignored");
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
yield promiseAddVisits(NetUtil.newURI("http://www.visit1.mozilla.org"));
yield check_autocomplete({
search: "visit1",
autofilled: "visit1.mozilla.org/",
completed: "visit1.mozilla.org/"
});
yield cleanup();
});
add_task(function* test_after_host() {
do_log_info("Autocompleting after an existing host completes to the url");
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
yield promiseAddVisits(NetUtil.newURI("http://www.visit3.mozilla.org"));
yield check_autocomplete({
search: "visit3.mozilla.org/",
autofilled: "visit3.mozilla.org/",
completed: "visit3.mozilla.org/"
});
yield cleanup();
});
add_task(function* test_respect_www() {
do_log_info("Searching for www.me should yield www.me.mozilla.org/");
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
yield promiseAddVisits(NetUtil.newURI("http://www.me.mozilla.org"));
yield check_autocomplete({
search: "www.me",
autofilled: "www.me.mozilla.org/",
completed: "www.me.mozilla.org/"
});
yield cleanup();
});
add_task(function* test_bookmark_first() {
do_log_info("With a bookmark and history, the query result should be the bookmark");
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
addBookmark({ url: "http://bookmark1.mozilla.org/", });
yield promiseAddVisits(NetUtil.newURI("http://bookmark1.mozilla.org/foo"));
yield check_autocomplete({
search: "bookmark",
autofilled: "bookmark1.mozilla.org/",
completed: "bookmark1.mozilla.org/"
});
yield cleanup();
});
add_task(function* test_full_path() {
do_log_info("Check to make sure we get the proper results with full paths");
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
let places = [{ uri: NetUtil.newURI("http://smokey.mozilla.org/foo/bar/baz?bacon=delicious") },
{ uri: NetUtil.newURI("http://smokey.mozilla.org/foo/bar/baz?bacon=smokey") }];
yield promiseAddVisits(places);
yield check_autocomplete({
search: "smokey",
autofilled: "smokey.mozilla.org/",
completed: "smokey.mozilla.org/"
});
yield cleanup();
});
add_task(function* test_complete_to_slash() {
do_log_info("Check to make sure we autocomplete to the following '/'");
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
let places = [{ uri: NetUtil.newURI("http://smokey.mozilla.org/foo/bar/baz?bacon=delicious") },
{ uri: NetUtil.newURI("http://smokey.mozilla.org/foo/bar/baz?bacon=smokey") }];
yield promiseAddVisits(places);
yield check_autocomplete({
search: "smokey.mozilla.org/fo",
autofilled: "smokey.mozilla.org/foo/",
completed: "http://smokey.mozilla.org/foo/",
});
yield cleanup();
});
add_task(function* test_complete_to_slash_with_www() {
do_log_info("Check to make sure we autocomplete to the following '/'");
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
let places = [{ uri: NetUtil.newURI("http://www.smokey.mozilla.org/foo/bar/baz?bacon=delicious") },
{ uri: NetUtil.newURI("http://www.smokey.mozilla.org/foo/bar/baz?bacon=smokey") }];
yield promiseAddVisits(places);
yield check_autocomplete({
search: "smokey.mozilla.org/fo",
autofilled: "smokey.mozilla.org/foo/",
completed: "http://www.smokey.mozilla.org/foo/",
});
yield cleanup();
});
add_task(function* test_complete_querystring() {
do_log_info("Check to make sure we autocomplete after ?");
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
yield promiseAddVisits(NetUtil.newURI("http://smokey.mozilla.org/foo?bacon=delicious"));
yield check_autocomplete({
search: "smokey.mozilla.org/foo?",
autofilled: "smokey.mozilla.org/foo?bacon=delicious",
completed: "http://smokey.mozilla.org/foo?bacon=delicious",
});
yield cleanup();
});
add_task(function* test_complete_fragment() {
do_log_info("Check to make sure we autocomplete after #");
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
yield promiseAddVisits(NetUtil.newURI("http://smokey.mozilla.org/foo?bacon=delicious#bar"));
yield check_autocomplete({
search: "smokey.mozilla.org/foo?bacon=delicious#bar",
autofilled: "smokey.mozilla.org/foo?bacon=delicious#bar",
completed: "http://smokey.mozilla.org/foo?bacon=delicious#bar",
});
yield cleanup();
});

View File

@ -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/. */
add_task(function* test_casing_1() {
do_log_info("Searching for cased entry 1");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "MOZ",
autofilled: "MOZilla.org/",
completed: "mozilla.org/"
});
yield cleanup();
});
add_task(function* test_casing_2() {
do_log_info("Searching for cased entry 2");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "mozilla.org/T",
autofilled: "mozilla.org/T",
completed: "mozilla.org/T"
});
yield cleanup();
});
add_task(function* test_casing_3() {
do_log_info("Searching for cased entry 3");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/Test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "mozilla.org/T",
autofilled: "mozilla.org/Test/",
completed: "http://mozilla.org/Test/"
});
yield cleanup();
});
add_task(function* test_casing_4() {
do_log_info("Searching for cased entry 4");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/Test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "mOzilla.org/t",
autofilled: "mOzilla.org/t",
completed: "mOzilla.org/t"
});
yield cleanup();
});
add_task(function* test_casing_5() {
do_log_info("Searching for cased entry 5");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/Test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "mOzilla.org/T",
autofilled: "mOzilla.org/Test/",
completed: "http://mozilla.org/Test/"
});
yield cleanup();
});
add_task(function* test_untrimmed_casing() {
do_log_info("Searching for untrimmed cased entry");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/Test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "http://mOz",
autofilled: "http://mOzilla.org/",
completed: "http://mozilla.org/"
});
yield cleanup();
});
add_task(function* test_untrimmed_www_casing() {
do_log_info("Searching for untrimmed cased entry with www");
yield promiseAddVisits({ uri: NetUtil.newURI("http://www.mozilla.org/Test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "http://www.mOz",
autofilled: "http://www.mOzilla.org/",
completed: "http://www.mozilla.org/"
});
yield cleanup();
});
add_task(function* test_untrimmed_path_casing() {
do_log_info("Searching for untrimmed cased entry with path");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/Test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "http://mOzilla.org/t",
autofilled: "http://mOzilla.org/t",
completed: "http://mOzilla.org/t"
});
yield cleanup();
});
add_task(function* test_untrimmed_path_casing_2() {
do_log_info("Searching for untrimmed cased entry with path 2");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/Test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "http://mOzilla.org/T",
autofilled: "http://mOzilla.org/Test/",
completed: "http://mozilla.org/Test/"
});
yield cleanup();
});
add_task(function* test_untrimmed_path_www_casing() {
do_log_info("Searching for untrimmed cased entry with www and path");
yield promiseAddVisits({ uri: NetUtil.newURI("http://www.mozilla.org/Test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "http://www.mOzilla.org/t",
autofilled: "http://www.mOzilla.org/t",
completed: "http://www.mOzilla.org/t"
});
yield cleanup();
});
add_task(function* test_untrimmed_path_www_casing_2() {
do_log_info("Searching for untrimmed cased entry with www and path 2");
yield promiseAddVisits({ uri: NetUtil.newURI("http://www.mozilla.org/Test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "http://www.mOzilla.org/T",
autofilled: "http://www.mOzilla.org/Test/",
completed: "http://www.mozilla.org/Test/"
});
yield cleanup();
});

View File

@ -0,0 +1,79 @@
/* 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/. */
// Inline should never return matches shorter than the search string, since
// that largely confuses completeDefaultIndex
add_task(function* test_not_autofill_ws_1() {
do_log_info("Do not autofill whitespaced entry 1");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/link/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "mozilla.org ",
autofilled: "mozilla.org ",
completed: "mozilla.org "
});
yield cleanup();
});
add_task(function* test_not_autofill_ws_2() {
do_log_info("Do not autofill whitespaced entry 2");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/link/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "mozilla.org/ ",
autofilled: "mozilla.org/ ",
completed: "mozilla.org/ "
});
yield cleanup();
});
add_task(function* test_not_autofill_ws_3() {
do_log_info("Do not autofill whitespaced entry 3");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/link/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "mozilla.org/link ",
autofilled: "mozilla.org/link ",
completed: "mozilla.org/link "
});
yield cleanup();
});
add_task(function* test_not_autofill_ws_4() {
do_log_info("Do not autofill whitespaced entry 4");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/link/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "mozilla.org/link/ ",
autofilled: "mozilla.org/link/ ",
completed: "mozilla.org/link/ "
});
yield cleanup();
});
add_task(function* test_not_autofill_ws_5() {
do_log_info("Do not autofill whitespaced entry 5");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/link/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "moz illa ",
autofilled: "moz illa ",
completed: "moz illa "
});
yield cleanup();
});
add_task(function* test_not_autofill_ws_6() {
do_log_info("Do not autofill whitespaced entry 6");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/link/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: " mozilla",
autofilled: " mozilla",
completed: " mozilla"
});
yield cleanup();
});

View File

@ -0,0 +1,68 @@
/* 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/. */
add_task(function* test_non_keyword() {
do_log_info("Searching for non-keyworded entry should autoFill it");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/test/"),
transition: TRANSITION_TYPED });
addBookmark({ url: "http://mozilla.org/test/" });
yield check_autocomplete({
search: "moz",
autofilled: "mozilla.org/",
completed: "mozilla.org/"
});
yield cleanup();
});
add_task(function* test_keyword() {
do_log_info("Searching for keyworded entry should not autoFill it");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/test/"),
transition: TRANSITION_TYPED });
addBookmark({ url: "http://mozilla.org/test/", keyword: "moz" });
yield check_autocomplete({
search: "moz",
autofilled: "moz",
completed: "moz",
});
yield cleanup();
});
add_task(function* test_more_than_keyword() {
do_log_info("Searching for more than keyworded entry should autoFill it");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/test/"),
transition: TRANSITION_TYPED });
addBookmark({ url: "http://mozilla.org/test/", keyword: "moz" });
yield check_autocomplete({
search: "mozi",
autofilled: "mozilla.org/",
completed: "mozilla.org/"
});
yield cleanup();
});
add_task(function* test_less_than_keyword() {
do_log_info("Searching for less than keyworded entry should autoFill it");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/test/"),
transition: TRANSITION_TYPED });
addBookmark({ url: "http://mozilla.org/test/", keyword: "moz" });
yield check_autocomplete({
search: "mo",
autofilled: "mozilla.org/",
completed: "mozilla.org/",
});
yield cleanup();
});
add_task(function* test_keyword_casing() {
do_log_info("Searching for keyworded entry is case-insensitive");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/test/"),
transition: TRANSITION_TYPED });
addBookmark({ url: "http://mozilla.org/test/", keyword: "moz" });
yield check_autocomplete({
search: "MoZ",
autofilled: "MoZ",
completed: "MoZ"
});
yield cleanup();
});

View File

@ -0,0 +1,57 @@
/* 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/. */
add_task(function* test_no_slash() {
do_log_info("Searching for host match without slash should match host");
yield promiseAddVisits({ uri: NetUtil.newURI("http://file.org/test/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("file:///c:/test.html"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "file",
autofilled: "file.org/",
completed: "file.org/"
});
yield cleanup();
});
add_task(function* test_w_slash() {
do_log_info("Searching match with slash at the end should do nothing");
yield promiseAddVisits({ uri: NetUtil.newURI("http://file.org/test/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("file:///c:/test.html"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "file.org/",
autofilled: "file.org/",
completed: "file.org/"
});
yield cleanup();
});
add_task(function* test_middle() {
do_log_info("Searching match with slash in the middle should match url");
yield promiseAddVisits({ uri: NetUtil.newURI("http://file.org/test/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("file:///c:/test.html"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "file.org/t",
autofilled: "file.org/test/",
completed: "http://file.org/test/"
});
yield cleanup();
});
add_task(function* test_nonhost() {
do_log_info("Searching for non-host match without slash should not match url");
yield promiseAddVisits({ uri: NetUtil.newURI("file:///c:/test.html"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "file",
autofilled: "file",
completed: "file"
});
yield cleanup();
});

View File

@ -0,0 +1,298 @@
/* 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/. */
add_task(function* test_untrimmed_secure_www() {
do_log_info("Searching for untrimmed https://www entry");
yield promiseAddVisits({ uri: NetUtil.newURI("https://www.mozilla.org/test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "mo",
autofilled: "mozilla.org/",
completed: "https://www.mozilla.org/"
});
yield cleanup();
});
add_task(function* test_untrimmed_secure_www_path() {
do_log_info("Searching for untrimmed https://www entry with path");
yield promiseAddVisits({ uri: NetUtil.newURI("https://www.mozilla.org/test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "mozilla.org/t",
autofilled: "mozilla.org/test/",
completed: "https://www.mozilla.org/test/"
});
yield cleanup();
});
add_task(function* test_untrimmed_secure() {
do_log_info("Searching for untrimmed https:// entry");
yield promiseAddVisits({ uri: NetUtil.newURI("https://mozilla.org/test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "mo",
autofilled: "mozilla.org/",
completed: "https://mozilla.org/"
});
yield cleanup();
});
add_task(function* test_untrimmed_secure_path() {
do_log_info("Searching for untrimmed https:// entry with path");
yield promiseAddVisits({ uri: NetUtil.newURI("https://mozilla.org/test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "mozilla.org/t",
autofilled: "mozilla.org/test/",
completed: "https://mozilla.org/test/"
});
yield cleanup();
});
add_task(function* test_untrimmed_www() {
do_log_info("Searching for untrimmed http://www entry");
yield promiseAddVisits({ uri: NetUtil.newURI("http://www.mozilla.org/test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "mo",
autofilled: "mozilla.org/",
completed: "www.mozilla.org/"
});
yield cleanup();
});
add_task(function* test_untrimmed_www_path() {
do_log_info("Searching for untrimmed http://www entry with path");
yield promiseAddVisits({ uri: NetUtil.newURI("http://www.mozilla.org/test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "mozilla.org/t",
autofilled: "mozilla.org/test/",
completed: "http://www.mozilla.org/test/"
});
yield cleanup();
});
add_task(function* test_untrimmed_ftp() {
do_log_info("Searching for untrimmed ftp:// entry");
yield promiseAddVisits({ uri: NetUtil.newURI("ftp://mozilla.org/test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "mo",
autofilled: "mozilla.org/",
completed: "ftp://mozilla.org/"
});
yield cleanup();
});
add_task(function* test_untrimmed_ftp_path() {
do_log_info("Searching for untrimmed ftp:// entry with path");
yield promiseAddVisits({ uri: NetUtil.newURI("ftp://mozilla.org/test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "mozilla.org/t",
autofilled: "mozilla.org/test/",
completed: "ftp://mozilla.org/test/"
});
yield cleanup();
});
add_task(function* test_priority_1() {
do_log_info("Ensuring correct priority 1");
yield promiseAddVisits([{ uri: NetUtil.newURI("https://www.mozilla.org/test/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("https://mozilla.org/test/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("ftp://mozilla.org/test/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("http://www.mozilla.org/test/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("http://mozilla.org/test/"),
transition: TRANSITION_TYPED }]);
yield check_autocomplete({
search: "mo",
autofilled: "mozilla.org/",
completed: "mozilla.org/"
});
yield cleanup();
});
add_task(function* test_periority_2() {
do_log_info( "Ensuring correct priority 2");
yield promiseAddVisits([{ uri: NetUtil.newURI("https://mozilla.org/test/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("ftp://mozilla.org/test/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("http://www.mozilla.org/test/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("http://mozilla.org/test/"),
transition: TRANSITION_TYPED }]);
yield check_autocomplete({
search: "mo",
autofilled: "mozilla.org/",
completed: "mozilla.org/"
});
yield cleanup();
});
add_task(function* test_periority_3() {
do_log_info("Ensuring correct priority 3");
yield promiseAddVisits([{ uri: NetUtil.newURI("ftp://mozilla.org/test/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("http://www.mozilla.org/test/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("http://mozilla.org/test/"),
transition: TRANSITION_TYPED }]);
yield check_autocomplete({
search: "mo",
autofilled: "mozilla.org/",
completed: "mozilla.org/"
});
yield cleanup();
});
add_task(function* test_periority_4() {
do_log_info("Ensuring correct priority 4");
yield promiseAddVisits([{ uri: NetUtil.newURI("http://www.mozilla.org/test/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("http://mozilla.org/test/"),
transition: TRANSITION_TYPED }]);
yield check_autocomplete({
search: "mo",
autofilled: "mozilla.org/",
completed: "mozilla.org/"
});
yield cleanup();
});
add_task(function* test_priority_5() {
do_log_info("Ensuring correct priority 5");
yield promiseAddVisits([{ uri: NetUtil.newURI("ftp://mozilla.org/test/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("ftp://www.mozilla.org/test/"),
transition: TRANSITION_TYPED }]);
yield check_autocomplete({
search: "mo",
autofilled: "mozilla.org/",
completed: "ftp://mozilla.org/"
});
yield cleanup();
});
add_task(function* test_priority_6() {
do_log_info("Ensuring correct priority 6");
yield promiseAddVisits([{ uri: NetUtil.newURI("http://www.mozilla.org/test1/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("http://www.mozilla.org/test2/"),
transition: TRANSITION_TYPED }]);
yield check_autocomplete({
search: "mo",
autofilled: "mozilla.org/",
completed: "www.mozilla.org/"
});
yield cleanup();
});
add_task(function* test_longer_domain() {
do_log_info("Ensuring longer domain can't match");
// The .co should be preferred, but should not get the https from the .com.
// The .co domain must be added later to activate the trigger bug.
yield promiseAddVisits([{ uri: NetUtil.newURI("https://mozilla.com/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("http://mozilla.co/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("http://mozilla.co/"),
transition: TRANSITION_TYPED }]);
yield check_autocomplete({
search: "mo",
autofilled: "mozilla.co/",
completed: "mozilla.co/"
});
yield cleanup();
});
add_task(function* test_escaped_chars() {
do_log_info("Searching for URL with characters that are normally escaped");
yield promiseAddVisits({ uri: NetUtil.newURI("https://www.mozilla.org/啊-test"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "https://www.mozilla.org/啊-test",
autofilled: "https://www.mozilla.org/啊-test",
completed: "https://www.mozilla.org/啊-test"
});
yield cleanup();
});
add_task(function* test_unsecure_secure() {
do_log_info("Don't return unsecure URL when searching for secure ones");
yield promiseAddVisits({ uri: NetUtil.newURI("http://test.moz.org/test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "https://test.moz.org/t",
autofilled: "https://test.moz.org/test/",
completed: "https://test.moz.org/test/"
});
yield cleanup();
});
add_task(function* test_unsecure_secure_domain() {
do_log_info("Don't return unsecure domain when searching for secure ones");
yield promiseAddVisits({ uri: NetUtil.newURI("http://test.moz.org/test/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "https://test.moz",
autofilled: "https://test.moz.org/",
completed: "https://test.moz.org/"
});
yield cleanup();
});
add_task(function* test_untyped_www() {
do_log_info("Untyped is not accounted for www");
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
yield promiseAddVisits({ uri: NetUtil.newURI("http://www.moz.org/test/") });
yield check_autocomplete({
search: "mo",
autofilled: "moz.org/",
completed: "moz.org/"
});
yield cleanup();
});
add_task(function* test_untyped_ftp() {
do_log_info("Untyped is not accounted for ftp");
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
yield promiseAddVisits({ uri: NetUtil.newURI("ftp://moz.org/test/") });
yield check_autocomplete({
search: "mo",
autofilled: "moz.org/",
completed: "moz.org/"
});
yield cleanup();
});
add_task(function* test_untyped_secure() {
do_log_info("Untyped is not accounted for https");
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
yield promiseAddVisits({ uri: NetUtil.newURI("https://moz.org/test/") });
yield check_autocomplete({
search: "mo",
autofilled: "moz.org/",
completed: "moz.org/"
});
yield cleanup();
});
add_task(function* test_untyped_secure_www() {
do_log_info("Untyped is not accounted for https://www");
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
yield promiseAddVisits({ uri: NetUtil.newURI("https://www.moz.org/test/") });
yield check_autocomplete({
search: "mo",
autofilled: "moz.org/",
completed: "moz.org/"
});
yield cleanup();
});

View File

@ -0,0 +1,78 @@
/* 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/. */
// First do searches with typed behavior forced to false, so later tests will
// ensure autocomplete is able to dinamically switch behavior.
add_task(function* test_domain() {
do_log_info("Searching for domain should autoFill it");
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
yield promiseAddVisits(NetUtil.newURI("http://mozilla.org/link/"));
yield check_autocomplete({
search: "moz",
autofilled: "mozilla.org/",
completed: "mozilla.org/"
});
yield cleanup();
});
add_task(function* test_url() {
do_log_info("Searching for url should autoFill it");
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
yield promiseAddVisits(NetUtil.newURI("http://mozilla.org/link/"));
yield check_autocomplete({
search: "mozilla.org/li",
autofilled: "mozilla.org/link/",
completed: "http://mozilla.org/link/"
});
yield cleanup();
});
// Now do searches with typed behavior forced to true.
add_task(function* test_untyped_domain() {
do_log_info("Searching for non-typed domain should not autoFill it");
yield promiseAddVisits(NetUtil.newURI("http://mozilla.org/link/"));
yield check_autocomplete({
search: "moz",
autofilled: "moz",
completed: "moz"
});
yield cleanup();
});
add_task(function* test_typed_domain() {
do_log_info("Searching for typed domain should autoFill it");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/typed/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "moz",
autofilled: "mozilla.org/",
completed: "mozilla.org/"
});
yield cleanup();
});
add_task(function* test_untyped_url() {
do_log_info("Searching for non-typed url should not autoFill it");
yield promiseAddVisits(NetUtil.newURI("http://mozilla.org/link/"));
yield check_autocomplete({
search: "mozilla.org/li",
autofilled: "mozilla.org/li",
completed: "mozilla.org/li"
});
yield cleanup();
});
add_task(function* test_typed_url() {
do_log_info("Searching for typed url should autoFill it");
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/link/"),
transition: TRANSITION_TYPED });
yield check_autocomplete({
search: "mozilla.org/li",
autofilled: "mozilla.org/link/",
completed: "http://mozilla.org/link/"
});
yield cleanup();
});

View File

@ -0,0 +1,31 @@
/* 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/. */
// Ensure inline autocomplete doesn't return zero frecency pages.
add_task(function* test_zzero_frec_domain() {
do_log_info("Searching for zero frecency domain should not autoFill it");
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/framed_link/"),
transition: TRANSITION_FRAMED_LINK });
yield check_autocomplete({
search: "moz",
autofilled: "moz",
completed: "moz"
});
yield cleanup();
});
add_task(function* test_zzero_frec_url() {
do_log_info("Searching for zero frecency url should not autoFill it");
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/framed_link/"),
transition: TRANSITION_FRAMED_LINK });
yield check_autocomplete({
search: "mozilla.org/f",
autofilled: "mozilla.org/f",
completed: "mozilla.org/f"
});
yield cleanup();
});

View File

@ -0,0 +1,12 @@
[DEFAULT]
head = head_autocomplete.js
tail =
[test_autocomplete_functional.js]
[test_casing.js]
[test_do_not_trim.js]
[test_keywords.js]
[test_queryurl.js]
[test_trimming.js]
[test_typed.js]
[test_zero_frecency.js]