Bug 1433511 - Properly handle default popup permissions in the site identity popup. r=prathiksha

We were not correctly setting the menulist value for default popup permissions,
which went largely unnoticed so far because the user had no way of actually setting
these permissions explicitly. It might happen with policy engine in the future
and so we should fix this.

MozReview-Commit-ID: 1VQc1NRGGX

--HG--
extra : rebase_source : 91dd30d11913316e1fc50c09b3ca37ae6430c938
This commit is contained in:
Johann Hofmann 2018-02-07 12:10:26 +01:00
Родитель ba54406ac4
Коммит 9b1ad03ff0
2 изменённых файлов: 36 добавлений и 2 удалений

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

@ -7994,8 +7994,10 @@ var gIdentityHandler = {
for (let state of SitePermissions.getAvailableStates(aPermission.id)) {
let menuitem = document.createElement("menuitem");
// We need to correctly display the default/unknown state, which has its
// own integer value (0) but represents one of the other states.
if (state == SitePermissions.getDefault(aPermission.id)) {
menuitem.setAttribute("value", 0);
menuitem.setAttribute("value", "0");
} else {
menuitem.setAttribute("value", state);
}
@ -8004,7 +8006,12 @@ var gIdentityHandler = {
}
menulist.appendChild(menupopup);
menulist.setAttribute("value", aPermission.state);
if (aPermission.state == SitePermissions.getDefault(aPermission.id)) {
menulist.value = "0";
} else {
menulist.value = aPermission.state;
}
// Avoiding listening to the "select" event on purpose. See Bug 1404262.
menulist.addEventListener("command", () => {

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

@ -165,3 +165,30 @@ add_task(async function check_permission_state_change() {
gBrowser.removeTab(tab);
});
// Explicitly set the permission to the otherwise default state and check that
// the label still displays correctly.
add_task(async function check_explicit_default_permission() {
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, URL);
// DENY only works if triggered through Services.perms (it's very edge-casey),
// since SitePermissions.jsm considers setting default permissions to be removal.
Services.perms.add(URI, "popup", Ci.nsIPermissionManager.DENY_ACTION);
await openIdentityPopup();
let menulist = document.getElementById("identity-popup-popup-menulist");
Assert.equal(menulist.value, "0");
Assert.equal(menulist.label, "Block");
await closeIdentityPopup();
SitePermissions.set(URI, "popup", SitePermissions.ALLOW);
await openIdentityPopup();
menulist = document.getElementById("identity-popup-popup-menulist");
Assert.equal(menulist.value, "1");
Assert.equal(menulist.label, "Allow");
await closeIdentityPopup();
SitePermissions.remove(URI, "popup");
gBrowser.removeTab(tab);
});