This source file includes following definitions.
- SetUp
- SetPolicies
- VerifyValues
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/incognito_mode_policy_handler.h"
#include "chrome/common/pref_names.h"
#include "components/policy/core/browser/configuration_policy_pref_store.h"
#include "components/policy/core/browser/configuration_policy_pref_store_test.h"
#include "grit/generated_resources.h"
#include "policy/policy_constants.h"
namespace policy {
class IncognitoModePolicyHandlerTest
: public ConfigurationPolicyPrefStoreTest {
public:
virtual void SetUp() OVERRIDE {
handler_list_.AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
new IncognitoModePolicyHandler));
}
protected:
static const int kIncognitoModeAvailabilityNotSet = -1;
enum ObsoleteIncognitoEnabledValue {
INCOGNITO_ENABLED_UNKNOWN,
INCOGNITO_ENABLED_TRUE,
INCOGNITO_ENABLED_FALSE
};
void SetPolicies(ObsoleteIncognitoEnabledValue incognito_enabled,
int availability) {
PolicyMap policy;
if (incognito_enabled != INCOGNITO_ENABLED_UNKNOWN) {
policy.Set(key::kIncognitoEnabled, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER,
base::Value::CreateBooleanValue(
incognito_enabled == INCOGNITO_ENABLED_TRUE),
NULL);
}
if (availability >= 0) {
policy.Set(key::kIncognitoModeAvailability, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER,
base::Value::CreateIntegerValue(availability),
NULL);
}
UpdateProviderPolicy(policy);
}
void VerifyValues(IncognitoModePrefs::Availability availability) {
const base::Value* value = NULL;
EXPECT_TRUE(store_->GetValue(prefs::kIncognitoModeAvailability, &value));
EXPECT_TRUE(base::FundamentalValue(availability).Equals(value));
}
};
TEST_F(IncognitoModePolicyHandlerTest,
NoObsoletePolicyAndIncognitoEnabled) {
SetPolicies(INCOGNITO_ENABLED_UNKNOWN, IncognitoModePrefs::ENABLED);
VerifyValues(IncognitoModePrefs::ENABLED);
}
TEST_F(IncognitoModePolicyHandlerTest,
NoObsoletePolicyAndIncognitoDisabled) {
SetPolicies(INCOGNITO_ENABLED_UNKNOWN, IncognitoModePrefs::DISABLED);
VerifyValues(IncognitoModePrefs::DISABLED);
}
TEST_F(IncognitoModePolicyHandlerTest,
NoObsoletePolicyAndIncognitoForced) {
SetPolicies(INCOGNITO_ENABLED_UNKNOWN, IncognitoModePrefs::FORCED);
VerifyValues(IncognitoModePrefs::FORCED);
}
TEST_F(IncognitoModePolicyHandlerTest,
NoObsoletePolicyAndNoIncognitoAvailability) {
SetPolicies(INCOGNITO_ENABLED_UNKNOWN, kIncognitoModeAvailabilityNotSet);
const base::Value* value = NULL;
EXPECT_FALSE(store_->GetValue(prefs::kIncognitoModeAvailability, &value));
}
TEST_F(IncognitoModePolicyHandlerTest,
ObsoletePolicyDoesNotAffectAvailabilityEnabled) {
SetPolicies(INCOGNITO_ENABLED_FALSE, IncognitoModePrefs::ENABLED);
VerifyValues(IncognitoModePrefs::ENABLED);
}
TEST_F(IncognitoModePolicyHandlerTest,
ObsoletePolicyDoesNotAffectAvailabilityForced) {
SetPolicies(INCOGNITO_ENABLED_TRUE, IncognitoModePrefs::FORCED);
VerifyValues(IncognitoModePrefs::FORCED);
}
TEST_F(IncognitoModePolicyHandlerTest,
ObsoletePolicySetsPreferenceToEnabled) {
SetPolicies(INCOGNITO_ENABLED_TRUE, kIncognitoModeAvailabilityNotSet);
VerifyValues(IncognitoModePrefs::ENABLED);
}
TEST_F(IncognitoModePolicyHandlerTest,
ObsoletePolicySetsPreferenceToDisabled) {
SetPolicies(INCOGNITO_ENABLED_FALSE, kIncognitoModeAvailabilityNotSet);
VerifyValues(IncognitoModePrefs::DISABLED);
}
}