michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: function test() { michael@0: info("Test various cases where the escape key should hide the split console."); michael@0: michael@0: let toolbox; michael@0: let hud; michael@0: let jsterm; michael@0: let hudMessages; michael@0: let variablesView; michael@0: michael@0: Task.spawn(runner).then(finish); michael@0: michael@0: function* runner() { michael@0: let {tab} = yield loadTab("data:text/html;charset=utf-8,
Web Console test for splitting"); michael@0: let target = TargetFactory.forTab(tab); michael@0: toolbox = yield gDevTools.showToolbox(target, "inspector"); michael@0: michael@0: yield testCreateSplitConsoleAfterEscape(); michael@0: michael@0: yield showAutoCompletePopoup(); michael@0: michael@0: yield testHideAutoCompletePopupAfterEscape(); michael@0: michael@0: yield executeJS(); michael@0: yield clickMessageAndShowVariablesView(); michael@0: jsterm.inputNode.focus(); michael@0: michael@0: yield testHideVariablesViewAfterEscape(); michael@0: michael@0: yield clickMessageAndShowVariablesView(); michael@0: yield startPropertyEditor(); michael@0: michael@0: yield testCancelPropertyEditorAfterEscape(); michael@0: yield testHideVariablesViewAfterEscape(); michael@0: yield testHideSplitConsoleAfterEscape(); michael@0: } michael@0: michael@0: function testCreateSplitConsoleAfterEscape() { michael@0: let result = toolbox.once("webconsole-ready", () => { michael@0: hud = toolbox.getPanel("webconsole").hud; michael@0: jsterm = hud.jsterm; michael@0: ok(toolbox.splitConsole, "Split console is created."); michael@0: }); michael@0: michael@0: let contentWindow = toolbox.frame.contentWindow; michael@0: contentWindow.focus(); michael@0: EventUtils.sendKey("ESCAPE", contentWindow); michael@0: michael@0: return result; michael@0: } michael@0: michael@0: function testShowSplitConsoleAfterEscape() { michael@0: let result = toolbox.once("split-console", () => { michael@0: ok(toolbox.splitConsole, "Split console is shown."); michael@0: }); michael@0: EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow); michael@0: michael@0: return result; michael@0: } michael@0: michael@0: function testHideSplitConsoleAfterEscape() { michael@0: let result = toolbox.once("split-console", () => { michael@0: ok(!toolbox.splitConsole, "Split console is hidden."); michael@0: }); michael@0: EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow); michael@0: michael@0: return result; michael@0: } michael@0: michael@0: function testHideVariablesViewAfterEscape() { michael@0: let result = jsterm.once("sidebar-closed", () => { michael@0: ok(!hud.ui.jsterm.sidebar, michael@0: "Variables view is hidden."); michael@0: ok(toolbox.splitConsole, michael@0: "Split console is open after hiding the variables view."); michael@0: }); michael@0: EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow); michael@0: michael@0: return result; michael@0: } michael@0: michael@0: function testHideAutoCompletePopupAfterEscape() { michael@0: let deferred = promise.defer(); michael@0: let popup = jsterm.autocompletePopup; michael@0: michael@0: popup._panel.addEventListener("popuphidden", function popupHidden() { michael@0: popup._panel.removeEventListener("popuphidden", popupHidden, false); michael@0: ok(!popup.isOpen, michael@0: "Auto complete popup is hidden."); michael@0: ok(toolbox.splitConsole, michael@0: "Split console is open after hiding the autocomplete popup."); michael@0: michael@0: deferred.resolve(); michael@0: }, false); michael@0: michael@0: EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testCancelPropertyEditorAfterEscape() { michael@0: EventUtils.sendKey("ESCAPE", variablesView.window); michael@0: ok(hud.ui.jsterm.sidebar, michael@0: "Variables view is open after canceling property editor."); michael@0: ok(toolbox.splitConsole, michael@0: "Split console is open after editing."); michael@0: } michael@0: michael@0: function executeJS() { michael@0: jsterm.execute("var foo = { bar: \"baz\" }; foo;"); michael@0: hudMessages = yield waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "Object { bar: \"baz\" }", michael@0: category: CATEGORY_OUTPUT, michael@0: objects: true michael@0: }], michael@0: }); michael@0: } michael@0: michael@0: function clickMessageAndShowVariablesView() { michael@0: let result = jsterm.once("variablesview-fetched", (event, vview) => { michael@0: variablesView = vview; michael@0: }); michael@0: michael@0: let clickable = hudMessages[0].clickableElements[0]; michael@0: EventUtils.synthesizeMouse(clickable, 2, 2, {}, hud.iframeWindow); michael@0: michael@0: return result; michael@0: } michael@0: michael@0: function startPropertyEditor() { michael@0: let results = yield findVariableViewProperties(variablesView, [ michael@0: {name: "bar", value: "baz"} michael@0: ], {webconsole: hud}); michael@0: results[0].matchedProp.focus(); michael@0: EventUtils.synthesizeKey("VK_RETURN", variablesView.window); michael@0: } michael@0: michael@0: function showAutoCompletePopoup() { michael@0: let deferred = promise.defer(); michael@0: let popupPanel = jsterm.autocompletePopup._panel; michael@0: michael@0: popupPanel.addEventListener("popupshown", function popupShown() { michael@0: popupPanel.removeEventListener("popupshown", popupShown, false); michael@0: deferred.resolve(); michael@0: }, false); michael@0: michael@0: jsterm.inputNode.focus(); michael@0: jsterm.setInputValue("document.location."); michael@0: EventUtils.sendKey("TAB", hud.iframeWindow); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function finish() { michael@0: toolbox.destroy().then(() => { michael@0: toolbox = null; michael@0: hud = null; michael@0: jsterm = null; michael@0: hudMessages = null; michael@0: variablesView = null; michael@0: michael@0: finishTest(); michael@0: }); michael@0: } michael@0: }