1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_bug_613280_jsterm_copy.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,80 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.7 + * 1.8 + * Contributor(s): 1.9 + * Mihai Șucan <mihai.sucan@gmail.com> 1.10 + */ 1.11 + 1.12 +const TEST_URI = "data:text/html;charset=utf-8,Web Console test for bug 613280"; 1.13 + 1.14 +function test() { 1.15 + addTab(TEST_URI); 1.16 + browser.addEventListener("load", function onLoad() { 1.17 + browser.removeEventListener("load", onLoad, true); 1.18 + openConsole(null, function(HUD) { 1.19 + content.console.log("foobarBazBug613280"); 1.20 + waitForMessages({ 1.21 + webconsole: HUD, 1.22 + messages: [{ 1.23 + text: "foobarBazBug613280", 1.24 + category: CATEGORY_WEBDEV, 1.25 + severity: SEVERITY_LOG, 1.26 + }], 1.27 + }).then(performTest.bind(null, HUD)); 1.28 + }); 1.29 + }, true); 1.30 +} 1.31 + 1.32 +function performTest(HUD, [result]) { 1.33 + let msg = [...result.matched][0]; 1.34 + let input = HUD.jsterm.inputNode; 1.35 + let selection = getSelection(); 1.36 + let contentSelection = content.getSelection(); 1.37 + 1.38 + let clipboard_setup = function() { 1.39 + goDoCommand("cmd_copy"); 1.40 + }; 1.41 + 1.42 + let clipboard_copy_done = function() { 1.43 + finishTest(); 1.44 + }; 1.45 + 1.46 + // Check if we first need to clear any existing selections. 1.47 + if (selection.rangeCount > 0 || contentSelection.rangeCount > 0 || 1.48 + input.selectionStart != input.selectionEnd) { 1.49 + if (input.selectionStart != input.selectionEnd) { 1.50 + input.selectionStart = input.selectionEnd = 0; 1.51 + } 1.52 + 1.53 + if (selection.rangeCount > 0) { 1.54 + selection.removeAllRanges(); 1.55 + } 1.56 + 1.57 + if (contentSelection.rangeCount > 0) { 1.58 + contentSelection.removeAllRanges(); 1.59 + } 1.60 + 1.61 + goUpdateCommand("cmd_copy"); 1.62 + } 1.63 + 1.64 + let controller = top.document.commandDispatcher. 1.65 + getControllerForCommand("cmd_copy"); 1.66 + is(controller.isCommandEnabled("cmd_copy"), false, "cmd_copy is disabled"); 1.67 + 1.68 + HUD.ui.output.selectMessage(msg); 1.69 + HUD.outputNode.focus(); 1.70 + 1.71 + goUpdateCommand("cmd_copy"); 1.72 + 1.73 + controller = top.document.commandDispatcher. 1.74 + getControllerForCommand("cmd_copy"); 1.75 + is(controller.isCommandEnabled("cmd_copy"), true, "cmd_copy is enabled"); 1.76 + 1.77 + let selectionText = HUD.iframeWindow.getSelection() + ""; 1.78 + isnot(selectionText.indexOf("foobarBazBug613280"), -1, 1.79 + "selection text includes 'foobarBazBug613280'"); 1.80 + 1.81 + waitForClipboard((str) => { return str.trim() == selectionText.trim(); }, 1.82 + clipboard_setup, clipboard_copy_done, clipboard_copy_done); 1.83 +}