tor-browser

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

browser_net_json_text_mime.js (4369B)


      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 {
     12    L10N,
     13  } = require("resource://devtools/client/netmonitor/src/utils/l10n.js");
     14 
     15  const { tab, monitor } = await initNetMonitor(JSON_TEXT_MIME_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  // Execute requests.
     29  await performRequests(monitor, tab, 1);
     30 
     31  const requestItem = document.querySelector(".request-list-item");
     32  const requestsListStatus = requestItem.querySelector(".status-code");
     33  EventUtils.sendMouseEvent({ type: "mouseover" }, requestsListStatus);
     34  await waitUntil(() => requestsListStatus.title);
     35  await waitForDOMIfNeeded(requestItem, ".requests-list-timings-total");
     36 
     37  await verifyRequestItemTarget(
     38    document,
     39    getDisplayedRequests(store.getState()),
     40    getSortedRequests(store.getState())[0],
     41    "GET",
     42    CONTENT_TYPE_SJS + "?fmt=json-text-mime",
     43    {
     44      status: 200,
     45      statusText: "OK",
     46      type: "plain",
     47      fullMimeType: "text/plain; charset=utf-8",
     48      size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 41),
     49      time: true,
     50    }
     51  );
     52 
     53  let wait = waitForDOM(document, "#response-panel .data-header");
     54  const waitForPropsView = waitForDOM(
     55    document,
     56    "#response-panel .properties-view",
     57    1
     58  );
     59 
     60  store.dispatch(Actions.toggleNetworkDetails());
     61  clickOnSidebarTab(document, "response");
     62  await Promise.all([wait, waitForPropsView]);
     63 
     64  testJsonSectionInResponseTab();
     65 
     66  wait = waitForDOM(document, "#response-panel .cm-content");
     67  const rawResponseToggle = document.querySelector(
     68    "#response-panel .raw-data-toggle-input .devtools-checkbox-toggle"
     69  );
     70  clickElement(rawResponseToggle, monitor);
     71  await wait;
     72 
     73  testResponseTab();
     74 
     75  // Uncheck the toggle with the keyboard so we test Bug 1917296
     76  ok(rawResponseToggle.checked, "Raw toggle is checked");
     77  wait = waitForDOM(document, "#response-panel .data-header");
     78  rawResponseToggle.focus();
     79  EventUtils.synthesizeKey("VK_SPACE", {}, rawResponseToggle.ownerGlobal);
     80  await wait;
     81  ok(!rawResponseToggle.checked, "Raw toggle is unchecked");
     82 
     83  await teardown(monitor);
     84 
     85  function testJsonSectionInResponseTab() {
     86    const tabpanel = document.querySelector("#response-panel");
     87    is(
     88      tabpanel.querySelectorAll(".treeRow").length,
     89      1,
     90      "There should be 1 json properties displayed in this tabpanel."
     91    );
     92 
     93    const labels = tabpanel.querySelectorAll("tr .treeLabelCell .treeLabel");
     94    const values = tabpanel.querySelectorAll("tr .treeValueCell .objectBox");
     95 
     96    is(
     97      labels[0].textContent,
     98      "greeting",
     99      "The first json property name was incorrect."
    100    );
    101    is(
    102      values[0].textContent,
    103      `"Hello third-party JSON!"`,
    104      "The first json property value was incorrect."
    105    );
    106  }
    107 
    108  function testResponseTab() {
    109    const tabpanel = document.querySelector("#response-panel");
    110 
    111    is(
    112      tabpanel.querySelector(".response-error-header") === null,
    113      true,
    114      "The response error header doesn't have the intended visibility."
    115    );
    116    const jsonView = tabpanel.querySelector(".data-label") || {};
    117    is(
    118      jsonView.textContent === L10N.getStr("jsonScopeName"),
    119      true,
    120      "The response json view has the intended visibility."
    121    );
    122    is(
    123      tabpanel.querySelector(".cm-content") === null,
    124      false,
    125      "The response editor has the intended visibility."
    126    );
    127    is(
    128      tabpanel.querySelector(".raw-data-toggle-input .devtools-checkbox-toggle")
    129        .checked,
    130      true,
    131      "The raw response toggle should be on."
    132    );
    133    is(
    134      tabpanel.querySelector(".response-image-box") === null,
    135      true,
    136      "The response image box doesn't have the intended visibility."
    137    );
    138    is(
    139      tabpanel.querySelectorAll(".empty-notice").length,
    140      0,
    141      "The empty notice should not be displayed in this tabpanel."
    142    );
    143  }
    144 });