browser_contextmenu_iframe.js (1998B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const TEST_LINK = "https://example.com/"; 7 const RESOURCE_LINK = 8 getRootDirectory(gTestPath).replace( 9 "chrome://mochitests/content", 10 "https://example.com" 11 ) + "test_contextmenu_iframe.html"; 12 13 /* This test checks that a context menu can open up 14 * a frame into it's own tab. */ 15 16 add_task(async function test_open_iframe() { 17 let testTab = await BrowserTestUtils.openNewForegroundTab( 18 gBrowser, 19 RESOURCE_LINK 20 ); 21 const selector = "#iframe"; 22 const openPromise = BrowserTestUtils.waitForNewTab( 23 gBrowser, 24 TEST_LINK, 25 false 26 ); 27 const contextMenu = document.getElementById("contentAreaContextMenu"); 28 is(contextMenu.state, "closed", "checking if popup is closed"); 29 let awaitPopupShown = BrowserTestUtils.waitForEvent( 30 contextMenu, 31 "popupshown" 32 ); 33 await BrowserTestUtils.synthesizeMouseAtCenter( 34 selector, 35 { 36 type: "contextmenu", 37 button: 2, 38 centered: true, 39 }, 40 gBrowser.selectedBrowser 41 ); 42 await awaitPopupShown; 43 info("Popup Shown"); 44 const awaitPopupHidden = BrowserTestUtils.waitForEvent( 45 contextMenu, 46 "popuphidden" 47 ); 48 49 // Open frame submenu 50 const frameItem = contextMenu.querySelector("#frame"); 51 const menuPopup = frameItem.menupopup; 52 const menuPopupPromise = BrowserTestUtils.waitForEvent( 53 menuPopup, 54 "popupshown" 55 ); 56 frameItem.openMenu(true); 57 await menuPopupPromise; 58 59 let domItem = contextMenu.querySelector("#context-openframeintab"); 60 info("Going to click item " + domItem.id); 61 ok( 62 BrowserTestUtils.isVisible(domItem), 63 "DOM context menu item tab should be visible" 64 ); 65 ok(!domItem.disabled, "DOM context menu item tab shouldn't be disabled"); 66 contextMenu.activateItem(domItem); 67 68 let openedTab = await openPromise; 69 await awaitPopupHidden; 70 await BrowserTestUtils.removeTab(openedTab); 71 72 BrowserTestUtils.removeTab(testTab); 73 });