tor-browser

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

browser_jsterm_screenshot_command_user.js (1713B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Test that screenshot command works properly
      5 
      6 "use strict";
      7 
      8 const TEST_URI = `data:text/html,<!DOCTYPE html><meta charset=utf8><script>
      9  function screenshot() {
     10    console.log("contextScreen");
     11  }
     12 </script>`;
     13 
     14 add_task(async function () {
     15  await addTab(TEST_URI);
     16 
     17  const hud = await openConsole();
     18  ok(hud, "web console opened");
     19 
     20  await testCommand(hud);
     21  await testUserScreenshotFunction(hud);
     22 });
     23 
     24 async function testCommand(hud) {
     25  const command = `:screenshot --clipboard`;
     26  await executeAndWaitForMessageByType(
     27    hud,
     28    command,
     29    "Screenshot copied to clipboard.",
     30    ".console-api"
     31  );
     32  ok(true, ":screenshot was executed as expected");
     33 
     34  const helpMessage = await executeAndWaitForMessageByType(
     35    hud,
     36    `:screenshot --help`,
     37    "Save an image of the page",
     38    ".console-api"
     39  );
     40  ok(helpMessage, ":screenshot --help was executed as expected");
     41  is(
     42    helpMessage.node.innerText.match(/--\w+/g).join("\n"),
     43    [
     44      "--clipboard",
     45      "--delay",
     46      "--dpr",
     47      "--fullpage",
     48      "--selector",
     49      "--file",
     50      "--filename",
     51    ].join("\n"),
     52    "Help message references the arguments of the screenshot command"
     53  );
     54 }
     55 
     56 // if a user defines a screenshot, as is the case in the Test URI, the
     57 // command should not overwrite the screenshot function
     58 async function testUserScreenshotFunction(hud) {
     59  const command = `screenshot()`;
     60  await executeAndWaitForMessageByType(
     61    hud,
     62    command,
     63    "contextScreen",
     64    ".console-api"
     65  );
     66  ok(
     67    true,
     68    "content screenshot function is not overidden and was executed as expected"
     69  );
     70 }