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:
Rob Wu 2020-08-12 14:50:42 +00:00
Родитель 16fadcf1aa
Коммит 070087f72c
6 изменённых файлов: 85 добавлений и 1 удалений

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

@ -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();"

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

@ -0,0 +1,5 @@
"use strict";
module.exports = {
extends: ["plugin:mozilla/browser-test"],
};

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

@ -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',