Bug 1704925 - Stop synthesizing context menu events in search mochitests. r=adw

I'm adding #mac-reviewers for visibility on the workarounds used in this patch.

Differential Revision: https://phabricator.services.mozilla.com/D111929
This commit is contained in:
Harry Twyford 2021-04-13 22:36:04 +00:00
Родитель 2408151c29
Коммит edafb679ab
3 изменённых файлов: 54 добавлений и 32 удалений

Просмотреть файл

@ -64,7 +64,12 @@ async function openNewSearchTab(event_args, expect_new_window = false) {
);
}
EventUtils.synthesizeMouseAtCenter(searchItem, event_args);
if ("button" in event_args) {
// Bug 1704879: activateItem does not currently support button
EventUtils.synthesizeMouseAtCenter(searchItem, event_args);
} else {
contextMenu.activateItem(searchItem, event_args);
}
if (expect_new_window) {
let win = await searchTabPromise;
@ -108,13 +113,20 @@ add_task(async function test_whereToOpenLink() {
);
BrowserTestUtils.removeTab(searchTab);
searchTab = await openNewSearchTab({ button: 1 });
isnot(
searchTab,
gBrowser.selectedTab,
"Search tab is opened in background (middle mouse)"
);
BrowserTestUtils.removeTab(searchTab);
// TODO bug 1704883: Re-enable this subtest. Native context menus on macOS do
// not yet support alternate mouse buttons.
if (
!AppConstants.platform == "macosx" ||
!Services.prefs.getBoolPref("widget.macos.native-context-menus", false)
) {
searchTab = await openNewSearchTab({ button: 1 });
isnot(
searchTab,
gBrowser.selectedTab,
"Search tab is opened in background (middle mouse)"
);
BrowserTestUtils.removeTab(searchTab);
}
searchTab = await openNewSearchTab({ ctrlKey: true });
isnot(
@ -146,13 +158,20 @@ add_task(async function test_whereToOpenLink() {
);
BrowserTestUtils.removeTab(searchTab);
searchTab = await openNewSearchTab({ button: 1 });
is(
searchTab,
gBrowser.selectedTab,
"Search tab is opened in foreground (middle mouse)"
);
BrowserTestUtils.removeTab(searchTab);
// TODO bug 1704883: Re-enable this subtest. Native context menus on macOS do
// not yet support alternate mouse buttons.
if (
!AppConstants.platform == "macosx" ||
!Services.prefs.getBoolPref("widget.macos.native-context-menus", false)
) {
searchTab = await openNewSearchTab({ button: 1 });
is(
searchTab,
gBrowser.selectedTab,
"Search tab is opened in foreground (middle mouse)"
);
BrowserTestUtils.removeTab(searchTab);
}
searchTab = await openNewSearchTab({ ctrlKey: true });
is(

Просмотреть файл

@ -3,16 +3,6 @@
const TEST_ENGINE_NAME = "Foo";
const TEST_ENGINE_BASENAME = "testEngine.xml";
const searchPopup = document.getElementById("PopupSearchAutoComplete");
const oneOffInstance = searchPopup.oneOffButtons;
const contextMenu = oneOffInstance.querySelector(
".search-one-offs-context-menu"
);
const oneOffButtons = oneOffInstance.buttons;
const searchInNewTabMenuItem = oneOffInstance.querySelector(
".search-one-offs-context-open-in-new-tab"
);
let searchbar;
let searchIcon;
@ -29,6 +19,11 @@ add_task(async function init() {
});
add_task(async function telemetry() {
let searchPopup = document.getElementById("PopupSearchAutoComplete");
let oneOffInstance = searchPopup.oneOffButtons;
let oneOffButtons = oneOffInstance.buttons;
// Open the popup.
let shownPromise = promiseEvent(searchPopup, "popupshown");
let builtPromise = promiseEvent(oneOffInstance, "rebuild");
@ -51,6 +46,9 @@ add_task(async function telemetry() {
);
// Open the context menu on the one-off.
let contextMenu = oneOffInstance.querySelector(
".search-one-offs-context-menu"
);
let promise = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
EventUtils.synthesizeMouseAtCenter(oneOffButton, {
type: "contextmenu",
@ -59,8 +57,11 @@ add_task(async function telemetry() {
await promise;
// Click the Search in New Tab menu item.
let searchInNewTabMenuItem = contextMenu.querySelector(
".search-one-offs-context-open-in-new-tab"
);
promise = BrowserTestUtils.waitForNewTab(gBrowser);
EventUtils.synthesizeMouseAtCenter(searchInNewTabMenuItem, {});
contextMenu.activateItem(searchInNewTabMenuItem);
let tab = await promise;
// By default the search will open in the background and the popup will stay open:

Просмотреть файл

@ -386,14 +386,16 @@ add_task(async function contextmenu_closes_popup() {
is(textbox.selectionStart, 0, "Should have selected all of the text");
is(textbox.selectionEnd, 3, "Should have selected all of the text");
promise = promiseEvent(searchPopup, "popuphidden");
context_click(textbox);
await promise;
let contextPopup = searchbar._menupopup;
promise = promiseEvent(contextPopup, "popuphidden");
let contextMenuShownPromise = promiseEvent(contextPopup, "popupshown");
let searchPopupHiddenPromise = promiseEvent(searchPopup, "popuphidden");
context_click(textbox);
await contextMenuShownPromise;
await searchPopupHiddenPromise;
let contextMenuHiddenPromise = promiseEvent(contextPopup, "popuphidden");
contextPopup.hidePopup();
await promise;
await contextMenuHiddenPromise;
textbox.value = "";
});