Bug 1933321 - Get rid of dom.block_multiple_popups; r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D230232
This commit is contained in:
Edgar Chen
2024-11-26 20:43:00 +00:00
parent 79f1ffdd8d
commit 44d3acf16f
5 changed files with 57 additions and 191 deletions

View File

@@ -2297,7 +2297,7 @@ PopupBlocker::PopupControlState BrowsingContext::RevisePopupAbuseLevel(
// PopupBlocker::openBlocked state.
if ((abuse == PopupBlocker::openAllowed ||
abuse == PopupBlocker::openControlled) &&
StaticPrefs::dom_block_multiple_popups() && !IsPopupAllowed() &&
!IsPopupAllowed() &&
!ConsumeTransientUserActivationForMultiplePopupBlocking()) {
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, "DOM"_ns,
doc, nsContentUtils::eDOM_PROPERTIES,

View File

@@ -92,23 +92,6 @@ function startOpeningTwoPopups(browser) {
});
}
add_task(async _ => {
info("All opened if the pref is off");
await withTestPage(2, async function (browser) {
await SpecialPowers.pushPrefEnv({
set: [
// XXXedgar, perhaps dom.block_multiple_popups will be removed at some
// point, we would need to update this test then.
["dom.block_multiple_popups", false],
],
});
await BrowserTestUtils.synthesizeMouseAtCenter("#openPopups", {}, browser);
await SpecialPowers.popPrefEnv();
});
});
add_task(async _ => {
info("2 window.open()s in a click event allowed because whitelisted domain.");

View File

@@ -29,183 +29,68 @@ var a = $("link"),
checkOpened = function() { ok(window.open("http://example.com"), "not properly opened") },
checkBlocked = function() { ok(!window.open("http://example.com"), "not properly blocked") };
add_task(async function check_sanity() {
await new Promise(resolve => setTimeout(resolve, 200));
const popupSpamMaximum = 3;
const eventInAllowedList = "click";
const eventNotInAllowedList = "mouseup";
async function testPopupSpamMaximum() {
// Opening a popup from an event in the allowed event list doesnt affect the
// popup spam count.
for (var count = 0, n = 0; n < popupSpamMaximum; n++) {
sendWithUserActivation(a, eventInAllowedList, checkOpened);
}
sendWithUserActivation(a, eventInAllowedList, checkOpened);
for (var count = 0, n = 0; n < popupSpamMaximum; n++) {
sendWithUserActivation(a, eventNotInAllowedList, checkOpened);
}
sendWithUserActivation(a, eventNotInAllowedList, checkBlocked);
// Close one spam popup.
await window.open.close(1);
sendWithUserActivation(a, eventNotInAllowedList, checkOpened);
sendWithUserActivation(a, eventNotInAllowedList, checkBlocked);
// Still allow opening a popup from an event in the allowed event list even if
// the popup spam count has reached its maximum.
sendWithUserActivation(a, eventInAllowedList, checkOpened);
await window.open.close();
}
add_setup(async function init() {
await SpecialPowers.pushPrefEnv({"set": [
// Enable popup blocker
["dom.disable_open_during_load", true],
["dom.popup_allowed_events", eventInAllowedList],
["dom.popup_maximum", popupSpamMaximum],
]});
});
add_task(async function test_unknown_permission() {
await SpecialPowers.pushPermissions([{'type': 'popup', 'remove': true, 'context': document}]);
ok(await SpecialPowers.testPermission('popup', UNKNOWN_ACTION, document), 'popup value should have UNKNOWN permission');
await SpecialPowers.pushPermissions([{'type': 'popup', 'allow': true, 'context': document}]);
await testPopupSpamMaximum();
await SpecialPowers.popPermissions();
})
add_task(async function run_allow_permission() {
await SpecialPowers.pushPermissions([{'type': 'popup', 'allow': ALLOW_ACTION, 'context': document}]);
ok(await SpecialPowers.testPermission('popup', ALLOW_ACTION, document), 'popup value should have ALLOW permission');
await SpecialPowers.pushPrefEnv({"set": [
["dom.disable_open_during_load", true],
// XXXedgar: Now dom.block_multiple_popups is also true by default in testng
// profile. However, this test primarily focuses on behavior when the
// preference is turned off. If dom.block_multiple_popups is removed in the
// future at some point, this test will need to be updated accordingly.
["dom.block_multiple_popups", false],
["dom.popup_allowed_events", "click mouseup"],
["dom.popup_maximum", 3]
]});
await testPopupSpamMaximum();
// Note: UNKNOWN_ACTION is the same as DENY_ACTION.
await SpecialPowers.popPermissions();
});
add_task(async function run_deny_permission() {
await SpecialPowers.pushPermissions([{'type': 'popup', 'allow': DENY_ACTION, 'context': document}]);
});
ok(await SpecialPowers.testPermission('popup', DENY_ACTION, document), 'popup value should have ALLOW permission');
add_task(async function run_tests() {
send(a, "click", checkOpened);
send(a, "click", checkOpened);
send(a, "click", checkOpened);
send(a, "click", checkOpened);
await window.open.close();
await testPopupSpamMaximum();
// dom.block_multiple_popups is true by default in testing profile, but we
// modify it above.
await SpecialPowers.pushPrefEnv({ set: [["dom.block_multiple_popups", true]] });
SpecialPowers.wrap(document).notifyUserGestureActivation();
send(a, "click", checkOpened);
send(a, "click", checkBlocked);
await window.open.close();
await SpecialPowers.popPrefEnv();
await SpecialPowers.pushPrefEnv({"set": [["dom.popup_maximum", 3]]});
});
add_task(async function run_tests2() {
for (var count = 0, n = 0; n < 3; n++) {
send(a, "mouseup", function() { if (window.open("http://example.com")) count++ });
}
send(a, "mouseup", checkBlocked);
await window.open.close(1);
send(a, "mouseup", checkOpened);
send(a, "mouseup", checkBlocked);
send(a, "mouseup", checkBlocked);
await window.open.close();
ok(count > 0, "Windows left open by previous tests?");
while (count --> 0) {
send(a, "mouseup", checkOpened);
}
send(a, "mouseup", checkBlocked);
await window.open.close();
await SpecialPowers.pushPrefEnv({"set": [["dom.popup_maximum", 2]]});
});
add_task(async function run_tests3() {
send(a, "mouseover", checkBlocked);
await window.open.close();
await SpecialPowers.pushPermissions([{'type': 'popup', 'allow': ALLOW_ACTION, 'context': document}]);
await SpecialPowers.pushPrefEnv({"set": [["dom.popup_maximum", 3]]});
});
add_task(async function run_tests4() {
var count;
send(a, "click", checkOpened);
send(a, "click", checkOpened);
send(a, "click", checkOpened);
send(a, "click", checkOpened);
await window.open.close();
send(a, "mouseup", checkOpened);
send(a, "mouseup", checkOpened);
send(a, "mouseup", checkOpened);
send(a, "mouseup", checkOpened);
await window.open.close();
for (count = 0, n = 0; n < 3; n++) {
send(a, "mouseover", function() { if (window.open("http://example.com")) count++ });
}
send(a, "mouseover", checkBlocked);
await window.open.close(1);
send(a, "mouseover", checkOpened);
send(a, "mouseover", checkBlocked);
send(a, "mouseover", checkBlocked);
await window.open.close();
ok(count > 0, "Windows left open by previous tests?");
while (count --> 0) {
send(a, "mouseover", checkOpened);
}
send(a, "mouseover", checkBlocked);
await window.open.close();
await SpecialPowers.pushPrefEnv({"set": [["dom.popup_allowed_events", "click"]]});
});
add_task(async function run_tests5() {
await SpecialPowers.pushPermissions([{'type': 'popup', 'allow': DENY_ACTION, 'context': document}]);
});
add_task(async function run_tests6() {
send(a, "click", checkOpened);
send(a, "click", checkOpened);
send(a, "click", checkOpened);
send(a, "click", checkOpened);
await window.open.close();
await SpecialPowers.pushPrefEnv({"set": [["dom.popup_maximum", 2]]});
});
add_task(async function run_tests7() {
send(a, "mouseup", checkBlocked);
await window.open.close();
send(a, "mouseover", checkBlocked);
await window.open.close();
await SpecialPowers.pushPermissions([{'type': 'popup', 'allow': ALLOW_ACTION, 'context': document}]);
await SpecialPowers.pushPrefEnv({"set": [["dom.popup_maximum", 3]]});
});
add_task(async function run_tests8() {
var count;
send(a, "click", checkOpened);
send(a, "click", checkOpened);
send(a, "click", checkOpened);
send(a, "click", checkOpened);
await window.open.close();
for (count = 0, n = 0; n < 3; n++) {
send(a, "mouseup", function() { if (window.open("http://example.com")) count++ });
}
send(a, "mouseup", checkBlocked);
await window.open.close(1);
send(a, "mouseup", checkOpened);
send(a, "mouseup", checkBlocked);
send(a, "mouseup", checkBlocked);
await window.open.close();
ok(count > 0, "Windows left open by previous tests?");
while (count --> 0) {
send(a, "mouseup", checkOpened);
}
send(a, "mouseup", checkBlocked);
await window.open.close();
for (count = 0, n = 0; n < 3; n++) {
send(a, "mouseover", function() { if (window.open("http://example.com")) count++ });
}
send(a, "mouseover", checkBlocked);
await window.open.close(1);
send(a, "mouseover", checkOpened);
send(a, "mouseover", checkBlocked);
send(a, "mouseover", checkBlocked);
await window.open.close();
ok(count > 0, "Windows left open by previous tests?");
while (count --> 0) {
send(a, "mouseover", checkOpened);
}
send(a, "mouseover", checkBlocked);
await window.open.close();
await SpecialPowers.popPermissions();
});
</script>

View File

@@ -17,6 +17,10 @@ function send(element, event, handler) {
element.removeEventListener(event, unique_handler);
}
}
function sendWithUserActivation(element, event, handler) {
SpecialPowers.wrap(document).notifyUserGestureActivation();
send(element, event, handler);
}
/**
* Because it's not nice to leave popup windows open after the tests are

View File

@@ -2325,12 +2325,6 @@
value: true
mirror: always
# Block multiple window.open() per single event.
- name: dom.block_multiple_popups
type: bool
value: true
mirror: always
# The maximum number of popup that is allowed to be opened. Set to -1 for no
# limit.
- name: dom.popup_maximum