tor-browser

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

browser_net_json-null.js (3932B)


      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 containing null values are properly displayed.
      8 */
      9 
     10 add_task(async function () {
     11  const { tab, monitor } = await initNetMonitor(JSON_BASIC_URL + "?name=null", {
     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 
     19  store.dispatch(Actions.batchEnable(false));
     20 
     21  // Execute requests.
     22  await performRequests(monitor, tab, 1);
     23 
     24  const onResponsePanelReady = waitForDOM(
     25    document,
     26    "#response-panel .data-header"
     27  );
     28 
     29  const onPropsViewReady = waitForDOM(
     30    document,
     31    "#response-panel .properties-view",
     32    1
     33  );
     34  store.dispatch(Actions.toggleNetworkDetails());
     35  clickOnSidebarTab(document, "response");
     36  await Promise.all([onResponsePanelReady, onPropsViewReady]);
     37 
     38  const tabpanel = document.querySelector("#response-panel");
     39  is(
     40    tabpanel.querySelectorAll(".raw-data-toggle").length,
     41    1,
     42    "There should be 1 raw response toggle."
     43  );
     44  is(
     45    tabpanel.querySelectorAll(".treeRow").length,
     46    1,
     47    "There should be 1 json properties displayed in this tabpanel."
     48  );
     49  is(
     50    tabpanel.querySelectorAll(".empty-notice").length,
     51    0,
     52    "The empty notice should not be displayed in this tabpanel."
     53  );
     54 
     55  const labels = tabpanel.querySelectorAll("tr .treeLabelCell .treeLabel");
     56  const values = tabpanel.querySelectorAll("tr .treeValueCell .objectBox");
     57 
     58  is(
     59    labels[0].textContent,
     60    "greeting",
     61    "The first json property name was incorrect."
     62  );
     63  is(
     64    values[0].textContent,
     65    "null",
     66    "The first json property value was incorrect."
     67  );
     68 
     69  const onCodeMirrorReady = waitForDOM(document, "#response-panel .cm-content");
     70 
     71  const rawResponseToggle = document.querySelector(
     72    "#response-panel .raw-data-toggle-input .devtools-checkbox-toggle"
     73  );
     74  clickElement(rawResponseToggle, monitor);
     75 
     76  await onCodeMirrorReady;
     77 
     78  checkResponsePanelDisplaysJSON();
     79 
     80  await teardown(monitor);
     81 
     82  /**
     83   * Helper to assert that the response panel found in the provided document is currently
     84   * showing a preview of a JSON object.
     85   */
     86  function checkResponsePanelDisplaysJSON() {
     87    const panel = document.querySelector("#response-panel");
     88    is(
     89      panel.querySelector(".response-error-header") === null,
     90      true,
     91      "The response error header doesn't have the intended visibility."
     92    );
     93    const jsonView = panel.querySelector(".data-label") || {};
     94    is(
     95      jsonView.textContent === L10N.getStr("jsonScopeName"),
     96      true,
     97      "The response json view has the intended visibility."
     98    );
     99    is(
    100      panel.querySelector(".cm-content") === null,
    101      false,
    102      "The response editor has the intended visibility."
    103    );
    104    is(
    105      panel.querySelector(".response-image-box") === null,
    106      true,
    107      "The response image box doesn't have the intended visibility."
    108    );
    109  }
    110 });
    111 
    112 add_task(async function () {
    113  const { tab, monitor } = await initNetMonitor(
    114    JSON_BASIC_URL + "?name=root-null",
    115    {
    116      requestCount: 1,
    117    }
    118  );
    119  info("Starting test... ");
    120 
    121  const { document, store, windowRequire } = monitor.panelWin;
    122  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
    123 
    124  store.dispatch(Actions.batchEnable(false));
    125 
    126  // Execute requests.
    127  await performRequests(monitor, tab, 1);
    128 
    129  const onCodeMirrorReady = waitForDOM(document, "#response-panel .cm-content");
    130 
    131  store.dispatch(Actions.toggleNetworkDetails());
    132  clickOnSidebarTab(document, "response");
    133  const [codeMirrorCodeEl] = await onCodeMirrorReady;
    134  is(
    135    codeMirrorCodeEl.querySelector(".cm-line").textContent,
    136    "null",
    137    "root null JSON object is displayed in a CodeMirror editor"
    138  );
    139 
    140  await teardown(monitor);
    141 });