1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/customizableui/test/browser_940013_registerToolbarNode_calls_registerArea.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,70 @@ 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 kToolbarId = "test-registerToolbarNode-toolbar"; 1.11 +const kButtonId = "test-registerToolbarNode-button"; 1.12 +registerCleanupFunction(cleanup); 1.13 + 1.14 +// Registering a toolbar with defaultset attribute should work 1.15 +add_task(function() { 1.16 + ok(CustomizableUI.inDefaultState, "Everything should be in its default state."); 1.17 + let btn = createDummyXULButton(kButtonId); 1.18 + let toolbar = document.createElement("toolbar"); 1.19 + toolbar.id = kToolbarId; 1.20 + toolbar.setAttribute("customizable", true); 1.21 + toolbar.setAttribute("defaultset", kButtonId); 1.22 + gNavToolbox.appendChild(toolbar); 1.23 + ok(CustomizableUI.areas.indexOf(kToolbarId) != -1, 1.24 + "Toolbar should have been registered automatically."); 1.25 + is(CustomizableUI.getAreaType(kToolbarId), CustomizableUI.TYPE_TOOLBAR, 1.26 + "Area should be registered as toolbar"); 1.27 + assertAreaPlacements(kToolbarId, [kButtonId]); 1.28 + ok(!CustomizableUI.inDefaultState, "No longer in default state after toolbar is registered and visible."); 1.29 + CustomizableUI.unregisterArea(kToolbarId, true); 1.30 + toolbar.remove(); 1.31 + ok(CustomizableUI.inDefaultState, "Everything should be in its default state."); 1.32 + btn.remove(); 1.33 +}); 1.34 + 1.35 +// Registering a toolbar without a defaultset attribute should 1.36 +// wait for the registerArea call 1.37 +add_task(function() { 1.38 + ok(CustomizableUI.inDefaultState, "Everything should be in its default state."); 1.39 + let btn = createDummyXULButton(kButtonId); 1.40 + let toolbar = document.createElement("toolbar"); 1.41 + toolbar.id = kToolbarId; 1.42 + toolbar.setAttribute("customizable", true); 1.43 + gNavToolbox.appendChild(toolbar); 1.44 + ok(CustomizableUI.areas.indexOf(kToolbarId) == -1, 1.45 + "Toolbar should not yet have been registered automatically."); 1.46 + CustomizableUI.registerArea(kToolbarId, {defaultPlacements: [kButtonId]}); 1.47 + ok(CustomizableUI.areas.indexOf(kToolbarId) != -1, 1.48 + "Toolbar should have been registered now."); 1.49 + is(CustomizableUI.getAreaType(kToolbarId), CustomizableUI.TYPE_TOOLBAR, 1.50 + "Area should be registered as toolbar"); 1.51 + assertAreaPlacements(kToolbarId, [kButtonId]); 1.52 + ok(!CustomizableUI.inDefaultState, "No longer in default state after toolbar is registered and visible."); 1.53 + CustomizableUI.unregisterArea(kToolbarId, true); 1.54 + toolbar.remove(); 1.55 + ok(CustomizableUI.inDefaultState, "Everything should be in its default state."); 1.56 + btn.remove(); 1.57 +}); 1.58 + 1.59 +add_task(function asyncCleanup() { 1.60 + yield resetCustomization(); 1.61 +}); 1.62 + 1.63 +function cleanup() { 1.64 + let toolbar = document.getElementById(kToolbarId); 1.65 + if (toolbar) { 1.66 + toolbar.remove(); 1.67 + } 1.68 + let btn = document.getElementById(kButtonId) || 1.69 + gNavToolbox.querySelector("#" + kButtonId); 1.70 + if (btn) { 1.71 + btn.remove(); 1.72 + } 1.73 +}