Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /*
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
6 function test() {
7 info("Test various cases where the escape key should hide the split console.");
9 let toolbox;
10 let hud;
11 let jsterm;
12 let hudMessages;
13 let variablesView;
15 Task.spawn(runner).then(finish);
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");
22 yield testCreateSplitConsoleAfterEscape();
24 yield showAutoCompletePopoup();
26 yield testHideAutoCompletePopupAfterEscape();
28 yield executeJS();
29 yield clickMessageAndShowVariablesView();
30 jsterm.inputNode.focus();
32 yield testHideVariablesViewAfterEscape();
34 yield clickMessageAndShowVariablesView();
35 yield startPropertyEditor();
37 yield testCancelPropertyEditorAfterEscape();
38 yield testHideVariablesViewAfterEscape();
39 yield testHideSplitConsoleAfterEscape();
40 }
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 });
49 let contentWindow = toolbox.frame.contentWindow;
50 contentWindow.focus();
51 EventUtils.sendKey("ESCAPE", contentWindow);
53 return result;
54 }
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);
62 return result;
63 }
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);
71 return result;
72 }
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);
83 return result;
84 }
86 function testHideAutoCompletePopupAfterEscape() {
87 let deferred = promise.defer();
88 let popup = jsterm.autocompletePopup;
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.");
97 deferred.resolve();
98 }, false);
100 EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow);
102 return deferred.promise;
103 }
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 }
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 }
125 function clickMessageAndShowVariablesView() {
126 let result = jsterm.once("variablesview-fetched", (event, vview) => {
127 variablesView = vview;
128 });
130 let clickable = hudMessages[0].clickableElements[0];
131 EventUtils.synthesizeMouse(clickable, 2, 2, {}, hud.iframeWindow);
133 return result;
134 }
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 }
144 function showAutoCompletePopoup() {
145 let deferred = promise.defer();
146 let popupPanel = jsterm.autocompletePopup._panel;
148 popupPanel.addEventListener("popupshown", function popupShown() {
149 popupPanel.removeEventListener("popupshown", popupShown, false);
150 deferred.resolve();
151 }, false);
153 jsterm.inputNode.focus();
154 jsterm.setInputValue("document.location.");
155 EventUtils.sendKey("TAB", hud.iframeWindow);
157 return deferred.promise;
158 }
160 function finish() {
161 toolbox.destroy().then(() => {
162 toolbox = null;
163 hud = null;
164 jsterm = null;
165 hudMessages = null;
166 variablesView = null;
168 finishTest();
169 });
170 }
171 }