browser/devtools/webconsole/test/browser_webconsole_bug_613280_jsterm_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 /*
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 */
michael@0 8
michael@0 9 const TEST_URI = "data:text/html;charset=utf-8,Web Console test for bug 613280";
michael@0 10
michael@0 11 function test() {
michael@0 12 addTab(TEST_URI);
michael@0 13 browser.addEventListener("load", function onLoad() {
michael@0 14 browser.removeEventListener("load", onLoad, true);
michael@0 15 openConsole(null, function(HUD) {
michael@0 16 content.console.log("foobarBazBug613280");
michael@0 17 waitForMessages({
michael@0 18 webconsole: HUD,
michael@0 19 messages: [{
michael@0 20 text: "foobarBazBug613280",
michael@0 21 category: CATEGORY_WEBDEV,
michael@0 22 severity: SEVERITY_LOG,
michael@0 23 }],
michael@0 24 }).then(performTest.bind(null, HUD));
michael@0 25 });
michael@0 26 }, true);
michael@0 27 }
michael@0 28
michael@0 29 function performTest(HUD, [result]) {
michael@0 30 let msg = [...result.matched][0];
michael@0 31 let input = HUD.jsterm.inputNode;
michael@0 32 let selection = getSelection();
michael@0 33 let contentSelection = content.getSelection();
michael@0 34
michael@0 35 let clipboard_setup = function() {
michael@0 36 goDoCommand("cmd_copy");
michael@0 37 };
michael@0 38
michael@0 39 let clipboard_copy_done = function() {
michael@0 40 finishTest();
michael@0 41 };
michael@0 42
michael@0 43 // Check if we first need to clear any existing selections.
michael@0 44 if (selection.rangeCount > 0 || contentSelection.rangeCount > 0 ||
michael@0 45 input.selectionStart != input.selectionEnd) {
michael@0 46 if (input.selectionStart != input.selectionEnd) {
michael@0 47 input.selectionStart = input.selectionEnd = 0;
michael@0 48 }
michael@0 49
michael@0 50 if (selection.rangeCount > 0) {
michael@0 51 selection.removeAllRanges();
michael@0 52 }
michael@0 53
michael@0 54 if (contentSelection.rangeCount > 0) {
michael@0 55 contentSelection.removeAllRanges();
michael@0 56 }
michael@0 57
michael@0 58 goUpdateCommand("cmd_copy");
michael@0 59 }
michael@0 60
michael@0 61 let controller = top.document.commandDispatcher.
michael@0 62 getControllerForCommand("cmd_copy");
michael@0 63 is(controller.isCommandEnabled("cmd_copy"), false, "cmd_copy is disabled");
michael@0 64
michael@0 65 HUD.ui.output.selectMessage(msg);
michael@0 66 HUD.outputNode.focus();
michael@0 67
michael@0 68 goUpdateCommand("cmd_copy");
michael@0 69
michael@0 70 controller = top.document.commandDispatcher.
michael@0 71 getControllerForCommand("cmd_copy");
michael@0 72 is(controller.isCommandEnabled("cmd_copy"), true, "cmd_copy is enabled");
michael@0 73
michael@0 74 let selectionText = HUD.iframeWindow.getSelection() + "";
michael@0 75 isnot(selectionText.indexOf("foobarBazBug613280"), -1,
michael@0 76 "selection text includes 'foobarBazBug613280'");
michael@0 77
michael@0 78 waitForClipboard((str) => { return str.trim() == selectionText.trim(); },
michael@0 79 clipboard_setup, clipboard_copy_done, clipboard_copy_done);
michael@0 80 }

mercurial