browser/devtools/webconsole/test/browser_webconsole_bug_587617_output_copy.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_587617_output_copy.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,83 @@
     1.4 +/* ***** BEGIN LICENSE BLOCK *****
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.7 + *
     1.8 + * Contributor(s):
     1.9 + *  Mihai Șucan <mihai.sucan@gmail.com>
    1.10 + *  Patrick Walton <pcwalton@mozilla.com>
    1.11 + *
    1.12 + * ***** END LICENSE BLOCK ***** */
    1.13 +
    1.14 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html";
    1.15 +
    1.16 +let HUD, outputNode;
    1.17 +
    1.18 +function test() {
    1.19 +  addTab(TEST_URI);
    1.20 +  browser.addEventListener("load", function onLoad() {
    1.21 +    browser.removeEventListener("load", onLoad, true);
    1.22 +    openConsole(null, consoleOpened);
    1.23 +  }, true);
    1.24 +}
    1.25 +
    1.26 +function consoleOpened(aHud) {
    1.27 +  HUD = aHud;
    1.28 +
    1.29 +  // See bugs 574036, 586386 and 587617.
    1.30 +  outputNode = HUD.outputNode;
    1.31 +
    1.32 +  HUD.jsterm.clearOutput();
    1.33 +
    1.34 +  let controller = top.document.commandDispatcher.
    1.35 +                   getControllerForCommand("cmd_copy");
    1.36 +  is(controller.isCommandEnabled("cmd_copy"), false, "cmd_copy is disabled");
    1.37 +
    1.38 +  content.console.log("Hello world! bug587617");
    1.39 +
    1.40 +  waitForMessages({
    1.41 +    webconsole: HUD,
    1.42 +    messages: [{
    1.43 +      text: "bug587617",
    1.44 +      category: CATEGORY_WEBDEV,
    1.45 +      severity: SEVERITY_LOG,
    1.46 +    }],
    1.47 +  }).then(([result]) => {
    1.48 +    let msg = [...result.matched][0];
    1.49 +    HUD.ui.output.selectMessage(msg);
    1.50 +
    1.51 +    outputNode.focus();
    1.52 +
    1.53 +    goUpdateCommand("cmd_copy");
    1.54 +    controller = top.document.commandDispatcher.getControllerForCommand("cmd_copy");
    1.55 +    is(controller.isCommandEnabled("cmd_copy"), true, "cmd_copy is enabled");
    1.56 +
    1.57 +    let selection = HUD.iframeWindow.getSelection() + "";
    1.58 +    isnot(selection.indexOf("bug587617"), -1,
    1.59 +          "selection text includes 'bug587617'");
    1.60 +
    1.61 +    waitForClipboard((str) => { return selection.trim() == str.trim(); },
    1.62 +      () => { goDoCommand("cmd_copy") },
    1.63 +      testContextMenuCopy, testContextMenuCopy);
    1.64 +  });
    1.65 +}
    1.66 +
    1.67 +// Test that the context menu "Copy" (which has a different code path) works
    1.68 +// properly as well.
    1.69 +function testContextMenuCopy() {
    1.70 +  let contextMenuId = outputNode.parentNode.getAttribute("context");
    1.71 +  let contextMenu = HUD.ui.document.getElementById(contextMenuId);
    1.72 +  ok(contextMenu, "the output node has a context menu");
    1.73 +
    1.74 +  let copyItem = contextMenu.querySelector("*[command='cmd_copy']");
    1.75 +  ok(copyItem, "the context menu on the output node has a \"Copy\" item");
    1.76 +
    1.77 +  let selection = HUD.iframeWindow.getSelection() + "";
    1.78 +
    1.79 +  copyItem.doCommand();
    1.80 +
    1.81 +  waitForClipboard((str) => { return selection.trim() == str.trim(); },
    1.82 +    () => { goDoCommand("cmd_copy") },
    1.83 +    finishTest, finishTest);
    1.84 +  HUD = outputNode = null;
    1.85 +}
    1.86 +

mercurial