fune/browser/components/customizableui/test/browser_886323_buildArea_removable_nodes.js
Mike Conley 42a671591b Bug 1797836 - Part 2: Update CUI to have a general TYPE_PANEL instead of TYPE_MENU_PANEL. r=desktop-theme-reviewers,dao,sclements
Long ago, the menu panel in was a customizable area that users could drag things into.

That changed back around 2017 in bug 1354117 when the Photon redesign was built. The
menu panel become a static menu, but we also made it possible to permanently move things
to the overflow panel of the nav-bar.

It looks like we never updated the area type constant from referring to the old menu panel
though, so it's "TYPE_MENU_PANEL", and registering a node for it happens with
registerMenuPanel. This patch changes to constant to TYPE_PANEL and updates the registration
method to registerPanelNode.

I a check around the codebase as well as GitHub looking to see if there were any
system add-ons or experimental WebExtensions that rely on TYPE_MENU_PANEL / registerMenuPanel,
but I couldn't find any.

Differential Revision: https://phabricator.services.mozilla.com/D161078
2022-11-08 14:51:40 +00:00

58 lines
1.9 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const kButtonId = "test-886323-removable-moved-node";
const kLazyAreaId = "test-886323-lazy-area-for-removability-testing";
var gNavBar = document.getElementById(CustomizableUI.AREA_NAVBAR);
var gLazyArea;
// Removable nodes shouldn't be moved by buildArea
add_task(async function() {
let dummyBtn = createDummyXULButton(kButtonId, "Dummy");
dummyBtn.setAttribute("removable", "true");
CustomizableUI.getCustomizationTarget(gNavBar).appendChild(dummyBtn);
let popupSet = document.getElementById("mainPopupSet");
gLazyArea = document.createXULElement("panel");
gLazyArea.id = kLazyAreaId;
gLazyArea.hidden = true;
popupSet.appendChild(gLazyArea);
CustomizableUI.registerArea(kLazyAreaId, {
type: CustomizableUI.TYPE_PANEL,
defaultPlacements: [],
});
CustomizableUI.addWidgetToArea(kButtonId, kLazyAreaId);
assertAreaPlacements(
kLazyAreaId,
[kButtonId],
"Placements should have changed because widget is removable."
);
let btn = document.getElementById(kButtonId);
btn.setAttribute("removable", "false");
gLazyArea._customizationTarget = gLazyArea;
CustomizableUI.registerToolbarNode(gLazyArea, []);
assertAreaPlacements(
kLazyAreaId,
[],
"Placements should no longer include widget."
);
is(
btn.parentNode.id,
CustomizableUI.getCustomizationTarget(gNavBar).id,
"Button shouldn't actually have moved as it's not removable"
);
btn = document.getElementById(kButtonId);
if (btn) {
btn.remove();
}
CustomizableUI.removeWidgetFromArea(kButtonId);
CustomizableUI.unregisterArea(kLazyAreaId);
gLazyArea.remove();
});
add_task(async function asyncCleanup() {
await resetCustomization();
});