michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* ***** BEGIN LICENSE BLOCK ***** michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: * michael@0: * Contributor(s): michael@0: * Patrick Walton michael@0: * michael@0: * ***** END LICENSE BLOCK ***** */ michael@0: michael@0: const TEST_URI = "http://example.com/"; michael@0: michael@0: function test() { michael@0: let hud; michael@0: michael@0: addTab(TEST_URI); michael@0: browser.addEventListener("load", function onLoad() { michael@0: browser.removeEventListener("load", onLoad, true); michael@0: openConsole(null, testSelectionWhenMovingBetweenBoxes); michael@0: }, true); michael@0: michael@0: function testSelectionWhenMovingBetweenBoxes(aHud) { michael@0: hud = aHud; michael@0: let jsterm = hud.jsterm; michael@0: michael@0: // Fill the console with some output. michael@0: jsterm.clearOutput(); michael@0: jsterm.execute("1 + 2"); michael@0: jsterm.execute("3 + 4"); michael@0: jsterm.execute("5 + 6"); michael@0: michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "3", michael@0: category: CATEGORY_OUTPUT, michael@0: }, michael@0: { michael@0: text: "7", michael@0: category: CATEGORY_OUTPUT, michael@0: }, michael@0: { michael@0: text: "11", michael@0: category: CATEGORY_OUTPUT, michael@0: }], michael@0: }).then(performTestsAfterOutput); michael@0: } michael@0: michael@0: function performTestsAfterOutput() { michael@0: let outputNode = hud.outputNode; michael@0: michael@0: ok(outputNode.childNodes.length >= 3, "the output node has children after " + michael@0: "executing some JavaScript"); michael@0: michael@0: // Test that the global Firefox "Select All" functionality (e.g. Edit > michael@0: // Select All) works properly in the Web Console. michael@0: let commandController = hud.ui._commandController; michael@0: ok(commandController != null, "the window has a command controller object"); michael@0: michael@0: commandController.selectAll(); michael@0: michael@0: let selectedCount = hud.ui.output.getSelectedMessages().length; michael@0: is(selectedCount, outputNode.childNodes.length, michael@0: "all console messages are selected after performing a regular browser " + michael@0: "select-all operation"); michael@0: michael@0: hud.iframeWindow.getSelection().removeAllRanges(); michael@0: michael@0: // Test the context menu "Select All" (which has a different code path) works michael@0: // properly as well. michael@0: let contextMenuId = outputNode.parentNode.getAttribute("context"); michael@0: let contextMenu = hud.ui.document.getElementById(contextMenuId); michael@0: ok(contextMenu != null, "the output node has a context menu"); michael@0: michael@0: let selectAllItem = contextMenu.querySelector("*[command='cmd_selectAll']"); michael@0: ok(selectAllItem != null, michael@0: "the context menu on the output node has a \"Select All\" item"); michael@0: michael@0: outputNode.focus(); michael@0: michael@0: selectAllItem.doCommand(); michael@0: michael@0: let selectedCount = hud.ui.output.getSelectedMessages().length; michael@0: is(selectedCount, outputNode.childNodes.length, michael@0: "all console messages are selected after performing a select-all " + michael@0: "operation from the context menu"); michael@0: michael@0: hud.iframeWindow.getSelection().removeAllRanges(); michael@0: michael@0: finishTest(); michael@0: } michael@0: }