Commit fb6210ff authored by Prathiksha's avatar Prathiksha
Browse files

Bug 1433513 - Correctly handle new expire type (EXPIRE_POLICY) in the Site...

Bug 1433513 - Correctly handle new expire type (EXPIRE_POLICY) in the Site Identity panel and Page Info window. r=johannh

MozReview-Commit-ID: 7mfxnqI1C65

--HG--
extra : rebase_source : 6000e334bc43978a11a4d9de447445de2249933f
parent bef576f8
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -8009,7 +8009,9 @@ var gIdentityHandler = {
    nameLabel.setAttribute("class", "identity-popup-permission-label");
    nameLabel.textContent = SitePermissions.getPermissionLabel(aPermission.id);

    if (aPermission.id == "popup") {
    let isPolicyPermission = aPermission.scope == SitePermissions.SCOPE_POLICY;

    if (aPermission.id == "popup" && !isPolicyPermission) {
      let menulist = document.createElement("menulist");
      let menupopup = document.createElement("menupopup");
      let block = document.createElement("vbox");
@@ -8064,6 +8066,17 @@ var gIdentityHandler = {
    }
    stateLabel.textContent = SitePermissions.getCurrentStateLabel(state, scope);

    container.appendChild(img);
    container.appendChild(nameLabel);
    container.appendChild(stateLabel);

    /* We return the permission item here without a remove button if the permission is a
       SCOPE_POLICY permission. Policy permissions cannot be removed/changed for the duration
       of the browser session. */
    if (isPolicyPermission) {
      return container;
    }

    let button = document.createElement("button");
    button.setAttribute("class", "identity-popup-permission-remove-button");
    let tooltiptext = gNavigatorBundle.getString("permissions.remove.tooltip");
@@ -8128,9 +8141,6 @@ var gIdentityHandler = {
      histogram.add(aPermission.id, permissionType);
    });

    container.appendChild(img);
    container.appendChild(nameLabel);
    container.appendChild(stateLabel);
    container.appendChild(button);

    return container;
+7 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ function initRow(aPartId) {

  var checkbox = document.getElementById(aPartId + "Def");
  var command  = document.getElementById("cmd_" + aPartId + "Toggle");
  var {state} = SitePermissions.get(gPermURI, aPartId);
  var {state, scope} = SitePermissions.get(gPermURI, aPartId);
  let defaultState = SitePermissions.getDefault(aPartId);

  if (state != defaultState) {
@@ -79,6 +79,12 @@ function initRow(aPartId) {
    checkbox.checked = true;
    command.setAttribute("disabled", "true");
  }

  if (scope == SitePermissions.SCOPE_POLICY) {
    checkbox.setAttribute("disabled", "true");
    command.setAttribute("disabled", "true");
  }

  setRadioState(aPartId, state);
}

+42 −0
Original line number Diff line number Diff line
@@ -224,3 +224,45 @@ add_task(async function testPermissionShortcuts() {
    SitePermissions.remove(gBrowser.currentURI, "shortcuts");
  });
});

// Test the control center UI when policy permissions are set.
add_task(async function testPolicyPermission() {
  await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, async function() {
    await SpecialPowers.pushPrefEnv({set: [
      ["dom.disable_open_during_load", true],
    ]});

    let permissionsList = document.getElementById("identity-popup-permission-list");
    SitePermissions.set(gBrowser.currentURI, "popup", SitePermissions.ALLOW, SitePermissions.SCOPE_POLICY);

    await openIdentityPopup();

    // Check if the icon, nameLabel and stateLabel are visible.
    let img, labelText, labels;

    img = permissionsList.querySelector("image.identity-popup-permission-icon");
    ok(img, "There is an image for the popup permission");
    ok(img.classList.contains("popup-icon"), "proper class is in image class");

    labelText = SitePermissions.getPermissionLabel("popup");
    labels = permissionsList.querySelectorAll(".identity-popup-permission-label");
    is(labels.length, 1, "One permission visible in main view");
    is(labels[0].textContent, labelText, "Correct name label value");

    labelText = SitePermissions.getCurrentStateLabel(SitePermissions.ALLOW, SitePermissions.SCOPE_POLICY);
    labels = permissionsList.querySelectorAll(".identity-popup-permission-state-label");
    is(labels[0].textContent, labelText, "Correct state label value");

    // Check if the menulist and the remove button are hidden.
    // The menulist is specific to the "popup" permission.
    let menulist = document.getElementById("identity-popup-popup-menulist");
    ok(menulist == null, "The popup permission menulist is not visible");

    let removeButton = permissionsList.querySelector(".identity-popup-permission-remove-button");
    ok(removeButton == null, "The permission remove button is not visible");

    Services.perms.removeAll();
    await closeIdentityPopup();
  });
});
+10 −2
Original line number Diff line number Diff line
@@ -149,6 +149,7 @@ this.SitePermissions = {
  SCOPE_TEMPORARY: "{SitePermissions.SCOPE_TEMPORARY}",
  SCOPE_SESSION: "{SitePermissions.SCOPE_SESSION}",
  SCOPE_PERSISTENT: "{SitePermissions.SCOPE_PERSISTENT}",
  SCOPE_POLICY: "{SitePermissions.SCOPE_POLICY}",

  _defaultPrefBranch: Services.prefs.getBranch("permissions.default."),

@@ -188,7 +189,10 @@ this.SitePermissions = {
        let scope = this.SCOPE_PERSISTENT;
        if (permission.expireType == Services.perms.EXPIRE_SESSION) {
          scope = this.SCOPE_SESSION;
        } else if (permission.expireType == Services.perms.EXPIRE_POLICY) {
          scope = this.SCOPE_POLICY;
        }

        result.push({
          id: permission.type,
          scope,
@@ -358,6 +362,8 @@ this.SitePermissions = {
        result.state = permission.capability;
        if (permission.expireType == Services.perms.EXPIRE_SESSION) {
          result.scope = this.SCOPE_SESSION;
        } else if (permission.expireType == Services.perms.EXPIRE_POLICY) {
          result.scope = this.SCOPE_POLICY;
        }
      }
    }
@@ -430,6 +436,8 @@ this.SitePermissions = {
      let perms_scope = Services.perms.EXPIRE_NEVER;
      if (scope == this.SCOPE_SESSION) {
        perms_scope = Services.perms.EXPIRE_SESSION;
      } else if (scope == this.SCOPE_POLICY) {
        perms_scope = Services.perms.EXPIRE_POLICY;
      }

      Services.perms.add(uri, permissionID, state, perms_scope);
@@ -541,13 +549,13 @@ this.SitePermissions = {
      case this.PROMPT:
        return gStringBundle.GetStringFromName("state.current.prompt");
      case this.ALLOW:
        if (scope && scope != this.SCOPE_PERSISTENT)
        if (scope && scope != this.SCOPE_PERSISTENT && scope != this.SCOPE_POLICY)
          return gStringBundle.GetStringFromName("state.current.allowedTemporarily");
        return gStringBundle.GetStringFromName("state.current.allowed");
      case this.ALLOW_COOKIES_FOR_SESSION:
        return gStringBundle.GetStringFromName("state.current.allowedForSession");
      case this.BLOCK:
        if (scope && scope != this.SCOPE_PERSISTENT)
        if (scope && scope != this.SCOPE_PERSISTENT && scope != this.SCOPE_POLICY)
          return gStringBundle.GetStringFromName("state.current.blockedTemporarily");
        return gStringBundle.GetStringFromName("state.current.blocked");
      default: