forked from mirrors/gecko-dev
		
	 a14c746228
			
		
	
	
		a14c746228
		
	
	
	
	
		
			
			Bug 1805414 will move menu event handling to the DOM. With that change the current synthetic click behavior of XUL menuitems breaks. On current central, we rely on nsMenuFrame::HandleEvent not getting called at all for synthetic clicks, and instead we just fire a command event synchronously here: https://searchfox.org/mozilla-central/rev/a0d4f8f112c5c792ae272bf6ce50763ddd23ffa2/dom/xul/nsXULElement.cpp#1071 After my patch the command event is fired properly (potentially asynchronously too) by the regular menu activation machinery, which is preferable. * They fire a command event synchronously (even though on some platforms like macOS activating a context menu item is async). * They use a totally different codepath from what a user does. * They don't deal with native menus, etc. We have a proper API for this (activateItem) which takes a much more closer codepath to what users do, requires that the menu is shown, etc. Use that API instead for testing. As a benefit, tests now do not need to close the context menu manually when clicking on a menu item (because we trigger the same code path as users clicking the menu). Differential Revision: https://phabricator.services.mozilla.com/D164567
		
			
				
	
	
		
			73 lines
		
	
	
	
		
			2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			73 lines
		
	
	
	
		
			2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /* Any copyright is dedicated to the Public Domain.
 | |
|    http://creativecommons.org/publicdomain/zero/1.0/ */
 | |
| 
 | |
| "use strict";
 | |
| 
 | |
| const TEST_LINK = "https://example.com/";
 | |
| const RESOURCE_LINK =
 | |
|   getRootDirectory(gTestPath).replace(
 | |
|     "chrome://mochitests/content",
 | |
|     "https://example.com"
 | |
|   ) + "test_contextmenu_iframe.html";
 | |
| 
 | |
| /* This test checks that a context menu can open up
 | |
|  * a frame into it's own tab. */
 | |
| 
 | |
| add_task(async function test_open_iframe() {
 | |
|   let testTab = await BrowserTestUtils.openNewForegroundTab(
 | |
|     gBrowser,
 | |
|     RESOURCE_LINK
 | |
|   );
 | |
|   const selector = "#iframe";
 | |
|   const openPromise = BrowserTestUtils.waitForNewTab(
 | |
|     gBrowser,
 | |
|     TEST_LINK,
 | |
|     false
 | |
|   );
 | |
|   const contextMenu = document.getElementById("contentAreaContextMenu");
 | |
|   is(contextMenu.state, "closed", "checking if popup is closed");
 | |
|   let awaitPopupShown = BrowserTestUtils.waitForEvent(
 | |
|     contextMenu,
 | |
|     "popupshown"
 | |
|   );
 | |
|   await BrowserTestUtils.synthesizeMouseAtCenter(
 | |
|     selector,
 | |
|     {
 | |
|       type: "contextmenu",
 | |
|       button: 2,
 | |
|       centered: true,
 | |
|     },
 | |
|     gBrowser.selectedBrowser
 | |
|   );
 | |
|   await awaitPopupShown;
 | |
|   info("Popup Shown");
 | |
|   const awaitPopupHidden = BrowserTestUtils.waitForEvent(
 | |
|     contextMenu,
 | |
|     "popuphidden"
 | |
|   );
 | |
| 
 | |
|   // Open frame submenu
 | |
|   const frameItem = contextMenu.querySelector("#frame");
 | |
|   const menuPopup = frameItem.menupopup;
 | |
|   const menuPopupPromise = BrowserTestUtils.waitForEvent(
 | |
|     menuPopup,
 | |
|     "popupshown"
 | |
|   );
 | |
|   frameItem.openMenu(true);
 | |
|   await menuPopupPromise;
 | |
| 
 | |
|   let domItem = contextMenu.querySelector("#context-openframeintab");
 | |
|   info("Going to click item " + domItem.id);
 | |
|   ok(
 | |
|     BrowserTestUtils.is_visible(domItem),
 | |
|     "DOM context menu item tab should be visible"
 | |
|   );
 | |
|   ok(!domItem.disabled, "DOM context menu item tab shouldn't be disabled");
 | |
|   contextMenu.activateItem(domItem);
 | |
| 
 | |
|   let openedTab = await openPromise;
 | |
|   await awaitPopupHidden;
 | |
|   await BrowserTestUtils.removeTab(openedTab);
 | |
| 
 | |
|   BrowserTestUtils.removeTab(testTab);
 | |
| });
 |