|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests that grips are correctly applied to variables. |
|
6 */ |
|
7 |
|
8 const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html"; |
|
9 |
|
10 function test() { |
|
11 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
12 let variables = aPanel.panelWin.DebuggerView.Variables; |
|
13 let testScope = variables.addScope("test"); |
|
14 let testVar = testScope.addItem("something"); |
|
15 |
|
16 testVar.setGrip(1.618); |
|
17 |
|
18 is(testVar.target.querySelector(".value").getAttribute("value"), "1.618", |
|
19 "The grip information for the variable wasn't set correctly (1)."); |
|
20 is(testVar.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0, |
|
21 "Setting the grip alone shouldn't add any new tree nodes (1)."); |
|
22 is(testVar.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0, |
|
23 "Setting the grip alone shouldn't add any new tree nodes (2)."); |
|
24 |
|
25 testVar.setGrip({ |
|
26 type: "object", |
|
27 class: "Window" |
|
28 }); |
|
29 |
|
30 is(testVar.target.querySelector(".value").getAttribute("value"), "Window", |
|
31 "The grip information for the variable wasn't set correctly (2)."); |
|
32 is(testVar.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0, |
|
33 "Setting the grip alone shouldn't add any new tree nodes (3)."); |
|
34 is(testVar.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0, |
|
35 "Setting the grip alone shouldn't add any new tree nodes (4)."); |
|
36 |
|
37 testVar.addItems({ |
|
38 helloWorld: { |
|
39 value: "hello world", |
|
40 enumerable: true |
|
41 } |
|
42 }); |
|
43 |
|
44 is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 1, |
|
45 "A new detail node should have been added in the variable tree."); |
|
46 is(testVar.get("helloWorld").target.querySelector(".value").getAttribute("value"), "\"hello world\"", |
|
47 "The grip information for the variable wasn't set correctly (3)."); |
|
48 |
|
49 testVar.addItems({ |
|
50 helloWorld: { |
|
51 value: "hello jupiter", |
|
52 enumerable: true |
|
53 } |
|
54 }); |
|
55 |
|
56 is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 1, |
|
57 "Shouldn't be able to duplicate nodes added in the variable tree."); |
|
58 is(testVar.get("helloWorld").target.querySelector(".value").getAttribute("value"), "\"hello world\"", |
|
59 "The grip information for the variable wasn't preserved correctly (4)."); |
|
60 |
|
61 testVar.addItems({ |
|
62 someProp0: { |
|
63 value: "random string", |
|
64 enumerable: true |
|
65 }, |
|
66 someProp1: { |
|
67 value: "another string", |
|
68 enumerable: true |
|
69 } |
|
70 }); |
|
71 |
|
72 is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 3, |
|
73 "Two new detail nodes should have been added in the variable tree."); |
|
74 is(testVar.get("someProp0").target.querySelector(".value").getAttribute("value"), "\"random string\"", |
|
75 "The grip information for the variable wasn't set correctly (5)."); |
|
76 is(testVar.get("someProp1").target.querySelector(".value").getAttribute("value"), "\"another string\"", |
|
77 "The grip information for the variable wasn't set correctly (6)."); |
|
78 |
|
79 testVar.addItems({ |
|
80 someProp2: { |
|
81 value: { |
|
82 type: "null" |
|
83 }, |
|
84 enumerable: true |
|
85 }, |
|
86 someProp3: { |
|
87 value: { |
|
88 type: "undefined" |
|
89 }, |
|
90 enumerable: true |
|
91 }, |
|
92 someProp4: { |
|
93 value: { |
|
94 type: "object", |
|
95 class: "Object" |
|
96 }, |
|
97 enumerable: true |
|
98 } |
|
99 }); |
|
100 |
|
101 is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 6, |
|
102 "Three new detail nodes should have been added in the variable tree."); |
|
103 is(testVar.get("someProp2").target.querySelector(".value").getAttribute("value"), "null", |
|
104 "The grip information for the variable wasn't set correctly (7)."); |
|
105 is(testVar.get("someProp3").target.querySelector(".value").getAttribute("value"), "undefined", |
|
106 "The grip information for the variable wasn't set correctly (8)."); |
|
107 is(testVar.get("someProp4").target.querySelector(".value").getAttribute("value"), "Object", |
|
108 "The grip information for the variable wasn't set correctly (9)."); |
|
109 |
|
110 let parent = testVar.get("someProp2"); |
|
111 let child = parent.addItem("child", { |
|
112 value: { |
|
113 type: "null" |
|
114 } |
|
115 }); |
|
116 |
|
117 is(variables.getItemForNode(parent.target), parent, |
|
118 "VariablesView should have a record of the parent."); |
|
119 is(variables.getItemForNode(child.target), child, |
|
120 "VariablesView should have a record of the child."); |
|
121 is([...parent].length, 1, |
|
122 "Parent should have one child."); |
|
123 |
|
124 parent.remove(); |
|
125 |
|
126 is(variables.getItemForNode(parent.target), undefined, |
|
127 "VariablesView should not have a record of the parent anymore."); |
|
128 is(parent.target.parentNode, null, |
|
129 "Parent element should not have a parent.") |
|
130 is(variables.getItemForNode(child.target), undefined, |
|
131 "VariablesView should not have a record of the child anymore."); |
|
132 is(child.target.parentNode, null, |
|
133 "Child element should not have a parent.") |
|
134 is([...parent].length, 0, |
|
135 "Parent should have zero children."); |
|
136 |
|
137 testScope.remove(); |
|
138 |
|
139 is([...variables].length, 0, |
|
140 "VariablesView should have been emptied."); |
|
141 is(Cu.nondeterministicGetWeakMapKeys(variables._itemsByElement).length, 0, |
|
142 "VariablesView _itemsByElement map has been emptied."); |
|
143 is(variables._currHierarchy.size, 0, |
|
144 "VariablesView _currHierarchy map has been emptied."); |
|
145 is(variables._list.children.length, 0, |
|
146 "VariablesView element should have no children."); |
|
147 |
|
148 closeDebuggerAndFinish(aPanel); |
|
149 }); |
|
150 } |