|
1 /* |
|
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 */ |
|
8 |
|
9 const TEST_URI = "data:text/html;charset=utf-8,Web Console test for bug 613280"; |
|
10 |
|
11 function test() { |
|
12 addTab(TEST_URI); |
|
13 browser.addEventListener("load", function onLoad() { |
|
14 browser.removeEventListener("load", onLoad, true); |
|
15 openConsole(null, function(HUD) { |
|
16 content.console.log("foobarBazBug613280"); |
|
17 waitForMessages({ |
|
18 webconsole: HUD, |
|
19 messages: [{ |
|
20 text: "foobarBazBug613280", |
|
21 category: CATEGORY_WEBDEV, |
|
22 severity: SEVERITY_LOG, |
|
23 }], |
|
24 }).then(performTest.bind(null, HUD)); |
|
25 }); |
|
26 }, true); |
|
27 } |
|
28 |
|
29 function performTest(HUD, [result]) { |
|
30 let msg = [...result.matched][0]; |
|
31 let input = HUD.jsterm.inputNode; |
|
32 let selection = getSelection(); |
|
33 let contentSelection = content.getSelection(); |
|
34 |
|
35 let clipboard_setup = function() { |
|
36 goDoCommand("cmd_copy"); |
|
37 }; |
|
38 |
|
39 let clipboard_copy_done = function() { |
|
40 finishTest(); |
|
41 }; |
|
42 |
|
43 // Check if we first need to clear any existing selections. |
|
44 if (selection.rangeCount > 0 || contentSelection.rangeCount > 0 || |
|
45 input.selectionStart != input.selectionEnd) { |
|
46 if (input.selectionStart != input.selectionEnd) { |
|
47 input.selectionStart = input.selectionEnd = 0; |
|
48 } |
|
49 |
|
50 if (selection.rangeCount > 0) { |
|
51 selection.removeAllRanges(); |
|
52 } |
|
53 |
|
54 if (contentSelection.rangeCount > 0) { |
|
55 contentSelection.removeAllRanges(); |
|
56 } |
|
57 |
|
58 goUpdateCommand("cmd_copy"); |
|
59 } |
|
60 |
|
61 let controller = top.document.commandDispatcher. |
|
62 getControllerForCommand("cmd_copy"); |
|
63 is(controller.isCommandEnabled("cmd_copy"), false, "cmd_copy is disabled"); |
|
64 |
|
65 HUD.ui.output.selectMessage(msg); |
|
66 HUD.outputNode.focus(); |
|
67 |
|
68 goUpdateCommand("cmd_copy"); |
|
69 |
|
70 controller = top.document.commandDispatcher. |
|
71 getControllerForCommand("cmd_copy"); |
|
72 is(controller.isCommandEnabled("cmd_copy"), true, "cmd_copy is enabled"); |
|
73 |
|
74 let selectionText = HUD.iframeWindow.getSelection() + ""; |
|
75 isnot(selectionText.indexOf("foobarBazBug613280"), -1, |
|
76 "selection text includes 'foobarBazBug613280'"); |
|
77 |
|
78 waitForClipboard((str) => { return str.trim() == selectionText.trim(); }, |
|
79 clipboard_setup, clipboard_copy_done, clipboard_copy_done); |
|
80 } |