Bug 731865 - Show blocked popups when clicking 'Allow popups' [r=florian]

This commit is contained in:
Matt Brubeck 2014-09-29 08:00:32 -07:00
parent ad0103637b
commit 435d352548
5 changed files with 106 additions and 4 deletions

View File

@ -515,6 +515,9 @@ var gPopupBlockerObserver = {
var perm = shouldBlock ? pm.DENY_ACTION : pm.ALLOW_ACTION;
pm.add(gBrowser.currentURI, "popup", perm);
if (!shouldBlock)
this.showAllBlockedPopups(gBrowser.selectedBrowser);
gBrowser.getNotificationBox().removeCurrentNotification();
},
@ -569,6 +572,7 @@ var gPopupBlockerObserver = {
// xxxdz this should make the option say "Show file picker" and do it (Bug 590306)
if (!blockedPopup.popupWindowURI)
continue;
var popupURIspec = blockedPopup.popupWindowURI.spec;
// Sometimes the popup URI that we get back from the blockedPopup
@ -591,9 +595,6 @@ var gPopupBlockerObserver = {
var label = gNavigatorBundle.getFormattedString("popupShowPopupPrefix",
[popupURIspec]);
menuitem.setAttribute("label", label);
menuitem.setAttribute("popupWindowURI", popupURIspec);
menuitem.setAttribute("popupWindowFeatures", blockedPopup.popupWindowFeatures);
menuitem.setAttribute("popupWindowName", blockedPopup.popupWindowName);
menuitem.setAttribute("oncommand", "gPopupBlockerObserver.showBlockedPopup(event);");
menuitem.setAttribute("popupReportIndex", i);
menuitem.popupReportBrowser = browser;
@ -640,6 +641,18 @@ var gPopupBlockerObserver = {
browser.unblockPopup(popupReportIndex);
},
showAllBlockedPopups: function (aBrowser)
{
let popups = aBrowser.blockedPopups;
if (!popups)
return;
for (let i = 0; i < popups.length; i++) {
if (popups[i].popupWindowURI)
aBrowser.unblockPopup(i);
}
},
editPopupSettings: function ()
{
var host = "";

View File

@ -65,6 +65,7 @@ support-files =
offlineQuotaNotification.html
page_style_sample.html
parsingTestHelpers.jsm
popup_blocker.html
print_postdata.sjs
redirect_bug623155.sjs
searchSuggestionEngine.sjs
@ -371,6 +372,7 @@ skip-if = asan # Disabled because it takes a long time (see test for more inform
skip-if = e10s # Bug ?????? - test directly manipulates content (creates and fetches elements directly from content document)
[browser_popupUI.js]
skip-if = buildapp == 'mulet' || e10s # Bug ?????? - test directly manipulates content (tries to get a popup element directly from content)
[browser_popup_blocker.js]
[browser_printpreview.js]
skip-if = buildapp == 'mulet' || e10s # Bug ?????? - timeout after logging "Error: Channel closing: too late to send/recv, messages will be lost"
[browser_private_browsing_window.js]

View File

@ -0,0 +1,64 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const baseURL = "http://example.com/browser/browser/base/content/test/general/";
function test() {
waitForExplicitFinish();
Task.spawn(function* () {
// Enable the popup blocker.
yield pushPrefs(["dom.disable_open_during_load", true]);
// Open the test page.
let tab = gBrowser.loadOneTab(baseURL + "popup_blocker.html", { inBackground: false });
yield promiseTabLoaded(tab);
// Wait for the popup-blocked notification.
let notification;
yield promiseWaitForCondition(() =>
notification = gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"));
// Show the menu.
let popupShown = promiseWaitForEvent(window, "popupshown");
notification.querySelector("button").doCommand();
let popup_event = yield popupShown;
let menu = popup_event.target;
is(menu.id, "blockedPopupOptions", "Blocked popup menu shown");
// Check the menu contents.
let sep = menu.querySelector("menuseparator");
let popupCount = 0;
for (let i = sep.nextElementSibling; i; i = i.nextElementSibling) {
popupCount++;
}
is(popupCount, 2, "Two popups were blocked");
// Pressing "allow" should open all blocked popups.
let popupTabs = [];
function onTabOpen(event) {
popupTabs.push(event.target);
}
gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen);
// Press the button.
let allow = menu.querySelector("[observes='blockedPopupAllowSite']");
allow.doCommand();
yield promiseWaitForCondition(() =>
popupTabs.length == 2 &&
popupTabs.every(tab => tab.linkedBrowser.currentURI.spec != "about:blank"));
gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen);
is(popupTabs[0].linkedBrowser.currentURI.spec, "data:text/plain;charset=utf-8,a", "Popup a");
is(popupTabs[1].linkedBrowser.currentURI.spec, "data:text/plain;charset=utf-8,b", "Popup b");
// Clean up.
gBrowser.removeTab(tab);
for (let popup of popupTabs) {
gBrowser.removeTab(popup);
}
clearAllPermissionsByPrefix("popup");
finish();
});
}

View File

@ -150,15 +150,25 @@ function setTestPluginEnabledState(newEnabledState, pluginName) {
// after a test is done using the plugin doorhanger, we should just clear
// any permissions that may have crept in
function clearAllPluginPermissions() {
clearAllPermissionsByPrefix("plugin");
}
function clearAllPermissionsByPrefix(aPrefix) {
let perms = Services.perms.enumerator;
while (perms.hasMoreElements()) {
let perm = perms.getNext();
if (perm.type.startsWith('plugin')) {
if (perm.type.startsWith(aPrefix)) {
Services.perms.remove(perm.host, perm.type);
}
}
}
function pushPrefs(...aPrefs) {
let deferred = Promise.defer();
SpecialPowers.pushPrefEnv({"set": aPrefs}, deferred.resolve);
return deferred.promise;
}
function updateBlocklist(aCallback) {
var blocklistNotifier = Cc["@mozilla.org/extensions/blocklist;1"]
.getService(Ci.nsITimerCallback);

View File

@ -0,0 +1,13 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Page creating two popups</title>
</head>
<body>
<script type="text/javascript">
window.open("data:text/plain;charset=utf-8,a", "a");
window.open("data:text/plain;charset=utf-8,b", "b");
</script>
</body>
</html>