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 kToolbarId = "test-registerToolbarNode-toolbar"; michael@0: const kButtonId = "test-registerToolbarNode-button"; michael@0: registerCleanupFunction(cleanup); michael@0: michael@0: // Registering a toolbar with defaultset attribute should work michael@0: add_task(function() { michael@0: ok(CustomizableUI.inDefaultState, "Everything should be in its default state."); michael@0: let btn = createDummyXULButton(kButtonId); michael@0: let toolbar = document.createElement("toolbar"); michael@0: toolbar.id = kToolbarId; michael@0: toolbar.setAttribute("customizable", true); michael@0: toolbar.setAttribute("defaultset", kButtonId); michael@0: gNavToolbox.appendChild(toolbar); michael@0: ok(CustomizableUI.areas.indexOf(kToolbarId) != -1, michael@0: "Toolbar should have been registered automatically."); michael@0: is(CustomizableUI.getAreaType(kToolbarId), CustomizableUI.TYPE_TOOLBAR, michael@0: "Area should be registered as toolbar"); michael@0: assertAreaPlacements(kToolbarId, [kButtonId]); michael@0: ok(!CustomizableUI.inDefaultState, "No longer in default state after toolbar is registered and visible."); michael@0: CustomizableUI.unregisterArea(kToolbarId, true); michael@0: toolbar.remove(); michael@0: ok(CustomizableUI.inDefaultState, "Everything should be in its default state."); michael@0: btn.remove(); michael@0: }); michael@0: michael@0: // Registering a toolbar without a defaultset attribute should michael@0: // wait for the registerArea call michael@0: add_task(function() { michael@0: ok(CustomizableUI.inDefaultState, "Everything should be in its default state."); michael@0: let btn = createDummyXULButton(kButtonId); michael@0: let toolbar = document.createElement("toolbar"); michael@0: toolbar.id = kToolbarId; michael@0: toolbar.setAttribute("customizable", true); michael@0: gNavToolbox.appendChild(toolbar); michael@0: ok(CustomizableUI.areas.indexOf(kToolbarId) == -1, michael@0: "Toolbar should not yet have been registered automatically."); michael@0: CustomizableUI.registerArea(kToolbarId, {defaultPlacements: [kButtonId]}); michael@0: ok(CustomizableUI.areas.indexOf(kToolbarId) != -1, michael@0: "Toolbar should have been registered now."); michael@0: is(CustomizableUI.getAreaType(kToolbarId), CustomizableUI.TYPE_TOOLBAR, michael@0: "Area should be registered as toolbar"); michael@0: assertAreaPlacements(kToolbarId, [kButtonId]); michael@0: ok(!CustomizableUI.inDefaultState, "No longer in default state after toolbar is registered and visible."); michael@0: CustomizableUI.unregisterArea(kToolbarId, true); michael@0: toolbar.remove(); michael@0: ok(CustomizableUI.inDefaultState, "Everything should be in its default state."); michael@0: btn.remove(); michael@0: }); michael@0: michael@0: add_task(function asyncCleanup() { michael@0: yield resetCustomization(); michael@0: }); michael@0: michael@0: function cleanup() { michael@0: let toolbar = document.getElementById(kToolbarId); michael@0: if (toolbar) { michael@0: toolbar.remove(); michael@0: } michael@0: let btn = document.getElementById(kButtonId) || michael@0: gNavToolbox.querySelector("#" + kButtonId); michael@0: if (btn) { michael@0: btn.remove(); michael@0: } michael@0: }