|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests that VariablesView methods responsible for styling variables |
|
6 * as overridden work properly. |
|
7 */ |
|
8 |
|
9 const TAB_URL = EXAMPLE_URL + "doc_scope-variable-2.html"; |
|
10 |
|
11 function test() { |
|
12 Task.spawn(function() { |
|
13 let [tab, debuggee, panel] = yield initDebugger(TAB_URL); |
|
14 let win = panel.panelWin; |
|
15 let events = win.EVENTS; |
|
16 let variables = win.DebuggerView.Variables; |
|
17 |
|
18 // Allow this generator function to yield first. |
|
19 executeSoon(() => debuggee.test()); |
|
20 yield waitForSourceAndCaretAndScopes(panel, ".html", 23); |
|
21 |
|
22 let firstScope = variables.getScopeAtIndex(0); |
|
23 let secondScope = variables.getScopeAtIndex(1); |
|
24 let thirdScope = variables.getScopeAtIndex(2); |
|
25 let globalScope = variables.getScopeAtIndex(3); |
|
26 |
|
27 ok(firstScope, "The first scope is available."); |
|
28 ok(secondScope, "The second scope is available."); |
|
29 ok(thirdScope, "The third scope is available."); |
|
30 ok(globalScope, "The global scope is available."); |
|
31 |
|
32 is(firstScope.name, "Function scope [secondNest]", |
|
33 "The first scope's name is correct."); |
|
34 is(secondScope.name, "Function scope [firstNest]", |
|
35 "The second scope's name is correct."); |
|
36 is(thirdScope.name, "Function scope [test]", |
|
37 "The third scope's name is correct."); |
|
38 is(globalScope.name, "Global scope [Window]", |
|
39 "The global scope's name is correct."); |
|
40 |
|
41 is(firstScope.expanded, true, |
|
42 "The first scope's expansion state is correct."); |
|
43 is(secondScope.expanded, false, |
|
44 "The second scope's expansion state is correct."); |
|
45 is(thirdScope.expanded, false, |
|
46 "The third scope's expansion state is correct."); |
|
47 is(globalScope.expanded, false, |
|
48 "The global scope's expansion state is correct."); |
|
49 |
|
50 is(firstScope._store.size, 3, |
|
51 "The first scope should have all the variables available."); |
|
52 is(secondScope._store.size, 0, |
|
53 "The second scope should have no variables available yet."); |
|
54 is(thirdScope._store.size, 0, |
|
55 "The third scope should have no variables available yet."); |
|
56 is(globalScope._store.size, 0, |
|
57 "The global scope should have no variables available yet."); |
|
58 |
|
59 // Test getOwnerScopeForVariableOrProperty with simple variables. |
|
60 |
|
61 let thisVar = firstScope.get("this"); |
|
62 let thisOwner = variables.getOwnerScopeForVariableOrProperty(thisVar); |
|
63 is(thisOwner, firstScope, |
|
64 "The getOwnerScopeForVariableOrProperty method works properly (1)."); |
|
65 |
|
66 let someVar1 = firstScope.get("a"); |
|
67 let someOwner1 = variables.getOwnerScopeForVariableOrProperty(someVar1); |
|
68 is(someOwner1, firstScope, |
|
69 "The getOwnerScopeForVariableOrProperty method works properly (2)."); |
|
70 |
|
71 // Test getOwnerScopeForVariableOrProperty with first-degree properties. |
|
72 |
|
73 let argsVar1 = firstScope.get("arguments"); |
|
74 let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES); |
|
75 argsVar1.expand(); |
|
76 yield fetched; |
|
77 |
|
78 let calleeProp1 = argsVar1.get("callee"); |
|
79 let calleeOwner1 = variables.getOwnerScopeForVariableOrProperty(calleeProp1); |
|
80 is(calleeOwner1, firstScope, |
|
81 "The getOwnerScopeForVariableOrProperty method works properly (3)."); |
|
82 |
|
83 // Test getOwnerScopeForVariableOrProperty with second-degree properties. |
|
84 |
|
85 let protoVar1 = argsVar1.get("__proto__"); |
|
86 let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES); |
|
87 protoVar1.expand(); |
|
88 yield fetched; |
|
89 |
|
90 let constrProp1 = protoVar1.get("constructor"); |
|
91 let constrOwner1 = variables.getOwnerScopeForVariableOrProperty(constrProp1); |
|
92 is(constrOwner1, firstScope, |
|
93 "The getOwnerScopeForVariableOrProperty method works properly (4)."); |
|
94 |
|
95 // Test getOwnerScopeForVariableOrProperty with a simple variable |
|
96 // from non-topmost scopes. |
|
97 |
|
98 // Only need to wait for a single FETCHED_VARIABLES event, just for the |
|
99 // global scope, because the other local scopes already have the |
|
100 // arguments and variables available as evironment bindings. |
|
101 let fetched = waitForDebuggerEvents(panel, events.FETCHED_VARIABLES); |
|
102 secondScope.expand(); |
|
103 thirdScope.expand(); |
|
104 globalScope.expand(); |
|
105 yield fetched; |
|
106 |
|
107 let someVar2 = secondScope.get("a"); |
|
108 let someOwner2 = variables.getOwnerScopeForVariableOrProperty(someVar2); |
|
109 is(someOwner2, secondScope, |
|
110 "The getOwnerScopeForVariableOrProperty method works properly (5)."); |
|
111 |
|
112 let someVar3 = thirdScope.get("a"); |
|
113 let someOwner3 = variables.getOwnerScopeForVariableOrProperty(someVar3); |
|
114 is(someOwner3, thirdScope, |
|
115 "The getOwnerScopeForVariableOrProperty method works properly (6)."); |
|
116 |
|
117 // Test getOwnerScopeForVariableOrProperty with first-degree properies |
|
118 // from non-topmost scopes. |
|
119 |
|
120 let argsVar2 = secondScope.get("arguments"); |
|
121 let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES); |
|
122 argsVar2.expand(); |
|
123 yield fetched; |
|
124 |
|
125 let calleeProp2 = argsVar2.get("callee"); |
|
126 let calleeOwner2 = variables.getOwnerScopeForVariableOrProperty(calleeProp2); |
|
127 is(calleeOwner2, secondScope, |
|
128 "The getOwnerScopeForVariableOrProperty method works properly (7)."); |
|
129 |
|
130 let argsVar3 = thirdScope.get("arguments"); |
|
131 let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES); |
|
132 argsVar3.expand(); |
|
133 yield fetched; |
|
134 |
|
135 let calleeProp3 = argsVar3.get("callee"); |
|
136 let calleeOwner3 = variables.getOwnerScopeForVariableOrProperty(calleeProp3); |
|
137 is(calleeOwner3, thirdScope, |
|
138 "The getOwnerScopeForVariableOrProperty method works properly (8)."); |
|
139 |
|
140 // Test getOwnerScopeForVariableOrProperty with second-degree properties |
|
141 // from non-topmost scopes. |
|
142 |
|
143 let protoVar2 = argsVar2.get("__proto__"); |
|
144 let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES); |
|
145 protoVar2.expand(); |
|
146 yield fetched; |
|
147 |
|
148 let constrProp2 = protoVar2.get("constructor"); |
|
149 let constrOwner2 = variables.getOwnerScopeForVariableOrProperty(constrProp2); |
|
150 is(constrOwner2, secondScope, |
|
151 "The getOwnerScopeForVariableOrProperty method works properly (9)."); |
|
152 |
|
153 let protoVar3 = argsVar3.get("__proto__"); |
|
154 let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES); |
|
155 protoVar3.expand(); |
|
156 yield fetched; |
|
157 |
|
158 let constrProp3 = protoVar3.get("constructor"); |
|
159 let constrOwner3 = variables.getOwnerScopeForVariableOrProperty(constrProp3); |
|
160 is(constrOwner3, thirdScope, |
|
161 "The getOwnerScopeForVariableOrProperty method works properly (10)."); |
|
162 |
|
163 // Test getParentScopesForVariableOrProperty with simple variables. |
|
164 |
|
165 let varOwners1 = variables.getParentScopesForVariableOrProperty(someVar1); |
|
166 let varOwners2 = variables.getParentScopesForVariableOrProperty(someVar2); |
|
167 let varOwners3 = variables.getParentScopesForVariableOrProperty(someVar3); |
|
168 |
|
169 is(varOwners1.length, 0, |
|
170 "There should be no owner scopes for the first variable."); |
|
171 |
|
172 is(varOwners2.length, 1, |
|
173 "There should be one owner scope for the second variable."); |
|
174 is(varOwners2[0], firstScope, |
|
175 "The only owner scope for the second variable is correct."); |
|
176 |
|
177 is(varOwners3.length, 2, |
|
178 "There should be two owner scopes for the third variable."); |
|
179 is(varOwners3[0], firstScope, |
|
180 "The first owner scope for the third variable is correct."); |
|
181 is(varOwners3[1], secondScope, |
|
182 "The second owner scope for the third variable is correct."); |
|
183 |
|
184 // Test getParentScopesForVariableOrProperty with first-degree properties. |
|
185 |
|
186 let propOwners1 = variables.getParentScopesForVariableOrProperty(calleeProp1); |
|
187 let propOwners2 = variables.getParentScopesForVariableOrProperty(calleeProp2); |
|
188 let propOwners3 = variables.getParentScopesForVariableOrProperty(calleeProp3); |
|
189 |
|
190 is(propOwners1.length, 0, |
|
191 "There should be no owner scopes for the first property."); |
|
192 |
|
193 is(propOwners2.length, 1, |
|
194 "There should be one owner scope for the second property."); |
|
195 is(propOwners2[0], firstScope, |
|
196 "The only owner scope for the second property is correct."); |
|
197 |
|
198 is(propOwners3.length, 2, |
|
199 "There should be two owner scopes for the third property."); |
|
200 is(propOwners3[0], firstScope, |
|
201 "The first owner scope for the third property is correct."); |
|
202 is(propOwners3[1], secondScope, |
|
203 "The second owner scope for the third property is correct."); |
|
204 |
|
205 // Test getParentScopesForVariableOrProperty with second-degree properties. |
|
206 |
|
207 let secPropOwners1 = variables.getParentScopesForVariableOrProperty(constrProp1); |
|
208 let secPropOwners2 = variables.getParentScopesForVariableOrProperty(constrProp2); |
|
209 let secPropOwners3 = variables.getParentScopesForVariableOrProperty(constrProp3); |
|
210 |
|
211 is(secPropOwners1.length, 0, |
|
212 "There should be no owner scopes for the first inner property."); |
|
213 |
|
214 is(secPropOwners2.length, 1, |
|
215 "There should be one owner scope for the second inner property."); |
|
216 is(secPropOwners2[0], firstScope, |
|
217 "The only owner scope for the second inner property is correct."); |
|
218 |
|
219 is(secPropOwners3.length, 2, |
|
220 "There should be two owner scopes for the third inner property."); |
|
221 is(secPropOwners3[0], firstScope, |
|
222 "The first owner scope for the third inner property is correct."); |
|
223 is(secPropOwners3[1], secondScope, |
|
224 "The second owner scope for the third inner property is correct."); |
|
225 |
|
226 yield resumeDebuggerThenCloseAndFinish(panel); |
|
227 }); |
|
228 } |