|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 */ |
|
5 |
|
6 function test() { |
|
7 info("Test various cases where the escape key should hide the split console."); |
|
8 |
|
9 let toolbox; |
|
10 let hud; |
|
11 let jsterm; |
|
12 let hudMessages; |
|
13 let variablesView; |
|
14 |
|
15 Task.spawn(runner).then(finish); |
|
16 |
|
17 function* runner() { |
|
18 let {tab} = yield loadTab("data:text/html;charset=utf-8,<p>Web Console test for splitting"); |
|
19 let target = TargetFactory.forTab(tab); |
|
20 toolbox = yield gDevTools.showToolbox(target, "inspector"); |
|
21 |
|
22 yield testCreateSplitConsoleAfterEscape(); |
|
23 |
|
24 yield showAutoCompletePopoup(); |
|
25 |
|
26 yield testHideAutoCompletePopupAfterEscape(); |
|
27 |
|
28 yield executeJS(); |
|
29 yield clickMessageAndShowVariablesView(); |
|
30 jsterm.inputNode.focus(); |
|
31 |
|
32 yield testHideVariablesViewAfterEscape(); |
|
33 |
|
34 yield clickMessageAndShowVariablesView(); |
|
35 yield startPropertyEditor(); |
|
36 |
|
37 yield testCancelPropertyEditorAfterEscape(); |
|
38 yield testHideVariablesViewAfterEscape(); |
|
39 yield testHideSplitConsoleAfterEscape(); |
|
40 } |
|
41 |
|
42 function testCreateSplitConsoleAfterEscape() { |
|
43 let result = toolbox.once("webconsole-ready", () => { |
|
44 hud = toolbox.getPanel("webconsole").hud; |
|
45 jsterm = hud.jsterm; |
|
46 ok(toolbox.splitConsole, "Split console is created."); |
|
47 }); |
|
48 |
|
49 let contentWindow = toolbox.frame.contentWindow; |
|
50 contentWindow.focus(); |
|
51 EventUtils.sendKey("ESCAPE", contentWindow); |
|
52 |
|
53 return result; |
|
54 } |
|
55 |
|
56 function testShowSplitConsoleAfterEscape() { |
|
57 let result = toolbox.once("split-console", () => { |
|
58 ok(toolbox.splitConsole, "Split console is shown."); |
|
59 }); |
|
60 EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow); |
|
61 |
|
62 return result; |
|
63 } |
|
64 |
|
65 function testHideSplitConsoleAfterEscape() { |
|
66 let result = toolbox.once("split-console", () => { |
|
67 ok(!toolbox.splitConsole, "Split console is hidden."); |
|
68 }); |
|
69 EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow); |
|
70 |
|
71 return result; |
|
72 } |
|
73 |
|
74 function testHideVariablesViewAfterEscape() { |
|
75 let result = jsterm.once("sidebar-closed", () => { |
|
76 ok(!hud.ui.jsterm.sidebar, |
|
77 "Variables view is hidden."); |
|
78 ok(toolbox.splitConsole, |
|
79 "Split console is open after hiding the variables view."); |
|
80 }); |
|
81 EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow); |
|
82 |
|
83 return result; |
|
84 } |
|
85 |
|
86 function testHideAutoCompletePopupAfterEscape() { |
|
87 let deferred = promise.defer(); |
|
88 let popup = jsterm.autocompletePopup; |
|
89 |
|
90 popup._panel.addEventListener("popuphidden", function popupHidden() { |
|
91 popup._panel.removeEventListener("popuphidden", popupHidden, false); |
|
92 ok(!popup.isOpen, |
|
93 "Auto complete popup is hidden."); |
|
94 ok(toolbox.splitConsole, |
|
95 "Split console is open after hiding the autocomplete popup."); |
|
96 |
|
97 deferred.resolve(); |
|
98 }, false); |
|
99 |
|
100 EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow); |
|
101 |
|
102 return deferred.promise; |
|
103 } |
|
104 |
|
105 function testCancelPropertyEditorAfterEscape() { |
|
106 EventUtils.sendKey("ESCAPE", variablesView.window); |
|
107 ok(hud.ui.jsterm.sidebar, |
|
108 "Variables view is open after canceling property editor."); |
|
109 ok(toolbox.splitConsole, |
|
110 "Split console is open after editing."); |
|
111 } |
|
112 |
|
113 function executeJS() { |
|
114 jsterm.execute("var foo = { bar: \"baz\" }; foo;"); |
|
115 hudMessages = yield waitForMessages({ |
|
116 webconsole: hud, |
|
117 messages: [{ |
|
118 text: "Object { bar: \"baz\" }", |
|
119 category: CATEGORY_OUTPUT, |
|
120 objects: true |
|
121 }], |
|
122 }); |
|
123 } |
|
124 |
|
125 function clickMessageAndShowVariablesView() { |
|
126 let result = jsterm.once("variablesview-fetched", (event, vview) => { |
|
127 variablesView = vview; |
|
128 }); |
|
129 |
|
130 let clickable = hudMessages[0].clickableElements[0]; |
|
131 EventUtils.synthesizeMouse(clickable, 2, 2, {}, hud.iframeWindow); |
|
132 |
|
133 return result; |
|
134 } |
|
135 |
|
136 function startPropertyEditor() { |
|
137 let results = yield findVariableViewProperties(variablesView, [ |
|
138 {name: "bar", value: "baz"} |
|
139 ], {webconsole: hud}); |
|
140 results[0].matchedProp.focus(); |
|
141 EventUtils.synthesizeKey("VK_RETURN", variablesView.window); |
|
142 } |
|
143 |
|
144 function showAutoCompletePopoup() { |
|
145 let deferred = promise.defer(); |
|
146 let popupPanel = jsterm.autocompletePopup._panel; |
|
147 |
|
148 popupPanel.addEventListener("popupshown", function popupShown() { |
|
149 popupPanel.removeEventListener("popupshown", popupShown, false); |
|
150 deferred.resolve(); |
|
151 }, false); |
|
152 |
|
153 jsterm.inputNode.focus(); |
|
154 jsterm.setInputValue("document.location."); |
|
155 EventUtils.sendKey("TAB", hud.iframeWindow); |
|
156 |
|
157 return deferred.promise; |
|
158 } |
|
159 |
|
160 function finish() { |
|
161 toolbox.destroy().then(() => { |
|
162 toolbox = null; |
|
163 hud = null; |
|
164 jsterm = null; |
|
165 hudMessages = null; |
|
166 variablesView = null; |
|
167 |
|
168 finishTest(); |
|
169 }); |
|
170 } |
|
171 } |