fune/browser/components/customizableui/test/browser_disable_commands_customize.js
Gijs Kruitbosch b85bab8fe4 Bug 1670907 - moving buttons in customize mode should not disable them, r=mconley
When we move items in customize mode, we unwrap them, then move them, then wrap
them again. The unwrapping sets the `command` attribute back on the button, and
that also sets the `disabled` attribute on the button. The wrapping removes the
`command` attribute but leaves the `disabled` attribute.
When the `disabled` attribute is removed from the command, this does not
propagate to the button because the command attribute has not been put back.

To fix this, the patch avoids adding and immediately removing the command
attribute when moving items while in customize mode.

Differential Revision: https://phabricator.services.mozilla.com/D93338
2020-10-14 14:04:02 +00:00

74 lines
2.1 KiB
JavaScript

/* 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() {
await startCustomizing();
CustomizableUI.addWidgetToArea("print-button", "nav-bar");
ok(
!document.getElementById("print-button").hasAttribute("disabled"),
"Should not have disabled attribute when moving via API in customize mode"
);
await gCustomizeMode.reset();
ok(
!document.getElementById("print-button").hasAttribute("disabled"),
"Should not have disabled attribute when resetting in customize mode"
);
await endCustomizing();
});