tor-browser

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

browser_net_json-b64.js (2861B)


      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 encoded in base64 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  const { tab, monitor } = await initNetMonitor(JSON_B64_URL, {
     15    requestCount: 1,
     16  });
     17  info("Starting test... ");
     18 
     19  const { document, store, windowRequire } = monitor.panelWin;
     20  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     21 
     22  store.dispatch(Actions.batchEnable(false));
     23 
     24  // Execute requests.
     25  await performRequests(monitor, tab, 1);
     26 
     27  let wait = waitForDOM(document, "#response-panel .data-header");
     28  const waitForPropsView = waitForDOM(
     29    document,
     30    "#response-panel .properties-view",
     31    1
     32  );
     33 
     34  store.dispatch(Actions.toggleNetworkDetails());
     35 
     36  clickOnSidebarTab(document, "response");
     37 
     38  await Promise.all([wait, waitForPropsView]);
     39 
     40  const tabpanel = document.querySelector("#response-panel");
     41  is(
     42    tabpanel.querySelectorAll(".treeRow").length,
     43    1,
     44    "There should be 1 json properties displayed in this tabpanel."
     45  );
     46 
     47  const labels = tabpanel.querySelectorAll("tr .treeLabelCell .treeLabel");
     48  const values = tabpanel.querySelectorAll("tr .treeValueCell .objectBox");
     49 
     50  is(
     51    labels[0].textContent,
     52    "greeting",
     53    "The first json property name was incorrect."
     54  );
     55  is(
     56    values[0].textContent,
     57    `"This is a base 64 string."`,
     58    "The first json property value was incorrect."
     59  );
     60 
     61  // Open the response payload section, it should hide the json section
     62  wait = waitForDOM(document, "#response-panel .cm-content");
     63  const header = document.querySelector(
     64    "#response-panel .raw-data-toggle-input .devtools-checkbox-toggle"
     65  );
     66  clickElement(header, monitor);
     67  await wait;
     68 
     69  is(
     70    tabpanel.querySelector(".response-error-header") === null,
     71    true,
     72    "The response error header doesn't have the intended visibility."
     73  );
     74  const jsonView = tabpanel.querySelector(".data-label") || {};
     75  is(
     76    jsonView.textContent === L10N.getStr("jsonScopeName"),
     77    true,
     78    "The response json view has the intended visibility."
     79  );
     80  is(
     81    tabpanel.querySelector(".raw-data-toggle-input .devtools-checkbox-toggle")
     82      .checked,
     83    true,
     84    "The raw response toggle should be on."
     85  );
     86  is(
     87    tabpanel.querySelector(".cm-content") === null,
     88    false,
     89    "The response editor has the intended visibility."
     90  );
     91  is(
     92    tabpanel.querySelector(".response-image-box") === null,
     93    true,
     94    "The response image box doesn't have the intended visibility."
     95  );
     96  is(
     97    tabpanel.querySelectorAll(".empty-notice").length,
     98    0,
     99    "The empty notice should not be displayed in this tabpanel."
    100  );
    101 
    102  await teardown(monitor);
    103 });