diff --git a/browser/base/content/test/general/browser_selectpopup.js b/browser/base/content/test/general/browser_selectpopup.js index 28e03807a176..673f1b0baa21 100644 --- a/browser/base/content/test/general/browser_selectpopup.js +++ b/browser/base/content/test/general/browser_selectpopup.js @@ -416,3 +416,32 @@ add_task(function* test_large_popup() { yield BrowserTestUtils.removeTab(tab); }); + +// This test checks that a mousemove event is fired correctly at the menu and +// not at the browser, ensuring that any mouse capture has been cleared. +add_task(function* test_mousemove_correcttarget() { + const pageUrl = "data:text/html," + escape(PAGECONTENT_SMALL); + let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl); + + let selectPopup = document.getElementById("ContentSelectDropdown").menupopup; + + let popupShownPromise = BrowserTestUtils.waitForEvent(selectPopup, "popupshown"); + yield BrowserTestUtils.synthesizeMouseAtCenter("#one", { type: "mousedown" }, gBrowser.selectedBrowser); + yield popupShownPromise; + + yield new Promise(resolve => { + window.addEventListener("mousemove", function checkForMouseMove(event) { + window.removeEventListener("mousemove", checkForMouseMove, true); + is(event.target.localName.indexOf("menu"), 0, "mouse over menu"); + resolve(); + }, true); + + EventUtils.synthesizeMouseAtCenter(selectPopup.firstChild, { type: "mousemove" }); + }); + + yield BrowserTestUtils.synthesizeMouseAtCenter("#one", { type: "mouseup" }, gBrowser.selectedBrowser); + + yield hideSelectPopup(selectPopup); + + yield BrowserTestUtils.removeTab(tab); +}); diff --git a/layout/xul/nsMenuPopupFrame.cpp b/layout/xul/nsMenuPopupFrame.cpp index 88257c116eb4..9eb9e436be83 100644 --- a/layout/xul/nsMenuPopupFrame.cpp +++ b/layout/xul/nsMenuPopupFrame.cpp @@ -852,8 +852,8 @@ nsMenuPopupFrame::ShowPopup(bool aIsContextMenu) mPopupState = ePopupOpening; mIsOpenChanged = true; - // Clear mouse capture when a context menu is opened. - if (aIsContextMenu) { + // Clear mouse capture when a popup is opened. + if (mPopupType == ePopupTypeMenu) { nsIPresShell::SetCapturingContent(nullptr, 0); }