browser/devtools/webconsole/test/browser_webconsole_bug_613280_jsterm_copy.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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  */
     9 const TEST_URI = "data:text/html;charset=utf-8,Web Console test for bug 613280";
    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 }
    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();
    35   let clipboard_setup = function() {
    36     goDoCommand("cmd_copy");
    37   };
    39   let clipboard_copy_done = function() {
    40     finishTest();
    41   };
    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     }
    50     if (selection.rangeCount > 0) {
    51       selection.removeAllRanges();
    52     }
    54     if (contentSelection.rangeCount > 0) {
    55       contentSelection.removeAllRanges();
    56     }
    58     goUpdateCommand("cmd_copy");
    59   }
    61   let controller = top.document.commandDispatcher.
    62                    getControllerForCommand("cmd_copy");
    63   is(controller.isCommandEnabled("cmd_copy"), false, "cmd_copy is disabled");
    65   HUD.ui.output.selectMessage(msg);
    66   HUD.outputNode.focus();
    68   goUpdateCommand("cmd_copy");
    70   controller = top.document.commandDispatcher.
    71                getControllerForCommand("cmd_copy");
    72   is(controller.isCommandEnabled("cmd_copy"), true, "cmd_copy is enabled");
    74   let selectionText = HUD.iframeWindow.getSelection() + "";
    75   isnot(selectionText.indexOf("foobarBazBug613280"), -1,
    76         "selection text includes 'foobarBazBug613280'");
    78   waitForClipboard((str) => { return str.trim() == selectionText.trim(); },
    79                    clipboard_setup, clipboard_copy_done, clipboard_copy_done);
    80 }

mercurial