1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/customizableui/test/browser_bootstrapped_custom_toolbar.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 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 +const kTestBarID = "testBar"; 1.11 +const kWidgetID = "characterencoding-button"; 1.12 + 1.13 +function createTestBar(aLegacy) { 1.14 + let testBar = document.createElement("toolbar"); 1.15 + testBar.id = kTestBarID; 1.16 + testBar.setAttribute("customizable", "true"); 1.17 + CustomizableUI.registerArea(kTestBarID, { 1.18 + type: CustomizableUI.TYPE_TOOLBAR, 1.19 + legacy: aLegacy, 1.20 + }); 1.21 + gNavToolbox.appendChild(testBar); 1.22 + return testBar; 1.23 +} 1.24 + 1.25 +/** 1.26 + * Helper function that does the following: 1.27 + * 1.28 + * 1) Creates a custom toolbar and registers it 1.29 + * with CustomizableUI. Sets the legacy attribute 1.30 + * of the object passed to registerArea to aLegacy. 1.31 + * 2) Adds the widget with ID aWidgetID to that new 1.32 + * toolbar. 1.33 + * 3) Enters customize mode and makes sure that the 1.34 + * widget is still in the right toolbar. 1.35 + * 4) Exits customize mode, then removes and deregisters 1.36 + * the custom toolbar. 1.37 + * 5) Checks that the widget has no placement. 1.38 + * 6) Re-adds and re-registers a custom toolbar with the same 1.39 + * ID and options as the first one. 1.40 + * 7) Enters customize mode and checks that the widget is 1.41 + * properly back in the toolbar. 1.42 + * 8) Exits customize mode, removes and de-registers the 1.43 + * toolbar, and resets the toolbars to default. 1.44 + */ 1.45 +function checkRestoredPresence(aWidgetID, aLegacy) { 1.46 + return Task.spawn(function* () { 1.47 + let testBar = createTestBar(aLegacy); 1.48 + CustomizableUI.addWidgetToArea(aWidgetID, kTestBarID); 1.49 + let placement = CustomizableUI.getPlacementOfWidget(aWidgetID); 1.50 + is(placement.area, kTestBarID, 1.51 + "Expected " + aWidgetID + " to be in the test toolbar"); 1.52 + 1.53 + CustomizableUI.unregisterArea(testBar.id); 1.54 + testBar.remove(); 1.55 + 1.56 + let placement = CustomizableUI.getPlacementOfWidget(aWidgetID); 1.57 + is(placement, null, "Expected " + aWidgetID + " to be in the palette"); 1.58 + 1.59 + testBar = createTestBar(aLegacy); 1.60 + 1.61 + yield startCustomizing(); 1.62 + let placement = CustomizableUI.getPlacementOfWidget(aWidgetID); 1.63 + is(placement.area, kTestBarID, 1.64 + "Expected " + aWidgetID + " to be in the test toolbar"); 1.65 + yield endCustomizing(); 1.66 + 1.67 + CustomizableUI.unregisterArea(testBar.id); 1.68 + testBar.remove(); 1.69 + 1.70 + yield resetCustomization(); 1.71 + }); 1.72 +} 1.73 + 1.74 +add_task(function* () { 1.75 + yield checkRestoredPresence("downloads-button", false); 1.76 + yield checkRestoredPresence("downloads-button", true); 1.77 +}); 1.78 + 1.79 +add_task(function* () { 1.80 + yield checkRestoredPresence("characterencoding-button", false); 1.81 + yield checkRestoredPresence("characterencoding-button", true); 1.82 +});