Bug 1755181 - Reload sidebar contents on app locale change; r=platform-i18n-reviewers,nordzilla

Differential Revision: https://phabricator.services.mozilla.com/D140665
This commit is contained in:
Greg Tatum 2022-03-22 15:19:46 +00:00
Родитель f9d13a118f
Коммит b925c500e4
3 изменённых файлов: 79 добавлений и 0 удалений

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

@ -116,6 +116,8 @@ var SidebarUI = {
this._inited = true;
Services.obs.addObserver(this, "intl:app-locales-changed");
this._initDeferred.resolve();
},
@ -146,12 +148,32 @@ var SidebarUI = {
xulStore.persist(this._title, "value");
}
Services.obs.removeObserver(this, "intl:app-locales-changed");
if (this._observer) {
this._observer.disconnect();
this._observer = null;
}
},
/**
* The handler for Services.obs.addObserver.
**/
observe(_subject, topic, _data) {
switch (topic) {
case "intl:app-locales-changed": {
if (this.isOpen) {
// The <tree> component used in history and bookmarks, but it does not
// support live switching the app locale. Reload the entire sidebar to
// invalidate any old text.
this.hide();
this._show(this.lastOpenedId);
break;
}
}
}
},
/**
* Ensure the title stays in sync with the source element, which updates for
* l10n changes.

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

@ -1,6 +1,7 @@
[DEFAULT]
[browser_sidebar_adopt.js]
[browser_sidebar_app_locale_changed.js]
[browser_sidebar_keys.js]
[browser_sidebar_move.js]
[browser_sidebar_switcher.js]

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

@ -0,0 +1,56 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* This file tests that the sidebar recreates the contents of the <tree> element
* for live app locale switching.
*/
add_task(function cleanup() {
registerCleanupFunction(() => {
SidebarUI.hide();
});
});
/**
* @param {string} sidebarName
*/
async function testLiveReloading(sidebarName) {
info("Showing the sidebar " + sidebarName);
await SidebarUI.show(sidebarName);
function getTreeChildren() {
const sidebarDoc = document.querySelector("#sidebar").contentWindow
.document;
return sidebarDoc.querySelector(".sidebar-placesTreechildren");
}
const childrenBefore = getTreeChildren();
ok(childrenBefore, "Found the sidebar children");
is(childrenBefore, getTreeChildren(), "The children start out as equal");
info("Simulating an app locale change.");
Services.obs.notifyObservers(null, "intl:app-locales-changed");
await TestUtils.waitForCondition(
getTreeChildren,
"Waiting for a new child tree element."
);
isnot(
childrenBefore,
getTreeChildren(),
"The tree's contents are re-computed."
);
info("Hiding the sidebar");
SidebarUI.hide();
}
add_task(async function test_bookmarks_sidebar() {
await testLiveReloading("viewBookmarksSidebar");
});
add_task(async function test_history_sidebar() {
await testLiveReloading("viewHistorySidebar");
});