tor-browser

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

browser_net_req-resp-bodies.js (2590B)


      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 if request and response body logging stays on after opening the console.
      8 */
      9 
     10 add_task(async function () {
     11  const {
     12    L10N,
     13  } = require("resource://devtools/client/netmonitor/src/utils/l10n.js");
     14 
     15  const { tab, monitor } = await initNetMonitor(JSON_LONG_URL, {
     16    requestCount: 1,
     17  });
     18  info("Starting test... ");
     19 
     20  const { document, store, windowRequire } = monitor.panelWin;
     21  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     22  const { getDisplayedRequests, getSortedRequests } = windowRequire(
     23    "devtools/client/netmonitor/src/selectors/index"
     24  );
     25 
     26  store.dispatch(Actions.batchEnable(false));
     27 
     28  // Perform first batch of requests.
     29  await performRequests(monitor, tab, 1, { expectedEventTimings: 1 });
     30 
     31  await verifyRequest(0);
     32 
     33  // Switch to the webconsole.
     34  const onWebConsole = monitor.toolbox.once("webconsole-selected");
     35  monitor.toolbox.selectTool("webconsole");
     36  await onWebConsole;
     37 
     38  // Switch back to the netmonitor.
     39  const onNetMonitor = monitor.toolbox.once("netmonitor-selected");
     40  monitor.toolbox.selectTool("netmonitor");
     41  await onNetMonitor;
     42 
     43  // Reload debugee.
     44  const wait = waitForNetworkEvents(monitor, 1);
     45  await reloadBrowser();
     46  await wait;
     47 
     48  // Perform another batch of requests.
     49  await performRequests(monitor, tab, 1, { expectedEventTimings: 1 });
     50 
     51  await verifyRequest(1);
     52 
     53  return teardown(monitor);
     54 
     55  async function verifyRequest(index) {
     56    const requestItems = document.querySelectorAll(".request-list-item");
     57    for (const requestItem of requestItems) {
     58      requestItem.scrollIntoView();
     59      await waitUntil(() => requestItem.querySelector(".status-code"));
     60      const requestsListStatus = requestItem.querySelector(".status-code");
     61      EventUtils.sendMouseEvent({ type: "mouseover" }, requestsListStatus);
     62      await waitUntil(() => requestsListStatus.title);
     63      await waitForDOMIfNeeded(requestItem, ".requests-list-timings-total");
     64    }
     65    await verifyRequestItemTarget(
     66      document,
     67      getDisplayedRequests(store.getState()),
     68      getSortedRequests(store.getState())[index],
     69      "GET",
     70      CONTENT_TYPE_SJS + "?fmt=json-long",
     71      {
     72        status: 200,
     73        statusText: "OK",
     74        type: "json",
     75        fullMimeType: "text/json; charset=utf-8",
     76        size: L10N.getFormatStr(
     77          "networkMenu.size.kB",
     78          L10N.numberWithDecimals(85975 / 1000, 2)
     79        ),
     80        time: true,
     81      }
     82    );
     83  }
     84 });