| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/policy/core/browser/configuration_policy_pref_store.h" | 5 #include "components/policy/core/browser/configuration_policy_pref_store.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 namespace policy { | 42 namespace policy { |
| 43 | 43 |
| 44 // Test cases for list-valued policy settings. | 44 // Test cases for list-valued policy settings. |
| 45 class ConfigurationPolicyPrefStoreListTest | 45 class ConfigurationPolicyPrefStoreListTest |
| 46 : public ConfigurationPolicyPrefStoreTest { | 46 : public ConfigurationPolicyPrefStoreTest { |
| 47 void SetUp() override { | 47 void SetUp() override { |
| 48 handler_list_.AddHandler( | 48 handler_list_.AddHandler( |
| 49 base::WrapUnique<ConfigurationPolicyHandler>(new SimplePolicyHandler( | 49 base::WrapUnique<ConfigurationPolicyHandler>(new SimplePolicyHandler( |
| 50 kTestPolicy, kTestPref, base::Value::TYPE_LIST))); | 50 kTestPolicy, kTestPref, base::Value::Type::LIST))); |
| 51 } | 51 } |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 TEST_F(ConfigurationPolicyPrefStoreListTest, GetDefault) { | 54 TEST_F(ConfigurationPolicyPrefStoreListTest, GetDefault) { |
| 55 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); | 55 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 TEST_F(ConfigurationPolicyPrefStoreListTest, SetValue) { | 58 TEST_F(ConfigurationPolicyPrefStoreListTest, SetValue) { |
| 59 std::unique_ptr<base::ListValue> in_value(new base::ListValue()); | 59 std::unique_ptr<base::ListValue> in_value(new base::ListValue()); |
| 60 in_value->AppendString("test1"); | 60 in_value->AppendString("test1"); |
| 61 in_value->AppendString("test2,"); | 61 in_value->AppendString("test2,"); |
| 62 PolicyMap policy; | 62 PolicyMap policy; |
| 63 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 63 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 64 POLICY_SOURCE_CLOUD, in_value->CreateDeepCopy(), nullptr); | 64 POLICY_SOURCE_CLOUD, in_value->CreateDeepCopy(), nullptr); |
| 65 UpdateProviderPolicy(policy); | 65 UpdateProviderPolicy(policy); |
| 66 const base::Value* value = NULL; | 66 const base::Value* value = NULL; |
| 67 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); | 67 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); |
| 68 ASSERT_TRUE(value); | 68 ASSERT_TRUE(value); |
| 69 EXPECT_TRUE(in_value->Equals(value)); | 69 EXPECT_TRUE(in_value->Equals(value)); |
| 70 } | 70 } |
| 71 | 71 |
| 72 // Test cases for string-valued policy settings. | 72 // Test cases for string-valued policy settings. |
| 73 class ConfigurationPolicyPrefStoreStringTest | 73 class ConfigurationPolicyPrefStoreStringTest |
| 74 : public ConfigurationPolicyPrefStoreTest { | 74 : public ConfigurationPolicyPrefStoreTest { |
| 75 void SetUp() override { | 75 void SetUp() override { |
| 76 handler_list_.AddHandler( | 76 handler_list_.AddHandler( |
| 77 base::WrapUnique<ConfigurationPolicyHandler>(new SimplePolicyHandler( | 77 base::WrapUnique<ConfigurationPolicyHandler>(new SimplePolicyHandler( |
| 78 kTestPolicy, kTestPref, base::Value::TYPE_STRING))); | 78 kTestPolicy, kTestPref, base::Value::Type::STRING))); |
| 79 } | 79 } |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 TEST_F(ConfigurationPolicyPrefStoreStringTest, GetDefault) { | 82 TEST_F(ConfigurationPolicyPrefStoreStringTest, GetDefault) { |
| 83 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); | 83 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); |
| 84 } | 84 } |
| 85 | 85 |
| 86 TEST_F(ConfigurationPolicyPrefStoreStringTest, SetValue) { | 86 TEST_F(ConfigurationPolicyPrefStoreStringTest, SetValue) { |
| 87 PolicyMap policy; | 87 PolicyMap policy; |
| 88 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 88 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 89 POLICY_SOURCE_CLOUD, | 89 POLICY_SOURCE_CLOUD, |
| 90 base::MakeUnique<base::StringValue>("http://chromium.org"), | 90 base::MakeUnique<base::StringValue>("http://chromium.org"), |
| 91 nullptr); | 91 nullptr); |
| 92 UpdateProviderPolicy(policy); | 92 UpdateProviderPolicy(policy); |
| 93 const base::Value* value = NULL; | 93 const base::Value* value = NULL; |
| 94 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); | 94 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); |
| 95 ASSERT_TRUE(value); | 95 ASSERT_TRUE(value); |
| 96 EXPECT_TRUE(base::StringValue("http://chromium.org").Equals(value)); | 96 EXPECT_TRUE(base::StringValue("http://chromium.org").Equals(value)); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Test cases for boolean-valued policy settings. | 99 // Test cases for boolean-valued policy settings. |
| 100 class ConfigurationPolicyPrefStoreBooleanTest | 100 class ConfigurationPolicyPrefStoreBooleanTest |
| 101 : public ConfigurationPolicyPrefStoreTest { | 101 : public ConfigurationPolicyPrefStoreTest { |
| 102 void SetUp() override { | 102 void SetUp() override { |
| 103 handler_list_.AddHandler( | 103 handler_list_.AddHandler( |
| 104 base::WrapUnique<ConfigurationPolicyHandler>(new SimplePolicyHandler( | 104 base::WrapUnique<ConfigurationPolicyHandler>(new SimplePolicyHandler( |
| 105 kTestPolicy, kTestPref, base::Value::TYPE_BOOLEAN))); | 105 kTestPolicy, kTestPref, base::Value::Type::BOOLEAN))); |
| 106 } | 106 } |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 TEST_F(ConfigurationPolicyPrefStoreBooleanTest, GetDefault) { | 109 TEST_F(ConfigurationPolicyPrefStoreBooleanTest, GetDefault) { |
| 110 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); | 110 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 TEST_F(ConfigurationPolicyPrefStoreBooleanTest, SetValue) { | 113 TEST_F(ConfigurationPolicyPrefStoreBooleanTest, SetValue) { |
| 114 PolicyMap policy; | 114 PolicyMap policy; |
| 115 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 115 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 135 ASSERT_TRUE(result); | 135 ASSERT_TRUE(result); |
| 136 EXPECT_TRUE(boolean_value); | 136 EXPECT_TRUE(boolean_value); |
| 137 } | 137 } |
| 138 | 138 |
| 139 // Test cases for integer-valued policy settings. | 139 // Test cases for integer-valued policy settings. |
| 140 class ConfigurationPolicyPrefStoreIntegerTest | 140 class ConfigurationPolicyPrefStoreIntegerTest |
| 141 : public ConfigurationPolicyPrefStoreTest { | 141 : public ConfigurationPolicyPrefStoreTest { |
| 142 void SetUp() override { | 142 void SetUp() override { |
| 143 handler_list_.AddHandler( | 143 handler_list_.AddHandler( |
| 144 base::WrapUnique<ConfigurationPolicyHandler>(new SimplePolicyHandler( | 144 base::WrapUnique<ConfigurationPolicyHandler>(new SimplePolicyHandler( |
| 145 kTestPolicy, kTestPref, base::Value::TYPE_INTEGER))); | 145 kTestPolicy, kTestPref, base::Value::Type::INTEGER))); |
| 146 } | 146 } |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 TEST_F(ConfigurationPolicyPrefStoreIntegerTest, GetDefault) { | 149 TEST_F(ConfigurationPolicyPrefStoreIntegerTest, GetDefault) { |
| 150 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); | 150 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); |
| 151 } | 151 } |
| 152 | 152 |
| 153 TEST_F(ConfigurationPolicyPrefStoreIntegerTest, SetValue) { | 153 TEST_F(ConfigurationPolicyPrefStoreIntegerTest, SetValue) { |
| 154 PolicyMap policy; | 154 PolicyMap policy; |
| 155 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 155 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 156 POLICY_SOURCE_CLOUD, base::MakeUnique<base::FundamentalValue>(2), | 156 POLICY_SOURCE_CLOUD, base::MakeUnique<base::FundamentalValue>(2), |
| 157 nullptr); | 157 nullptr); |
| 158 UpdateProviderPolicy(policy); | 158 UpdateProviderPolicy(policy); |
| 159 const base::Value* value = NULL; | 159 const base::Value* value = NULL; |
| 160 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); | 160 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); |
| 161 EXPECT_TRUE(base::FundamentalValue(2).Equals(value)); | 161 EXPECT_TRUE(base::FundamentalValue(2).Equals(value)); |
| 162 } | 162 } |
| 163 | 163 |
| 164 // Exercises the policy refresh mechanism. | 164 // Exercises the policy refresh mechanism. |
| 165 class ConfigurationPolicyPrefStoreRefreshTest | 165 class ConfigurationPolicyPrefStoreRefreshTest |
| 166 : public ConfigurationPolicyPrefStoreTest { | 166 : public ConfigurationPolicyPrefStoreTest { |
| 167 protected: | 167 protected: |
| 168 void SetUp() override { | 168 void SetUp() override { |
| 169 ConfigurationPolicyPrefStoreTest::SetUp(); | 169 ConfigurationPolicyPrefStoreTest::SetUp(); |
| 170 store_->AddObserver(&observer_); | 170 store_->AddObserver(&observer_); |
| 171 handler_list_.AddHandler( | 171 handler_list_.AddHandler( |
| 172 base::WrapUnique<ConfigurationPolicyHandler>(new SimplePolicyHandler( | 172 base::WrapUnique<ConfigurationPolicyHandler>(new SimplePolicyHandler( |
| 173 kTestPolicy, kTestPref, base::Value::TYPE_STRING))); | 173 kTestPolicy, kTestPref, base::Value::Type::STRING))); |
| 174 } | 174 } |
| 175 | 175 |
| 176 void TearDown() override { | 176 void TearDown() override { |
| 177 store_->RemoveObserver(&observer_); | 177 store_->RemoveObserver(&observer_); |
| 178 ConfigurationPolicyPrefStoreTest::TearDown(); | 178 ConfigurationPolicyPrefStoreTest::TearDown(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 PrefStoreObserverMock observer_; | 181 PrefStoreObserverMock observer_; |
| 182 }; | 182 }; |
| 183 | 183 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 210 .WillRepeatedly(Return(true)); | 210 .WillRepeatedly(Return(true)); |
| 211 PolicyMap policy; | 211 PolicyMap policy; |
| 212 UpdateProviderPolicy(policy); | 212 UpdateProviderPolicy(policy); |
| 213 EXPECT_TRUE(observer_.initialized); | 213 EXPECT_TRUE(observer_.initialized); |
| 214 EXPECT_TRUE(observer_.initialization_success); | 214 EXPECT_TRUE(observer_.initialization_success); |
| 215 Mock::VerifyAndClearExpectations(&observer_); | 215 Mock::VerifyAndClearExpectations(&observer_); |
| 216 EXPECT_TRUE(store_->IsInitializationComplete()); | 216 EXPECT_TRUE(store_->IsInitializationComplete()); |
| 217 } | 217 } |
| 218 | 218 |
| 219 } // namespace policy | 219 } // namespace policy |
| OLD | NEW |