From 7edc39647c3aded03c2f93f4a27c4058bed0b5cb Mon Sep 17 00:00:00 2001 From: Markus Stange <mstange.moz@gmail.com> Date: Tue, 13 Apr 2021 16:22:15 +0000 Subject: [PATCH] Bug 1704569 - Don't synthesize events on menus in various "reopen in container" tests, and add missing awaits. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D111672 --- ...ser_multiselect_tabs_reopen_in_container.js | 10 +++------- .../test/browser/browser_reopenIn.js | 18 +++++++----------- .../contextualidentity/test/browser/head.js | 11 +++++------ 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/browser/base/content/test/tabs/browser_multiselect_tabs_reopen_in_container.js b/browser/base/content/test/tabs/browser_multiselect_tabs_reopen_in_container.js index 629b0f8de3fee..d190ef8b9b555 100644 --- a/browser/base/content/test/tabs/browser_multiselect_tabs_reopen_in_container.js +++ b/browser/base/content/test/tabs/browser_multiselect_tabs_reopen_in_container.js @@ -17,7 +17,7 @@ async function openTabMenuFor(tab) { } async function openReopenMenuForTab(tab) { - openTabMenuFor(tab); + await openTabMenuFor(tab); let reopenItem = tab.ownerDocument.getElementById( "context_reopenInContainer" @@ -26,11 +26,7 @@ async function openReopenMenuForTab(tab) { let reopenMenu = reopenItem.getElementsByTagName("menupopup")[0]; let reopenMenuShown = BrowserTestUtils.waitForEvent(reopenMenu, "popupshown"); - EventUtils.synthesizeMouseAtCenter( - reopenItem, - { type: "mousemove" }, - tab.ownerGlobal - ); + reopenItem.openMenu(true); await reopenMenuShown; return reopenMenu; @@ -56,7 +52,7 @@ function openTabInContainer(gBrowser, tab, reopenMenu, id) { let menuitem = reopenMenu.querySelector( `menuitem[data-usercontextid="${id}"]` ); - EventUtils.synthesizeMouseAtCenter(menuitem, {}, menuitem.ownerGlobal); + reopenMenu.activateItem(menuitem); return tabPromise; } diff --git a/browser/components/contextualidentity/test/browser/browser_reopenIn.js b/browser/components/contextualidentity/test/browser/browser_reopenIn.js index 2f89bf17f527a..9bda63b201c20 100644 --- a/browser/components/contextualidentity/test/browser/browser_reopenIn.js +++ b/browser/components/contextualidentity/test/browser/browser_reopenIn.js @@ -21,7 +21,7 @@ async function openTabMenuFor(tab) { } async function openReopenMenuForTab(tab) { - openTabMenuFor(tab); + await openTabMenuFor(tab); let reopenItem = tab.ownerDocument.getElementById( "context_reopenInContainer" @@ -30,11 +30,7 @@ async function openReopenMenuForTab(tab) { let reopenMenu = reopenItem.getElementsByTagName("menupopup")[0]; let reopenMenuShown = BrowserTestUtils.waitForEvent(reopenMenu, "popupshown"); - EventUtils.synthesizeMouseAtCenter( - reopenItem, - { type: "mousemove" }, - tab.ownerGlobal - ); + reopenItem.openMenu(true); await reopenMenuShown; return reopenMenu; @@ -60,7 +56,7 @@ function openTabInContainer(gBrowser, reopenMenu, id) { let menuitem = reopenMenu.querySelector( `menuitem[data-usercontextid="${id}"]` ); - EventUtils.synthesizeMouseAtCenter(menuitem, {}, menuitem.ownerGlobal); + reopenMenu.activateItem(menuitem); return tabPromise; } @@ -128,12 +124,12 @@ add_task(async function testDisabled() { "Tab with No Container should be opened" ); - openTabMenuFor(tab); + let tabMenu = await openTabMenuFor(tab); let reopenItem = document.getElementById("context_reopenInContainer"); ok(reopenItem.hidden, "Reopen in Container item should be hidden"); // Close the tab menu. - EventUtils.synthesizeKey("KEY_Escape"); + tabMenu.hidePopup(); BrowserTestUtils.removeTab(tab); }); @@ -155,14 +151,14 @@ add_task(async function testPrivateMode() { "Tab with No Container should be opened" ); - openTabMenuFor(tab); + let tabMenu = await openTabMenuFor(tab); let reopenItem = privateWindow.document.getElementById( "context_reopenInContainer" ); ok(reopenItem.hidden, "Reopen in Container item should be hidden"); // Close the tab menu. - EventUtils.synthesizeKey("KEY_Escape"); + tabMenu.hidePopup(); await BrowserTestUtils.closeWindow(privateWindow); }); diff --git a/browser/components/contextualidentity/test/browser/head.js b/browser/components/contextualidentity/test/browser/head.js index f02c49f248985..b5bf451d2537d 100644 --- a/browser/components/contextualidentity/test/browser/head.js +++ b/browser/components/contextualidentity/test/browser/head.js @@ -13,22 +13,20 @@ async function openTabMenuFor(tab) { } async function openReopenMenuForTab(tab) { - openTabMenuFor(tab); + await openTabMenuFor(tab); let reopenItem = tab.ownerDocument.getElementById( "context_reopenInContainer" ); ok(!reopenItem.hidden, "Reopen in Container item should be shown"); - const menuPopup = tab.ownerDocument.getElementById( - "context_reopenInContainer" - ).menupopup; + const menuPopup = reopenItem.menupopup; const menuPopupPromise = BrowserTestUtils.waitForEvent( menuPopup, "popupshown" ); info(`About to open a popup`); - menuPopup.openPopup(); + reopenItem.openMenu(true); info(`Waiting for the menu popup promise`); await menuPopupPromise; info(`Awaited menu popup promise`); @@ -40,7 +38,8 @@ function openTabInContainer(gBrowser, url, reopenMenu, id) { let menuitem = reopenMenu.querySelector( `menuitem[data-usercontextid="${id}"]` ); - EventUtils.synthesizeMouseAtCenter(menuitem, {}, menuitem.ownerGlobal); + info(`about to activate item`); + reopenMenu.activateItem(menuitem); return tabPromise; } -- GitLab