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: * Mihai Șucan michael@0: * Patrick Walton michael@0: * michael@0: * ***** END LICENSE BLOCK ***** */ michael@0: michael@0: const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html"; michael@0: michael@0: let HUD, outputNode; michael@0: michael@0: function test() { michael@0: addTab(TEST_URI); michael@0: browser.addEventListener("load", function onLoad() { michael@0: browser.removeEventListener("load", onLoad, true); michael@0: openConsole(null, consoleOpened); michael@0: }, true); michael@0: } michael@0: michael@0: function consoleOpened(aHud) { michael@0: HUD = aHud; michael@0: michael@0: // See bugs 574036, 586386 and 587617. michael@0: outputNode = HUD.outputNode; michael@0: michael@0: HUD.jsterm.clearOutput(); michael@0: michael@0: let controller = top.document.commandDispatcher. michael@0: getControllerForCommand("cmd_copy"); michael@0: is(controller.isCommandEnabled("cmd_copy"), false, "cmd_copy is disabled"); michael@0: michael@0: content.console.log("Hello world! bug587617"); michael@0: michael@0: waitForMessages({ michael@0: webconsole: HUD, michael@0: messages: [{ michael@0: text: "bug587617", michael@0: category: CATEGORY_WEBDEV, michael@0: severity: SEVERITY_LOG, michael@0: }], michael@0: }).then(([result]) => { michael@0: let msg = [...result.matched][0]; michael@0: HUD.ui.output.selectMessage(msg); michael@0: michael@0: outputNode.focus(); michael@0: michael@0: goUpdateCommand("cmd_copy"); michael@0: controller = top.document.commandDispatcher.getControllerForCommand("cmd_copy"); michael@0: is(controller.isCommandEnabled("cmd_copy"), true, "cmd_copy is enabled"); michael@0: michael@0: let selection = HUD.iframeWindow.getSelection() + ""; michael@0: isnot(selection.indexOf("bug587617"), -1, michael@0: "selection text includes 'bug587617'"); michael@0: michael@0: waitForClipboard((str) => { return selection.trim() == str.trim(); }, michael@0: () => { goDoCommand("cmd_copy") }, michael@0: testContextMenuCopy, testContextMenuCopy); michael@0: }); michael@0: } michael@0: michael@0: // Test that the context menu "Copy" (which has a different code path) works michael@0: // properly as well. michael@0: function testContextMenuCopy() { michael@0: let contextMenuId = outputNode.parentNode.getAttribute("context"); michael@0: let contextMenu = HUD.ui.document.getElementById(contextMenuId); michael@0: ok(contextMenu, "the output node has a context menu"); michael@0: michael@0: let copyItem = contextMenu.querySelector("*[command='cmd_copy']"); michael@0: ok(copyItem, "the context menu on the output node has a \"Copy\" item"); michael@0: michael@0: let selection = HUD.iframeWindow.getSelection() + ""; michael@0: michael@0: copyItem.doCommand(); michael@0: michael@0: waitForClipboard((str) => { return selection.trim() == str.trim(); }, michael@0: () => { goDoCommand("cmd_copy") }, michael@0: finishTest, finishTest); michael@0: HUD = outputNode = null; michael@0: } michael@0: