From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../sidebar/browser_sidebar_app_locale_changed.js | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 browser/base/content/test/sidebar/browser_sidebar_app_locale_changed.js (limited to 'browser/base/content/test/sidebar/browser_sidebar_app_locale_changed.js') 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 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": ` + + + + + + A Test Sidebar + + `, + "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(); +}); -- cgit v1.2.3