Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | // Test that multiple messages are copied into the clipboard and that they are |
michael@0 | 5 | // separated by new lines. See bug 916997. |
michael@0 | 6 | |
michael@0 | 7 | function test() |
michael@0 | 8 | { |
michael@0 | 9 | const TEST_URI = "data:text/html;charset=utf8,<p>hello world, bug 916997"; |
michael@0 | 10 | let clipboardValue = ""; |
michael@0 | 11 | |
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, consoleOpened); |
michael@0 | 16 | }, true); |
michael@0 | 17 | |
michael@0 | 18 | function consoleOpened(hud) |
michael@0 | 19 | { |
michael@0 | 20 | hud.jsterm.clearOutput(); |
michael@0 | 21 | |
michael@0 | 22 | let controller = top.document.commandDispatcher. |
michael@0 | 23 | getControllerForCommand("cmd_copy"); |
michael@0 | 24 | is(controller.isCommandEnabled("cmd_copy"), false, "cmd_copy is disabled"); |
michael@0 | 25 | |
michael@0 | 26 | content.console.log("Hello world! bug916997a"); |
michael@0 | 27 | content.console.log("Hello world 2! bug916997b"); |
michael@0 | 28 | |
michael@0 | 29 | waitForMessages({ |
michael@0 | 30 | webconsole: hud, |
michael@0 | 31 | messages: [{ |
michael@0 | 32 | text: "Hello world! bug916997a", |
michael@0 | 33 | category: CATEGORY_WEBDEV, |
michael@0 | 34 | severity: SEVERITY_LOG, |
michael@0 | 35 | }, { |
michael@0 | 36 | text: "Hello world 2! bug916997b", |
michael@0 | 37 | category: CATEGORY_WEBDEV, |
michael@0 | 38 | severity: SEVERITY_LOG, |
michael@0 | 39 | }], |
michael@0 | 40 | }).then(() => { |
michael@0 | 41 | hud.ui.output.selectAllMessages(); |
michael@0 | 42 | hud.outputNode.focus(); |
michael@0 | 43 | |
michael@0 | 44 | goUpdateCommand("cmd_copy"); |
michael@0 | 45 | controller = top.document.commandDispatcher.getControllerForCommand("cmd_copy"); |
michael@0 | 46 | is(controller.isCommandEnabled("cmd_copy"), true, "cmd_copy is enabled"); |
michael@0 | 47 | |
michael@0 | 48 | let selection = hud.iframeWindow.getSelection() + ""; |
michael@0 | 49 | info("selection '" + selection + "'"); |
michael@0 | 50 | waitForClipboard((str) => { |
michael@0 | 51 | clipboardValue = str; |
michael@0 | 52 | return str.indexOf("bug916997a") > -1 && str.indexOf("bug916997b") > -1; |
michael@0 | 53 | }, |
michael@0 | 54 | () => { goDoCommand("cmd_copy"); }, |
michael@0 | 55 | checkClipboard.bind(null, hud), |
michael@0 | 56 | () => { |
michael@0 | 57 | info("last clipboard value: '" + clipboardValue + "'"); |
michael@0 | 58 | finishTest(); |
michael@0 | 59 | }); |
michael@0 | 60 | }); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | function checkClipboard(hud) |
michael@0 | 64 | { |
michael@0 | 65 | info("clipboard value '" + clipboardValue + "'"); |
michael@0 | 66 | let lines = clipboardValue.trim().split("\n"); |
michael@0 | 67 | is(hud.outputNode.children.length, 2, "number of messages"); |
michael@0 | 68 | is(lines.length, hud.outputNode.children.length, "number of lines"); |
michael@0 | 69 | isnot(lines[0].indexOf("bug916997a"), -1, |
michael@0 | 70 | "first message text includes 'bug916997a'"); |
michael@0 | 71 | isnot(lines[1].indexOf("bug916997b"), -1, |
michael@0 | 72 | "second message text includes 'bug916997b'"); |
michael@0 | 73 | is(lines[0].indexOf("bug916997b"), -1, |
michael@0 | 74 | "first message text does not include 'bug916997b'"); |
michael@0 | 75 | finishTest(); |
michael@0 | 76 | } |
michael@0 | 77 | } |