summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_variables-view-04.js
blob: 53f28aef8a5e4192c383e19f5e554d175ce4de40 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests that grips are correctly applied to variables.
 */

const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";

function test() {
  let options = {
    source: TAB_URL,
    line: 1
  };
  initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
    let variables = aPanel.panelWin.DebuggerView.Variables;
    let testScope = variables.addScope("test");
    let testVar = testScope.addItem("something");

    testVar.setGrip(1.618);

    is(testVar.target.querySelector(".value").getAttribute("value"), "1.618",
      "The grip information for the variable wasn't set correctly (1).");
    is(testVar.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0,
      "Setting the grip alone shouldn't add any new tree nodes (1).");
    is(testVar.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0,
      "Setting the grip alone shouldn't add any new tree nodes (2).");

    testVar.setGrip({
      type: "object",
      class: "Window"
    });

    is(testVar.target.querySelector(".value").getAttribute("value"), "Window",
      "The grip information for the variable wasn't set correctly (2).");
    is(testVar.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0,
      "Setting the grip alone shouldn't add any new tree nodes (3).");
    is(testVar.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0,
      "Setting the grip alone shouldn't add any new tree nodes (4).");

    testVar.addItems({
      helloWorld: {
        value: "hello world",
        enumerable: true
      }
    });

    is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 1,
      "A new detail node should have been added in the variable tree.");
    is(testVar.get("helloWorld").target.querySelector(".value").getAttribute("value"), "\"hello world\"",
      "The grip information for the variable wasn't set correctly (3).");

    testVar.addItems({
      helloWorld: {
        value: "hello jupiter",
        enumerable: true
      }
    });

    is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 1,
      "Shouldn't be able to duplicate nodes added in the variable tree.");
    is(testVar.get("helloWorld").target.querySelector(".value").getAttribute("value"), "\"hello world\"",
      "The grip information for the variable wasn't preserved correctly (4).");

    testVar.addItems({
      someProp0: {
        value: "random string",
        enumerable: true
      },
      someProp1: {
        value: "another string",
        enumerable: true
      }
    });

    is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 3,
      "Two new detail nodes should have been added in the variable tree.");
    is(testVar.get("someProp0").target.querySelector(".value").getAttribute("value"), "\"random string\"",
      "The grip information for the variable wasn't set correctly (5).");
    is(testVar.get("someProp1").target.querySelector(".value").getAttribute("value"), "\"another string\"",
      "The grip information for the variable wasn't set correctly (6).");

    testVar.addItems({
      someProp2: {
        value: {
          type: "null"
        },
        enumerable: true
      },
      someProp3: {
        value: {
          type: "undefined"
        },
        enumerable: true
      },
      someProp4: {
        value: {
          type: "object",
          class: "Object"
        },
        enumerable: true
      }
    });

    is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 6,
      "Three new detail nodes should have been added in the variable tree.");
    is(testVar.get("someProp2").target.querySelector(".value").getAttribute("value"), "null",
      "The grip information for the variable wasn't set correctly (7).");
    is(testVar.get("someProp3").target.querySelector(".value").getAttribute("value"), "undefined",
      "The grip information for the variable wasn't set correctly (8).");
    is(testVar.get("someProp4").target.querySelector(".value").getAttribute("value"), "Object",
      "The grip information for the variable wasn't set correctly (9).");

    let parent = testVar.get("someProp2");
    let child = parent.addItem("child", {
      value: {
        type: "null"
      }
    });

    is(variables.getItemForNode(parent.target), parent,
       "VariablesView should have a record of the parent.");
    is(variables.getItemForNode(child.target), child,
       "VariablesView should have a record of the child.");
    is([...parent].length, 1,
       "Parent should have one child.");

    parent.remove();

    is(variables.getItemForNode(parent.target), undefined,
       "VariablesView should not have a record of the parent anymore.");
    is(parent.target.parentNode, null,
       "Parent element should not have a parent.");
    is(variables.getItemForNode(child.target), undefined,
       "VariablesView should not have a record of the child anymore.");
    is(child.target.parentNode, null,
       "Child element should not have a parent.");
    is([...parent].length, 0,
       "Parent should have zero children.");

    testScope.remove();

    is([...variables].length, 0,
       "VariablesView should have been emptied.");
    is(ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(variables._itemsByElement).length,
       0, "VariablesView _itemsByElement map has been emptied.");
    is(variables._currHierarchy.size, 0,
       "VariablesView _currHierarchy map has been emptied.");
    is(variables._list.children.length, 0,
       "VariablesView element should have no children.");

    closeDebuggerAndFinish(aPanel);
  });
}