tor-browser

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

browser_net_truncate-post-data.js (3469B)


      1 /* Any copyright is dedicated to the Public Domain.
      2  http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Get the default limit
      7 const defaultRequestBodyLimit = Services.prefs.getIntPref(
      8  "devtools.netmonitor.requestBodyLimit"
      9 );
     10 
     11 /**
     12 * Bug 1986196 -
     13 * Verifies that requests with large post data are not truncated if
     14 * devtools.netmonitor.requestBodyLimit is 0.
     15 */
     16 add_task(async function () {
     17  await pushPref("devtools.netmonitor.requestBodyLimit", 0);
     18 
     19  await checkPostDataRequest(false);
     20 });
     21 
     22 /**
     23 * Bug 1542172 -
     24 * Verifies that requests with large post data which are over
     25 * the limit are truncated and an error is displayed.
     26 */
     27 add_task(async function () {
     28  await pushPref("devtools.netmonitor.requestBodyLimit", 1000);
     29 
     30  await checkPostDataRequest(true);
     31 });
     32 
     33 /**
     34 * Bug 1542172 -
     35 * Verifies that requests with large post data which are within the limit
     36 * are not truncated and no error is displayed.
     37 */
     38 add_task(async function () {
     39  // Set a limit over the size of the post data which is 2 * defaultRequestBodyLimit
     40  await pushPref(
     41    "devtools.netmonitor.requestBodyLimit",
     42    defaultRequestBodyLimit * 3
     43  );
     44  await checkPostDataRequest(false);
     45 });
     46 
     47 async function checkPostDataRequest(expectErrorDisplay) {
     48  const { monitor, tab } = await initNetMonitor(POST_JSON_URL, {
     49    requestCount: 1,
     50  });
     51 
     52  info("Starting test... ");
     53 
     54  const {
     55    L10N,
     56  } = require("resource://devtools/client/netmonitor/src/utils/l10n.js");
     57 
     58  const { document, store, windowRequire } = monitor.panelWin;
     59  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     60  store.dispatch(Actions.batchEnable(false));
     61 
     62  requestLongerTimeout(2);
     63 
     64  info("Perform requests");
     65  await performRequestsAndWait(monitor, tab);
     66 
     67  await waitUntil(() => document.querySelector(".request-list-item"));
     68  const item = document.querySelectorAll(".request-list-item")[0];
     69  await waitUntil(() => item.querySelector(".requests-list-type").title);
     70 
     71  // Make sure the header and editor are loaded
     72  const waitHeader = waitForDOM(document, "#request-panel .data-header");
     73  const waitSourceEditor = waitForDOM(document, "#request-panel .cm-editor");
     74 
     75  store.dispatch(Actions.toggleNetworkDetails());
     76  clickOnSidebarTab(document, "request");
     77 
     78  await Promise.all([waitHeader, waitSourceEditor]);
     79 
     80  const tabpanel = document.querySelector("#request-panel");
     81  is(
     82    !!tabpanel.querySelector(".request-error-header"),
     83    expectErrorDisplay,
     84    "The request error header doesn't have the intended visibility."
     85  );
     86  if (expectErrorDisplay) {
     87    is(
     88      tabpanel.querySelector(".request-error-header").textContent,
     89      "Request has been truncated",
     90      "The error message shown is incorrect"
     91    );
     92  }
     93  const jsonView = tabpanel.querySelector(".data-label") || {};
     94  is(
     95    jsonView.textContent === L10N.getStr("jsonScopeName"),
     96    false,
     97    "The params json view doesn't have the intended visibility."
     98  );
     99 
    100  is(
    101    tabpanel.querySelector(".cm-editor") === null,
    102    false,
    103    "The Request Payload has the intended visibility."
    104  );
    105 
    106  await pushPref(
    107    "devtools.netmonitor.requestBodyLimit",
    108    defaultRequestBodyLimit
    109  );
    110  return teardown(monitor);
    111 }
    112 
    113 async function performRequestsAndWait(monitor, tab) {
    114  const wait = waitForNetworkEvents(monitor, 1);
    115  await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
    116    content.wrappedJSObject.performLargePostDataRequest();
    117  });
    118  await wait;
    119 }