Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android'
- Manifest: layout/xul/test/chrome.toml
<?xml version="1.0"?>
<!--
-->
onload="">
<!-- test results are displayed in the html:body -->
</body>
<hbox align="center" pack="center">
<menulist id="menu">
<menupopup id="popup">
<menuitem label="Target" id="target" />
</menupopup>
</menulist>
</hbox>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
const { AppConstants } = SpecialPowers.ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
function waitForEvent(target, event) {
info(`Waiting for ${event} event.`);
return new Promise(resolve => {
target.addEventListener(event, resolve, { once: true });
});
}
function waitForIdle() {
return new Promise(resolve => {
SpecialPowers.Services.tm.idleDispatchToMainThread(resolve);
});
}
add_setup(async function() {
await SimpleTest.promiseFocus();
});
add_task(async function test_ctrl_click() {
const isMac = AppConstants.platform === "macosx";
let popup = document.getElementById("popup");
let promise = waitForEvent(popup, "popupshown");
let menu = document.getElementById("menu");
synthesizeMouseAtCenter(menu, {});
// Wait for popup open.
await promise;
let commandReceived = false;
menu.addEventListener("command", function(e) {
ok(!isMac, `${AppConstants.platform} receives command event`);
commandReceived = true;
});
// Ctrl click in Mac won't dispatch command event and close popup, so we wait
// for idle instead.
promise = isMac ? waitForIdle() : waitForEvent(popup, "popuphidden");
let target = document.getElementById("target");
synthesizeMouseAtCenter(target, { ctrlKey: true });
await promise;
is(commandReceived, !isMac, `Check command event for ${AppConstants.platform}`);
is(popup.state, isMac ? "open" : "closed", `Check popup state for ${AppConstants.platform}`);
});
]]>
</script>
</window>