|
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 displays the right variables and |
|
6 * properties in the global scope when debugger is paused. |
|
7 */ |
|
8 |
|
9 const TAB_URL = EXAMPLE_URL + "doc_frame-parameters.html"; |
|
10 |
|
11 let gTab, gDebuggee, gPanel, gDebugger; |
|
12 let gVariables; |
|
13 |
|
14 function test() { |
|
15 // Debug test slaves are a bit slow at this test. |
|
16 requestLongerTimeout(2); |
|
17 |
|
18 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
19 gTab = aTab; |
|
20 gDebuggee = aDebuggee; |
|
21 gPanel = aPanel; |
|
22 gDebugger = gPanel.panelWin; |
|
23 gVariables = gDebugger.DebuggerView.Variables; |
|
24 |
|
25 waitForSourceAndCaretAndScopes(gPanel, ".html", 24) |
|
26 .then(expandGlobalScope) |
|
27 .then(testGlobalScope) |
|
28 .then(expandWindowVariable) |
|
29 .then(testWindowVariable) |
|
30 .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) |
|
31 .then(null, aError => { |
|
32 ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
|
33 }); |
|
34 |
|
35 EventUtils.sendMouseEvent({ type: "click" }, |
|
36 gDebuggee.document.querySelector("button"), |
|
37 gDebuggee); |
|
38 }); |
|
39 } |
|
40 |
|
41 function expandGlobalScope() { |
|
42 let deferred = promise.defer(); |
|
43 |
|
44 let globalScope = gVariables.getScopeAtIndex(1); |
|
45 is(globalScope.expanded, false, |
|
46 "The global scope should not be expanded by default."); |
|
47 |
|
48 gDebugger.once(gDebugger.EVENTS.FETCHED_VARIABLES, deferred.resolve); |
|
49 |
|
50 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
51 globalScope.target.querySelector(".name"), |
|
52 gDebugger); |
|
53 |
|
54 return deferred.promise; |
|
55 } |
|
56 |
|
57 function testGlobalScope() { |
|
58 let globalScope = gVariables.getScopeAtIndex(1); |
|
59 is(globalScope.expanded, true, |
|
60 "The global scope should now be expanded."); |
|
61 |
|
62 is(globalScope.get("InstallTrigger").target.querySelector(".name").getAttribute("value"), "InstallTrigger", |
|
63 "Should have the right property name for 'InstallTrigger'."); |
|
64 is(globalScope.get("InstallTrigger").target.querySelector(".value").getAttribute("value"), "InstallTriggerImpl", |
|
65 "Should have the right property value for 'InstallTrigger'."); |
|
66 |
|
67 is(globalScope.get("SpecialPowers").target.querySelector(".name").getAttribute("value"), "SpecialPowers", |
|
68 "Should have the right property name for 'SpecialPowers'."); |
|
69 is(globalScope.get("SpecialPowers").target.querySelector(".value").getAttribute("value"), "Object", |
|
70 "Should have the right property value for 'SpecialPowers'."); |
|
71 |
|
72 is(globalScope.get("window").target.querySelector(".name").getAttribute("value"), "window", |
|
73 "Should have the right property name for 'window'."); |
|
74 is(globalScope.get("window").target.querySelector(".value").getAttribute("value"), |
|
75 "Window \u2192 doc_frame-parameters.html", |
|
76 "Should have the right property value for 'window'."); |
|
77 |
|
78 is(globalScope.get("document").target.querySelector(".name").getAttribute("value"), "document", |
|
79 "Should have the right property name for 'document'."); |
|
80 is(globalScope.get("document").target.querySelector(".value").getAttribute("value"), |
|
81 "HTMLDocument \u2192 doc_frame-parameters.html", |
|
82 "Should have the right property value for 'document'."); |
|
83 |
|
84 is(globalScope.get("undefined").target.querySelector(".name").getAttribute("value"), "undefined", |
|
85 "Should have the right property name for 'undefined'."); |
|
86 is(globalScope.get("undefined").target.querySelector(".value").getAttribute("value"), "undefined", |
|
87 "Should have the right property value for 'undefined'."); |
|
88 |
|
89 is(globalScope.get("undefined").target.querySelector(".enum").childNodes.length, 0, |
|
90 "Should have no child enumerable properties for 'undefined'."); |
|
91 is(globalScope.get("undefined").target.querySelector(".nonenum").childNodes.length, 0, |
|
92 "Should have no child non-enumerable properties for 'undefined'."); |
|
93 } |
|
94 |
|
95 function expandWindowVariable() { |
|
96 let deferred = promise.defer(); |
|
97 |
|
98 let windowVar = gVariables.getScopeAtIndex(1).get("window"); |
|
99 is(windowVar.expanded, false, |
|
100 "The window variable should not be expanded by default."); |
|
101 |
|
102 gDebugger.once(gDebugger.EVENTS.FETCHED_PROPERTIES, deferred.resolve); |
|
103 |
|
104 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
105 windowVar.target.querySelector(".name"), |
|
106 gDebugger); |
|
107 |
|
108 return deferred.promise; |
|
109 } |
|
110 |
|
111 function testWindowVariable() { |
|
112 let windowVar = gVariables.getScopeAtIndex(1).get("window"); |
|
113 is(windowVar.expanded, true, |
|
114 "The window variable should now be expanded."); |
|
115 |
|
116 is(windowVar.get("InstallTrigger").target.querySelector(".name").getAttribute("value"), "InstallTrigger", |
|
117 "Should have the right property name for 'InstallTrigger'."); |
|
118 is(windowVar.get("InstallTrigger").target.querySelector(".value").getAttribute("value"), "InstallTriggerImpl", |
|
119 "Should have the right property value for 'InstallTrigger'."); |
|
120 |
|
121 is(windowVar.get("SpecialPowers").target.querySelector(".name").getAttribute("value"), "SpecialPowers", |
|
122 "Should have the right property name for 'SpecialPowers'."); |
|
123 is(windowVar.get("SpecialPowers").target.querySelector(".value").getAttribute("value"), "Object", |
|
124 "Should have the right property value for 'SpecialPowers'."); |
|
125 |
|
126 is(windowVar.get("window").target.querySelector(".name").getAttribute("value"), "window", |
|
127 "Should have the right property name for 'window'."); |
|
128 is(windowVar.get("window").target.querySelector(".value").getAttribute("value"), |
|
129 "Window \u2192 doc_frame-parameters.html", |
|
130 "Should have the right property value for 'window'."); |
|
131 |
|
132 is(windowVar.get("document").target.querySelector(".name").getAttribute("value"), "document", |
|
133 "Should have the right property name for 'document'."); |
|
134 is(windowVar.get("document").target.querySelector(".value").getAttribute("value"), |
|
135 "HTMLDocument \u2192 doc_frame-parameters.html", |
|
136 "Should have the right property value for 'document'."); |
|
137 |
|
138 is(windowVar.get("undefined").target.querySelector(".name").getAttribute("value"), "undefined", |
|
139 "Should have the right property name for 'undefined'."); |
|
140 is(windowVar.get("undefined").target.querySelector(".value").getAttribute("value"), "undefined", |
|
141 "Should have the right property value for 'undefined'."); |
|
142 |
|
143 is(windowVar.get("undefined").target.querySelector(".enum").childNodes.length, 0, |
|
144 "Should have no child enumerable properties for 'undefined'."); |
|
145 is(windowVar.get("undefined").target.querySelector(".nonenum").childNodes.length, 0, |
|
146 "Should have no child non-enumerable properties for 'undefined'."); |
|
147 } |
|
148 |
|
149 registerCleanupFunction(function() { |
|
150 gTab = null; |
|
151 gDebuggee = null; |
|
152 gPanel = null; |
|
153 gDebugger = null; |
|
154 gVariables = null; |
|
155 }); |