Bug 1499743 - Address Bar restriction characters: remove typed, change url and search r=adw

Remove the "~" typed restriction character.
Change the url restriction character to "$" and the search one to "?".

Differential Revision: https://phabricator.services.mozilla.com/D9494

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Marco Bonardo 2018-10-24 12:49:00 +00:00
Родитель 1dd0c173e2
Коммит 134e4ec293
11 изменённых файлов: 146 добавлений и 173 удалений

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

@ -34,9 +34,8 @@ add_task(async function init() {
});
add_task(async function mainTest() {
// Trigger an initial search. Use the "$" token to restrict matches to search
// suggestions.
await promiseAutocompleteResultPopup("$ test", window);
// Trigger an initial search. Restrict matches to search suggestions.
await promiseAutocompleteResultPopup(`${UrlbarTokenizer.RESTRICT.SEARCH} test`, window);
await promiseSuggestionsPresent("Waiting for initial suggestions");
// Now synthesize typing a character. promiseAutocompleteResultPopup doesn't

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

@ -2,16 +2,14 @@
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.defineModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
ChromeUtils.defineModuleGetter(this, "PlacesTestUtils",
"resource://testing-common/PlacesTestUtils.jsm");
ChromeUtils.defineModuleGetter(this, "Preferences",
"resource://gre/modules/Preferences.jsm");
ChromeUtils.defineModuleGetter(this, "HttpServer",
"resource://testing-common/httpd.js");
ChromeUtils.defineModuleGetter(this, "SearchTestUtils",
"resource://testing-common/SearchTestUtils.jsm");
XPCOMUtils.defineLazyModuleGetters(this, {
HttpServer: "resource://testing-common/httpd.js",
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
PlacesTestUtils: "resource://testing-common/PlacesTestUtils.jsm",
Preferences: "resource://gre/modules/Preferences.jsm",
SearchTestUtils: "resource://testing-common/SearchTestUtils.jsm",
UrlbarTokenizer: "resource:///modules/UrlbarTokenizer.jsm",
});
SearchTestUtils.init(Assert, registerCleanupFunction);

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

@ -131,12 +131,14 @@ const PREF_OTHER_DEFAULTS = new Map([
["keyword.enabled", true],
]);
const TYPES = [
"history",
"bookmark",
"openpage",
"searches",
];
// Maps preferences under browser.urlbar.suggest to behavior names, as defined
// in mozIPlacesAutoComplete.
const SUGGEST_PREF_TO_BEHAVIOR = {
history: "history",
bookmark: "bookmark",
openpage: "openpage",
searches: "search",
};
const PREF_TYPES = new Map([
["boolean", "Bool"],
@ -299,8 +301,9 @@ class Preferences {
}
case "defaultBehavior": {
let val = 0;
for (let type of [...TYPES, "history.onlyTyped"]) {
let behavior = type == "history.onlyTyped" ? "TYPED" : type.toUpperCase();
for (let type of [...Object.keys(SUGGEST_PREF_TO_BEHAVIOR), "history.onlyTyped"]) {
let behavior = type == "history.onlyTyped" ?
"TYPED" : SUGGEST_PREF_TO_BEHAVIOR[type].toUpperCase();
val |= this.get("suggest." + type) &&
Ci.mozIPlacesAutoComplete["BEHAVIOR_" + behavior];
}
@ -352,22 +355,23 @@ class Preferences {
this._linkingPrefs = true;
try {
let branch = Services.prefs.getBranch(PREF_URLBAR_BRANCH);
const SUGGEST_PREFS = Object.keys(SUGGEST_PREF_TO_BEHAVIOR);
if (changedPref.startsWith("suggest.")) {
// A suggest pref changed, fix autocomplete.enabled.
branch.setBoolPref("autocomplete.enabled",
TYPES.some(type => this.get("suggest." + type)));
SUGGEST_PREFS.some(type => this.get("suggest." + type)));
} else if (this.get("autocomplete.enabled")) {
// If autocomplete is enabled and all of the suggest.* prefs are
// disabled, reset the suggest.* prefs to their default value.
if (TYPES.every(type => !this.get("suggest." + type))) {
for (let type of TYPES) {
if (SUGGEST_PREFS.every(type => !this.get("suggest." + type))) {
for (let type of SUGGEST_PREFS) {
let def = PREF_URLBAR_DEFAULTS.get("suggest." + type);
branch.setBoolPref("suggest." + type, def);
}
}
} else {
// If autocomplete is disabled, deactivate all suggest preferences.
for (let type of TYPES) {
for (let type of SUGGEST_PREFS) {
branch.setBoolPref("suggest." + type, false);
}
}

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

@ -43,10 +43,25 @@ var UrlbarTokenizer = {
RESTRICT_BOOKMARK: 5,
RESTRICT_TAG: 6,
RESTRICT_OPENPAGE: 7,
RESTRICT_TYPED: 8,
RESTRICT_SEARCH: 9,
RESTRICT_TITLE: 10,
RESTRICT_URL: 11,
RESTRICT_SEARCH: 8,
RESTRICT_TITLE: 9,
RESTRICT_URL: 10,
},
// The special characters below can be typed into the urlbar to restrict
// the search to a certain category, like history, bookmarks or open pages; or
// to force a match on just the title or url.
// These restriction characters can be typed alone, or at word boundaries,
// provided their meaning cannot be confused, for example # could be present
// in a valid url, and thus it should not be interpreted as a restriction.
RESTRICT: {
HISTORY: "^",
BOOKMARK: "*",
TAG: "+",
OPENPAGE: "%",
SEARCH: "?",
TITLE: "#",
URL: "$",
},
/**
@ -168,22 +183,11 @@ var UrlbarTokenizer = {
},
};
// The special characters below can be typed into the urlbar to restrict
// the search to a certain category, like history, bookmarks or open pages; or
// to force a match on just the title or url.
// These restriction characters can be typed alone, or at word boundaries,
// provided their meaning cannot be confused, for example # could be present
// in a valid url, and thus it should not be interpreted as a restriction.
UrlbarTokenizer.CHAR_TO_TYPE_MAP = new Map([
["^", UrlbarTokenizer.TYPE.RESTRICT_HISTORY],
["*", UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK],
["+", UrlbarTokenizer.TYPE.RESTRICT_TAG],
["%", UrlbarTokenizer.TYPE.RESTRICT_OPENPAGE],
["~", UrlbarTokenizer.TYPE.RESTRICT_TYPED],
["$", UrlbarTokenizer.TYPE.RESTRICT_SEARCH],
["#", UrlbarTokenizer.TYPE.RESTRICT_TITLE],
["@", UrlbarTokenizer.TYPE.RESTRICT_URL],
]);
const CHAR_TO_TYPE_MAP = new Map(
Object.entries(UrlbarTokenizer.RESTRICT).map(
([type, char]) => [ char, UrlbarTokenizer.TYPE[`RESTRICT_${type}`] ]
)
);
/**
* Given a search string, splits it into string tokens.
@ -195,8 +199,8 @@ function splitString(searchString) {
// The first step is splitting on unicode whitespaces.
let tokens = searchString.trim().split(UrlbarTokenizer.REGEXP_SPACES);
let accumulator = [];
let hasRestrictionToken = tokens.some(t => UrlbarTokenizer.CHAR_TO_TYPE_MAP.has(t));
let chars = Array.from(UrlbarTokenizer.CHAR_TO_TYPE_MAP.keys()).join("");
let hasRestrictionToken = tokens.some(t => CHAR_TO_TYPE_MAP.has(t));
let chars = Array.from(CHAR_TO_TYPE_MAP.keys()).join("");
logger.debug("Restriction chars", chars);
for (let token of tokens) {
// It's possible we have to split a token, if there's no separate restriction
@ -248,7 +252,7 @@ function filterTokens(tokens) {
value: token,
type: UrlbarTokenizer.TYPE.TEXT,
};
let restrictionType = UrlbarTokenizer.CHAR_TO_TYPE_MAP.get(token);
let restrictionType = CHAR_TO_TYPE_MAP.get(token);
if (tokens.length > 1 &&
restrictionType &&
foundRestriction.length == 0 ||

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

@ -25,72 +25,80 @@ add_task(async function test_tokenizer() {
],
},
{ desc: "separate restriction char at beginning",
searchString: "* test",
searchString: `${UrlbarTokenizer.RESTRICT.BOOKMARK} test`,
expectedTokens: [
{ value: "*", type: UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK },
{ value: UrlbarTokenizer.RESTRICT.BOOKMARK, type: UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK },
{ value: "test", type: UrlbarTokenizer.TYPE.POSSIBLE_ORIGIN },
],
},
{ desc: "separate restriction char at end",
searchString: "test *",
searchString: `test ${UrlbarTokenizer.RESTRICT.BOOKMARK}`,
expectedTokens: [
{ value: "test", type: UrlbarTokenizer.TYPE.POSSIBLE_ORIGIN },
{ value: "*", type: UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK },
{ value: UrlbarTokenizer.RESTRICT.BOOKMARK, type: UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK },
],
},
{ desc: "boundary restriction char at end",
searchString: "test*",
searchString: `test${UrlbarTokenizer.RESTRICT.BOOKMARK}`,
expectedTokens: [
{ value: "test", type: UrlbarTokenizer.TYPE.POSSIBLE_ORIGIN },
{ value: "*", type: UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK },
{ value: UrlbarTokenizer.RESTRICT.BOOKMARK, type: UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK },
],
},
{ desc: "double boundary restriction char",
searchString: "*test#",
searchString: `${UrlbarTokenizer.RESTRICT.BOOKMARK}test${UrlbarTokenizer.RESTRICT.TITLE}`,
expectedTokens: [
{ value: "*", type: UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK },
{ value: "test#", type: UrlbarTokenizer.TYPE.TEXT },
{ value: UrlbarTokenizer.RESTRICT.BOOKMARK, type: UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK },
{ value: `test${UrlbarTokenizer.RESTRICT.TITLE}`, type: UrlbarTokenizer.TYPE.TEXT },
],
},
{ desc: "double non-combinable restriction char, single char string",
searchString: "t*$",
searchString: `t${UrlbarTokenizer.RESTRICT.BOOKMARK}${UrlbarTokenizer.RESTRICT.SEARCH}`,
expectedTokens: [
{ value: "t*", type: UrlbarTokenizer.TYPE.TEXT },
{ value: "$", type: UrlbarTokenizer.TYPE.RESTRICT_SEARCH },
{ value: `t${UrlbarTokenizer.RESTRICT.BOOKMARK}`, type: UrlbarTokenizer.TYPE.TEXT },
{ value: UrlbarTokenizer.RESTRICT.SEARCH, type: UrlbarTokenizer.TYPE.RESTRICT_SEARCH },
],
},
{ desc: "only boundary restriction chars",
searchString: "*#",
searchString: `${UrlbarTokenizer.RESTRICT.BOOKMARK}${UrlbarTokenizer.RESTRICT.TITLE}`,
expectedTokens: [
{ value: "*", type: UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK },
{ value: "#", type: UrlbarTokenizer.TYPE.RESTRICT_TITLE },
{ value: UrlbarTokenizer.RESTRICT.BOOKMARK, type: UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK },
{ value: UrlbarTokenizer.RESTRICT.TITLE, type: UrlbarTokenizer.TYPE.RESTRICT_TITLE },
],
},
{ desc: "only the boundary restriction char",
searchString: "*",
searchString: UrlbarTokenizer.RESTRICT.BOOKMARK,
expectedTokens: [
{ value: "*", type: UrlbarTokenizer.TYPE.TEXT },
{ value: UrlbarTokenizer.RESTRICT.BOOKMARK, type: UrlbarTokenizer.TYPE.TEXT },
],
},
{ desc: "boundary restriction char on path",
// Some restriction chars may be # or ?, that are also valid path parts.
// The next 2 tests will check we consider those as part of url paths.
{ desc: "boundary # char on path",
searchString: "test/#",
expectedTokens: [
{ value: "test/#", type: UrlbarTokenizer.TYPE.POSSIBLE_URL },
],
},
{ desc: "boundary ? char on path",
searchString: "test/?",
expectedTokens: [
{ value: "test/?", type: UrlbarTokenizer.TYPE.POSSIBLE_URL },
],
},
{ desc: "multiple boundary restriction chars suffix",
searchString: "test ^ ~",
searchString: `test ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.TAG}`,
expectedTokens: [
{ value: "test", type: UrlbarTokenizer.TYPE.POSSIBLE_ORIGIN },
{ value: "^", type: UrlbarTokenizer.TYPE.RESTRICT_HISTORY },
{ value: "~", type: UrlbarTokenizer.TYPE.TEXT },
{ value: UrlbarTokenizer.RESTRICT.HISTORY, type: UrlbarTokenizer.TYPE.RESTRICT_HISTORY },
{ value: UrlbarTokenizer.RESTRICT.TAG, type: UrlbarTokenizer.TYPE.TEXT },
],
},
{ desc: "multiple boundary restriction chars prefix",
searchString: "^ ~ test",
searchString: `${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.TAG} test`,
expectedTokens: [
{ value: "^", type: UrlbarTokenizer.TYPE.RESTRICT_HISTORY },
{ value: "~", type: UrlbarTokenizer.TYPE.TEXT },
{ value: UrlbarTokenizer.RESTRICT.HISTORY, type: UrlbarTokenizer.TYPE.RESTRICT_HISTORY },
{ value: UrlbarTokenizer.RESTRICT.TAG, type: UrlbarTokenizer.TYPE.TEXT },
{ value: "test", type: UrlbarTokenizer.TYPE.POSSIBLE_ORIGIN },
],
},
@ -101,9 +109,9 @@ add_task(async function test_tokenizer() {
],
},
{ desc: "ipv4 in bookmarks",
searchString: "* 192.168.1.1:8",
searchString: `${UrlbarTokenizer.RESTRICT.BOOKMARK} 192.168.1.1:8`,
expectedTokens: [
{ value: "*", type: UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK },
{ value: UrlbarTokenizer.RESTRICT.BOOKMARK, type: UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK },
{ value: "192.168.1.1:8", type: UrlbarTokenizer.TYPE.POSSIBLE_ORIGIN },
],
},

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

@ -78,20 +78,6 @@ const QUERYINDEX_PLACEID = 8;
const QUERYINDEX_SWITCHTAB = 9;
const QUERYINDEX_FRECENCY = 10;
// The special characters below can be typed into the urlbar to either restrict
// the search to visited history, bookmarked, tagged pages; or force a match on
// just the title text or url.
const TOKEN_TO_BEHAVIOR_MAP = new Map([
["^", "history"],
["*", "bookmark"],
["+", "tag"],
["%", "openpage"],
["~", "typed"],
["$", "searches"],
["#", "title"],
["@", "url"],
]);
// If a URL starts with one of these prefixes, then we don't provide search
// suggestions for it.
const DISALLOWED_URLLIKE_PREFIXES = [
@ -354,12 +340,22 @@ XPCOMUtils.defineLazyModuleGetters(this, {
UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm",
UrlbarProviderOpenTabs: "resource:///modules/UrlbarProviderOpenTabs.jsm",
UrlbarProvidersManager: "resource:///modules/UrlbarProvidersManager.jsm",
UrlbarTokenizer: "resource:///modules/UrlbarTokenizer.jsm",
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
});
XPCOMUtils.defineLazyPreferenceGetter(this, "syncUsernamePref",
"services.sync.username");
// The special characters below can be typed into the urlbar to either restrict
// the search to visited history, bookmarked, tagged pages; or force a match on
// just the title text or url.
XPCOMUtils.defineLazyGetter(this, "TOKEN_TO_BEHAVIOR_MAP", () => new Map(
Object.entries(UrlbarTokenizer.RESTRICT).map(
([type, char]) => [char, type.toLowerCase()]
)
));
function setTimeout(callback, ms) {
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.initWithCallback(callback, ms, timer.TYPE_ONE_SHOT);
@ -877,7 +873,7 @@ Search.prototype = {
query = query.substr(0, UrlbarPrefs.get("maxCharsForSearchSuggestions"));
// Avoid fetching suggestions if they are not required, private browsing
// mode is enabled, or the query may expose sensitive information.
if (this.hasBehavior("searches") &&
if (this.hasBehavior("search") &&
!this._inPrivateWindow &&
!this._prohibitSearchSuggestionsFor(query)) {
let engine;

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

@ -105,7 +105,7 @@ interface mozIPlacesAutoComplete : nsISupports
/**
* Include search suggestions from the currently selected search provider.
*/
const long BEHAVIOR_SEARCHES = 1 << 9;
const long BEHAVIOR_SEARCH = 1 << 9;
/**
* Populate list of Preloaded Sites from JSON.

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

@ -28,6 +28,7 @@ ChromeUtils.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyModuleGetters(this, {
UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm",
UrlbarProviderOpenTabs: "resource:///modules/UrlbarProviderOpenTabs.jsm",
UrlbarTokenizer: "resource:///modules/UrlbarTokenizer.jsm",
});
const TITLE_SEARCH_ENGINE_SEPARATOR = " \u00B7\u2013\u00B7 ";

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

@ -56,11 +56,14 @@ add_task(async function test_javascript_match() {
// Note the next few tests do *not* get a search result as enable-actions
// isn't specified.
info("Match only typed history");
info("Match only history");
await check_autocomplete({
search: "foo ^ ~",
matches: [ { uri: uri3, title: "title" },
{ uri: uri4, title: "title" } ],
search: `foo ${UrlbarTokenizer.RESTRICT.HISTORY}`,
matches: [ { uri: uri1, title: "title" },
{ uri: uri2, title: "title" },
{ uri: uri3, title: "title" },
{ uri: uri4, title: "title" },
{ uri: uri7, title: "title" } ],
});
info("Drop-down empty search matches only typed history");

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

@ -5,7 +5,6 @@ const ENGINE_NAME = "engine-suggestions.xml";
const SERVER_PORT = 9000;
const SUGGEST_PREF = "browser.urlbar.suggest.searches";
const SUGGEST_ENABLED_PREF = "browser.search.suggest.enabled";
const SUGGEST_RESTRICT_TOKEN = "$";
var suggestionsFn;
var previousSuggestionsFn;
@ -297,11 +296,12 @@ add_task(async function restrictToken() {
// Now do a restricted search to make sure only suggestions appear.
await check_autocomplete({
search: SUGGEST_RESTRICT_TOKEN + " hello",
search: `${UrlbarTokenizer.RESTRICT.SEARCH} hello`,
searchParam: "enable-actions",
matches: [
// TODO (bug 1177895) This is wrong.
makeSearchMatch(SUGGEST_RESTRICT_TOKEN + " hello", { engineName: ENGINE_NAME, heuristic: true }),
makeSearchMatch(`${UrlbarTokenizer.RESTRICT.SEARCH} hello`,
{ engineName: ENGINE_NAME, heuristic: true }),
{
uri: makeActionURI(("searchengine"), {
engineName: ENGINE_NAME,

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

@ -49,7 +49,7 @@ add_task(async function test_special_searches() {
// Test restricting searches
info("History restrict");
await check_autocomplete({
search: "^",
search: UrlbarTokenizer.RESTRICT.HISTORY,
matches: [ { uri: uri1, title: "title" },
{ uri: uri2, title: "foo.bar" },
{ uri: uri3, title: "title" },
@ -60,7 +60,7 @@ add_task(async function test_special_searches() {
info("Star restrict");
await check_autocomplete({
search: "*",
search: UrlbarTokenizer.RESTRICT.BOOKMARK,
matches: [ { uri: uri5, title: "title", style: [ "bookmark" ] },
{ uri: uri6, title: "foo.bar", style: [ "bookmark" ] },
{ uri: uri7, title: "title", style: [ "bookmark" ] },
@ -73,7 +73,7 @@ add_task(async function test_special_searches() {
info("Tag restrict");
await check_autocomplete({
search: "+",
search: UrlbarTokenizer.RESTRICT.TAG,
matches: [ { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
{ uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
@ -83,7 +83,7 @@ add_task(async function test_special_searches() {
// Test specials as any word position
info("Special as first word");
await check_autocomplete({
search: "^ foo bar",
search: `${UrlbarTokenizer.RESTRICT.HISTORY} foo bar`,
matches: [ { uri: uri2, title: "foo.bar" },
{ uri: uri3, title: "title" },
{ uri: uri4, title: "foo.bar" },
@ -93,7 +93,7 @@ add_task(async function test_special_searches() {
info("Special as middle word");
await check_autocomplete({
search: "foo ^ bar",
search: `foo ${UrlbarTokenizer.RESTRICT.HISTORY} bar`,
matches: [ { uri: uri2, title: "foo.bar" },
{ uri: uri3, title: "title" },
{ uri: uri4, title: "foo.bar" },
@ -103,7 +103,7 @@ add_task(async function test_special_searches() {
info("Special as last word");
await check_autocomplete({
search: "foo bar ^",
search: `foo bar ${UrlbarTokenizer.RESTRICT.HISTORY}`,
matches: [ { uri: uri2, title: "foo.bar" },
{ uri: uri3, title: "title" },
{ uri: uri4, title: "foo.bar" },
@ -112,9 +112,9 @@ add_task(async function test_special_searches() {
});
// Test restricting and matching searches with a term
info("foo ^ -> history");
info(`foo ${UrlbarTokenizer.RESTRICT.HISTORY} -> history`);
await check_autocomplete({
search: "foo ^",
search: `foo ${UrlbarTokenizer.RESTRICT.HISTORY}`,
matches: [ { uri: uri2, title: "foo.bar" },
{ uri: uri3, title: "title" },
{ uri: uri4, title: "foo.bar" },
@ -122,9 +122,9 @@ add_task(async function test_special_searches() {
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] } ],
});
info("foo * -> is star");
info(`foo ${UrlbarTokenizer.RESTRICT.BOOKMARK} -> is star`);
await check_autocomplete({
search: "foo *",
search: `foo ${UrlbarTokenizer.RESTRICT.BOOKMARK}`,
matches: [ { uri: uri6, title: "foo.bar", style: [ "bookmark" ] },
{ uri: uri7, title: "title", style: [ "bookmark" ] },
{ uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
@ -134,9 +134,9 @@ add_task(async function test_special_searches() {
{ uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ],
});
info("foo # -> in title");
info(`foo ${UrlbarTokenizer.RESTRICT.TITLE} -> in title`);
await check_autocomplete({
search: "foo #",
search: `foo ${UrlbarTokenizer.RESTRICT.TITLE}`,
matches: [ { uri: uri2, title: "foo.bar" },
{ uri: uri4, title: "foo.bar" },
{ uri: uri6, title: "foo.bar", style: [ "bookmark" ] },
@ -147,9 +147,9 @@ add_task(async function test_special_searches() {
{ uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ],
});
info("foo @ -> in url");
info(`foo ${UrlbarTokenizer.RESTRICT.URL} -> in url`);
await check_autocomplete({
search: "foo @",
search: `foo ${UrlbarTokenizer.RESTRICT.URL}`,
matches: [ { uri: uri3, title: "title" },
{ uri: uri4, title: "foo.bar" },
{ uri: uri7, title: "title", style: [ "bookmark" ] },
@ -158,63 +158,49 @@ add_task(async function test_special_searches() {
{ uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ],
});
info("foo + -> is tag");
info(`foo ${UrlbarTokenizer.RESTRICT.TAG} -> is tag`);
await check_autocomplete({
search: "foo +",
search: `foo ${UrlbarTokenizer.RESTRICT.TAG}`,
matches: [ { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
{ uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
{ uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ],
});
info("foo ~ -> is typed");
await check_autocomplete({
search: "foo ~",
matches: [ { uri: uri4, title: "foo.bar" },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] } ],
});
// Test various pairs of special searches
info("foo ^ * -> history, is star");
info(`foo ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.BOOKMARK} -> history, is star`);
await check_autocomplete({
search: "foo ^ *",
search: `foo ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.BOOKMARK}`,
matches: [ { uri: uri6, title: "foo.bar", style: [ "bookmark" ] },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ],
});
info("foo ^ # -> history, in title");
info(`foo ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.TITLE} -> history, in title`);
await check_autocomplete({
search: "foo ^ #",
search: `foo ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.TITLE}`,
matches: [ { uri: uri2, title: "foo.bar" },
{ uri: uri4, title: "foo.bar" },
{ uri: uri6, title: "foo.bar" },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] } ],
});
info("foo ^ @ -> history, in url");
info(`foo ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.URL} -> history, in url`);
await check_autocomplete({
search: "foo ^ @",
search: `foo ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.URL}`,
matches: [ { uri: uri3, title: "title" },
{ uri: uri4, title: "foo.bar" },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] } ],
});
info("foo ^ + -> history, is tag");
info(`foo ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.TAG} -> history, is tag`);
await check_autocomplete({
search: "foo ^ +",
search: `foo ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.TAG}`,
matches: [ { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] } ],
});
info("foo ^ ~ -> history, is typed");
info(`foo ${UrlbarTokenizer.RESTRICT.BOOKMARK} ${UrlbarTokenizer.RESTRICT.TITLE} -> is star, in title`);
await check_autocomplete({
search: "foo ^ ~",
matches: [ { uri: uri4, title: "foo.bar" },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] } ],
});
info("foo * # -> is star, in title");
await check_autocomplete({
search: "foo * #",
search: `foo ${UrlbarTokenizer.RESTRICT.BOOKMARK} ${UrlbarTokenizer.RESTRICT.TITLE}`,
matches: [ { uri: uri6, title: "foo.bar", style: [ "bookmark" ] },
{ uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
{ uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
@ -223,75 +209,49 @@ add_task(async function test_special_searches() {
{ uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ],
});
info("foo * @ -> is star, in url");
info(`foo ${UrlbarTokenizer.RESTRICT.BOOKMARK} ${UrlbarTokenizer.RESTRICT.URL} -> is star, in url`);
await check_autocomplete({
search: "foo * @",
search: `foo ${UrlbarTokenizer.RESTRICT.BOOKMARK} ${UrlbarTokenizer.RESTRICT.URL}`,
matches: [ { uri: uri7, title: "title", style: [ "bookmark" ] },
{ uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
{ uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ],
});
info("foo * + -> same as +");
info(`foo ${UrlbarTokenizer.RESTRICT.BOOKMARK} ${UrlbarTokenizer.RESTRICT.TAG} -> same as ${UrlbarTokenizer.RESTRICT.TAG}`);
await check_autocomplete({
search: "foo * +",
search: `foo ${UrlbarTokenizer.RESTRICT.BOOKMARK} ${UrlbarTokenizer.RESTRICT.TAG}`,
matches: [ { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
{ uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
{ uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ],
});
info("foo * ~ -> is star, is typed");
info(`foo ${UrlbarTokenizer.RESTRICT.TITLE} ${UrlbarTokenizer.RESTRICT.URL} -> in title, in url`);
await check_autocomplete({
search: "foo * ~",
matches: [ { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ],
});
info("foo # @ -> in title, in url");
await check_autocomplete({
search: "foo # @",
search: `foo ${UrlbarTokenizer.RESTRICT.TITLE} ${UrlbarTokenizer.RESTRICT.URL}`,
matches: [ { uri: uri4, title: "foo.bar" },
{ uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
{ uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ],
});
info("foo # + -> in title, is tag");
info(`foo ${UrlbarTokenizer.RESTRICT.TITLE} ${UrlbarTokenizer.RESTRICT.TAG} -> in title, is tag`);
await check_autocomplete({
search: "foo # +",
search: `foo ${UrlbarTokenizer.RESTRICT.TITLE} ${UrlbarTokenizer.RESTRICT.TAG}`,
matches: [ { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
{ uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
{ uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ],
});
info("foo # ~ -> in title, is typed");
info(`foo ${UrlbarTokenizer.RESTRICT.URL} ${UrlbarTokenizer.RESTRICT.TAG} -> in url, is tag`);
await check_autocomplete({
search: "foo # ~",
matches: [ { uri: uri4, title: "foo.bar" },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] } ],
});
info("foo @ + -> in url, is tag");
await check_autocomplete({
search: "foo @ +",
search: `foo ${UrlbarTokenizer.RESTRICT.URL} ${UrlbarTokenizer.RESTRICT.TAG}`,
matches: [ { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
{ uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ],
});
info("foo @ ~ -> in url, is typed");
await check_autocomplete({
search: "foo @ ~",
matches: [ { uri: uri4, title: "foo.bar" },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] } ],
});
info("foo + ~ -> is tag, is typed");
await check_autocomplete({
search: "foo + ~",
matches: [ { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] } ],
});
// Disable autoFill for the next tests, see test_autoFill_default_behavior.js
// for specific tests.
Services.prefs.setBoolPref("browser.urlbar.autoFill", false);