summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_jsterm_commands.js
blob: 7ff80228fe97b3eba45cbc8acf0e20fd858a5a29 (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
"use strict";

const TEST_URI = "data:text/html,test-page";

const {
  HELP_URL,
} = require("resource://devtools/client/webconsole/constants.js");

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

  info("Trigger the :help command");
  // Hook the browser method in order to prevent the URL from opening
  // as mochitest forbids opening remote URLs.
  const onUrlOpened = new Promise(resolve => {
    const originalMethod = window.openWebLinkIn;
    window.openWebLinkIn = url => {
      window.openWebLinkIn = originalMethod;
      resolve(url);
    };
  });
  execute(hud, ":help");
  info("Wait for the help URL to be requested to open");
  const url = await onUrlOpened;
  is(url, HELP_URL, "Expected url was opened when executing :help");

  info("Execute only ':'");
  await executeAndWaitForMessageByType(
    hud,
    ":",
    "Missing a command name after ':'",
    ".console-api.error"
  );

  // Any space after a `:`  would lead to the same exception
  info("Execute only ': '");
  await executeAndWaitForMessageByType(
    hud,
    ": ",
    "Missing a command name after ':'",
    ".console-api.error"
  );

  info("Execute only ': foo'");
  await executeAndWaitForMessageByType(
    hud,
    ": foo",
    "Missing a command name after ':'",
    ".console-api.error"
  );

  info("Execute unsupported command ':bar'");
  await executeAndWaitForMessageByType(
    hud,
    ":bar",
    "bar' is not a valid command",
    ".console-api.error"
  );

  info("Execute string with two commands");
  await executeAndWaitForMessageByType(
    hud,
    ":help :help",
    "Executing multiple commands in one evaluation is not supported",
    ".console-api.error"
  );
});