| |
1 /* Any copyright is dedicated to the Public Domain. |
| |
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
| |
3 |
| |
4 // Test that multiple messages are copied into the clipboard and that they are |
| |
5 // separated by new lines. See bug 916997. |
| |
6 |
| |
7 function test() |
| |
8 { |
| |
9 const TEST_URI = "data:text/html;charset=utf8,<p>hello world, bug 916997"; |
| |
10 let clipboardValue = ""; |
| |
11 |
| |
12 addTab(TEST_URI); |
| |
13 browser.addEventListener("load", function onLoad() { |
| |
14 browser.removeEventListener("load", onLoad, true); |
| |
15 openConsole(null, consoleOpened); |
| |
16 }, true); |
| |
17 |
| |
18 function consoleOpened(hud) |
| |
19 { |
| |
20 hud.jsterm.clearOutput(); |
| |
21 |
| |
22 let controller = top.document.commandDispatcher. |
| |
23 getControllerForCommand("cmd_copy"); |
| |
24 is(controller.isCommandEnabled("cmd_copy"), false, "cmd_copy is disabled"); |
| |
25 |
| |
26 content.console.log("Hello world! bug916997a"); |
| |
27 content.console.log("Hello world 2! bug916997b"); |
| |
28 |
| |
29 waitForMessages({ |
| |
30 webconsole: hud, |
| |
31 messages: [{ |
| |
32 text: "Hello world! bug916997a", |
| |
33 category: CATEGORY_WEBDEV, |
| |
34 severity: SEVERITY_LOG, |
| |
35 }, { |
| |
36 text: "Hello world 2! bug916997b", |
| |
37 category: CATEGORY_WEBDEV, |
| |
38 severity: SEVERITY_LOG, |
| |
39 }], |
| |
40 }).then(() => { |
| |
41 hud.ui.output.selectAllMessages(); |
| |
42 hud.outputNode.focus(); |
| |
43 |
| |
44 goUpdateCommand("cmd_copy"); |
| |
45 controller = top.document.commandDispatcher.getControllerForCommand("cmd_copy"); |
| |
46 is(controller.isCommandEnabled("cmd_copy"), true, "cmd_copy is enabled"); |
| |
47 |
| |
48 let selection = hud.iframeWindow.getSelection() + ""; |
| |
49 info("selection '" + selection + "'"); |
| |
50 waitForClipboard((str) => { |
| |
51 clipboardValue = str; |
| |
52 return str.indexOf("bug916997a") > -1 && str.indexOf("bug916997b") > -1; |
| |
53 }, |
| |
54 () => { goDoCommand("cmd_copy"); }, |
| |
55 checkClipboard.bind(null, hud), |
| |
56 () => { |
| |
57 info("last clipboard value: '" + clipboardValue + "'"); |
| |
58 finishTest(); |
| |
59 }); |
| |
60 }); |
| |
61 } |
| |
62 |
| |
63 function checkClipboard(hud) |
| |
64 { |
| |
65 info("clipboard value '" + clipboardValue + "'"); |
| |
66 let lines = clipboardValue.trim().split("\n"); |
| |
67 is(hud.outputNode.children.length, 2, "number of messages"); |
| |
68 is(lines.length, hud.outputNode.children.length, "number of lines"); |
| |
69 isnot(lines[0].indexOf("bug916997a"), -1, |
| |
70 "first message text includes 'bug916997a'"); |
| |
71 isnot(lines[1].indexOf("bug916997b"), -1, |
| |
72 "second message text includes 'bug916997b'"); |
| |
73 is(lines[0].indexOf("bug916997b"), -1, |
| |
74 "first message text does not include 'bug916997b'"); |
| |
75 finishTest(); |
| |
76 } |
| |
77 } |