Bug 1337772 - Part 2 - Explicitly trigger a mousedown event before opening the context menu in browser_context_menu.js. r=MattN
MozReview-Commit-ID: ADTskzMoK9t
--- a/browser/components/extensions/test/browser/head.js
+++ b/browser/components/extensions/test/browser/head.js
@@ -240,16 +240,17 @@ async function openContextMenuInFrame(fr
EventUtils.synthesizeMouseAtCenter(frame.contentDocument.body, {type: "contextmenu"}, frame.contentWindow);
await popupShownPromise;
return contentAreaContextMenu;
}
async function openContextMenu(selector = "#img1") {
let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
let popupShownPromise = BrowserTestUtils.waitForEvent(contentAreaContextMenu, "popupshown");
+ await BrowserTestUtils.synthesizeMouseAtCenter(selector, {type: "mousedown", button: 2}, gBrowser.selectedBrowser);
await BrowserTestUtils.synthesizeMouseAtCenter(selector, {type: "contextmenu"}, gBrowser.selectedBrowser);
await popupShownPromise;
return contentAreaContextMenu;
}
async function closeContextMenu() {
let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
let popupHiddenPromise = BrowserTestUtils.waitForEvent(contentAreaContextMenu, "popuphidden");
--- a/toolkit/components/passwordmgr/test/browser/browser_context_menu.js
+++ b/toolkit/components/passwordmgr/test/browser/browser_context_menu.js
@@ -265,31 +265,38 @@ add_task(function* test_context_menu_use
/**
* Synthesize mouse clicks to open the password manager context menu popup
* for a target password input element.
*
* assertCallback should return true if we should continue or else false.
*/
function* openPasswordContextMenu(browser, passwordInput, assertCallback = null) {
- // Synthesize a right mouse click over the password input element.
let contextMenuShownPromise = BrowserTestUtils.waitForEvent(CONTEXT_MENU, "popupshown");
- let eventDetails = {type: "contextmenu", button: 2};
- BrowserTestUtils.synthesizeMouseAtCenter(passwordInput, eventDetails, browser);
+
+ // Synthesize a right mouse click over the password input element, we have to trigger
+ // both events because formfill code relies on this event happening before the contextmenu
+ // (which it does for real user input) in order to not show the password autocomplete.
+ let eventDetails = {type: "mousedown", button: 2};
+ yield BrowserTestUtils.synthesizeMouseAtCenter(passwordInput, eventDetails, browser);
+ // Synthesize a contextmenu event to actually open the context menu.
+ eventDetails = {type: "contextmenu", button: 2};
+ yield BrowserTestUtils.synthesizeMouseAtCenter(passwordInput, eventDetails, browser);
+
yield contextMenuShownPromise;
if (assertCallback) {
let shouldContinue = yield assertCallback();
if (!shouldContinue) {
return;
}
}
// Synthesize a mouse click over the fill login menu header.
- let popupShownPromise = BrowserTestUtils.waitForEvent(POPUP_HEADER, "popupshown");
+ let popupShownPromise = BrowserTestUtils.waitForCondition(() => POPUP_HEADER.open);
EventUtils.synthesizeMouseAtCenter(POPUP_HEADER, {});
yield popupShownPromise;
}
/**
* Verify that only the expected form fields are filled.
*/
function* assertContextMenuFill(browser, formId, usernameFieldId, passwordFieldId, loginIndex) {
--- a/toolkit/components/passwordmgr/test/browser/browser_context_menu_autocomplete_interaction.js
+++ b/toolkit/components/passwordmgr/test/browser/browser_context_menu_autocomplete_interaction.js
@@ -57,22 +57,22 @@ function autocompleteUnexpectedPopupShow
/**
* Synthesize mouse clicks to open the context menu popup
* for a target login input element.
*/
function* openContextMenu(browser, loginInput) {
// First synthesize a mousedown. We need this to get the focus event with the "contextmenu" event.
let eventDetails1 = {type: "mousedown", button: 2};
- BrowserTestUtils.synthesizeMouseAtCenter(loginInput, eventDetails1, browser);
+ yield BrowserTestUtils.synthesizeMouseAtCenter(loginInput, eventDetails1, browser);
// Then synthesize the contextmenu click over the input element.
let contextMenuShownPromise = BrowserTestUtils.waitForEvent(window, "popupshown");
let eventDetails = {type: "contextmenu", button: 2};
- BrowserTestUtils.synthesizeMouseAtCenter(loginInput, eventDetails, browser);
+ yield BrowserTestUtils.synthesizeMouseAtCenter(loginInput, eventDetails, browser);
yield contextMenuShownPromise;
// Wait to see which popups are shown.
yield new Promise(resolve => setTimeout(resolve, 1000));
}
function loginList() {
return [