summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_webconsole_output_copy_newlines.js
blob: c2304cbd697711ad31a8de6bb1dc65fe177a2d5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that multiple messages are copied into the clipboard and that they are
// separated by new lines. See bug 916997.
const TEST_URI =
  "data:text/html,<!DOCTYPE html><meta charset=utf8>" +
  "Test copy multiple messages to clipboard";

add_task(async function () {
  const hud = await openNewTabAndConsole(TEST_URI);

  const messages = Array.from(
    { length: 10 },
    (_, i) => `Message number ${i + 1}`
  );
  const lastMessage = [...messages].pop();
  const onMessage = waitForMessageByType(hud, lastMessage, ".console-api");
  SpecialPowers.spawn(gBrowser.selectedBrowser, [messages], msgs => {
    msgs.forEach(msg => content.wrappedJSObject.console.log(msg));
  });
  const { node } = await onMessage;
  ok(node, "Messages were logged");

  // Select the whole output.
  const output = node.closest(".webconsole-output");
  selectNode(hud, output);

  info(
    "Wait for the clipboard to contain the text corresponding to all the messages"
  );
  await waitForClipboardPromise(
    () => {
      // The focus is on the JsTerm, so we need to blur it for the copy comand to work.
      output.ownerDocument.activeElement.blur();
      goDoCommand("cmd_copy");
    },
    data => data.trim() === messages.join("\n")
  );
});