browser_890262_destroyWidget_after_add_to_panel.js (1957B)
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 kLazyAreaId = "test-890262-lazy-area"; 8 const kWidget1Id = "test-890262-widget1"; 9 const kWidget2Id = "test-890262-widget2"; 10 11 setupArea(); 12 13 // Destroying a widget after defaulting it to a lazy area should work. 14 add_task(function () { 15 CustomizableUI.createWidget({ 16 id: kWidget1Id, 17 removable: true, 18 defaultArea: kLazyAreaId, 19 }); 20 let noError = true; 21 try { 22 CustomizableUI.destroyWidget(kWidget1Id); 23 } catch (ex) { 24 console.error(ex); 25 noError = false; 26 } 27 ok( 28 noError, 29 "Shouldn't throw an exception for a widget that was created in a not-yet-constructed area" 30 ); 31 }); 32 33 // Destroying a widget after moving it to a lazy area should work. 34 add_task(function () { 35 CustomizableUI.createWidget({ 36 id: kWidget2Id, 37 removable: true, 38 defaultArea: CustomizableUI.AREA_NAVBAR, 39 }); 40 41 CustomizableUI.addWidgetToArea(kWidget2Id, kLazyAreaId); 42 let noError = true; 43 try { 44 CustomizableUI.destroyWidget(kWidget2Id); 45 } catch (ex) { 46 console.error(ex); 47 noError = false; 48 } 49 ok( 50 noError, 51 "Shouldn't throw an exception for a widget that was added to a not-yet-constructed area" 52 ); 53 }); 54 55 add_task(async function asyncCleanup() { 56 let lazyArea = document.getElementById(kLazyAreaId); 57 if (lazyArea) { 58 lazyArea.remove(); 59 } 60 try { 61 CustomizableUI.unregisterArea(kLazyAreaId); 62 } catch (ex) {} // If we didn't register successfully for some reason 63 await resetCustomization(); 64 }); 65 66 function setupArea() { 67 let lazyArea = document.createXULElement("hbox"); 68 lazyArea.id = kLazyAreaId; 69 document.getElementById("nav-bar").appendChild(lazyArea); 70 CustomizableUI.registerArea(kLazyAreaId, { 71 type: CustomizableUI.TYPE_TOOLBAR, 72 defaultPlacements: [], 73 }); 74 }