tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_sidebar_app_locale_changed.js (3051B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 /**
      5 * This file tests that the sidebar recreates the contents of the <tree> element
      6 * for live app locale switching.
      7 */
      8 
      9 add_task(function cleanup() {
     10  registerCleanupFunction(() => {
     11    SidebarController.hide();
     12  });
     13 });
     14 
     15 /**
     16 * @param {string} sidebarName
     17 */
     18 async function testLiveReloading(sidebarName) {
     19  info("Showing the sidebar " + sidebarName);
     20  await SidebarController.show(sidebarName);
     21 
     22  function getTreeChildren() {
     23    const sidebarDoc =
     24      document.querySelector("#sidebar").contentWindow.document;
     25    return sidebarDoc.querySelector(".sidebar-placesTreechildren");
     26  }
     27 
     28  const childrenBefore = getTreeChildren();
     29  ok(childrenBefore, "Found the sidebar children");
     30  is(childrenBefore, getTreeChildren(), "The children start out as equal");
     31 
     32  info("Simulating an app locale change.");
     33  Services.obs.notifyObservers(null, "intl:app-locales-changed");
     34 
     35  await TestUtils.waitForCondition(
     36    getTreeChildren,
     37    "Waiting for a new child tree element."
     38  );
     39 
     40  isnot(
     41    childrenBefore,
     42    getTreeChildren(),
     43    "The tree's contents are re-computed."
     44  );
     45 
     46  info("Hiding the sidebar");
     47  SidebarController.hide();
     48 }
     49 
     50 add_task(async function test_bookmarks_sidebar() {
     51  if (!Services.prefs.getBoolPref("sidebar.revamp", false)) {
     52    await testLiveReloading("viewBookmarksSidebar");
     53  }
     54 });
     55 
     56 add_task(async function test_history_sidebar() {
     57  if (!Services.prefs.getBoolPref("sidebar.revamp", false)) {
     58    await testLiveReloading("viewHistorySidebar");
     59  }
     60 });
     61 
     62 add_task(async function test_ext_sidebar_panel_reloaded_on_locale_changes() {
     63  let extension = ExtensionTestUtils.loadExtension({
     64    manifest: {
     65      sidebar_action: {
     66        default_panel: "sidebar.html",
     67      },
     68    },
     69    useAddonManager: "temporary",
     70 
     71    files: {
     72      "sidebar.html": `<html>
     73          <head>
     74            <meta charset="utf-8"/>
     75            <script src="sidebar.js"></script>
     76          </head>
     77          <body>
     78            A Test Sidebar
     79          </body>
     80        </html>`,
     81      "sidebar.js": function () {
     82        const { browser } = this;
     83        window.onload = () => {
     84          browser.test.sendMessage("sidebar");
     85        };
     86      },
     87    },
     88  });
     89  await extension.startup();
     90  // Test sidebar is opened on install
     91  await extension.awaitMessage("sidebar");
     92 
     93  // Test sidebar is opened on simulated locale changes.
     94  info("Switch browser to bidi and expect the sidebar panel to be reloaded");
     95 
     96  await SpecialPowers.pushPrefEnv({
     97    set: [["intl.l10n.pseudo", "bidi"]],
     98  });
     99  await extension.awaitMessage("sidebar");
    100  is(
    101    window.document.documentElement.getAttribute("dir"),
    102    "rtl",
    103    "browser window changed direction to rtl as expected"
    104  );
    105 
    106  await SpecialPowers.popPrefEnv();
    107  await extension.awaitMessage("sidebar");
    108  is(
    109    window.document.documentElement.getAttribute("dir"),
    110    "ltr",
    111    "browser window changed direction to ltr as expected"
    112  );
    113 
    114  await extension.unload();
    115 });