summaryrefslogtreecommitdiffstats
path: root/devtools/client/jsonview/test/browser_jsonview_empty_object.js
blob: af3dfbc007d1f759a29c56880d07dd342ca28bfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

function testRootObject(objExpr, summary = objExpr) {
  return async function () {
    info("Test JSON with root empty object " + objExpr + " started");

    const TEST_JSON_URL = "data:application/json," + objExpr;
    await addJsonViewTab(TEST_JSON_URL);

    const objectText = await getElementText(".jsonPanelBox .panelContent");
    is(objectText, summary, "The root object " + objExpr + " is visible");
  };
}

function testNestedObject(objExpr, summary = objExpr) {
  return async function () {
    info("Test JSON with nested empty object " + objExpr + " started");

    const TEST_JSON_URL = "data:application/json,[" + objExpr + "]";
    await addJsonViewTab(TEST_JSON_URL);

    const objectCellCount = await getElementCount(
      ".jsonPanelBox .treeTable .objectCell"
    );
    is(objectCellCount, 1, "There must be one object cell");

    const objectCellText = await getElementText(
      ".jsonPanelBox .treeTable .objectCell"
    );
    is(objectCellText, summary, objExpr + " has a visible summary");

    // Collapse auto-expanded node.
    await clickJsonNode(".jsonPanelBox .treeTable .treeLabel");

    const textAfter = await getElementText(
      ".jsonPanelBox .treeTable .objectCell"
    );
    is(textAfter, summary, objExpr + " still has a visible summary");
  };
}

add_task(testRootObject("null"));
add_task(testNestedObject("null"));
add_task(testNestedObject("[]"));
add_task(testNestedObject("{}"));