browser/components/customizableui/test/browser_947987_removable_default.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 let kWidgetId = "test-removable-widget-default";
michael@0 8 const kNavBar = CustomizableUI.AREA_NAVBAR;
michael@0 9 let widgetCounter = 0;
michael@0 10
michael@0 11 registerCleanupFunction(removeCustomToolbars);
michael@0 12
michael@0 13 // Sanity checks
michael@0 14 add_task(function() {
michael@0 15 let brokenSpec = {id: kWidgetId + (widgetCounter++), removable: false};
michael@0 16 SimpleTest.doesThrow(function() CustomizableUI.createWidget(brokenSpec),
michael@0 17 "Creating non-removable widget without defaultArea should throw.");
michael@0 18
michael@0 19 // Widget without removable set should be removable:
michael@0 20 let wrapper = CustomizableUI.createWidget({id: kWidgetId + (widgetCounter++)});
michael@0 21 ok(CustomizableUI.isWidgetRemovable(wrapper.id), "Should be removable by default.");
michael@0 22 CustomizableUI.destroyWidget(wrapper.id);
michael@0 23 });
michael@0 24
michael@0 25 // Test non-removable widget with defaultArea
michael@0 26 add_task(function() {
michael@0 27 // Non-removable widget with defaultArea should work:
michael@0 28 let spec = {id: kWidgetId + (widgetCounter++), removable: false,
michael@0 29 defaultArea: kNavBar};
michael@0 30 let widgetWrapper;
michael@0 31 try {
michael@0 32 widgetWrapper = CustomizableUI.createWidget(spec);
michael@0 33 } catch (ex) {
michael@0 34 ok(false, "Creating a non-removable widget with a default area should not throw.");
michael@0 35 return;
michael@0 36 }
michael@0 37
michael@0 38 let placement = CustomizableUI.getPlacementOfWidget(spec.id);
michael@0 39 ok(placement, "Widget should be placed.");
michael@0 40 is(placement.area, kNavBar, "Widget should be in navbar");
michael@0 41 let singleWrapper = widgetWrapper.forWindow(window);
michael@0 42 ok(singleWrapper, "Widget should exist in window.");
michael@0 43 ok(singleWrapper.node, "Widget node should exist in window.");
michael@0 44 let expectedParent = CustomizableUI.getCustomizeTargetForArea(kNavBar, window);
michael@0 45 is(singleWrapper.node.parentNode, expectedParent, "Widget should be in navbar.");
michael@0 46
michael@0 47 let otherWin = yield openAndLoadWindow(true);
michael@0 48 placement = CustomizableUI.getPlacementOfWidget(spec.id);
michael@0 49 ok(placement, "Widget should be placed.");
michael@0 50 is(placement && placement.area, kNavBar, "Widget should be in navbar");
michael@0 51
michael@0 52 singleWrapper = widgetWrapper.forWindow(otherWin);
michael@0 53 ok(singleWrapper, "Widget should exist in other window.");
michael@0 54 if (singleWrapper) {
michael@0 55 ok(singleWrapper.node, "Widget node should exist in other window.");
michael@0 56 if (singleWrapper.node) {
michael@0 57 let expectedParent = CustomizableUI.getCustomizeTargetForArea(kNavBar, otherWin);
michael@0 58 is(singleWrapper.node.parentNode, expectedParent,
michael@0 59 "Widget should be in navbar in other window.");
michael@0 60 }
michael@0 61 }
michael@0 62 CustomizableUI.destroyWidget(spec.id);
michael@0 63 yield promiseWindowClosed(otherWin);
michael@0 64 });
michael@0 65
michael@0 66 add_task(function asyncCleanup() {
michael@0 67 yield resetCustomization();
michael@0 68 });

mercurial