test_menuitem_ctrl_click.xhtml (2496B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> 3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 4 <!-- 5 https://bugzilla.mozilla.org/show_bug.cgi?id=1630828 6 --> 7 <window title="Mozilla Bug 1630828" 8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 9 onload=""> 10 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 11 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> 12 13 <!-- test results are displayed in the html:body --> 14 <body xmlns="http://www.w3.org/1999/xhtml"> 15 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1630828" 16 target="_blank">Mozilla Bug 1630828</a> 17 </body> 18 19 <hbox align="center" pack="center"> 20 <menulist id="menu"> 21 <menupopup id="popup"> 22 <menuitem label="Target" id="target" /> 23 </menupopup> 24 </menulist> 25 </hbox> 26 <!-- test code goes here --> 27 <script type="application/javascript"> 28 <![CDATA[ 29 30 const { AppConstants } = SpecialPowers.ChromeUtils.importESModule( 31 "resource://gre/modules/AppConstants.sys.mjs" 32 ); 33 34 function waitForEvent(target, event) { 35 info(`Waiting for ${event} event.`); 36 return new Promise(resolve => { 37 target.addEventListener(event, resolve, { once: true }); 38 }); 39 } 40 41 function waitForIdle() { 42 return new Promise(resolve => { 43 SpecialPowers.Services.tm.idleDispatchToMainThread(resolve); 44 }); 45 } 46 47 add_setup(async function() { 48 await SimpleTest.promiseFocus(); 49 }); 50 51 add_task(async function test_ctrl_click() { 52 const isMac = AppConstants.platform === "macosx"; 53 54 let popup = document.getElementById("popup"); 55 let promise = waitForEvent(popup, "popupshown"); 56 let menu = document.getElementById("menu"); 57 synthesizeMouseAtCenter(menu, {}); 58 // Wait for popup open. 59 await promise; 60 61 let commandReceived = false; 62 menu.addEventListener("command", function(e) { 63 ok(!isMac, `${AppConstants.platform} receives command event`); 64 commandReceived = true; 65 }); 66 67 // Ctrl click in Mac won't dispatch command event and close popup, so we wait 68 // for idle instead. 69 promise = isMac ? waitForIdle() : waitForEvent(popup, "popuphidden"); 70 let target = document.getElementById("target"); 71 synthesizeMouseAtCenter(target, { ctrlKey: true }); 72 await promise; 73 74 is(commandReceived, !isMac, `Check command event for ${AppConstants.platform}`); 75 is(popup.state, isMac ? "open" : "closed", `Check popup state for ${AppConstants.platform}`); 76 }); 77 78 ]]> 79 </script> 80 </window>