browser_create_button_widget.js (2701B)
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 kButton = "test_dynamically_created_button"; 8 var initialLocation = gBrowser.currentURI.spec; 9 10 add_task(async function () { 11 info("Check dynamically created button functionality"); 12 13 // Let's create a simple button that will open about:addons. 14 let widgetSpec = { 15 id: kButton, 16 type: "button", 17 tooltiptext: "I am an accessible name", 18 onClick() { 19 gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "about:addons"); 20 }, 21 }; 22 CustomizableUI.createWidget(widgetSpec); 23 CustomizableUI.addWidgetToArea(kButton, CustomizableUI.AREA_NAVBAR); 24 ok( 25 !CustomizableUI.isWebExtensionWidget(kButton), 26 "This button should not be considered an extension widget." 27 ); 28 29 // check the button's functionality in navigation bar 30 let button = document.getElementById(kButton); 31 let navBar = document.getElementById("nav-bar"); 32 ok(button, "Dynamically created button exists"); 33 ok(navBar.contains(button), "Dynamically created button is in the navbar"); 34 await checkButtonFunctionality(button); 35 36 resetTabs(); 37 38 // move the add-on button in the Panel Menu 39 CustomizableUI.addWidgetToArea( 40 kButton, 41 CustomizableUI.AREA_FIXED_OVERFLOW_PANEL 42 ); 43 ok( 44 !navBar.contains(button), 45 "Dynamically created button was removed from the browser bar" 46 ); 47 48 await waitForOverflowButtonShown(); 49 50 // check the button's functionality in the Overflow Panel. 51 await document.getElementById("nav-bar").overflowable.show(); 52 var panelMenu = document.getElementById("widget-overflow-mainView"); 53 let buttonInPanel = panelMenu.getElementsByAttribute("id", kButton); 54 ok( 55 panelMenu.contains(button), 56 "Dynamically created button was added to the Panel Menu" 57 ); 58 await checkButtonFunctionality(buttonInPanel[0]); 59 }); 60 61 add_task(async function asyncCleanup() { 62 resetTabs(); 63 64 // reset the UI to the default state 65 await resetCustomization(); 66 ok(CustomizableUI.inDefaultState, "The UI is in default state again."); 67 68 // destroy the widget 69 CustomizableUI.destroyWidget(kButton); 70 }); 71 72 function resetTabs() { 73 // close all opened tabs 74 while (gBrowser.tabs.length > 1) { 75 gBrowser.removeTab(gBrowser.selectedTab); 76 } 77 78 // restore the initial tab 79 BrowserTestUtils.addTab(gBrowser, initialLocation); 80 gBrowser.removeTab(gBrowser.selectedTab); 81 } 82 83 async function checkButtonFunctionality(aButton) { 84 aButton.click(); 85 await BrowserTestUtils.browserLoaded( 86 gBrowser.selectedBrowser, 87 false, 88 "about:addons" 89 ); 90 }