browser_popupNotification_selection_required.js (1860B)
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 function test() { 6 waitForExplicitFinish(); 7 8 ok(PopupNotifications, "PopupNotifications object exists"); 9 ok(PopupNotifications.panel, "PopupNotifications panel exists"); 10 11 setup(); 12 } 13 14 function promiseElementVisible(element) { 15 // HTMLElement.offsetParent is null when the element is not visisble 16 // (or if the element has |position: fixed|). See: 17 // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent 18 return TestUtils.waitForCondition( 19 () => element.offsetParent !== null, 20 "Waiting for element to be visible" 21 ); 22 } 23 24 var gNotification; 25 26 var tests = [ 27 // Test that passing selection required prevents the button from clicking 28 { 29 id: "require_selection_check", 30 run() { 31 this.notifyObj = new BasicNotification(this.id); 32 this.notifyObj.options.checkbox = { 33 label: "This is a checkbox", 34 }; 35 gNotification = showNotification(this.notifyObj); 36 }, 37 async onShown(popup) { 38 checkPopup(popup, this.notifyObj); 39 let notification = popup.children[0]; 40 notification.setAttribute("invalidselection", true); 41 await promiseElementVisible(notification.checkbox); 42 EventUtils.synthesizeMouseAtCenter(notification.checkbox, {}); 43 ok( 44 notification.button.disabled, 45 "should be disabled when invalidselection" 46 ); 47 notification.removeAttribute("invalidselection"); 48 EventUtils.synthesizeMouseAtCenter(notification.checkbox, {}); 49 ok( 50 !notification.button.disabled, 51 "should not be disabled when invalidselection is not present" 52 ); 53 triggerMainCommand(popup); 54 }, 55 onHidden() {}, 56 }, 57 ];