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.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 "use strict";
     7 const kTestBarID = "testBar";
     8 const kWidgetID = "characterencoding-button";
    10 function createTestBar(aLegacy) {
    11   let testBar = document.createElement("toolbar");
    12   testBar.id = kTestBarID;
    13   testBar.setAttribute("customizable", "true");
    14   CustomizableUI.registerArea(kTestBarID, {
    15     type: CustomizableUI.TYPE_TOOLBAR,
    16     legacy: aLegacy,
    17   });
    18   gNavToolbox.appendChild(testBar);
    19   return testBar;
    20 }
    22 /**
    23  * Helper function that does the following:
    24  *
    25  * 1) Creates a custom toolbar and registers it
    26  *    with CustomizableUI. Sets the legacy attribute
    27  *    of the object passed to registerArea to aLegacy.
    28  * 2) Adds the widget with ID aWidgetID to that new
    29  *    toolbar.
    30  * 3) Enters customize mode and makes sure that the
    31  *    widget is still in the right toolbar.
    32  * 4) Exits customize mode, then removes and deregisters
    33  *    the custom toolbar.
    34  * 5) Checks that the widget has no placement.
    35  * 6) Re-adds and re-registers a custom toolbar with the same
    36  *    ID and options as the first one.
    37  * 7) Enters customize mode and checks that the widget is
    38  *    properly back in the toolbar.
    39  * 8) Exits customize mode, removes and de-registers the
    40  *    toolbar, and resets the toolbars to default.
    41  */
    42 function checkRestoredPresence(aWidgetID, aLegacy) {
    43   return Task.spawn(function* () {
    44     let testBar = createTestBar(aLegacy);
    45     CustomizableUI.addWidgetToArea(aWidgetID, kTestBarID);
    46     let placement = CustomizableUI.getPlacementOfWidget(aWidgetID);
    47     is(placement.area, kTestBarID,
    48        "Expected " + aWidgetID + " to be in the test toolbar");
    50     CustomizableUI.unregisterArea(testBar.id);
    51     testBar.remove();
    53     let placement = CustomizableUI.getPlacementOfWidget(aWidgetID);
    54     is(placement, null, "Expected " + aWidgetID + " to be in the palette");
    56     testBar = createTestBar(aLegacy);
    58     yield startCustomizing();
    59     let placement = CustomizableUI.getPlacementOfWidget(aWidgetID);
    60     is(placement.area, kTestBarID,
    61        "Expected " + aWidgetID + " to be in the test toolbar");
    62     yield endCustomizing();
    64     CustomizableUI.unregisterArea(testBar.id);
    65     testBar.remove();
    67     yield resetCustomization();
    68   });
    69 }
    71 add_task(function* () {
    72   yield checkRestoredPresence("downloads-button", false);
    73   yield checkRestoredPresence("downloads-button", true);
    74 });
    76 add_task(function* () {
    77   yield checkRestoredPresence("characterencoding-button", false);
    78   yield checkRestoredPresence("characterencoding-button", true);
    79 });

mercurial