|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Make sure that the variables view is correctly populated in 'with' frames. |
|
6 */ |
|
7 |
|
8 const TAB_URL = EXAMPLE_URL + "doc_with-frame.html"; |
|
9 |
|
10 let gTab, gDebuggee, gPanel, gDebugger; |
|
11 let gVariables; |
|
12 |
|
13 function test() { |
|
14 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
15 gTab = aTab; |
|
16 gDebuggee = aDebuggee; |
|
17 gPanel = aPanel; |
|
18 gDebugger = gPanel.panelWin; |
|
19 gVariables = gDebugger.DebuggerView.Variables; |
|
20 |
|
21 // The first 'with' scope should be expanded by default, but the |
|
22 // variables haven't been fetched yet. This is how 'with' scopes work. |
|
23 promise.all([ |
|
24 waitForSourceAndCaret(gPanel, ".html", 22), |
|
25 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES), |
|
26 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES) |
|
27 ]).then(testFirstWithScope) |
|
28 .then(expandSecondWithScope) |
|
29 .then(testSecondWithScope) |
|
30 .then(expandFunctionScope) |
|
31 .then(testFunctionScope) |
|
32 .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) |
|
33 .then(null, aError => { |
|
34 ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
|
35 }); |
|
36 |
|
37 EventUtils.sendMouseEvent({ type: "click" }, |
|
38 gDebuggee.document.querySelector("button"), |
|
39 gDebuggee); |
|
40 }); |
|
41 } |
|
42 |
|
43 function testFirstWithScope() { |
|
44 let firstWithScope = gVariables.getScopeAtIndex(0); |
|
45 is(firstWithScope.expanded, true, |
|
46 "The first 'with' scope should be expanded by default."); |
|
47 ok(firstWithScope.target.querySelector(".name").getAttribute("value").contains("[Object]"), |
|
48 "The first 'with' scope should be properly identified."); |
|
49 |
|
50 let withEnums = firstWithScope._enum.childNodes; |
|
51 let withNonEnums = firstWithScope._nonenum.childNodes; |
|
52 |
|
53 is(withEnums.length, 3, |
|
54 "The first 'with' scope should contain all the created enumerable elements."); |
|
55 is(withNonEnums.length, 1, |
|
56 "The first 'with' scope should contain all the created non-enumerable elements."); |
|
57 |
|
58 is(withEnums[0].querySelector(".name").getAttribute("value"), "this", |
|
59 "Should have the right property name for 'this'."); |
|
60 is(withEnums[0].querySelector(".value").getAttribute("value"), |
|
61 "Window \u2192 doc_with-frame.html", |
|
62 "Should have the right property value for 'this'."); |
|
63 ok(withEnums[0].querySelector(".value").className.contains("token-other"), |
|
64 "Should have the right token class for 'this'."); |
|
65 |
|
66 is(withEnums[1].querySelector(".name").getAttribute("value"), "alpha", |
|
67 "Should have the right property name for 'alpha'."); |
|
68 is(withEnums[1].querySelector(".value").getAttribute("value"), "1", |
|
69 "Should have the right property value for 'alpha'."); |
|
70 ok(withEnums[1].querySelector(".value").className.contains("token-number"), |
|
71 "Should have the right token class for 'alpha'."); |
|
72 |
|
73 is(withEnums[2].querySelector(".name").getAttribute("value"), "beta", |
|
74 "Should have the right property name for 'beta'."); |
|
75 is(withEnums[2].querySelector(".value").getAttribute("value"), "2", |
|
76 "Should have the right property value for 'beta'."); |
|
77 ok(withEnums[2].querySelector(".value").className.contains("token-number"), |
|
78 "Should have the right token class for 'beta'."); |
|
79 |
|
80 is(withNonEnums[0].querySelector(".name").getAttribute("value"), "__proto__", |
|
81 "Should have the right property name for '__proto__'."); |
|
82 is(withNonEnums[0].querySelector(".value").getAttribute("value"), "Object", |
|
83 "Should have the right property value for '__proto__'."); |
|
84 ok(withNonEnums[0].querySelector(".value").className.contains("token-other"), |
|
85 "Should have the right token class for '__proto__'."); |
|
86 } |
|
87 |
|
88 function expandSecondWithScope() { |
|
89 let deferred = promise.defer(); |
|
90 |
|
91 let secondWithScope = gVariables.getScopeAtIndex(1); |
|
92 is(secondWithScope.expanded, false, |
|
93 "The second 'with' scope should not be expanded by default."); |
|
94 |
|
95 gDebugger.once(gDebugger.EVENTS.FETCHED_VARIABLES, deferred.resolve); |
|
96 |
|
97 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
98 secondWithScope.target.querySelector(".name"), |
|
99 gDebugger); |
|
100 |
|
101 return deferred.promise; |
|
102 } |
|
103 |
|
104 function testSecondWithScope() { |
|
105 let secondWithScope = gVariables.getScopeAtIndex(1); |
|
106 is(secondWithScope.expanded, true, |
|
107 "The second 'with' scope should now be expanded."); |
|
108 ok(secondWithScope.target.querySelector(".name").getAttribute("value").contains("[Math]"), |
|
109 "The second 'with' scope should be properly identified."); |
|
110 |
|
111 let withEnums = secondWithScope._enum.childNodes; |
|
112 let withNonEnums = secondWithScope._nonenum.childNodes; |
|
113 |
|
114 is(withEnums.length, 0, |
|
115 "The second 'with' scope should contain all the created enumerable elements."); |
|
116 isnot(withNonEnums.length, 0, |
|
117 "The second 'with' scope should contain all the created non-enumerable elements."); |
|
118 |
|
119 is(secondWithScope.get("E").target.querySelector(".name").getAttribute("value"), "E", |
|
120 "Should have the right property name for 'E'."); |
|
121 is(secondWithScope.get("E").target.querySelector(".value").getAttribute("value"), "2.718281828459045", |
|
122 "Should have the right property value for 'E'."); |
|
123 ok(secondWithScope.get("E").target.querySelector(".value").className.contains("token-number"), |
|
124 "Should have the right token class for 'E'."); |
|
125 |
|
126 is(secondWithScope.get("PI").target.querySelector(".name").getAttribute("value"), "PI", |
|
127 "Should have the right property name for 'PI'."); |
|
128 is(secondWithScope.get("PI").target.querySelector(".value").getAttribute("value"), "3.141592653589793", |
|
129 "Should have the right property value for 'PI'."); |
|
130 ok(secondWithScope.get("PI").target.querySelector(".value").className.contains("token-number"), |
|
131 "Should have the right token class for 'PI'."); |
|
132 |
|
133 is(secondWithScope.get("random").target.querySelector(".name").getAttribute("value"), "random", |
|
134 "Should have the right property name for 'random'."); |
|
135 is(secondWithScope.get("random").target.querySelector(".value").getAttribute("value"), "random()", |
|
136 "Should have the right property value for 'random'."); |
|
137 ok(secondWithScope.get("random").target.querySelector(".value").className.contains("token-other"), |
|
138 "Should have the right token class for 'random'."); |
|
139 |
|
140 is(secondWithScope.get("__proto__").target.querySelector(".name").getAttribute("value"), "__proto__", |
|
141 "Should have the right property name for '__proto__'."); |
|
142 is(secondWithScope.get("__proto__").target.querySelector(".value").getAttribute("value"), "Object", |
|
143 "Should have the right property value for '__proto__'."); |
|
144 ok(secondWithScope.get("__proto__").target.querySelector(".value").className.contains("token-other"), |
|
145 "Should have the right token class for '__proto__'."); |
|
146 } |
|
147 |
|
148 function expandFunctionScope() { |
|
149 let funcScope = gVariables.getScopeAtIndex(2); |
|
150 is(funcScope.expanded, false, |
|
151 "The function scope shouldn't be expanded by default, but the " + |
|
152 "variables have been already fetched. This is how local scopes work."); |
|
153 |
|
154 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
155 funcScope.target.querySelector(".name"), |
|
156 gDebugger); |
|
157 |
|
158 return promise.resolve(null); |
|
159 } |
|
160 |
|
161 function testFunctionScope() { |
|
162 let funcScope = gVariables.getScopeAtIndex(2); |
|
163 is(funcScope.expanded, true, |
|
164 "The function scope should now be expanded."); |
|
165 ok(funcScope.target.querySelector(".name").getAttribute("value").contains("[test]"), |
|
166 "The function scope should be properly identified."); |
|
167 |
|
168 let funcEnums = funcScope._enum.childNodes; |
|
169 let funcNonEnums = funcScope._nonenum.childNodes; |
|
170 |
|
171 is(funcEnums.length, 6, |
|
172 "The function scope should contain all the created enumerable elements."); |
|
173 is(funcNonEnums.length, 0, |
|
174 "The function scope should contain all the created non-enumerable elements."); |
|
175 |
|
176 is(funcScope.get("aNumber").target.querySelector(".name").getAttribute("value"), "aNumber", |
|
177 "Should have the right property name for 'aNumber'."); |
|
178 is(funcScope.get("aNumber").target.querySelector(".value").getAttribute("value"), "10", |
|
179 "Should have the right property value for 'aNumber'."); |
|
180 ok(funcScope.get("aNumber").target.querySelector(".value").className.contains("token-number"), |
|
181 "Should have the right token class for 'aNumber'."); |
|
182 |
|
183 is(funcScope.get("a").target.querySelector(".name").getAttribute("value"), "a", |
|
184 "Should have the right property name for 'a'."); |
|
185 is(funcScope.get("a").target.querySelector(".value").getAttribute("value"), "314.1592653589793", |
|
186 "Should have the right property value for 'a'."); |
|
187 ok(funcScope.get("a").target.querySelector(".value").className.contains("token-number"), |
|
188 "Should have the right token class for 'a'."); |
|
189 |
|
190 is(funcScope.get("r").target.querySelector(".name").getAttribute("value"), "r", |
|
191 "Should have the right property name for 'r'."); |
|
192 is(funcScope.get("r").target.querySelector(".value").getAttribute("value"), "10", |
|
193 "Should have the right property value for 'r'."); |
|
194 ok(funcScope.get("r").target.querySelector(".value").className.contains("token-number"), |
|
195 "Should have the right token class for 'r'."); |
|
196 |
|
197 is(funcScope.get("foo").target.querySelector(".name").getAttribute("value"), "foo", |
|
198 "Should have the right property name for 'foo'."); |
|
199 is(funcScope.get("foo").target.querySelector(".value").getAttribute("value"), "6.283185307179586", |
|
200 "Should have the right property value for 'foo'."); |
|
201 ok(funcScope.get("foo").target.querySelector(".value").className.contains("token-number"), |
|
202 "Should have the right token class for 'foo'."); |
|
203 } |
|
204 |
|
205 registerCleanupFunction(function() { |
|
206 gTab = null; |
|
207 gDebuggee = null; |
|
208 gPanel = null; |
|
209 gDebugger = null; |
|
210 gVariables = null; |
|
211 }); |