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: * Contributor(s): michael@0: * Mihai Șucan michael@0: */ michael@0: michael@0: const TEST_URI = "data:text/html;charset=utf-8,Web Console test for bug 613280"; 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, function(HUD) { michael@0: content.console.log("foobarBazBug613280"); michael@0: waitForMessages({ michael@0: webconsole: HUD, michael@0: messages: [{ michael@0: text: "foobarBazBug613280", michael@0: category: CATEGORY_WEBDEV, michael@0: severity: SEVERITY_LOG, michael@0: }], michael@0: }).then(performTest.bind(null, HUD)); michael@0: }); michael@0: }, true); michael@0: } michael@0: michael@0: function performTest(HUD, [result]) { michael@0: let msg = [...result.matched][0]; michael@0: let input = HUD.jsterm.inputNode; michael@0: let selection = getSelection(); michael@0: let contentSelection = content.getSelection(); michael@0: michael@0: let clipboard_setup = function() { michael@0: goDoCommand("cmd_copy"); michael@0: }; michael@0: michael@0: let clipboard_copy_done = function() { michael@0: finishTest(); michael@0: }; michael@0: michael@0: // Check if we first need to clear any existing selections. michael@0: if (selection.rangeCount > 0 || contentSelection.rangeCount > 0 || michael@0: input.selectionStart != input.selectionEnd) { michael@0: if (input.selectionStart != input.selectionEnd) { michael@0: input.selectionStart = input.selectionEnd = 0; michael@0: } michael@0: michael@0: if (selection.rangeCount > 0) { michael@0: selection.removeAllRanges(); michael@0: } michael@0: michael@0: if (contentSelection.rangeCount > 0) { michael@0: contentSelection.removeAllRanges(); michael@0: } michael@0: michael@0: goUpdateCommand("cmd_copy"); michael@0: } 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: HUD.ui.output.selectMessage(msg); michael@0: HUD.outputNode.focus(); michael@0: michael@0: goUpdateCommand("cmd_copy"); michael@0: michael@0: controller = top.document.commandDispatcher. michael@0: getControllerForCommand("cmd_copy"); michael@0: is(controller.isCommandEnabled("cmd_copy"), true, "cmd_copy is enabled"); michael@0: michael@0: let selectionText = HUD.iframeWindow.getSelection() + ""; michael@0: isnot(selectionText.indexOf("foobarBazBug613280"), -1, michael@0: "selection text includes 'foobarBazBug613280'"); michael@0: michael@0: waitForClipboard((str) => { return str.trim() == selectionText.trim(); }, michael@0: clipboard_setup, clipboard_copy_done, clipboard_copy_done); michael@0: }