Backport 1548478 - Fix fluent warnings about missing translations for Bookmark Panel messages (#5047)

This commit is contained in:
Andrei Oprea 2019-05-21 16:42:06 +00:00 коммит произвёл GitHub
Родитель 3e42f671b5
Коммит fa19dcca4b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 16 добавлений и 7 удалений

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

@ -38,10 +38,7 @@ class _BookmarkPanelHub {
this._handleMessageRequest = handleMessageRequest;
this._addImpression = addImpression;
this._dispatch = dispatch;
this._l10n = new DOMLocalization([
"browser/branding/sync-brand.ftl",
"browser/newtab/asrouter.ftl",
]);
this._l10n = new DOMLocalization();
this._initialized = true;
}
@ -92,6 +89,9 @@ class _BookmarkPanelHub {
};
if (response && response.content) {
// Only insert localization files if we need to show a message
win.MozXULElement.insertFTLIfNeeded("browser/newtab/asrouter.ftl");
win.MozXULElement.insertFTLIfNeeded("browser/branding/sync-brand.ftl");
this.showMessage(response.content, target, win);
this.sendImpression();
this.sendUserEventTelemetry("IMPRESSION", win);
@ -149,7 +149,6 @@ class _BookmarkPanelHub {
recommendation.appendChild(title);
recommendation.appendChild(content);
recommendation.appendChild(cta);
this._l10n.translateElements([...recommendation.children]);
target.container.appendChild(recommendation);
}

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

@ -18,7 +18,7 @@ describe("BookmarkPanelHub", () => {
sandbox = sinon.createSandbox();
globals = new GlobalOverrider();
fakeL10n = {setAttributes: sandbox.stub(), translateElements: sandbox.stub()};
fakeL10n = {setAttributes: sandbox.stub()};
globals.set("DOMLocalization", function() { return fakeL10n; }); // eslint-disable-line prefer-arrow-callback
globals.set("FxAccounts", {config: {promiseEmailFirstURI: sandbox.stub()}});
isBrowserPrivateStub = sandbox.stub().returns(false);
@ -61,7 +61,10 @@ describe("BookmarkPanelHub", () => {
close: sandbox.stub(),
};
fakeDispatch = sandbox.stub();
fakeWindow = {ownerGlobal: {openLinkIn: sandbox.stub(), gBrowser: {selectedBrowser: "browser"}}};
fakeWindow = {
ownerGlobal: {openLinkIn: sandbox.stub(), gBrowser: {selectedBrowser: "browser"}},
MozXULElement: {insertFTLIfNeeded: sandbox.stub()},
};
});
afterEach(() => {
instance.uninit();
@ -140,6 +143,13 @@ describe("BookmarkPanelHub", () => {
assert.calledWithExactly(instance.showMessage, "content", fakeTarget, fakeWindow);
assert.calledOnce(instance.sendImpression);
});
it("should insert the appropriate ftl files with translations", () => {
instance.onResponse({content: "content"}, fakeTarget, fakeWindow);
assert.calledTwice(fakeWindow.MozXULElement.insertFTLIfNeeded);
assert.calledWith(fakeWindow.MozXULElement.insertFTLIfNeeded, "browser/newtab/asrouter.ftl");
assert.calledWith(fakeWindow.MozXULElement.insertFTLIfNeeded, "browser/branding/sync-brand.ftl");
});
it("should dispatch a user impression", () => {
sandbox.spy(instance, "sendUserEventTelemetry");