browser_940013_registerToolbarNode_calls_registerArea.js (1928B)
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/. */ 4 5 "use strict"; 6 7 const kToolbarId = "test-registerToolbarNode-toolbar"; 8 const kButtonId = "test-registerToolbarNode-button"; 9 registerCleanupFunction(cleanup); 10 11 // Registering a toolbar without a defaultset attribute should 12 // wait for the registerArea call 13 add_task(async function () { 14 ok( 15 CustomizableUI.inDefaultState, 16 "Everything should be in its default state." 17 ); 18 let btn = createDummyXULButton(kButtonId); 19 let toolbar = document.createXULElement("toolbar"); 20 toolbar.id = kToolbarId; 21 toolbar.setAttribute("customizable", true); 22 gNavToolbox.appendChild(toolbar); 23 CustomizableUI.registerToolbarNode(toolbar); 24 ok( 25 !CustomizableUI.areas.includes(kToolbarId), 26 "Toolbar should not yet have been registered automatically." 27 ); 28 CustomizableUI.registerArea(kToolbarId, { defaultPlacements: [kButtonId] }); 29 ok( 30 CustomizableUI.areas.includes(kToolbarId), 31 "Toolbar should have been registered now." 32 ); 33 is( 34 CustomizableUI.getAreaType(kToolbarId), 35 CustomizableUI.TYPE_TOOLBAR, 36 "Area should be registered as toolbar" 37 ); 38 assertAreaPlacements(kToolbarId, [kButtonId]); 39 ok( 40 !CustomizableUI.inDefaultState, 41 "No longer in default state after toolbar is registered and visible." 42 ); 43 CustomizableUI.unregisterArea(kToolbarId, true); 44 toolbar.remove(); 45 ok( 46 CustomizableUI.inDefaultState, 47 "Everything should be in its default state." 48 ); 49 btn.remove(); 50 }); 51 52 async function cleanup() { 53 let toolbar = document.getElementById(kToolbarId); 54 if (toolbar) { 55 toolbar.remove(); 56 } 57 let btn = 58 document.getElementById(kButtonId) || 59 gNavToolbox.querySelector("#" + kButtonId); 60 if (btn) { 61 btn.remove(); 62 } 63 await resetCustomization(); 64 }