tor-browser

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

browser_net_json_custom_mime.js (4009B)


      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 JSON responses with unusal/custom MIME types are handled correctly.
      8 */
      9 
     10 add_task(async function () {
     11  const { tab, monitor } = await initNetMonitor(JSON_CUSTOM_MIME_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 { L10N } = windowRequire("devtools/client/netmonitor/src/utils/l10n");
     19  const { getDisplayedRequests, getSortedRequests } = windowRequire(
     20    "devtools/client/netmonitor/src/selectors/index"
     21  );
     22 
     23  store.dispatch(Actions.batchEnable(false));
     24 
     25  // Execute requests.
     26  await performRequests(monitor, tab, 1);
     27 
     28  const requestItem = document.querySelector(".request-list-item");
     29  const requestsListStatus = requestItem.querySelector(".status-code");
     30  EventUtils.sendMouseEvent({ type: "mouseover" }, requestsListStatus);
     31  await waitUntil(() => requestsListStatus.title);
     32  await waitForDOMIfNeeded(requestItem, ".requests-list-timings-total");
     33 
     34  await verifyRequestItemTarget(
     35    document,
     36    getDisplayedRequests(store.getState()),
     37    getSortedRequests(store.getState())[0],
     38    "GET",
     39    CONTENT_TYPE_SJS + "?fmt=json-custom-mime",
     40    {
     41      status: 200,
     42      statusText: "OK",
     43      type: "x-bigcorp-json",
     44      fullMimeType: "text/x-bigcorp-json; charset=utf-8",
     45      size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 41),
     46      time: true,
     47    }
     48  );
     49 
     50  let wait = waitForDOM(document, "#response-panel .data-header");
     51  const waitForPropsView = waitForDOM(
     52    document,
     53    "#response-panel .properties-view",
     54    1
     55  );
     56 
     57  store.dispatch(Actions.toggleNetworkDetails());
     58  clickOnSidebarTab(document, "response");
     59  await Promise.all([wait, waitForPropsView]);
     60 
     61  testJsonSectionInResponseTab();
     62 
     63  wait = waitForDOM(document, "#response-panel .cm-content");
     64  const rawResponseToggle = document.querySelector(
     65    "#response-panel .raw-data-toggle-input .devtools-checkbox-toggle"
     66  );
     67  clickElement(rawResponseToggle, monitor);
     68  await wait;
     69 
     70  testResponseTab();
     71 
     72  await teardown(monitor);
     73 
     74  function testJsonSectionInResponseTab() {
     75    const tabpanel = document.querySelector("#response-panel");
     76    is(
     77      tabpanel.querySelectorAll(".treeRow").length,
     78      1,
     79      "There should be 1 json properties displayed in this tabpanel."
     80    );
     81 
     82    const labels = tabpanel.querySelectorAll("tr .treeLabelCell .treeLabel");
     83    const values = tabpanel.querySelectorAll("tr .treeValueCell .objectBox");
     84 
     85    is(
     86      labels[0].textContent,
     87      "greeting",
     88      "The first json property name was incorrect."
     89    );
     90    is(
     91      values[0].textContent,
     92      `"Hello oddly-named JSON!"`,
     93      "The first json property value was incorrect."
     94    );
     95  }
     96 
     97  function testResponseTab() {
     98    const tabpanel = document.querySelector("#response-panel");
     99 
    100    is(
    101      tabpanel.querySelector(".response-error-header") === null,
    102      true,
    103      "The response error header doesn't have the intended visibility."
    104    );
    105    const jsonView = tabpanel.querySelector(".data-label") || {};
    106    is(
    107      jsonView.textContent === L10N.getStr("jsonScopeName"),
    108      true,
    109      "The response json view has the intended visibility."
    110    );
    111    is(
    112      tabpanel.querySelector(".raw-data-toggle-input .devtools-checkbox-toggle")
    113        .checked,
    114      true,
    115      "The raw response toggle should be on."
    116    );
    117    is(
    118      tabpanel.querySelector(".cm-content") === null,
    119      false,
    120      "The response editor has the intended visibility."
    121    );
    122    is(
    123      tabpanel.querySelector(".response-image-box") === null,
    124      true,
    125      "The response image box doesn't have the intended visibility."
    126    );
    127    is(
    128      tabpanel.querySelectorAll(".empty-notice").length,
    129      0,
    130      "The empty notice should not be displayed in this tabpanel."
    131    );
    132  }
    133 });