B2G/gecko/toolkit/mozapps/extensions/test/xpcshell/test_blocklistchange.js
// Checks that an add-ons properties match expected values
Checks that an add-ons properties match expected values
Checks that an add - ons properties match expected values
function check_addon(aAddon, aExpectedVersion, aExpectedUserDisabled,
                     aExpectedSoftDisabled, aExpectedState) {
  dump("Testing " + aAddon.id + " version " + aAddon.version + "\n");
  dump(aAddon.userDisabled + " " + aAddon.softDisabled + "\n");
  do_check_neq(aAddon, null);
  do_check_eq(aAddon.version, aExpectedVersion);
  do_check_eq(aAddon.blocklistState, aExpectedState);
  do_check_eq(aAddon.userDisabled, aExpectedUserDisabled);
  do_check_eq(aAddon.softDisabled, aExpectedSoftDisabled);
  if (aAddon.softDisabled)
    do_check_true(aAddon.userDisabled);
  if (aExpectedState == Ci.nsIBlocklistService.STATE_BLOCKED) {
    do_check_false(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_ENABLE));
    do_check_false(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_DISABLE));
  }
  else if (aAddon.userDisabled) {
    do_check_true(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_ENABLE));
    do_check_false(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_DISABLE));
  }
  else {
    do_check_false(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_ENABLE));
    if (aAddon.type != "theme")
      do_check_true(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_DISABLE));
  }
  do_check_eq(aAddon.appDisabled, aExpectedState == Ci.nsIBlocklistService.STATE_BLOCKED);
  let willBeActive = aAddon.isActive;
  if (hasFlag(aAddon.pendingOperations, AddonManager.PENDING_DISABLE))
    willBeActive = false;
  else if (hasFlag(aAddon.pendingOperations, AddonManager.PENDING_ENABLE))
    willBeActive = true;
  if (aExpectedUserDisabled || aExpectedState == Ci.nsIBlocklistService.STATE_BLOCKED) {
    do_check_false(willBeActive);
  }
  else {
    do_check_true(willBeActive);
  }
}
function check_addon ( aAddon , aExpectedVersion , aExpectedUserDisabled , aExpectedSoftDisabled , aExpectedState ) { dump ( "Testing " + aAddon . id + " version " + aAddon . version + "\n" ) ; dump ( aAddon . userDisabled + " " + aAddon . softDisabled + "\n" ) ; do_check_neq ( aAddon , null ) ; do_check_eq ( aAddon . version , aExpectedVersion ) ; do_check_eq ( aAddon . blocklistState , aExpectedState ) ; do_check_eq ( aAddon . userDisabled , aExpectedUserDisabled ) ; do_check_eq ( aAddon . softDisabled , aExpectedSoftDisabled ) ; if ( aAddon . softDisabled ) do_check_true ( aAddon . userDisabled ) ; if ( aExpectedState == Ci . nsIBlocklistService . STATE_BLOCKED ) { do_check_false ( hasFlag ( aAddon . permissions , AddonManager . PERM_CAN_ENABLE ) ) ; do_check_false ( hasFlag ( aAddon . permissions , AddonManager . PERM_CAN_DISABLE ) ) ; } else if ( aAddon . userDisabled ) { do_check_true ( hasFlag ( aAddon . permissions , AddonManager . PERM_CAN_ENABLE ) ) ; do_check_false ( hasFlag ( aAddon . permissions , AddonManager . PERM_CAN_DISABLE ) ) ; } else { do_check_false ( hasFlag ( aAddon . permissions , AddonManager . PERM_CAN_ENABLE ) ) ; if ( aAddon . type != "theme" ) do_check_true ( hasFlag ( aAddon . permissions , AddonManager . PERM_CAN_DISABLE ) ) ; } do_check_eq ( aAddon . appDisabled , aExpectedState == Ci . nsIBlocklistService . STATE_BLOCKED ) ; let willBeActive = aAddon . isActive ; if ( hasFlag ( aAddon . pendingOperations , AddonManager . PENDING_DISABLE ) ) willBeActive = false ; else if ( hasFlag ( aAddon . pendingOperations , AddonManager . PENDING_ENABLE ) ) willBeActive = true ; if ( aExpectedUserDisabled || aExpectedState == Ci . nsIBlocklistService . STATE_BLOCKED ) { do_check_false ( willBeActive ) ; } else { do_check_true ( willBeActive ) ; } }
Checks that an add-ons properties match expected values
Checks that an add - ons properties match expected values