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.

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

mercurial