Bug 1526818 - QuantumBar: Expose an autocomplete.properties bundle from UrlbarUtils r=adw

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Omkar Konaraddi 2019-07-12 20:54:04 +00:00
Родитель 62f76168bd
Коммит 885533af6a
6 изменённых файлов: 31 добавлений и 38 удалений

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

@ -36,12 +36,6 @@ XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.repository.getLogger("Urlbar.Provider.UnifiedComplete")
);
XPCOMUtils.defineLazyGetter(this, "bundle", () =>
Services.strings.createBundle(
"chrome://global/locale/autocomplete.properties"
)
);
// See UnifiedComplete.
const TITLE_TAGS_SEPARATOR = " \u2013 ";
@ -299,13 +293,16 @@ function makeUrlbarResult(tokens, info) {
action.params.url
);
} else if (tokens && tokens.length > 1) {
title = bundle.formatStringFromName("bookmarkKeywordSearch", [
info.comment,
tokens
.slice(1)
.map(t => t.value)
.join(" "),
]);
title = UrlbarUtils.strings.formatStringFromName(
"bookmarkKeywordSearch",
[
info.comment,
tokens
.slice(1)
.map(t => t.value)
.join(" "),
]
);
}
return new UrlbarResult(
UrlbarUtils.RESULT_TYPE.KEYWORD,

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

@ -432,6 +432,12 @@ XPCOMUtils.defineLazyGetter(UrlbarUtils.ICON, "DEFAULT", () => {
return PlacesUtils.favicons.defaultFavicon.spec;
});
XPCOMUtils.defineLazyGetter(UrlbarUtils, "strings", () => {
return Services.strings.createBundle(
"chrome://global/locale/autocomplete.properties"
);
});
/**
* UrlbarQueryContext defines a user's autocomplete input from within the urlbar.
* It supplements it with details of how the search results should be obtained

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

@ -10,19 +10,12 @@ const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
Services: "resource://gre/modules/Services.jsm",
UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm",
UrlbarTokenizer: "resource:///modules/UrlbarTokenizer.jsm",
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
AppConstants: "resource://gre/modules/AppConstants.jsm",
});
XPCOMUtils.defineLazyGetter(this, "bundle", function() {
return Services.strings.createBundle(
"chrome://global/locale/autocomplete.properties"
);
});
/**
* Receives and displays address bar autocomplete results.
*/
@ -631,7 +624,7 @@ class UrlbarView {
let setURL = false;
switch (result.type) {
case UrlbarUtils.RESULT_TYPE.TAB_SWITCH:
action = bundle.GetStringFromName("switchToTab2");
action = UrlbarUtils.strings.GetStringFromName("switchToTab2");
setURL = true;
break;
case UrlbarUtils.RESULT_TYPE.REMOTE_TAB:
@ -639,9 +632,10 @@ class UrlbarView {
setURL = true;
break;
case UrlbarUtils.RESULT_TYPE.SEARCH:
action = bundle.formatStringFromName("searchWithEngine", [
result.payload.engine,
]);
action = UrlbarUtils.strings.formatStringFromName(
"searchWithEngine",
[result.payload.engine]
);
break;
case UrlbarUtils.RESULT_TYPE.KEYWORD:
isVisitAction = result.payload.input.trim() == result.payload.keyword;
@ -675,7 +669,7 @@ class UrlbarView {
}
if (isVisitAction) {
action = bundle.GetStringFromName("visit");
action = UrlbarUtils.strings.GetStringFromName("visit");
title.setAttribute("isurl", "true");
} else {
title.removeAttribute("isurl");
@ -855,9 +849,10 @@ class UrlbarView {
}
let item = this._rows.children[i];
let action = item.querySelector(".urlbarView-action");
action.textContent = bundle.formatStringFromName("searchWithEngine", [
(engine && engine.name) || result.payload.engine,
]);
action.textContent = UrlbarUtils.strings.formatStringFromName(
"searchWithEngine",
[(engine && engine.name) || result.payload.engine]
);
// If we just changed the engine from the original engine and it had an
// icon, then make sure the result now uses the new engine's icon or
// failing that the default icon. If we changed it back to the original

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

@ -87,9 +87,7 @@ add_task(async function test_display_keyword_without_query() {
);
Assert.equal(
result.displayed.action,
Services.strings
.createBundle("chrome://global/locale/autocomplete.properties")
.GetStringFromName("visit"),
UrlbarUtils.strings.GetStringFromName("visit"),
"Should have visit indicated"
);
});

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

@ -51,12 +51,11 @@ add_task(async function() {
Assert.equal(result.type, UrlbarUtils.RESULT_TYPE.SEARCH);
Assert.equal(result.displayed.title, "foobar");
let bundle = Services.strings.createBundle(
"chrome://global/locale/autocomplete.properties"
);
Assert.equal(
result.displayed.action,
bundle.formatStringFromName("searchWithEngine", ["SearchEngine"]),
UrlbarUtils.strings.formatStringFromName("searchWithEngine", [
"SearchEngine",
]),
"Should have the correct action text"
);

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

@ -131,9 +131,7 @@ async function checkInput(inputStr) {
);
Assert.equal(
result.displayed.action,
Services.strings
.createBundle("chrome://global/locale/autocomplete.properties")
.GetStringFromName("visit"),
UrlbarUtils.strings.GetStringFromName("visit"),
"Should be displaying the correct action text"
);
}