browser_hidden_widget_overflow.js (3896B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Tests that if only hidden widgets are overflowed that the 8 * OverflowableToolbar won't show the overflow panel anchor. 9 */ 10 11 const kHiddenButtonID = "fake-hidden-button"; 12 const kDisplayNoneButtonID = "display-none-button"; 13 const kWebExtensionButtonID1 = "fake-webextension-button-1"; 14 const kWebExtensionButtonID2 = "fake-webextension-button-2"; 15 let gWin = null; 16 17 add_setup(async function () { 18 gWin = await BrowserTestUtils.openNewBrowserWindow(); 19 20 // To make it easier to write a test where we can control overflowing 21 // for a test that can run in a bunch of environments with slightly 22 // different rules on when things will overflow, we'll go ahead and 23 // just remove everything removable from the nav-bar by default. Then 24 // we'll add our hidden item, and a single WebExtension item, and 25 // force toolbar overflow. 26 let widgetIDs = CustomizableUI.getWidgetIdsInArea(CustomizableUI.AREA_NAVBAR); 27 for (let widgetID of widgetIDs) { 28 if (CustomizableUI.isWidgetRemovable(widgetID)) { 29 CustomizableUI.removeWidgetFromArea(widgetID); 30 } 31 } 32 33 CustomizableUI.createWidget({ 34 id: kWebExtensionButtonID1, 35 label: "Test WebExtension widget 1", 36 defaultArea: CustomizableUI.AREA_NAVBAR, 37 webExtension: true, 38 }); 39 40 CustomizableUI.createWidget({ 41 id: kWebExtensionButtonID2, 42 label: "Test WebExtension widget 2", 43 defaultArea: CustomizableUI.AREA_NAVBAR, 44 webExtension: true, 45 }); 46 47 // Let's force the WebExtension widgets to be significantly wider. This 48 // just makes it easier to ensure that both of these (which are to the left 49 // of the hidden widget) get overflowed. 50 for (let webExtID of [kWebExtensionButtonID1, kWebExtensionButtonID2]) { 51 let webExtNode = CustomizableUI.getWidget(webExtID).forWindow(gWin).node; 52 webExtNode.style.minWidth = "150px"; 53 } 54 55 CustomizableUI.createWidget({ 56 id: kHiddenButtonID, 57 label: "Test hidden=true widget", 58 defaultArea: CustomizableUI.AREA_NAVBAR, 59 }); 60 61 // Now hide the button with hidden=true so that it has no dimensions. 62 let hiddenButtonNode = 63 CustomizableUI.getWidget(kHiddenButtonID).forWindow(gWin).node; 64 hiddenButtonNode.hidden = true; 65 66 CustomizableUI.createWidget({ 67 id: kDisplayNoneButtonID, 68 label: "Test display:none widget", 69 defaultArea: CustomizableUI.AREA_NAVBAR, 70 }); 71 72 // Now hide the button with display: none so that it has no dimensions. 73 let displayNoneButtonNode = 74 CustomizableUI.getWidget(kDisplayNoneButtonID).forWindow(gWin).node; 75 displayNoneButtonNode.style.display = "none"; 76 77 registerCleanupFunction(async () => { 78 CustomizableUI.destroyWidget(kWebExtensionButtonID1); 79 CustomizableUI.destroyWidget(kWebExtensionButtonID2); 80 CustomizableUI.destroyWidget(kHiddenButtonID); 81 CustomizableUI.destroyWidget(kDisplayNoneButtonID); 82 await BrowserTestUtils.closeWindow(gWin); 83 await CustomizableUI.reset(); 84 }); 85 }); 86 87 add_task(async function test_hidden_widget_overflow() { 88 gWin.resizeTo(kForceOverflowWidthPx, window.outerHeight); 89 90 // Wait until the left-most fake WebExtension button is overflowing. 91 let webExtNode = CustomizableUI.getWidget(kWebExtensionButtonID1).forWindow( 92 gWin 93 ).node; 94 await BrowserTestUtils.waitForMutationCondition( 95 webExtNode, 96 { attributes: true }, 97 () => { 98 return webExtNode.hasAttribute("overflowedItem"); 99 } 100 ); 101 102 let hiddenButtonNode = 103 CustomizableUI.getWidget(kHiddenButtonID).forWindow(gWin).node; 104 Assert.ok( 105 hiddenButtonNode.hasAttribute("overflowedItem"), 106 "Hidden button should be overflowed." 107 ); 108 109 let overflowButton = gWin.document.getElementById("nav-bar-overflow-button"); 110 111 Assert.ok( 112 !BrowserTestUtils.isVisible(overflowButton), 113 "Overflow panel button should be hidden." 114 ); 115 });