browser/devtools/webconsole/test/browser_webconsole_bug_587617_output_copy.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 /* ***** BEGIN LICENSE BLOCK *****
     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  *  Patrick Walton <pcwalton@mozilla.com>
     8  *
     9  * ***** END LICENSE BLOCK ***** */
    11 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html";
    13 let HUD, outputNode;
    15 function test() {
    16   addTab(TEST_URI);
    17   browser.addEventListener("load", function onLoad() {
    18     browser.removeEventListener("load", onLoad, true);
    19     openConsole(null, consoleOpened);
    20   }, true);
    21 }
    23 function consoleOpened(aHud) {
    24   HUD = aHud;
    26   // See bugs 574036, 586386 and 587617.
    27   outputNode = HUD.outputNode;
    29   HUD.jsterm.clearOutput();
    31   let controller = top.document.commandDispatcher.
    32                    getControllerForCommand("cmd_copy");
    33   is(controller.isCommandEnabled("cmd_copy"), false, "cmd_copy is disabled");
    35   content.console.log("Hello world! bug587617");
    37   waitForMessages({
    38     webconsole: HUD,
    39     messages: [{
    40       text: "bug587617",
    41       category: CATEGORY_WEBDEV,
    42       severity: SEVERITY_LOG,
    43     }],
    44   }).then(([result]) => {
    45     let msg = [...result.matched][0];
    46     HUD.ui.output.selectMessage(msg);
    48     outputNode.focus();
    50     goUpdateCommand("cmd_copy");
    51     controller = top.document.commandDispatcher.getControllerForCommand("cmd_copy");
    52     is(controller.isCommandEnabled("cmd_copy"), true, "cmd_copy is enabled");
    54     let selection = HUD.iframeWindow.getSelection() + "";
    55     isnot(selection.indexOf("bug587617"), -1,
    56           "selection text includes 'bug587617'");
    58     waitForClipboard((str) => { return selection.trim() == str.trim(); },
    59       () => { goDoCommand("cmd_copy") },
    60       testContextMenuCopy, testContextMenuCopy);
    61   });
    62 }
    64 // Test that the context menu "Copy" (which has a different code path) works
    65 // properly as well.
    66 function testContextMenuCopy() {
    67   let contextMenuId = outputNode.parentNode.getAttribute("context");
    68   let contextMenu = HUD.ui.document.getElementById(contextMenuId);
    69   ok(contextMenu, "the output node has a context menu");
    71   let copyItem = contextMenu.querySelector("*[command='cmd_copy']");
    72   ok(copyItem, "the context menu on the output node has a \"Copy\" item");
    74   let selection = HUD.iframeWindow.getSelection() + "";
    76   copyItem.doCommand();
    78   waitForClipboard((str) => { return selection.trim() == str.trim(); },
    79     () => { goDoCommand("cmd_copy") },
    80     finishTest, finishTest);
    81   HUD = outputNode = null;
    82 }

mercurial