tor-browser

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

browser_disable_commands_customize.js (2427B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Most commands don't make sense in customize mode. Check that they're
      8 * disabled, so shortcuts can't activate them either. Also check that
      9 * some basic commands (close tab/window, quit, new tab, new window)
     10 * remain functional.
     11 */
     12 add_task(async function test_disable_commands() {
     13  let disabledCommands = ["cmd_print", "Browser:SavePage", "Browser:SendLink"];
     14  let enabledCommands = [
     15    "cmd_newNavigatorTab",
     16    "cmd_newNavigator",
     17    "cmd_quitApplication",
     18    "cmd_close",
     19    "cmd_closeWindow",
     20  ];
     21 
     22  function checkDisabled() {
     23    for (let cmd of disabledCommands) {
     24      is(
     25        document.getElementById(cmd).getAttribute("disabled"),
     26        "true",
     27        `Command ${cmd} should be disabled`
     28      );
     29    }
     30    for (let cmd of enabledCommands) {
     31      ok(
     32        !document.getElementById(cmd).hasAttribute("disabled"),
     33        `Command ${cmd} should NOT be disabled`
     34      );
     35    }
     36  }
     37  await startCustomizing();
     38 
     39  checkDisabled();
     40 
     41  // Do a reset just for fun, making sure we don't accidentally
     42  // break things:
     43  await gCustomizeMode.reset();
     44 
     45  checkDisabled();
     46 
     47  await endCustomizing();
     48  for (let cmd of disabledCommands.concat(enabledCommands)) {
     49    ok(
     50      !document.getElementById(cmd).hasAttribute("disabled"),
     51      `Command ${cmd} should NOT be disabled after customize mode`
     52    );
     53  }
     54 });
     55 
     56 /**
     57 * When buttons are connected to a command, they should not get
     58 * disabled just because we move them.
     59 */
     60 add_task(async function test_dont_disable_when_moving() {
     61  let button = gNavToolbox.palette.querySelector("#print-button");
     62  ok(button.hasAttribute("command"), "Button should have a command attribute.");
     63  await startCustomizing();
     64  CustomizableUI.addWidgetToArea("print-button", "nav-bar");
     65  await endCustomizing();
     66  ok(
     67    !button.hasAttribute("disabled"),
     68    "Should not have disabled attribute after adding the button."
     69  );
     70  ok(
     71    button.hasAttribute("command"),
     72    "Button should still have a command attribute."
     73  );
     74 
     75  await startCustomizing();
     76  await gCustomizeMode.reset();
     77  await endCustomizing();
     78  ok(
     79    !button.hasAttribute("disabled"),
     80    "Should not have disabled attribute when resetting in customize mode"
     81  );
     82  ok(
     83    button.hasAttribute("command"),
     84    "Button should still have a command attribute."
     85  );
     86 });