tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_jsterm_commands.js (1711B)


      1 "use strict";
      2 
      3 const TEST_URI = "data:text/html,test-page";
      4 
      5 const {
      6  HELP_URL,
      7 } = require("resource://devtools/client/webconsole/constants.js");
      8 
      9 add_task(async function () {
     10  const hud = await openNewTabAndConsole(TEST_URI);
     11 
     12  info("Trigger the :help command");
     13  // Hook the browser method in order to prevent the URL from opening
     14  // as mochitest forbids opening remote URLs.
     15  const onUrlOpened = new Promise(resolve => {
     16    const originalMethod = window.openWebLinkIn;
     17    window.openWebLinkIn = url => {
     18      window.openWebLinkIn = originalMethod;
     19      resolve(url);
     20    };
     21  });
     22  execute(hud, ":help");
     23  info("Wait for the help URL to be requested to open");
     24  const url = await onUrlOpened;
     25  is(url, HELP_URL, "Expected url was opened when executing :help");
     26 
     27  info("Execute only ':'");
     28  await executeAndWaitForMessageByType(
     29    hud,
     30    ":",
     31    "Missing a command name after ':'",
     32    ".console-api.error"
     33  );
     34 
     35  // Any space after a `:`  would lead to the same exception
     36  info("Execute only ': '");
     37  await executeAndWaitForMessageByType(
     38    hud,
     39    ": ",
     40    "Missing a command name after ':'",
     41    ".console-api.error"
     42  );
     43 
     44  info("Execute only ': foo'");
     45  await executeAndWaitForMessageByType(
     46    hud,
     47    ": foo",
     48    "Missing a command name after ':'",
     49    ".console-api.error"
     50  );
     51 
     52  info("Execute unsupported command ':bar'");
     53  await executeAndWaitForMessageByType(
     54    hud,
     55    ":bar",
     56    "bar' is not a valid command",
     57    ".console-api.error"
     58  );
     59 
     60  info("Execute string with two commands");
     61  await executeAndWaitForMessageByType(
     62    hud,
     63    ":help :help",
     64    "Executing multiple commands in one evaluation is not supported",
     65    ".console-api.error"
     66  );
     67 });