michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: const kTestBarID = "testBar"; michael@0: const kWidgetID = "characterencoding-button"; michael@0: michael@0: function createTestBar(aLegacy) { michael@0: let testBar = document.createElement("toolbar"); michael@0: testBar.id = kTestBarID; michael@0: testBar.setAttribute("customizable", "true"); michael@0: CustomizableUI.registerArea(kTestBarID, { michael@0: type: CustomizableUI.TYPE_TOOLBAR, michael@0: legacy: aLegacy, michael@0: }); michael@0: gNavToolbox.appendChild(testBar); michael@0: return testBar; michael@0: } michael@0: michael@0: /** michael@0: * Helper function that does the following: michael@0: * michael@0: * 1) Creates a custom toolbar and registers it michael@0: * with CustomizableUI. Sets the legacy attribute michael@0: * of the object passed to registerArea to aLegacy. michael@0: * 2) Adds the widget with ID aWidgetID to that new michael@0: * toolbar. michael@0: * 3) Enters customize mode and makes sure that the michael@0: * widget is still in the right toolbar. michael@0: * 4) Exits customize mode, then removes and deregisters michael@0: * the custom toolbar. michael@0: * 5) Checks that the widget has no placement. michael@0: * 6) Re-adds and re-registers a custom toolbar with the same michael@0: * ID and options as the first one. michael@0: * 7) Enters customize mode and checks that the widget is michael@0: * properly back in the toolbar. michael@0: * 8) Exits customize mode, removes and de-registers the michael@0: * toolbar, and resets the toolbars to default. michael@0: */ michael@0: function checkRestoredPresence(aWidgetID, aLegacy) { michael@0: return Task.spawn(function* () { michael@0: let testBar = createTestBar(aLegacy); michael@0: CustomizableUI.addWidgetToArea(aWidgetID, kTestBarID); michael@0: let placement = CustomizableUI.getPlacementOfWidget(aWidgetID); michael@0: is(placement.area, kTestBarID, michael@0: "Expected " + aWidgetID + " to be in the test toolbar"); michael@0: michael@0: CustomizableUI.unregisterArea(testBar.id); michael@0: testBar.remove(); michael@0: michael@0: let placement = CustomizableUI.getPlacementOfWidget(aWidgetID); michael@0: is(placement, null, "Expected " + aWidgetID + " to be in the palette"); michael@0: michael@0: testBar = createTestBar(aLegacy); michael@0: michael@0: yield startCustomizing(); michael@0: let placement = CustomizableUI.getPlacementOfWidget(aWidgetID); michael@0: is(placement.area, kTestBarID, michael@0: "Expected " + aWidgetID + " to be in the test toolbar"); michael@0: yield endCustomizing(); michael@0: michael@0: CustomizableUI.unregisterArea(testBar.id); michael@0: testBar.remove(); michael@0: michael@0: yield resetCustomization(); michael@0: }); michael@0: } michael@0: michael@0: add_task(function* () { michael@0: yield checkRestoredPresence("downloads-button", false); michael@0: yield checkRestoredPresence("downloads-button", true); michael@0: }); michael@0: michael@0: add_task(function* () { michael@0: yield checkRestoredPresence("characterencoding-button", false); michael@0: yield checkRestoredPresence("characterencoding-button", true); michael@0: });