mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 01:05:45 +00:00
Bug 1657992 - Handle middle-click on long-press backForwardMenu only once + tests r=dao
Differential Revision: https://phabricator.services.mozilla.com/D86784
This commit is contained in:
parent
16fadcf1aa
commit
070087f72c
@ -208,7 +208,9 @@
|
||||
</menupopup>
|
||||
|
||||
<!-- bug 415444/582485: event.stopPropagation is here for the cloned version
|
||||
of this menupopup -->
|
||||
of this menupopup, to prevent already-handled clicks on menu items from
|
||||
propagating to the back or forward button.
|
||||
-->
|
||||
<menupopup id="backForwardMenu"
|
||||
onpopupshowing="return FillHistoryMenu(event.target);"
|
||||
oncommand="gotoHistoryIndex(event); event.stopPropagation();"
|
||||
|
5
browser/base/content/test/backforward/.eslintrc.js
Normal file
5
browser/base/content/test/backforward/.eslintrc.js
Normal file
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
extends: ["plugin:mozilla/browser-test"],
|
||||
};
|
1
browser/base/content/test/backforward/browser.ini
Normal file
1
browser/base/content/test/backforward/browser.ini
Normal file
@ -0,0 +1 @@
|
||||
[browser_longpress_session_history_menu.js]
|
@ -0,0 +1,70 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// Tests that the session history can be shown by long-pressing the back button.
|
||||
// And that middle-click opens one tab (as a regression test for bug 1657992).
|
||||
add_task(async function restore_history_entry_by_middle_click() {
|
||||
let tab1 = await BrowserTestUtils.openNewForegroundTab(
|
||||
gBrowser,
|
||||
"http://example.com"
|
||||
);
|
||||
|
||||
await SpecialPowers.spawn(tab1.linkedBrowser, [], () => {
|
||||
content.history.pushState(null, null, "2.html");
|
||||
content.history.pushState(null, null, "3.html");
|
||||
});
|
||||
|
||||
await new Promise(resolve => SessionStore.getSessionHistory(tab1, resolve));
|
||||
|
||||
let backButton = document.getElementById("back-button");
|
||||
// This is the popup (clone of backForwardMenu) from SetClickAndHoldHandlers.
|
||||
let historyMenu = backButton.firstElementChild;
|
||||
|
||||
info("waiting for the history menu to open");
|
||||
|
||||
let popupShownPromise = BrowserTestUtils.waitForEvent(
|
||||
historyMenu,
|
||||
"popupshown"
|
||||
);
|
||||
|
||||
// Trigger gClickAndHoldListenersOnElement logic in browser.js to open the
|
||||
// history menu that opens after a long press.
|
||||
EventUtils.synthesizeMouseAtCenter(backButton, { type: "mousedown" });
|
||||
let event = await popupShownPromise;
|
||||
EventUtils.synthesizeMouseAtCenter(backButton, { type: "mouseup" });
|
||||
|
||||
info("Waiting for menu items to be populated");
|
||||
await new Promise(resolve => SessionStore.getSessionHistory(tab1, resolve));
|
||||
|
||||
SimpleTest.isDeeply(
|
||||
Array.from(event.target.children, node => node.getAttribute("uri")),
|
||||
[
|
||||
"http://example.com/3.html",
|
||||
"http://example.com/2.html",
|
||||
"http://example.com/",
|
||||
],
|
||||
"Expected session history items"
|
||||
);
|
||||
let historyMenuItem = event.target.children[1];
|
||||
|
||||
let popupHiddenPromise = BrowserTestUtils.waitForEvent(
|
||||
historyMenu,
|
||||
"popuphidden"
|
||||
);
|
||||
|
||||
let tabRestoredPromise = BrowserTestUtils.waitForEvent(
|
||||
gBrowser.tabContainer,
|
||||
"SSTabRestored"
|
||||
);
|
||||
|
||||
EventUtils.sendMouseEvent({ type: "click", button: 1 }, historyMenuItem);
|
||||
|
||||
info("Waiting for history menu to be hidden");
|
||||
await popupHiddenPromise;
|
||||
info("Waiting for history item to be restored in a new tab");
|
||||
let newTab = (await tabRestoredPromise).target;
|
||||
is(newTab.linkedBrowser.currentURI.spec, "http://example.com/2.html");
|
||||
|
||||
BrowserTestUtils.removeTab(newTab);
|
||||
BrowserTestUtils.removeTab(tab1);
|
||||
});
|
@ -732,6 +732,11 @@ function checkForMiddleClick(node, event) {
|
||||
);
|
||||
node.dispatchEvent(cmdEvent);
|
||||
|
||||
// Stop the propagation of the click event, to prevent the event from being
|
||||
// handled more than once.
|
||||
// E.g. see https://bugzilla.mozilla.org/show_bug.cgi?id=1657992#c4
|
||||
event.stopPropagation();
|
||||
|
||||
// If the middle-click was on part of a menu, close the menu.
|
||||
// (Menus close automatically with left-click but not with middle-click.)
|
||||
closeMenus(event.target);
|
||||
|
@ -20,6 +20,7 @@ MOCHITEST_CHROME_MANIFESTS += [
|
||||
BROWSER_CHROME_MANIFESTS += [
|
||||
'content/test/about/browser.ini',
|
||||
'content/test/alerts/browser.ini',
|
||||
'content/test/backforward/browser.ini',
|
||||
'content/test/caps/browser.ini',
|
||||
'content/test/captivePortal/browser.ini',
|
||||
'content/test/contextMenu/browser.ini',
|
||||
|
Loading…
Reference in New Issue
Block a user