summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_jsterm_screenshot_command_user.js
blob: 2fcf4248a17686a8739bafd13d2a07d924e974c0 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Test that screenshot command works properly

"use strict";

const TEST_URI = `data:text/html,<!DOCTYPE html><meta charset=utf8><script>
  function screenshot() {
    console.log("contextScreen");
  }
</script>`;

add_task(async function () {
  await addTab(TEST_URI);

  const hud = await openConsole();
  ok(hud, "web console opened");

  await testCommand(hud);
  await testUserScreenshotFunction(hud);
});

async function testCommand(hud) {
  const command = `:screenshot --clipboard`;
  await executeAndWaitForMessageByType(
    hud,
    command,
    "Screenshot copied to clipboard.",
    ".console-api"
  );
  ok(true, ":screenshot was executed as expected");

  const helpMessage = await executeAndWaitForMessageByType(
    hud,
    `:screenshot --help`,
    "Save an image of the page",
    ".console-api"
  );
  ok(helpMessage, ":screenshot --help was executed as expected");
  is(
    helpMessage.node.innerText.match(/--\w+/g).join("\n"),
    [
      "--clipboard",
      "--delay",
      "--dpr",
      "--fullpage",
      "--selector",
      "--file",
      "--filename",
    ].join("\n"),
    "Help message references the arguments of the screenshot command"
  );
}

// if a user defines a screenshot, as is the case in the Test URI, the
// command should not overwrite the screenshot function
async function testUserScreenshotFunction(hud) {
  const command = `screenshot()`;
  await executeAndWaitForMessageByType(
    hud,
    command,
    "contextScreen",
    ".console-api"
  );
  ok(
    true,
    "content screenshot function is not overidden and was executed as expected"
  );
}