diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/base/content/test/sidebar/browser_sidebar_app_locale_changed.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | browser/base/content/test/sidebar/browser_sidebar_app_locale_changed.js | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/browser/base/content/test/sidebar/browser_sidebar_app_locale_changed.js b/browser/base/content/test/sidebar/browser_sidebar_app_locale_changed.js new file mode 100644 index 0000000000..5b07da9839 --- /dev/null +++ b/browser/base/content/test/sidebar/browser_sidebar_app_locale_changed.js @@ -0,0 +1,111 @@ +/* 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"); +}); + +add_task(async function test_ext_sidebar_panel_reloaded_on_locale_changes() { + let extension = ExtensionTestUtils.loadExtension({ + manifest: { + sidebar_action: { + default_panel: "sidebar.html", + }, + }, + useAddonManager: "temporary", + + files: { + "sidebar.html": `<html> + <head> + <meta charset="utf-8"/> + <script src="sidebar.js"></script> + </head> + <body> + A Test Sidebar + </body> + </html>`, + "sidebar.js": function () { + const { browser } = this; + window.onload = () => { + browser.test.sendMessage("sidebar"); + }; + }, + }, + }); + await extension.startup(); + // Test sidebar is opened on install + await extension.awaitMessage("sidebar"); + + // Test sidebar is opened on simulated locale changes. + info("Switch browser to bidi and expect the sidebar panel to be reloaded"); + + await SpecialPowers.pushPrefEnv({ + set: [["intl.l10n.pseudo", "bidi"]], + }); + await extension.awaitMessage("sidebar"); + is( + window.document.documentElement.getAttribute("dir"), + "rtl", + "browser window changed direction to rtl as expected" + ); + + await SpecialPowers.popPrefEnv(); + await extension.awaitMessage("sidebar"); + is( + window.document.documentElement.getAttribute("dir"), + "ltr", + "browser window changed direction to ltr as expected" + ); + + await extension.unload(); +}); |