summaryrefslogtreecommitdiffstats
path: root/browser/components/customizableui/test/browser_disable_commands_customize.js
blob: f3eb06efbe7d73c2e826f368ed937400e427671c (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Most commands don't make sense in customize mode. Check that they're
 * disabled, so shortcuts can't activate them either. Also check that
 * some basic commands (close tab/window, quit, new tab, new window)
 * remain functional.
 */
add_task(async function test_disable_commands() {
  let disabledCommands = ["cmd_print", "Browser:SavePage", "Browser:SendLink"];
  let enabledCommands = [
    "cmd_newNavigatorTab",
    "cmd_newNavigator",
    "cmd_quitApplication",
    "cmd_close",
    "cmd_closeWindow",
  ];

  function checkDisabled() {
    for (let cmd of disabledCommands) {
      is(
        document.getElementById(cmd).getAttribute("disabled"),
        "true",
        `Command ${cmd} should be disabled`
      );
    }
    for (let cmd of enabledCommands) {
      ok(
        !document.getElementById(cmd).hasAttribute("disabled"),
        `Command ${cmd} should NOT be disabled`
      );
    }
  }
  await startCustomizing();

  checkDisabled();

  // Do a reset just for fun, making sure we don't accidentally
  // break things:
  await gCustomizeMode.reset();

  checkDisabled();

  await endCustomizing();
  for (let cmd of disabledCommands.concat(enabledCommands)) {
    ok(
      !document.getElementById(cmd).hasAttribute("disabled"),
      `Command ${cmd} should NOT be disabled after customize mode`
    );
  }
});

/**
 * When buttons are connected to a command, they should not get
 * disabled just because we move them.
 */
add_task(async function test_dont_disable_when_moving() {
  let button = gNavToolbox.palette.querySelector("#print-button");
  ok(button.hasAttribute("command"), "Button should have a command attribute.");
  await startCustomizing();
  CustomizableUI.addWidgetToArea("print-button", "nav-bar");
  await endCustomizing();
  ok(
    !button.hasAttribute("disabled"),
    "Should not have disabled attribute after adding the button."
  );
  ok(
    button.hasAttribute("command"),
    "Button should still have a command attribute."
  );

  await startCustomizing();
  await gCustomizeMode.reset();
  await endCustomizing();
  ok(
    !button.hasAttribute("disabled"),
    "Should not have disabled attribute when resetting in customize mode"
  );
  ok(
    button.hasAttribute("command"),
    "Button should still have a command attribute."
  );
});