tor-browser

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

browser_jsonview_expand_collapse.js (1845B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 ChromeUtils.defineLazyGetter(this, "jsonViewStrings", () => {
      7  return Services.strings.createBundle(
      8    "chrome://devtools/locale/jsonview.properties"
      9  );
     10 });
     11 
     12 const TEST_JSON_URL = URL_ROOT + "array_json.json";
     13 const EXPAND_THRESHOLD = 100 * 1024;
     14 
     15 add_task(async function () {
     16  info("Test expand/collapse small JSON started");
     17 
     18  await addJsonViewTab(TEST_JSON_URL);
     19 
     20  /* Initial sanity check */
     21  const countBefore = await getElementCount(".treeRow");
     22  is(countBefore, 6, "There must be six rows");
     23 
     24  /* Test the "Collapse All" button */
     25  let selector = ".jsonPanelBox .toolbar button.collapse";
     26  await clickJsonNode(selector);
     27  let countAfter = await getElementCount(".treeRow");
     28  is(countAfter, 3, "There must be three rows");
     29 
     30  /* Test the "Expand All" button */
     31  selector = ".jsonPanelBox .toolbar button.expand";
     32  is(
     33    await getElementText(selector),
     34    jsonViewStrings.GetStringFromName("jsonViewer.ExpandAll"),
     35    "Expand button doesn't warn that the action will be slow"
     36  );
     37  await clickJsonNode(selector);
     38  countAfter = await getElementCount(".treeRow");
     39  is(countAfter, 6, "There must be six expanded rows");
     40 });
     41 
     42 add_task(async function () {
     43  info("Test expand button for big JSON started");
     44 
     45  const json = JSON.stringify({
     46    data: Array(1e5)
     47      .fill()
     48      .map(() => "hoot"),
     49    status: "ok",
     50  });
     51  Assert.greater(
     52    json.length,
     53    EXPAND_THRESHOLD,
     54    "The generated JSON must be larger than 100kB"
     55  );
     56  await addJsonViewTab("data:application/json," + json);
     57  is(
     58    await getElementText(".jsonPanelBox .toolbar button.expand"),
     59    jsonViewStrings.GetStringFromName("jsonViewer.ExpandAllSlow"),
     60    "Expand button warns that the action will be slow"
     61  );
     62 });