Bug 1337772 - Part 2 - Explicitly trigger a mousedown event before opening the context menu in browser_context_menu.js. r=MattN
authorJohann Hofmann <jhofmann@mozilla.com>
Thu, 06 Apr 2017 11:00:11 +0200
changeset 558342 6d936a886de840f007e1f7b9dfa2469b48d5e673
parent 558341 31159cce08ef418fb0626f33d31259540cac12d7
child 558343 ba97ba73f72d4e8a36e9e05400b5a3056624a43e
push id52860
push userbmo:walkingice0204@gmail.com
push dateFri, 07 Apr 2017 13:29:26 +0000
reviewersMattN
bugs1337772
milestone55.0a1
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
browser/components/extensions/test/browser/head.js
toolkit/components/passwordmgr/test/browser/browser_context_menu.js
toolkit/components/passwordmgr/test/browser/browser_context_menu_autocomplete_interaction.js
--- 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 [