browser_980155_add_overflow_toolbar.js (2542B)
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 kToolbarName = "test-new-overflowable-toolbar"; 8 const kTestWidgetPrefix = "test-widget-for-overflowable-toolbar-"; 9 10 add_task(async function addOverflowingToolbar() { 11 let originalWindowWidth = window.outerWidth; 12 13 let widgetIds = []; 14 registerCleanupFunction(() => { 15 try { 16 for (let id of widgetIds) { 17 CustomizableUI.destroyWidget(id); 18 } 19 } catch (ex) { 20 console.error(ex); 21 } 22 }); 23 24 for (let i = 0; i < 10; i++) { 25 let id = kTestWidgetPrefix + i; 26 widgetIds.push(id); 27 let spec = { 28 id, 29 type: "button", 30 removable: true, 31 label: "test", 32 tooltiptext: "" + i, 33 }; 34 CustomizableUI.createWidget(spec); 35 } 36 37 let toolbarNode = createOverflowableToolbarWithPlacements( 38 kToolbarName, 39 widgetIds 40 ); 41 assertAreaPlacements(kToolbarName, widgetIds); 42 43 for (let id of widgetIds) { 44 document.getElementById(id).style.minWidth = "200px"; 45 } 46 47 isnot( 48 toolbarNode.overflowable, 49 null, 50 "Toolbar should have overflowable controller" 51 ); 52 isnot( 53 CustomizableUI.getCustomizationTarget(toolbarNode), 54 null, 55 "Toolbar should have customization target" 56 ); 57 isnot( 58 CustomizableUI.getCustomizationTarget(toolbarNode), 59 toolbarNode, 60 "Customization target should not be toolbar node" 61 ); 62 63 let oldChildCount = 64 CustomizableUI.getCustomizationTarget(toolbarNode).childElementCount; 65 let overflowableList = document.getElementById( 66 kToolbarName + "-overflow-list" 67 ); 68 let oldOverflowCount = overflowableList.childElementCount; 69 70 isnot(oldChildCount, 0, "Toolbar should have non-overflowing widgets"); 71 72 window.resizeTo(kForceOverflowWidthPx, window.outerHeight); 73 await TestUtils.waitForCondition(() => 74 toolbarNode.hasAttribute("overflowing") 75 ); 76 ok( 77 toolbarNode.hasAttribute("overflowing"), 78 "Should have an overflowing toolbar." 79 ); 80 Assert.less( 81 CustomizableUI.getCustomizationTarget(toolbarNode).childElementCount, 82 oldChildCount, 83 "Should have fewer children." 84 ); 85 Assert.greater( 86 overflowableList.childElementCount, 87 oldOverflowCount, 88 "Should have more overflowed widgets." 89 ); 90 91 window.resizeTo(originalWindowWidth, window.outerHeight); 92 }); 93 94 add_task(async function asyncCleanup() { 95 removeCustomToolbars(); 96 await resetCustomization(); 97 });