browser_947987_removable_default.js (2849B)
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 var kWidgetId = "test-removable-widget-default"; 8 const kNavBar = CustomizableUI.AREA_NAVBAR; 9 var widgetCounter = 0; 10 11 registerCleanupFunction(removeCustomToolbars); 12 13 // Sanity checks 14 add_task(function () { 15 let brokenSpec = { id: kWidgetId + widgetCounter++, removable: false }; 16 SimpleTest.doesThrow( 17 () => CustomizableUI.createWidget(brokenSpec), 18 "Creating non-removable widget without defaultArea should throw." 19 ); 20 21 // Widget without removable set should be removable: 22 let wrapper = CustomizableUI.createWidget({ 23 id: kWidgetId + widgetCounter++, 24 }); 25 ok( 26 CustomizableUI.isWidgetRemovable(wrapper.id), 27 "Should be removable by default." 28 ); 29 CustomizableUI.destroyWidget(wrapper.id); 30 }); 31 32 // Test non-removable widget with defaultArea 33 add_task(async function () { 34 // Non-removable widget with defaultArea should work: 35 let spec = { 36 id: kWidgetId + widgetCounter++, 37 removable: false, 38 defaultArea: kNavBar, 39 }; 40 let widgetWrapper; 41 try { 42 widgetWrapper = CustomizableUI.createWidget(spec); 43 } catch (ex) { 44 ok( 45 false, 46 "Creating a non-removable widget with a default area should not throw." 47 ); 48 return; 49 } 50 51 let placement = CustomizableUI.getPlacementOfWidget(spec.id); 52 ok(placement, "Widget should be placed."); 53 is(placement.area, kNavBar, "Widget should be in navbar"); 54 let singleWrapper = widgetWrapper.forWindow(window); 55 ok(singleWrapper, "Widget should exist in window."); 56 ok(singleWrapper.node, "Widget node should exist in window."); 57 let expectedParent = CustomizableUI.getCustomizeTargetForArea( 58 kNavBar, 59 window 60 ); 61 is( 62 singleWrapper.node.parentNode, 63 expectedParent, 64 "Widget should be in navbar." 65 ); 66 67 let otherWin = await openAndLoadWindow(true); 68 placement = CustomizableUI.getPlacementOfWidget(spec.id); 69 ok(placement, "Widget should be placed."); 70 is(placement && placement.area, kNavBar, "Widget should be in navbar"); 71 72 singleWrapper = widgetWrapper.forWindow(otherWin); 73 ok(singleWrapper, "Widget should exist in other window."); 74 if (singleWrapper) { 75 ok(singleWrapper.node, "Widget node should exist in other window."); 76 if (singleWrapper.node) { 77 let expectedParentInOtherWin = CustomizableUI.getCustomizeTargetForArea( 78 kNavBar, 79 otherWin 80 ); 81 is( 82 singleWrapper.node.parentNode, 83 expectedParentInOtherWin, 84 "Widget should be in navbar in other window." 85 ); 86 } 87 } 88 CustomizableUI.destroyWidget(spec.id); 89 await promiseWindowClosed(otherWin); 90 }); 91 92 add_task(async function asyncCleanup() { 93 await resetCustomization(); 94 });