tor-browser

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

browser_sidebar_move.js (2144B)


      1 registerCleanupFunction(() => {
      2  Services.prefs.clearUserPref("sidebar.position_start");
      3  SidebarController.hide();
      4 });
      5 
      6 const EXPECTED_START_ORDINALS = [
      7  ["sidebar-main", 1],
      8  ["sidebar-launcher-splitter", 2],
      9  ["sidebar-box", 3],
     10  ["sidebar-splitter", 4],
     11  ["tabbrowser-tabbox", 5],
     12  ["ai-window-splitter", 6],
     13  ["ai-window-box", 7],
     14 ];
     15 
     16 const EXPECTED_END_ORDINALS = [
     17  ["sidebar-main", 7],
     18  ["sidebar-launcher-splitter", 6],
     19  ["sidebar-box", 5],
     20  ["sidebar-splitter", 4],
     21  ["tabbrowser-tabbox", 3],
     22  ["ai-window-splitter", 2],
     23  ["ai-window-box", 1],
     24 ];
     25 
     26 function getBrowserChildrenWithOrdinals() {
     27  let browser = document.getElementById("browser");
     28  return [...browser.children].map(node => {
     29    return [node.id, node.style.order];
     30  });
     31 }
     32 
     33 add_task(async function () {
     34  await SidebarController.show("viewBookmarksSidebar");
     35  SidebarController.showSwitcherPanel();
     36 
     37  let reversePositionButton = document.getElementById(
     38    "sidebar-reverse-position"
     39  );
     40  let originalLabel = reversePositionButton.getAttribute("label");
     41  let box = document.getElementById("sidebar-box");
     42 
     43  // Default (position: left)
     44  Assert.deepEqual(
     45    getBrowserChildrenWithOrdinals(),
     46    EXPECTED_START_ORDINALS,
     47    "Correct browser ordinal (start)"
     48  );
     49  ok(!box.hasAttribute("sidebar-positionend"), "Positioned start");
     50 
     51  // Moved to right
     52  SidebarController.reversePosition();
     53  SidebarController.showSwitcherPanel();
     54  Assert.deepEqual(
     55    getBrowserChildrenWithOrdinals(),
     56    EXPECTED_END_ORDINALS,
     57    "Correct browser ordinal (end)"
     58  );
     59  isnot(
     60    reversePositionButton.getAttribute("label"),
     61    originalLabel,
     62    "Label changed"
     63  );
     64  ok(box.hasAttribute("sidebar-positionend"), "Positioned end");
     65 
     66  // Moved to back to left
     67  SidebarController.reversePosition();
     68  SidebarController.showSwitcherPanel();
     69  Assert.deepEqual(
     70    getBrowserChildrenWithOrdinals(),
     71    EXPECTED_START_ORDINALS,
     72    "Correct browser ordinal (start)"
     73  );
     74  ok(!box.hasAttribute("sidebar-positionend"), "Positioned start");
     75  is(
     76    reversePositionButton.getAttribute("label"),
     77    originalLabel,
     78    "Label is back to normal"
     79  );
     80 });