fune/browser/components/preferences/tests/browser_containers_name_input.js
Gijs Kruitbosch 6aaf11538a Bug 1650931 - don't use hidden attribute to hide the containers category item, so switching to it works correctly, r=preferences-reviewers,mstriemer
In bug 1648222, the `gotoPref` helper that switches between different
preference panes was altered to disallow switching to hidden categories, so
that if there were no experimental pref entries, we don't show the
'Firefox experiments' category in the prefs.

Unfortunately, the containers category is always hidden, and only accessible
from the 'settings' button for containers and the URL (ie
`about:preferences#containers`), but the added requirement for categories to
not have the `hidden` attribute broke showing this category.

This patch fixes this by hiding the category using CSS instead. It also
cleans up some other use of the hidden attribute.

Note that the sync category is also hidden by default, but shown at
https://searchfox.org/mozilla-central/rev/91d82d7cbf05a71954dfa49d0e43824c7c973e62/browser/components/preferences/preferences.js#97-103

Differential Revision: https://phabricator.services.mozilla.com/D82505
2020-07-07 16:02:29 +00:00

65 lines
1.7 KiB
JavaScript

const CONTAINERS_URL =
"chrome://browser/content/preferences/dialogs/containers.xhtml";
add_task(async function setup() {
await openPreferencesViaOpenPreferencesAPI("containers", { leaveOpen: true });
registerCleanupFunction(async function() {
BrowserTestUtils.removeTab(gBrowser.selectedTab);
});
});
add_task(async function() {
async function openDialog() {
let doc = gBrowser.selectedBrowser.contentDocument;
let dialogPromise = promiseLoadSubDialog(CONTAINERS_URL);
let addButton = doc.getElementById("containersAdd");
addButton.doCommand();
let dialog = await dialogPromise;
return dialog.document;
}
let { contentDocument } = gBrowser.selectedBrowser;
let containerNodes = Array.from(
contentDocument.querySelectorAll("[data-category=paneContainers]")
);
ok(
containerNodes.find(node => node.getBoundingClientRect().width > 0),
"Should actually be showing the container nodes."
);
let doc = await openDialog();
let name = doc.getElementById("name");
let btnApplyChanges = doc.getElementById("btnApplyChanges");
Assert.equal(name.value, "", "The name textbox should initlally be empty");
Assert.ok(
btnApplyChanges.disabled,
"The done button should initially be disabled"
);
function setName(value) {
name.value = value;
let event = new doc.defaultView.InputEvent("input", { data: value });
SpecialPowers.dispatchEvent(doc.defaultView, name, event);
}
setName("test");
Assert.ok(
!btnApplyChanges.disabled,
"The done button should be enabled when the value is not empty"
);
setName("");
Assert.ok(
btnApplyChanges.disabled,
"The done button should be disabled when the value is empty"
);
});