|
1 /* ***** BEGIN LICENSE BLOCK ***** |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 * |
|
5 * Contributor(s): |
|
6 * Mihai Șucan <mihai.sucan@gmail.com> |
|
7 * Patrick Walton <pcwalton@mozilla.com> |
|
8 * |
|
9 * ***** END LICENSE BLOCK ***** */ |
|
10 |
|
11 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html"; |
|
12 |
|
13 let HUD, outputNode; |
|
14 |
|
15 function test() { |
|
16 addTab(TEST_URI); |
|
17 browser.addEventListener("load", function onLoad() { |
|
18 browser.removeEventListener("load", onLoad, true); |
|
19 openConsole(null, consoleOpened); |
|
20 }, true); |
|
21 } |
|
22 |
|
23 function consoleOpened(aHud) { |
|
24 HUD = aHud; |
|
25 |
|
26 // See bugs 574036, 586386 and 587617. |
|
27 outputNode = HUD.outputNode; |
|
28 |
|
29 HUD.jsterm.clearOutput(); |
|
30 |
|
31 let controller = top.document.commandDispatcher. |
|
32 getControllerForCommand("cmd_copy"); |
|
33 is(controller.isCommandEnabled("cmd_copy"), false, "cmd_copy is disabled"); |
|
34 |
|
35 content.console.log("Hello world! bug587617"); |
|
36 |
|
37 waitForMessages({ |
|
38 webconsole: HUD, |
|
39 messages: [{ |
|
40 text: "bug587617", |
|
41 category: CATEGORY_WEBDEV, |
|
42 severity: SEVERITY_LOG, |
|
43 }], |
|
44 }).then(([result]) => { |
|
45 let msg = [...result.matched][0]; |
|
46 HUD.ui.output.selectMessage(msg); |
|
47 |
|
48 outputNode.focus(); |
|
49 |
|
50 goUpdateCommand("cmd_copy"); |
|
51 controller = top.document.commandDispatcher.getControllerForCommand("cmd_copy"); |
|
52 is(controller.isCommandEnabled("cmd_copy"), true, "cmd_copy is enabled"); |
|
53 |
|
54 let selection = HUD.iframeWindow.getSelection() + ""; |
|
55 isnot(selection.indexOf("bug587617"), -1, |
|
56 "selection text includes 'bug587617'"); |
|
57 |
|
58 waitForClipboard((str) => { return selection.trim() == str.trim(); }, |
|
59 () => { goDoCommand("cmd_copy") }, |
|
60 testContextMenuCopy, testContextMenuCopy); |
|
61 }); |
|
62 } |
|
63 |
|
64 // Test that the context menu "Copy" (which has a different code path) works |
|
65 // properly as well. |
|
66 function testContextMenuCopy() { |
|
67 let contextMenuId = outputNode.parentNode.getAttribute("context"); |
|
68 let contextMenu = HUD.ui.document.getElementById(contextMenuId); |
|
69 ok(contextMenu, "the output node has a context menu"); |
|
70 |
|
71 let copyItem = contextMenu.querySelector("*[command='cmd_copy']"); |
|
72 ok(copyItem, "the context menu on the output node has a \"Copy\" item"); |
|
73 |
|
74 let selection = HUD.iframeWindow.getSelection() + ""; |
|
75 |
|
76 copyItem.doCommand(); |
|
77 |
|
78 waitForClipboard((str) => { return selection.trim() == str.trim(); }, |
|
79 () => { goDoCommand("cmd_copy") }, |
|
80 finishTest, finishTest); |
|
81 HUD = outputNode = null; |
|
82 } |
|
83 |