| Index: chrome/browser/policy/configuration_policy_handler_unittest.cc
|
| diff --git a/chrome/browser/policy/configuration_policy_handler_unittest.cc b/chrome/browser/policy/configuration_policy_handler_unittest.cc
|
| index a57f1fb489e875458e8e3e6167732ba2ecddf86b..99d45b821e5625b92bd98da79e451a58841a29e3 100644
|
| --- a/chrome/browser/policy/configuration_policy_handler_unittest.cc
|
| +++ b/chrome/browser/policy/configuration_policy_handler_unittest.cc
|
| @@ -21,6 +21,8 @@ StringToIntEnumListPolicyHandler::MappingEntry kTestTypeMap[] = {
|
| { "two", 2 },
|
| };
|
|
|
| +int kTestAllowedSet[] = { 0, 2 };
|
| +
|
| const char kTestPref[] = "unit_test.test_pref";
|
|
|
| } // namespace
|
| @@ -478,6 +480,82 @@ TEST(IntPercentageToDoublePolicyHandler, ApplyPolicySettingsDontClamp) {
|
| EXPECT_TRUE(base::Value::Equals(expected.get(), value));
|
| }
|
|
|
| +TEST(IntSetPolicyHandlerTest, CheckPolicySettings) {
|
| + PolicyMap policy_map;
|
| + PolicyErrorMap errors;
|
| +
|
| + // This tests needs to modify an int policy. The exact policy used and its
|
| + // semantics outside the test are irrelevant.
|
| + IntSetPolicyHandler handler(
|
| + key::kDiskCacheSize, kTestPref,
|
| + kTestAllowedSet, kTestAllowedSet + arraysize(kTestAllowedSet));
|
| +
|
| + // Check that values lying in the accepted set are not rejected.
|
| + policy_map.Set(key::kDiskCacheSize, POLICY_LEVEL_MANDATORY,
|
| + POLICY_SCOPE_USER, base::Value::CreateIntegerValue(0));
|
| + errors.Clear();
|
| + EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
|
| + EXPECT_TRUE(errors.empty());
|
| +
|
| + policy_map.Set(key::kDiskCacheSize, POLICY_LEVEL_MANDATORY,
|
| + POLICY_SCOPE_USER, base::Value::CreateIntegerValue(2));
|
| + errors.Clear();
|
| + EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
|
| + EXPECT_TRUE(errors.empty());
|
| +
|
| + // Check that values not found in the accepted set are rejected and yield an
|
| + // error message.
|
| + policy_map.Set(key::kDiskCacheSize, POLICY_LEVEL_MANDATORY,
|
| + POLICY_SCOPE_USER, base::Value::CreateIntegerValue(1));
|
| + errors.Clear();
|
| + EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
|
| + EXPECT_FALSE(errors.empty());
|
| +
|
| + policy_map.Set(key::kDiskCacheSize, POLICY_LEVEL_MANDATORY,
|
| + POLICY_SCOPE_USER, base::Value::CreateIntegerValue(3));
|
| + errors.Clear();
|
| + EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
|
| + EXPECT_FALSE(errors.empty());
|
| +
|
| + // Check that an entirely invalid value is rejected and yields an error
|
| + // message.
|
| + policy_map.Set(key::kDiskCacheSize, POLICY_LEVEL_MANDATORY,
|
| + POLICY_SCOPE_USER, base::Value::CreateStringValue("invalid"));
|
| + errors.Clear();
|
| + EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
|
| + EXPECT_FALSE(errors.empty());
|
| +}
|
| +
|
| +TEST(IntSetPolicyHandlerTest, ApplyPolicySettings) {
|
| + PolicyMap policy_map;
|
| + PrefValueMap prefs;
|
| + scoped_ptr<base::Value> expected;
|
| + const base::Value* value;
|
| +
|
| + // This tests needs to modify an int policy. The exact policy used and its
|
| + // semantics outside the test are irrelevant.
|
| + IntSetPolicyHandler handler(
|
| + key::kDiskCacheSize, kTestPref,
|
| + kTestAllowedSet, kTestAllowedSet + arraysize(kTestAllowedSet));
|
| +
|
| + // Check that values lying in the accepted set are written to the pref.
|
| + policy_map.Set(key::kDiskCacheSize, POLICY_LEVEL_MANDATORY,
|
| + POLICY_SCOPE_USER, base::Value::CreateIntegerValue(0));
|
| + prefs.Clear();
|
| + handler.ApplyPolicySettings(policy_map, &prefs);
|
| + expected.reset(base::Value::CreateIntegerValue(0));
|
| + EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
|
| + EXPECT_TRUE(base::Value::Equals(expected.get(), value));
|
| +
|
| + policy_map.Set(key::kDiskCacheSize, POLICY_LEVEL_MANDATORY,
|
| + POLICY_SCOPE_USER, base::Value::CreateIntegerValue(2));
|
| + prefs.Clear();
|
| + handler.ApplyPolicySettings(policy_map, &prefs);
|
| + expected.reset(base::Value::CreateIntegerValue(2));
|
| + EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
|
| + EXPECT_TRUE(base::Value::Equals(expected.get(), value));
|
| +}
|
| +
|
| TEST(ExtensionListPolicyHandlerTest, CheckPolicySettings) {
|
| base::ListValue list;
|
| PolicyMap policy_map;
|
|
|