Bug 1759593 - prevent multiple actions also for modified-clicks on links, to prevent nested links causing multiple tabs to open, r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D142467
This commit is contained in:
Gijs Kruitbosch 2022-03-30 20:17:27 +00:00
Родитель 27ed680c0b
Коммит 9a914288ae
3 изменённых файлов: 49 добавлений и 3 удалений

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

@ -184,9 +184,9 @@ class ClickHandlerChild extends JSWindowActorChild {
// actions here to avoid leaking clipboard content unexpectedly.
// Note that whether the link will work actually or not does not matter
// because in this case, user does not intent to paste clipboard content.
if (event.button === 1) {
event.preventMultipleActions();
}
// We also need to do this to prevent multiple tabs opening if there are
// nested link elements.
event.preventMultipleActions();
this.sendAsyncMessage("Content:Click", json);
}

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

@ -1,3 +1,4 @@
[browser_nested_link_clicks.js]
[browser_untrusted_click_event.js]
support-files =
click.html

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

@ -0,0 +1,45 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Nested links should only open a single tab when ctrl-clicked.
*/
add_task(async function nested_link_click_opens_single_tab() {
await BrowserTestUtils.withNewTab(
"https://example.com/empty",
async browser => {
await SpecialPowers.spawn(browser, [], () => {
let doc = content.document;
let outerLink = doc.createElement("a");
outerLink.href = "https://mozilla.org/";
let link = doc.createElement("a");
link.href = "https://example.org/linked";
link.textContent = "Click me";
link.id = "mylink";
outerLink.append(link);
doc.body.append(outerLink);
});
let startingNumberOfTabs = gBrowser.tabs.length;
let newTabPromise = BrowserTestUtils.waitForNewTab(
gBrowser,
"https://example.org/linked",
true
);
await BrowserTestUtils.synthesizeMouseAtCenter(
"#mylink",
{ accelKey: true },
browser
);
let tab = await newTabPromise;
is(
gBrowser.tabs.length,
startingNumberOfTabs + 1,
"Should only have opened 1 tab."
);
BrowserTestUtils.removeTab(tab);
}
);
});