|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests that creating, collpasing and expanding variables in the |
|
6 * variables view works as expected. |
|
7 */ |
|
8 |
|
9 const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html"; |
|
10 |
|
11 function test() { |
|
12 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
13 let variables = aPanel.panelWin.DebuggerView.Variables; |
|
14 let testScope = variables.addScope("test"); |
|
15 let testVar = testScope.addItem("something"); |
|
16 let duplVar = testScope.addItem("something"); |
|
17 |
|
18 info("Scope id: " + testScope.id); |
|
19 info("Scope name: " + testScope.name); |
|
20 info("Variable id: " + testVar.id); |
|
21 info("Variable name: " + testVar.name); |
|
22 |
|
23 ok(testScope, |
|
24 "Should have created a scope."); |
|
25 is(duplVar, null, |
|
26 "Shouldn't be able to duplicate variables in the same scope."); |
|
27 |
|
28 ok(testVar, |
|
29 "Should have created a variable."); |
|
30 ok(testVar.id.contains("something"), |
|
31 "The newly created variable should have the default id set."); |
|
32 is(testVar.name, "something", |
|
33 "The newly created variable should have the desired name set."); |
|
34 |
|
35 ok(!testVar.displayValue, |
|
36 "The newly created variable should not have a displayed value yet (1)."); |
|
37 ok(!testVar.displayValueClassName, |
|
38 "The newly created variable should not have a displayed value yet (2)."); |
|
39 |
|
40 ok(testVar.target, |
|
41 "The newly created scope should point to a target node."); |
|
42 ok(testVar.target.id.contains("something"), |
|
43 "Should have the correct variable id on the element."); |
|
44 |
|
45 is(testVar.target.querySelector(".name").getAttribute("value"), "something", |
|
46 "Any new variable should have the designated name."); |
|
47 is(testVar.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0, |
|
48 "Any new variable should have a container with no enumerable child nodes."); |
|
49 is(testVar.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0, |
|
50 "Any new variable should have a container with no non-enumerable child nodes."); |
|
51 |
|
52 ok(!testVar.expanded, |
|
53 "Any new created scope should be initially collapsed."); |
|
54 ok(testVar.visible, |
|
55 "Any new created scope should be initially visible."); |
|
56 |
|
57 let expandCallbackArg = null; |
|
58 let collapseCallbackArg = null; |
|
59 let toggleCallbackArg = null; |
|
60 let hideCallbackArg = null; |
|
61 let showCallbackArg = null; |
|
62 |
|
63 testVar.onexpand = aScope => expandCallbackArg = aScope; |
|
64 testVar.oncollapse = aScope => collapseCallbackArg = aScope; |
|
65 testVar.ontoggle = aScope => toggleCallbackArg = aScope; |
|
66 testVar.onhide = aScope => hideCallbackArg = aScope; |
|
67 testVar.onshow = aScope => showCallbackArg = aScope; |
|
68 |
|
69 testVar.expand(); |
|
70 ok(testVar.expanded, |
|
71 "The testVar shouldn't be collapsed anymore."); |
|
72 is(expandCallbackArg, testVar, |
|
73 "The expandCallback wasn't called as it should."); |
|
74 |
|
75 testVar.collapse(); |
|
76 ok(!testVar.expanded, |
|
77 "The testVar should be collapsed again."); |
|
78 is(collapseCallbackArg, testVar, |
|
79 "The collapseCallback wasn't called as it should."); |
|
80 |
|
81 testVar.expanded = true; |
|
82 ok(testVar.expanded, |
|
83 "The testVar shouldn't be collapsed anymore."); |
|
84 |
|
85 testVar.toggle(); |
|
86 ok(!testVar.expanded, |
|
87 "The testVar should be collapsed again."); |
|
88 is(toggleCallbackArg, testVar, |
|
89 "The toggleCallback wasn't called as it should."); |
|
90 |
|
91 testVar.hide(); |
|
92 ok(!testVar.visible, |
|
93 "The testVar should be invisible after hiding."); |
|
94 is(hideCallbackArg, testVar, |
|
95 "The hideCallback wasn't called as it should."); |
|
96 |
|
97 testVar.show(); |
|
98 ok(testVar.visible, |
|
99 "The testVar should be visible again."); |
|
100 is(showCallbackArg, testVar, |
|
101 "The showCallback wasn't called as it should."); |
|
102 |
|
103 testVar.visible = false; |
|
104 ok(!testVar.visible, |
|
105 "The testVar should be invisible after hiding."); |
|
106 ok(!testVar.expanded, |
|
107 "The testVar should remember it is collapsed even if it is hidden."); |
|
108 |
|
109 testVar.visible = true; |
|
110 ok(testVar.visible, |
|
111 "The testVar should be visible after reshowing."); |
|
112 ok(!testVar.expanded, |
|
113 "The testVar should remember it is collapsed after it is reshown."); |
|
114 |
|
115 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
116 testVar.target.querySelector(".name"), |
|
117 aPanel.panelWin); |
|
118 |
|
119 ok(testVar.expanded, |
|
120 "Clicking the testVar name should expand it."); |
|
121 |
|
122 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
123 testVar.target.querySelector(".name"), |
|
124 aPanel.panelWin); |
|
125 |
|
126 ok(!testVar.expanded, |
|
127 "Clicking again the testVar name should collapse it."); |
|
128 |
|
129 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
130 testVar.target.querySelector(".arrow"), |
|
131 aPanel.panelWin); |
|
132 |
|
133 ok(testVar.expanded, |
|
134 "Clicking the testVar arrow should expand it."); |
|
135 |
|
136 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
137 testVar.target.querySelector(".arrow"), |
|
138 aPanel.panelWin); |
|
139 |
|
140 ok(!testVar.expanded, |
|
141 "Clicking again the testVar arrow should collapse it."); |
|
142 |
|
143 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
144 testVar.target.querySelector(".title"), |
|
145 aPanel.panelWin); |
|
146 |
|
147 ok(testVar.expanded, |
|
148 "Clicking the testVar title should expand it again."); |
|
149 |
|
150 testVar.addItem("child", { |
|
151 value: { |
|
152 type: "object", |
|
153 class: "Object" |
|
154 } |
|
155 }); |
|
156 |
|
157 let testChild = testVar.get("child"); |
|
158 ok(testChild, |
|
159 "Should have created a child property."); |
|
160 ok(testChild.id.contains("child"), |
|
161 "The newly created property should have the default id set."); |
|
162 is(testChild.name, "child", |
|
163 "The newly created property should have the desired name set."); |
|
164 |
|
165 is(testChild.displayValue, "Object", |
|
166 "The newly created property should not have a displayed value yet (1)."); |
|
167 is(testChild.displayValueClassName, "token-other", |
|
168 "The newly created property should not have a displayed value yet (2)."); |
|
169 |
|
170 ok(testChild.target, |
|
171 "The newly created scope should point to a target node."); |
|
172 ok(testChild.target.id.contains("child"), |
|
173 "Should have the correct property id on the element."); |
|
174 |
|
175 is(testChild.target.querySelector(".name").getAttribute("value"), "child", |
|
176 "Any new property should have the designated name."); |
|
177 is(testChild.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0, |
|
178 "Any new property should have a container with no enumerable child nodes."); |
|
179 is(testChild.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0, |
|
180 "Any new property should have a container with no non-enumerable child nodes."); |
|
181 |
|
182 ok(!testChild.expanded, |
|
183 "Any new created scope should be initially collapsed."); |
|
184 ok(testChild.visible, |
|
185 "Any new created scope should be initially visible."); |
|
186 |
|
187 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
188 testChild.target.querySelector(".name"), |
|
189 aPanel.panelWin); |
|
190 |
|
191 ok(testChild.expanded, |
|
192 "Clicking the testChild name should expand it."); |
|
193 |
|
194 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
195 testChild.target.querySelector(".name"), |
|
196 aPanel.panelWin); |
|
197 |
|
198 ok(!testChild.expanded, |
|
199 "Clicking again the testChild name should collapse it."); |
|
200 |
|
201 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
202 testChild.target.querySelector(".arrow"), |
|
203 aPanel.panelWin); |
|
204 |
|
205 ok(testChild.expanded, |
|
206 "Clicking the testChild arrow should expand it."); |
|
207 |
|
208 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
209 testChild.target.querySelector(".arrow"), |
|
210 aPanel.panelWin); |
|
211 |
|
212 ok(!testChild.expanded, |
|
213 "Clicking again the testChild arrow should collapse it."); |
|
214 |
|
215 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
216 testChild.target.querySelector(".title"), |
|
217 aPanel.panelWin); |
|
218 |
|
219 closeDebuggerAndFinish(aPanel); |
|
220 }); |
|
221 } |