tor-browser

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

browser_net_simple-request.js (2652B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Test whether the UI state properly reflects existence of requests
      8 * displayed in the Net panel. The following parts of the UI are
      9 * tested:
     10 * 1) Side panel visibility
     11 * 2) Side panel toggle button
     12 * 3) Empty user message visibility
     13 * 4) Number of requests displayed
     14 */
     15 add_task(async function () {
     16  const { monitor } = await initNetMonitor(SIMPLE_URL, {
     17    requestCount: 1,
     18  });
     19  info("Starting test... ");
     20 
     21  const { document, store, windowRequire } = monitor.panelWin;
     22  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     23 
     24  store.dispatch(Actions.batchEnable(false));
     25 
     26  ok(
     27    document.querySelector(".request-list-empty-notice"),
     28    "An empty notice should be displayed when the frontend is opened."
     29  );
     30  is(
     31    store.getState().requests.requests.length,
     32    0,
     33    "The requests menu should be empty when the frontend is opened."
     34  );
     35  is(
     36    !!document.querySelector(".network-details-bar"),
     37    false,
     38    "The network details panel should be hidden when the frontend is opened."
     39  );
     40 
     41  await reloadAndWait();
     42 
     43  ok(
     44    !document.querySelector(".request-list-empty-notice"),
     45    "The empty notice should be hidden after the first request."
     46  );
     47  is(
     48    store.getState().requests.requests.length,
     49    1,
     50    "The requests menu should not be empty after the first request."
     51  );
     52  is(
     53    !!document.querySelector(".network-details-bar"),
     54    false,
     55    "The network details panel should still be hidden after the first request."
     56  );
     57 
     58  await reloadAndWait();
     59 
     60  ok(
     61    !document.querySelector(".request-list-empty-notice"),
     62    "The empty notice should be still hidden after a reload."
     63  );
     64  is(
     65    store.getState().requests.requests.length,
     66    1,
     67    "The requests menu should not be empty after a reload."
     68  );
     69  is(
     70    !!document.querySelector(".network-details-bar"),
     71    false,
     72    "The network details panel should still be hidden after a reload."
     73  );
     74 
     75  await clearNetworkEvents(monitor);
     76 
     77  ok(
     78    document.querySelector(".request-list-empty-notice"),
     79    "An empty notice should be displayed again after clear."
     80  );
     81  is(
     82    store.getState().requests.requests.length,
     83    0,
     84    "The requests menu should be empty after clear."
     85  );
     86  is(
     87    !!document.querySelector(".network-details-bar"),
     88    false,
     89    "The network details panel should still be hidden after clear."
     90  );
     91 
     92  return teardown(monitor);
     93 
     94  async function reloadAndWait() {
     95    const wait = waitForNetworkEvents(monitor, 1);
     96    await reloadBrowser();
     97    return wait;
     98  }
     99 });