browser_toolbox_toolbar_overflow_button_visibility.js (2413B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test for the toolbox tabs rearrangement when the visibility of toolbox buttons were changed. 7 8 const { Toolbox } = require("resource://devtools/client/framework/toolbox.js"); 9 10 add_task(async function () { 11 const tab = await addTab("about:blank"); 12 const toolbox = await openToolboxForTab( 13 tab, 14 "options", 15 Toolbox.HostType.BOTTOM 16 ); 17 const toolboxButtonPreferences = toolbox.toolbarButtons.map( 18 button => button.visibilityswitch 19 ); 20 21 const win = getWindow(toolbox); 22 const { outerWidth: originalWindowWidth, outerHeight: originalWindowHeight } = 23 win; 24 registerCleanupFunction(() => { 25 for (const preference of toolboxButtonPreferences) { 26 Services.prefs.clearUserPref(preference); 27 } 28 29 win.resizeTo(originalWindowWidth, originalWindowHeight); 30 }); 31 32 const optionsTool = toolbox.getCurrentPanel(); 33 const checkButtons = optionsTool.panelWin.document.querySelectorAll( 34 "#enabled-toolbox-buttons-box input[type=checkbox]" 35 ); 36 37 info( 38 "Test the count of shown devtools tab after making all buttons to be visible" 39 ); 40 await resizeWindow(toolbox, 800); 41 42 // Bug 1770282 - On MacOS the tabs aren't available right away and could cause intermittent failure 43 await waitFor(() => { 44 return !!toolbox.doc.querySelector(".devtools-tab"); 45 }); 46 47 // Once, make all toolbox button to be invisible. 48 setToolboxButtonsVisibility(checkButtons, false); 49 // Get count of shown devtools tab elements. 50 const initialTabCount = toolbox.doc.querySelectorAll(".devtools-tab").length; 51 // Make all toolbox button to be visible. 52 setToolboxButtonsVisibility(checkButtons, true); 53 Assert.less( 54 toolbox.doc.querySelectorAll(".devtools-tab").length, 55 initialTabCount, 56 "Count of shown devtools tab should decreased" 57 ); 58 59 info( 60 "Test the count of shown devtools tab after making all buttons to be invisible" 61 ); 62 setToolboxButtonsVisibility(checkButtons, false); 63 is( 64 toolbox.doc.querySelectorAll(".devtools-tab").length, 65 initialTabCount, 66 "Count of shown devtools tab should be same to 1st count" 67 ); 68 }); 69 70 function setToolboxButtonsVisibility(checkButtons, doVisible) { 71 for (const checkButton of checkButtons) { 72 if (checkButton.checked === doVisible) { 73 continue; 74 } 75 76 checkButton.click(); 77 } 78 }