browser/components/customizableui/test/browser_947987_removable_default.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/customizableui/test/browser_947987_removable_default.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,68 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +let kWidgetId = "test-removable-widget-default";
    1.11 +const kNavBar = CustomizableUI.AREA_NAVBAR;
    1.12 +let widgetCounter = 0;
    1.13 +
    1.14 +registerCleanupFunction(removeCustomToolbars);
    1.15 +
    1.16 +// Sanity checks
    1.17 +add_task(function() {
    1.18 +  let brokenSpec = {id: kWidgetId + (widgetCounter++), removable: false};
    1.19 +  SimpleTest.doesThrow(function() CustomizableUI.createWidget(brokenSpec),
    1.20 +                       "Creating non-removable widget without defaultArea should throw.");
    1.21 +
    1.22 +  // Widget without removable set should be removable:
    1.23 +  let wrapper = CustomizableUI.createWidget({id: kWidgetId + (widgetCounter++)});
    1.24 +  ok(CustomizableUI.isWidgetRemovable(wrapper.id), "Should be removable by default.");
    1.25 +  CustomizableUI.destroyWidget(wrapper.id);
    1.26 +});
    1.27 +
    1.28 +// Test non-removable widget with defaultArea
    1.29 +add_task(function() {
    1.30 +  // Non-removable widget with defaultArea should work:
    1.31 +  let spec = {id: kWidgetId + (widgetCounter++), removable: false,
    1.32 +              defaultArea: kNavBar};
    1.33 +  let widgetWrapper;
    1.34 +  try {
    1.35 +    widgetWrapper = CustomizableUI.createWidget(spec);
    1.36 +  } catch (ex) {
    1.37 +    ok(false, "Creating a non-removable widget with a default area should not throw.");
    1.38 +    return;
    1.39 +  }
    1.40 +
    1.41 +  let placement = CustomizableUI.getPlacementOfWidget(spec.id);
    1.42 +  ok(placement, "Widget should be placed.");
    1.43 +  is(placement.area, kNavBar, "Widget should be in navbar");
    1.44 +  let singleWrapper = widgetWrapper.forWindow(window);
    1.45 +  ok(singleWrapper, "Widget should exist in window.");
    1.46 +  ok(singleWrapper.node, "Widget node should exist in window.");
    1.47 +  let expectedParent = CustomizableUI.getCustomizeTargetForArea(kNavBar, window);
    1.48 +  is(singleWrapper.node.parentNode, expectedParent, "Widget should be in navbar.");
    1.49 +
    1.50 +  let otherWin = yield openAndLoadWindow(true);
    1.51 +  placement = CustomizableUI.getPlacementOfWidget(spec.id);
    1.52 +  ok(placement, "Widget should be placed.");
    1.53 +  is(placement && placement.area, kNavBar, "Widget should be in navbar");
    1.54 +
    1.55 +  singleWrapper = widgetWrapper.forWindow(otherWin);
    1.56 +  ok(singleWrapper, "Widget should exist in other window.");
    1.57 +  if (singleWrapper) {
    1.58 +    ok(singleWrapper.node, "Widget node should exist in other window.");
    1.59 +    if (singleWrapper.node) {
    1.60 +      let expectedParent = CustomizableUI.getCustomizeTargetForArea(kNavBar, otherWin);
    1.61 +      is(singleWrapper.node.parentNode, expectedParent,
    1.62 +         "Widget should be in navbar in other window.");
    1.63 +    }
    1.64 +  }
    1.65 +  CustomizableUI.destroyWidget(spec.id);
    1.66 +  yield promiseWindowClosed(otherWin);
    1.67 +});
    1.68 +
    1.69 +add_task(function asyncCleanup() {
    1.70 +  yield resetCustomization();
    1.71 +});

mercurial