browser/devtools/webconsole/test/browser_webconsole_split_escape_key.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial