browser/devtools/webconsole/test/browser_webconsole_bug_586388_select_all.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_bug_586388_select_all.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,92 @@
     1.4 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.5 +/* ***** BEGIN LICENSE BLOCK *****
     1.6 + * Any copyright is dedicated to the Public Domain.
     1.7 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.8 + *
     1.9 + * Contributor(s):
    1.10 + *  Patrick Walton <pcwalton@mozilla.com>
    1.11 + *
    1.12 + * ***** END LICENSE BLOCK ***** */
    1.13 +
    1.14 +const TEST_URI = "http://example.com/";
    1.15 +
    1.16 +function test() {
    1.17 +  let hud;
    1.18 +
    1.19 +  addTab(TEST_URI);
    1.20 +  browser.addEventListener("load", function onLoad() {
    1.21 +    browser.removeEventListener("load", onLoad, true);
    1.22 +    openConsole(null, testSelectionWhenMovingBetweenBoxes);
    1.23 +  }, true);
    1.24 +
    1.25 +  function testSelectionWhenMovingBetweenBoxes(aHud) {
    1.26 +    hud = aHud;
    1.27 +    let jsterm = hud.jsterm;
    1.28 +
    1.29 +    // Fill the console with some output.
    1.30 +    jsterm.clearOutput();
    1.31 +    jsterm.execute("1 + 2");
    1.32 +    jsterm.execute("3 + 4");
    1.33 +    jsterm.execute("5 + 6");
    1.34 +
    1.35 +    waitForMessages({
    1.36 +      webconsole: hud,
    1.37 +      messages: [{
    1.38 +        text: "3",
    1.39 +        category: CATEGORY_OUTPUT,
    1.40 +      },
    1.41 +      {
    1.42 +        text: "7",
    1.43 +        category: CATEGORY_OUTPUT,
    1.44 +      },
    1.45 +      {
    1.46 +        text: "11",
    1.47 +        category: CATEGORY_OUTPUT,
    1.48 +      }],
    1.49 +    }).then(performTestsAfterOutput);
    1.50 +  }
    1.51 +
    1.52 +  function performTestsAfterOutput() {
    1.53 +    let outputNode = hud.outputNode;
    1.54 +
    1.55 +    ok(outputNode.childNodes.length >= 3, "the output node has children after " +
    1.56 +       "executing some JavaScript");
    1.57 +
    1.58 +    // Test that the global Firefox "Select All" functionality (e.g. Edit >
    1.59 +    // Select All) works properly in the Web Console.
    1.60 +    let commandController = hud.ui._commandController;
    1.61 +    ok(commandController != null, "the window has a command controller object");
    1.62 +
    1.63 +    commandController.selectAll();
    1.64 +
    1.65 +    let selectedCount = hud.ui.output.getSelectedMessages().length;
    1.66 +    is(selectedCount, outputNode.childNodes.length,
    1.67 +       "all console messages are selected after performing a regular browser " +
    1.68 +       "select-all operation");
    1.69 +
    1.70 +    hud.iframeWindow.getSelection().removeAllRanges();
    1.71 +
    1.72 +    // Test the context menu "Select All" (which has a different code path) works
    1.73 +    // properly as well.
    1.74 +    let contextMenuId = outputNode.parentNode.getAttribute("context");
    1.75 +    let contextMenu = hud.ui.document.getElementById(contextMenuId);
    1.76 +    ok(contextMenu != null, "the output node has a context menu");
    1.77 +
    1.78 +    let selectAllItem = contextMenu.querySelector("*[command='cmd_selectAll']");
    1.79 +    ok(selectAllItem != null,
    1.80 +       "the context menu on the output node has a \"Select All\" item");
    1.81 +
    1.82 +    outputNode.focus();
    1.83 +
    1.84 +    selectAllItem.doCommand();
    1.85 +
    1.86 +    let selectedCount = hud.ui.output.getSelectedMessages().length;
    1.87 +    is(selectedCount, outputNode.childNodes.length,
    1.88 +       "all console messages are selected after performing a select-all " +
    1.89 +       "operation from the context menu");
    1.90 +
    1.91 +    hud.iframeWindow.getSelection().removeAllRanges();
    1.92 +
    1.93 +    finishTest();
    1.94 +  }
    1.95 +}

mercurial