browser/devtools/webconsole/test/browser_webconsole_bug_586388_select_all.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:fd08760632fb
1 /* vim:set ts=2 sw=2 sts=2 et: */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Any copyright is dedicated to the Public Domain.
4 * http://creativecommons.org/publicdomain/zero/1.0/
5 *
6 * Contributor(s):
7 * Patrick Walton <pcwalton@mozilla.com>
8 *
9 * ***** END LICENSE BLOCK ***** */
10
11 const TEST_URI = "http://example.com/";
12
13 function test() {
14 let hud;
15
16 addTab(TEST_URI);
17 browser.addEventListener("load", function onLoad() {
18 browser.removeEventListener("load", onLoad, true);
19 openConsole(null, testSelectionWhenMovingBetweenBoxes);
20 }, true);
21
22 function testSelectionWhenMovingBetweenBoxes(aHud) {
23 hud = aHud;
24 let jsterm = hud.jsterm;
25
26 // Fill the console with some output.
27 jsterm.clearOutput();
28 jsterm.execute("1 + 2");
29 jsterm.execute("3 + 4");
30 jsterm.execute("5 + 6");
31
32 waitForMessages({
33 webconsole: hud,
34 messages: [{
35 text: "3",
36 category: CATEGORY_OUTPUT,
37 },
38 {
39 text: "7",
40 category: CATEGORY_OUTPUT,
41 },
42 {
43 text: "11",
44 category: CATEGORY_OUTPUT,
45 }],
46 }).then(performTestsAfterOutput);
47 }
48
49 function performTestsAfterOutput() {
50 let outputNode = hud.outputNode;
51
52 ok(outputNode.childNodes.length >= 3, "the output node has children after " +
53 "executing some JavaScript");
54
55 // Test that the global Firefox "Select All" functionality (e.g. Edit >
56 // Select All) works properly in the Web Console.
57 let commandController = hud.ui._commandController;
58 ok(commandController != null, "the window has a command controller object");
59
60 commandController.selectAll();
61
62 let selectedCount = hud.ui.output.getSelectedMessages().length;
63 is(selectedCount, outputNode.childNodes.length,
64 "all console messages are selected after performing a regular browser " +
65 "select-all operation");
66
67 hud.iframeWindow.getSelection().removeAllRanges();
68
69 // Test the context menu "Select All" (which has a different code path) works
70 // properly as well.
71 let contextMenuId = outputNode.parentNode.getAttribute("context");
72 let contextMenu = hud.ui.document.getElementById(contextMenuId);
73 ok(contextMenu != null, "the output node has a context menu");
74
75 let selectAllItem = contextMenu.querySelector("*[command='cmd_selectAll']");
76 ok(selectAllItem != null,
77 "the context menu on the output node has a \"Select All\" item");
78
79 outputNode.focus();
80
81 selectAllItem.doCommand();
82
83 let selectedCount = hud.ui.output.getSelectedMessages().length;
84 is(selectedCount, outputNode.childNodes.length,
85 "all console messages are selected after performing a select-all " +
86 "operation from the context menu");
87
88 hud.iframeWindow.getSelection().removeAllRanges();
89
90 finishTest();
91 }
92 }

mercurial