tor-browser

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

test_sidebar_state.js (2831B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 https://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const { sinon } = ChromeUtils.importESModule(
      7  "resource://testing-common/Sinon.sys.mjs"
      8 );
      9 
     10 const { SidebarState } = ChromeUtils.importESModule(
     11  "moz-src:///browser/components/sidebar/SidebarState.sys.mjs"
     12 );
     13 
     14 const mockElement = {
     15  setAttribute(name, value) {
     16    this[name] = value;
     17  },
     18  style: { width: "200px" },
     19  toggleAttribute: sinon.stub(),
     20 };
     21 const mockLitElement = Object.assign(mockElement, {
     22  requestUpdate: sinon.stub(),
     23 });
     24 
     25 const mockGlobal = {
     26  document: { getElementById: () => mockElement },
     27  gBrowser: { tabContainer: mockElement },
     28 };
     29 const mockController = {
     30  _box: mockElement,
     31  hide: sinon.stub(),
     32  showInitially: sinon.stub(),
     33  sidebarContainer: { ownerGlobal: mockGlobal },
     34  sidebarMain: mockLitElement,
     35  sidebarRevampEnabled: true,
     36  sidebarRevampVisibility: "always-show",
     37  sidebars: new Set(["viewBookmarksSidebar"]),
     38  updateToolbarButton: sinon.stub(),
     39  SidebarManager: { hasSidebarLauncherBeenVisible: false },
     40 };
     41 
     42 add_task(async function test_load_legacy_session_restore_data() {
     43  const sidebarState = new SidebarState(mockController);
     44 
     45  sidebarState.loadInitialState({
     46    width: "300px",
     47    command: "viewBookmarksSidebar",
     48    expanded: true,
     49    hidden: false,
     50  });
     51 
     52  const props = sidebarState.getProperties();
     53  Assert.equal(props.panelWidth, 300, "The panel was resized.");
     54  Assert.equal(props.launcherExpanded, true, "The launcher is expanded.");
     55  Assert.equal(props.launcherVisible, true, "The launcher is visible.");
     56  Assert.ok(
     57    mockController.showInitially.calledWith("viewBookmarksSidebar"),
     58    "Bookmarks panel was shown."
     59  );
     60 });
     61 
     62 add_task(async function test_load_prerevamp_session_restore_data() {
     63  const sidebarState = new SidebarState(mockController);
     64 
     65  sidebarState.loadInitialState({
     66    command: "viewBookmarksSidebar",
     67  });
     68 
     69  const props = sidebarState.getProperties();
     70  Assert.ok(props.panelOpen, "The panel is marked as open.");
     71  Assert.equal(props.launcherVisible, true, "The launcher is visible.");
     72  Assert.equal(props.command, "viewBookmarksSidebar", "The command matches.");
     73  Assert.ok(
     74    mockController.showInitially.calledWith("viewBookmarksSidebar"),
     75    "Bookmarks panel was shown."
     76  );
     77 });
     78 
     79 add_task(async function test_load_hidden_panel_state() {
     80  const sidebarState = new SidebarState(mockController);
     81 
     82  sidebarState.loadInitialState({
     83    command: "viewBookmarksSidebar",
     84    panelOpen: false,
     85    launcherVisible: true,
     86  });
     87 
     88  const props = sidebarState.getProperties();
     89  Assert.ok(!props.panelOpen, "The panel is marked as closed.");
     90  Assert.equal(props.launcherVisible, true, "The launcher is visible.");
     91  Assert.equal(props.command, "viewBookmarksSidebar", "The command matches.");
     92 });