tor-browser

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

browser_net_pane-toggle.js (2860B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Tests if toggling the details pane works as expected.
      8 */
      9 
     10 add_task(async function () {
     11  const { monitor } = await initNetMonitor(SIMPLE_URL, {
     12    requestCount: 1,
     13  });
     14  info("Starting test... ");
     15 
     16  const { document, store, windowRequire } = monitor.panelWin;
     17  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     18  const { getSelectedRequest, getSortedRequests } = windowRequire(
     19    "devtools/client/netmonitor/src/selectors/index"
     20  );
     21 
     22  store.dispatch(Actions.batchEnable(false));
     23 
     24  ok(
     25    !document.querySelector(".sidebar-toggle"),
     26    "The pane toggle button should not be visible."
     27  );
     28  is(
     29    !!document.querySelector(".network-details-bar"),
     30    false,
     31    "The details pane should be hidden when the frontend is opened."
     32  );
     33  is(
     34    getSelectedRequest(store.getState()),
     35    undefined,
     36    "There should be no selected item in the requests menu."
     37  );
     38 
     39  const networkEvent = waitForNetworkEvents(monitor, 1);
     40  await reloadBrowser();
     41  await networkEvent;
     42 
     43  ok(
     44    !document.querySelector(".sidebar-toggle"),
     45    "The pane toggle button should not be visible after the first request."
     46  );
     47  is(
     48    !!document.querySelector(".network-details-bar"),
     49    false,
     50    "The details pane should still be hidden after the first request."
     51  );
     52  is(
     53    getSelectedRequest(store.getState()),
     54    undefined,
     55    "There should still be no selected item in the requests menu."
     56  );
     57 
     58  store.dispatch(Actions.toggleNetworkDetails());
     59 
     60  const toggleButton = document.querySelector(".sidebar-toggle");
     61 
     62  is(
     63    toggleButton.classList.contains("pane-collapsed"),
     64    false,
     65    "The pane toggle button should now indicate that the details pane is " +
     66      "not collapsed anymore."
     67  );
     68  is(
     69    !!document.querySelector(".network-details-bar"),
     70    true,
     71    "The details pane should not be hidden after toggle button was pressed."
     72  );
     73  isnot(
     74    getSelectedRequest(store.getState()),
     75    undefined,
     76    "There should be a selected item in the requests menu."
     77  );
     78  is(
     79    getSelectedIndex(store.getState()),
     80    0,
     81    "The first item should be selected in the requests menu."
     82  );
     83 
     84  EventUtils.sendMouseEvent({ type: "click" }, toggleButton);
     85 
     86  is(
     87    !!document.querySelector(".network-details-bar"),
     88    false,
     89    "The details pane should now be hidden after the toggle button was pressed again."
     90  );
     91  is(
     92    getSelectedRequest(store.getState()),
     93    undefined,
     94    "There should now be no selected item in the requests menu."
     95  );
     96 
     97  await teardown(monitor);
     98 
     99  function getSelectedIndex(state) {
    100    if (!state.requests.selectedId) {
    101      return -1;
    102    }
    103    return getSortedRequests(state).findIndex(
    104      r => r.id === state.requests.selectedId
    105    );
    106  }
    107 });