зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1550025 - In Quantum Bar the restriction tokens should bypass the restriction prefs. r=adw
Differential Revision: https://phabricator.services.mozilla.com/D30490 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
4b72fd9bba
Коммит
ca2c358730
|
@ -441,31 +441,27 @@ function getAcceptableMatchSources(context) {
|
|||
// Check prefs and restriction tokens.
|
||||
switch (source) {
|
||||
case UrlbarUtils.RESULT_SOURCE.BOOKMARKS:
|
||||
if (UrlbarPrefs.get("suggest.bookmark") &&
|
||||
(!restrictTokenType ||
|
||||
restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK ||
|
||||
restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_TAG)) {
|
||||
if (restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK ||
|
||||
restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_TAG ||
|
||||
(!restrictTokenType && UrlbarPrefs.get("suggest.bookmark"))) {
|
||||
acceptedSources.push(source);
|
||||
}
|
||||
break;
|
||||
case UrlbarUtils.RESULT_SOURCE.HISTORY:
|
||||
if (UrlbarPrefs.get("suggest.history") &&
|
||||
(!restrictTokenType ||
|
||||
restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_HISTORY)) {
|
||||
if (restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_HISTORY ||
|
||||
(!restrictTokenType && UrlbarPrefs.get("suggest.history"))) {
|
||||
acceptedSources.push(source);
|
||||
}
|
||||
break;
|
||||
case UrlbarUtils.RESULT_SOURCE.SEARCH:
|
||||
if (UrlbarPrefs.get("suggest.searches") &&
|
||||
(!restrictTokenType ||
|
||||
restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_SEARCH)) {
|
||||
if (restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_SEARCH ||
|
||||
(!restrictTokenType && UrlbarPrefs.get("suggest.searches"))) {
|
||||
acceptedSources.push(source);
|
||||
}
|
||||
break;
|
||||
case UrlbarUtils.RESULT_SOURCE.TABS:
|
||||
if (UrlbarPrefs.get("suggest.openpage") &&
|
||||
(!restrictTokenType ||
|
||||
restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_OPENPAGE)) {
|
||||
if (restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_OPENPAGE ||
|
||||
(!restrictTokenType && UrlbarPrefs.get("suggest.openpage"))) {
|
||||
acceptedSources.push(source);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -250,3 +250,85 @@ add_task(async function test_nofilter_immediate() {
|
|||
Assert.deepEqual(context.results[0].source, UrlbarUtils.RESULT_SOURCE.TABS,
|
||||
"Should find only a tab match");
|
||||
});
|
||||
|
||||
add_task(async function test_nofilter_restrict() {
|
||||
// Checks that even if a pref is disabled, we still return results on a
|
||||
// restriction token.
|
||||
let controller = new UrlbarController({
|
||||
browserWindow: {
|
||||
location: {
|
||||
href: AppConstants.BROWSER_CHROME_URL,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
let matches = [
|
||||
new UrlbarResult(UrlbarUtils.RESULT_TYPE.TAB_SWITCH,
|
||||
UrlbarUtils.RESULT_SOURCE.TABS,
|
||||
{ url: "http://mozilla.org/foo_tab/" }),
|
||||
new UrlbarResult(UrlbarUtils.RESULT_TYPE.URL,
|
||||
UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
|
||||
{ url: "http://mozilla.org/foo_bookmark/" }),
|
||||
new UrlbarResult(UrlbarUtils.RESULT_TYPE.URL,
|
||||
UrlbarUtils.RESULT_SOURCE.HISTORY,
|
||||
{ url: "http://mozilla.org/foo_history/" }),
|
||||
new UrlbarResult(UrlbarUtils.RESULT_TYPE.SEARCH,
|
||||
UrlbarUtils.RESULT_SOURCE.SEARCH,
|
||||
{ engine: "noengine" }),
|
||||
];
|
||||
|
||||
/**
|
||||
* A test provider.
|
||||
*/
|
||||
class TestProvider extends UrlbarProvider {
|
||||
get name() {
|
||||
return "MyProvider";
|
||||
}
|
||||
get type() {
|
||||
return UrlbarUtils.PROVIDER_TYPE.IMMEDIATE;
|
||||
}
|
||||
get sources() {
|
||||
return [
|
||||
UrlbarUtils.RESULT_SOURCE.TABS,
|
||||
UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
|
||||
UrlbarUtils.RESULT_SOURCE.HISTORY,
|
||||
UrlbarUtils.RESULT_SOURCE.SEARCH,
|
||||
];
|
||||
}
|
||||
async startQuery(context, add) {
|
||||
Assert.ok(true, "expected provider was invoked");
|
||||
for (let match of matches) {
|
||||
add(this, match);
|
||||
}
|
||||
}
|
||||
cancelQuery(context) {}
|
||||
}
|
||||
UrlbarProvidersManager.registerProvider(new TestProvider());
|
||||
|
||||
let typeToPropertiesMap = new Map([
|
||||
["HISTORY", {source: "HISTORY", pref: "history"}],
|
||||
["BOOKMARK", {source: "BOOKMARKS", pref: "bookmark"}],
|
||||
["OPENPAGE", {source: "TABS", pref: "openpage"}],
|
||||
["SEARCH", {source: "SEARCH", pref: "searches"}],
|
||||
]);
|
||||
for (let [type, token] of Object.entries(UrlbarTokenizer.RESTRICT)) {
|
||||
let properties = typeToPropertiesMap.get(type);
|
||||
if (!properties) {
|
||||
continue;
|
||||
}
|
||||
info("Restricting on " + type);
|
||||
let context = createContext(token + " foo", {
|
||||
providers: ["MyProvider"],
|
||||
});
|
||||
// Disable the corresponding pref.
|
||||
const pref = "browser.urlbar.suggest." + properties.pref;
|
||||
info("Disabling " + pref);
|
||||
Services.prefs.setBoolPref(pref, false);
|
||||
await controller.startQuery(context, controller);
|
||||
Assert.equal(context.results.length, 1, "Should find one result");
|
||||
Assert.equal(context.results[0].source,
|
||||
UrlbarUtils.RESULT_SOURCE[properties.source],
|
||||
"Check result source");
|
||||
Services.prefs.clearUserPref(pref);
|
||||
}
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче