summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_webconsole_output_copy.js
blob: 74cbc98f8ae050a9924a049c73f97bebb574a645 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test copy to clipboard on the console output. See Bug 587617.
const TEST_URI =
  "data:text/html,<!DOCTYPE html>Test copy to clipboard on the console output";

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

  const smokeMessage = "Hello world!";
  const onMessage = waitForMessageByType(hud, smokeMessage, ".console-api");
  SpecialPowers.spawn(gBrowser.selectedBrowser, [smokeMessage], function (msg) {
    content.wrappedJSObject.console.log(msg);
  });
  const { node } = await onMessage;
  ok(true, "Message was logged");

  const selection = selectNode(hud, node);

  const selectionString = selection.toString().trim();
  is(
    selectionString,
    smokeMessage,
    `selection has expected "${smokeMessage}" value`
  );

  await waitForClipboardPromise(
    () => {
      // The focus is on the JsTerm, so we need to blur it for the copy comand to work.
      node.ownerDocument.activeElement.blur();
      goDoCommand("cmd_copy");
    },
    data => {
      return data.trim() === smokeMessage;
    }
  );
});