tor-browser

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

browser_jsonview_empty_object.js (1559B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 function testRootObject(objExpr, summary = objExpr) {
      7  return async function () {
      8    info("Test JSON with root empty object " + objExpr + " started");
      9 
     10    const TEST_JSON_URL = "data:application/json," + objExpr;
     11    await addJsonViewTab(TEST_JSON_URL);
     12 
     13    const objectText = await getElementText(".jsonPanelBox .panelContent");
     14    is(objectText, summary, "The root object " + objExpr + " is visible");
     15  };
     16 }
     17 
     18 function testNestedObject(objExpr, summary = objExpr) {
     19  return async function () {
     20    info("Test JSON with nested empty object " + objExpr + " started");
     21 
     22    const TEST_JSON_URL = "data:application/json,[" + objExpr + "]";
     23    await addJsonViewTab(TEST_JSON_URL);
     24 
     25    const objectCellCount = await getElementCount(
     26      ".jsonPanelBox .treeTable .objectCell"
     27    );
     28    is(objectCellCount, 1, "There must be one object cell");
     29 
     30    const objectCellText = await getElementText(
     31      ".jsonPanelBox .treeTable .objectCell"
     32    );
     33    is(objectCellText, summary, objExpr + " has a visible summary");
     34 
     35    // Collapse auto-expanded node.
     36    await clickJsonNode(".jsonPanelBox .treeTable .treeLabel");
     37 
     38    const textAfter = await getElementText(
     39      ".jsonPanelBox .treeTable .objectCell"
     40    );
     41    is(textAfter, summary, objExpr + " still has a visible summary");
     42  };
     43 }
     44 
     45 add_task(testRootObject("null"));
     46 add_task(testNestedObject("null"));
     47 add_task(testNestedObject("[]"));
     48 add_task(testNestedObject("{}"));