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.

     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 ***** */
    11 const TEST_URI = "http://example.com/";
    13 function test() {
    14   let hud;
    16   addTab(TEST_URI);
    17   browser.addEventListener("load", function onLoad() {
    18     browser.removeEventListener("load", onLoad, true);
    19     openConsole(null, testSelectionWhenMovingBetweenBoxes);
    20   }, true);
    22   function testSelectionWhenMovingBetweenBoxes(aHud) {
    23     hud = aHud;
    24     let jsterm = hud.jsterm;
    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");
    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   }
    49   function performTestsAfterOutput() {
    50     let outputNode = hud.outputNode;
    52     ok(outputNode.childNodes.length >= 3, "the output node has children after " +
    53        "executing some JavaScript");
    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");
    60     commandController.selectAll();
    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");
    67     hud.iframeWindow.getSelection().removeAllRanges();
    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");
    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");
    79     outputNode.focus();
    81     selectAllItem.doCommand();
    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");
    88     hud.iframeWindow.getSelection().removeAllRanges();
    90     finishTest();
    91   }
    92 }

mercurial