tor-browser

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

browser_net_json-long.js (5029B)


      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 very long JSON responses 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_LONG_URL, {
     16    requestCount: 1,
     17  });
     18  info("Starting test... ");
     19 
     20  // This is receiving over 80 KB of json and will populate over 6000 items
     21  // in a variables view instance. Debug builds are slow.
     22  requestLongerTimeout(4);
     23 
     24  const { document, store, windowRequire } = monitor.panelWin;
     25  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     26  const { getDisplayedRequests, getSortedRequests } = windowRequire(
     27    "devtools/client/netmonitor/src/selectors/index"
     28  );
     29 
     30  store.dispatch(Actions.batchEnable(false));
     31 
     32  // Execute requests.
     33  await performRequests(monitor, tab, 1);
     34 
     35  const requestItem = document.querySelector(".request-list-item");
     36  const requestsListStatus = requestItem.querySelector(".status-code");
     37  EventUtils.sendMouseEvent({ type: "mouseover" }, requestsListStatus);
     38  await waitUntil(() => requestsListStatus.title);
     39  await waitForDOMIfNeeded(requestItem, ".requests-list-timings-total");
     40 
     41  await verifyRequestItemTarget(
     42    document,
     43    getDisplayedRequests(store.getState()),
     44    getSortedRequests(store.getState())[0],
     45    "GET",
     46    CONTENT_TYPE_SJS + "?fmt=json-long",
     47    {
     48      status: 200,
     49      statusText: "OK",
     50      type: "json",
     51      fullMimeType: "text/json; charset=utf-8",
     52      size: L10N.getFormatStr(
     53        "networkMenu.size.kB",
     54        L10N.numberWithDecimals(85975 / 1000, 2)
     55      ),
     56      time: true,
     57    }
     58  );
     59 
     60  let wait = waitForDOM(document, "#response-panel .data-header");
     61  const waitForPropsView = waitForDOM(
     62    document,
     63    "#response-panel .properties-view",
     64    1
     65  );
     66 
     67  store.dispatch(Actions.toggleNetworkDetails());
     68 
     69  clickOnSidebarTab(document, "response");
     70 
     71  await Promise.all([wait, waitForPropsView]);
     72 
     73  // Scroll the properties view to the bottom
     74  const lastItem = document.querySelector(
     75    "#response-panel .properties-view tr.treeRow:last-child"
     76  );
     77  lastItem.scrollIntoView();
     78 
     79  testJsonInResposeTab();
     80 
     81  wait = waitForDOM(document, "#response-panel .cm-content");
     82  const rawResponseToggle = document.querySelector(
     83    "#response-panel .raw-data-toggle-input .devtools-checkbox-toggle"
     84  );
     85  clickElement(rawResponseToggle, monitor);
     86  await wait;
     87 
     88  testResponseTab();
     89 
     90  await teardown(monitor);
     91 
     92  function testJsonInResposeTab() {
     93    const tabpanel = document.querySelector("#response-panel");
     94    is(
     95      tabpanel.querySelectorAll(".treeRow").length,
     96      2047,
     97      "There should be 2047 json properties displayed in this tabpanel."
     98    );
     99 
    100    const labels = tabpanel.querySelectorAll("tr .treeLabelCell .treeLabel");
    101    const values = tabpanel.querySelectorAll("tr .treeValueCell .objectBox");
    102 
    103    is(
    104      labels[0].textContent,
    105      "0",
    106      "The first json property name was incorrect."
    107    );
    108    is(
    109      values[0].textContent,
    110      '{ greeting: "Hello long string JSON!" }',
    111      "The first json property value was incorrect."
    112    );
    113 
    114    is(
    115      labels[1].textContent,
    116      "1",
    117      "The second json property name was incorrect."
    118    );
    119    is(
    120      values[1].textContent,
    121      '"Hello long string JSON!"',
    122      "The second json property value was incorrect."
    123    );
    124 
    125    const view = tabpanel.querySelector(".properties-view .treeTable");
    126    is(scrolledToBottom(view), true, "The view is not scrollable");
    127  }
    128 
    129  function testResponseTab() {
    130    const tabpanel = document.querySelector("#response-panel");
    131 
    132    is(
    133      tabpanel.querySelector(".response-error-header") === null,
    134      true,
    135      "The response error header doesn't have the intended visibility."
    136    );
    137    const jsonView = tabpanel.querySelector(".data-label") || {};
    138    is(
    139      jsonView.textContent === L10N.getStr("jsonScopeName"),
    140      true,
    141      "The response json view has the intended visibility."
    142    );
    143    is(
    144      tabpanel.querySelector(".source-editor-mount").clientHeight !== 0,
    145      true,
    146      "The source editor container has visible height."
    147    );
    148    is(
    149      tabpanel.querySelector(".cm-content") === null,
    150      false,
    151      "The response editor has the intended visibility."
    152    );
    153    is(
    154      tabpanel.querySelector(".response-image-box") === null,
    155      true,
    156      "The response image box doesn't have the intended visibility."
    157    );
    158    is(
    159      tabpanel.querySelectorAll(".empty-notice").length,
    160      0,
    161      "The empty notice should not be displayed in this tabpanel."
    162    );
    163 
    164    is(
    165      tabpanel.querySelector(".data-label").textContent,
    166      L10N.getStr("jsonScopeName"),
    167      "The json view section doesn't have the correct title."
    168    );
    169  }
    170 
    171  function scrolledToBottom(element) {
    172    return element.scrollTop + element.clientHeight >= element.scrollHeight;
    173  }
    174 });