tor-browser

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

browser_net_post-data-raw-payloads.js (2441B)


      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 the POST requests display the correct information in the UI,
      8 * for raw payloads with attached content-type headers.
      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(POST_RAW_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 
     23  store.dispatch(Actions.batchEnable(false));
     24 
     25  // Execute requests.
     26  await performRequests(monitor, tab, 1);
     27 
     28  // Wait for raw data toggle to be displayed
     29  const wait = waitForDOM(
     30    document,
     31    "#request-panel .raw-data-toggle-input .devtools-checkbox-toggle"
     32  );
     33  EventUtils.sendMouseEvent(
     34    { type: "mousedown" },
     35    document.querySelectorAll(".request-list-item")[0]
     36  );
     37  clickOnSidebarTab(document, "request");
     38  await wait;
     39 
     40  const tabpanel = document.querySelector("#request-panel");
     41 
     42  ok(
     43    tabpanel.querySelector(".treeTable"),
     44    "The request params doesn't have the intended visibility."
     45  );
     46  Assert.strictEqual(
     47    tabpanel.querySelector(".editor-mount"),
     48    null,
     49    "The request post data doesn't have the indented visibility."
     50  );
     51 
     52  is(
     53    tabpanel.querySelectorAll(".raw-data-toggle") !== null,
     54    true,
     55    "The raw request data toggle should be displayed in this tabpanel."
     56  );
     57  is(
     58    tabpanel.querySelectorAll(".empty-notice").length,
     59    0,
     60    "The empty notice should not be displayed in this tabpanel."
     61  );
     62 
     63  is(
     64    tabpanel.querySelector(".data-label").textContent,
     65    L10N.getStr("paramsFormData"),
     66    "The post section doesn't have the correct title."
     67  );
     68 
     69  const labels = tabpanel.querySelectorAll("tr .treeLabelCell .treeLabel");
     70  const values = tabpanel.querySelectorAll("tr .treeValueCell .objectBox");
     71 
     72  is(labels[0].textContent, "foo", "The first query param name was incorrect.");
     73  is(
     74    values[0].textContent,
     75    `"bar"`,
     76    "The first query param value was incorrect."
     77  );
     78  is(
     79    labels[1].textContent,
     80    "baz",
     81    "The second query param name was incorrect."
     82  );
     83  is(
     84    values[1].textContent,
     85    `"123"`,
     86    "The second query param value was incorrect."
     87  );
     88 
     89  return teardown(monitor);
     90 });