browser/devtools/webconsole/test/browser_webconsole_bug_586388_select_all.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial