browser/components/customizableui/test/browser_bootstrapped_custom_toolbar.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 const kTestBarID = "testBar";
michael@0 8 const kWidgetID = "characterencoding-button";
michael@0 9
michael@0 10 function createTestBar(aLegacy) {
michael@0 11 let testBar = document.createElement("toolbar");
michael@0 12 testBar.id = kTestBarID;
michael@0 13 testBar.setAttribute("customizable", "true");
michael@0 14 CustomizableUI.registerArea(kTestBarID, {
michael@0 15 type: CustomizableUI.TYPE_TOOLBAR,
michael@0 16 legacy: aLegacy,
michael@0 17 });
michael@0 18 gNavToolbox.appendChild(testBar);
michael@0 19 return testBar;
michael@0 20 }
michael@0 21
michael@0 22 /**
michael@0 23 * Helper function that does the following:
michael@0 24 *
michael@0 25 * 1) Creates a custom toolbar and registers it
michael@0 26 * with CustomizableUI. Sets the legacy attribute
michael@0 27 * of the object passed to registerArea to aLegacy.
michael@0 28 * 2) Adds the widget with ID aWidgetID to that new
michael@0 29 * toolbar.
michael@0 30 * 3) Enters customize mode and makes sure that the
michael@0 31 * widget is still in the right toolbar.
michael@0 32 * 4) Exits customize mode, then removes and deregisters
michael@0 33 * the custom toolbar.
michael@0 34 * 5) Checks that the widget has no placement.
michael@0 35 * 6) Re-adds and re-registers a custom toolbar with the same
michael@0 36 * ID and options as the first one.
michael@0 37 * 7) Enters customize mode and checks that the widget is
michael@0 38 * properly back in the toolbar.
michael@0 39 * 8) Exits customize mode, removes and de-registers the
michael@0 40 * toolbar, and resets the toolbars to default.
michael@0 41 */
michael@0 42 function checkRestoredPresence(aWidgetID, aLegacy) {
michael@0 43 return Task.spawn(function* () {
michael@0 44 let testBar = createTestBar(aLegacy);
michael@0 45 CustomizableUI.addWidgetToArea(aWidgetID, kTestBarID);
michael@0 46 let placement = CustomizableUI.getPlacementOfWidget(aWidgetID);
michael@0 47 is(placement.area, kTestBarID,
michael@0 48 "Expected " + aWidgetID + " to be in the test toolbar");
michael@0 49
michael@0 50 CustomizableUI.unregisterArea(testBar.id);
michael@0 51 testBar.remove();
michael@0 52
michael@0 53 let placement = CustomizableUI.getPlacementOfWidget(aWidgetID);
michael@0 54 is(placement, null, "Expected " + aWidgetID + " to be in the palette");
michael@0 55
michael@0 56 testBar = createTestBar(aLegacy);
michael@0 57
michael@0 58 yield startCustomizing();
michael@0 59 let placement = CustomizableUI.getPlacementOfWidget(aWidgetID);
michael@0 60 is(placement.area, kTestBarID,
michael@0 61 "Expected " + aWidgetID + " to be in the test toolbar");
michael@0 62 yield endCustomizing();
michael@0 63
michael@0 64 CustomizableUI.unregisterArea(testBar.id);
michael@0 65 testBar.remove();
michael@0 66
michael@0 67 yield resetCustomization();
michael@0 68 });
michael@0 69 }
michael@0 70
michael@0 71 add_task(function* () {
michael@0 72 yield checkRestoredPresence("downloads-button", false);
michael@0 73 yield checkRestoredPresence("downloads-button", true);
michael@0 74 });
michael@0 75
michael@0 76 add_task(function* () {
michael@0 77 yield checkRestoredPresence("characterencoding-button", false);
michael@0 78 yield checkRestoredPresence("characterencoding-button", true);
michael@0 79 });

mercurial