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: let kWidgetId = "test-removable-widget-default"; michael@0: const kNavBar = CustomizableUI.AREA_NAVBAR; michael@0: let widgetCounter = 0; michael@0: michael@0: registerCleanupFunction(removeCustomToolbars); michael@0: michael@0: // Sanity checks michael@0: add_task(function() { michael@0: let brokenSpec = {id: kWidgetId + (widgetCounter++), removable: false}; michael@0: SimpleTest.doesThrow(function() CustomizableUI.createWidget(brokenSpec), michael@0: "Creating non-removable widget without defaultArea should throw."); michael@0: michael@0: // Widget without removable set should be removable: michael@0: let wrapper = CustomizableUI.createWidget({id: kWidgetId + (widgetCounter++)}); michael@0: ok(CustomizableUI.isWidgetRemovable(wrapper.id), "Should be removable by default."); michael@0: CustomizableUI.destroyWidget(wrapper.id); michael@0: }); michael@0: michael@0: // Test non-removable widget with defaultArea michael@0: add_task(function() { michael@0: // Non-removable widget with defaultArea should work: michael@0: let spec = {id: kWidgetId + (widgetCounter++), removable: false, michael@0: defaultArea: kNavBar}; michael@0: let widgetWrapper; michael@0: try { michael@0: widgetWrapper = CustomizableUI.createWidget(spec); michael@0: } catch (ex) { michael@0: ok(false, "Creating a non-removable widget with a default area should not throw."); michael@0: return; michael@0: } michael@0: michael@0: let placement = CustomizableUI.getPlacementOfWidget(spec.id); michael@0: ok(placement, "Widget should be placed."); michael@0: is(placement.area, kNavBar, "Widget should be in navbar"); michael@0: let singleWrapper = widgetWrapper.forWindow(window); michael@0: ok(singleWrapper, "Widget should exist in window."); michael@0: ok(singleWrapper.node, "Widget node should exist in window."); michael@0: let expectedParent = CustomizableUI.getCustomizeTargetForArea(kNavBar, window); michael@0: is(singleWrapper.node.parentNode, expectedParent, "Widget should be in navbar."); michael@0: michael@0: let otherWin = yield openAndLoadWindow(true); michael@0: placement = CustomizableUI.getPlacementOfWidget(spec.id); michael@0: ok(placement, "Widget should be placed."); michael@0: is(placement && placement.area, kNavBar, "Widget should be in navbar"); michael@0: michael@0: singleWrapper = widgetWrapper.forWindow(otherWin); michael@0: ok(singleWrapper, "Widget should exist in other window."); michael@0: if (singleWrapper) { michael@0: ok(singleWrapper.node, "Widget node should exist in other window."); michael@0: if (singleWrapper.node) { michael@0: let expectedParent = CustomizableUI.getCustomizeTargetForArea(kNavBar, otherWin); michael@0: is(singleWrapper.node.parentNode, expectedParent, michael@0: "Widget should be in navbar in other window."); michael@0: } michael@0: } michael@0: CustomizableUI.destroyWidget(spec.id); michael@0: yield promiseWindowClosed(otherWin); michael@0: }); michael@0: michael@0: add_task(function asyncCleanup() { michael@0: yield resetCustomization(); michael@0: });