| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/prefs/pref_store_observer_mock.h" | 9 #include "base/prefs/pref_store_observer_mock.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 const char kTestPolicy[] = "test.policy"; | 32 const char kTestPolicy[] = "test.policy"; |
| 33 const char kTestPref[] = "test.pref"; | 33 const char kTestPref[] = "test.pref"; |
| 34 | 34 |
| 35 } // namespace | 35 } // namespace |
| 36 | 36 |
| 37 namespace policy { | 37 namespace policy { |
| 38 | 38 |
| 39 // Test cases for list-valued policy settings. | 39 // Test cases for list-valued policy settings. |
| 40 class ConfigurationPolicyPrefStoreListTest | 40 class ConfigurationPolicyPrefStoreListTest |
| 41 : public ConfigurationPolicyPrefStoreTest { | 41 : public ConfigurationPolicyPrefStoreTest { |
| 42 virtual void SetUp() override { | 42 void SetUp() override { |
| 43 handler_list_.AddHandler( | 43 handler_list_.AddHandler( |
| 44 make_scoped_ptr<ConfigurationPolicyHandler>(new SimplePolicyHandler( | 44 make_scoped_ptr<ConfigurationPolicyHandler>(new SimplePolicyHandler( |
| 45 kTestPolicy, kTestPref, base::Value::TYPE_LIST))); | 45 kTestPolicy, kTestPref, base::Value::TYPE_LIST))); |
| 46 } | 46 } |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 TEST_F(ConfigurationPolicyPrefStoreListTest, GetDefault) { | 49 TEST_F(ConfigurationPolicyPrefStoreListTest, GetDefault) { |
| 50 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); | 50 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 TEST_F(ConfigurationPolicyPrefStoreListTest, SetValue) { | 53 TEST_F(ConfigurationPolicyPrefStoreListTest, SetValue) { |
| 54 base::ListValue* in_value = new base::ListValue(); | 54 base::ListValue* in_value = new base::ListValue(); |
| 55 in_value->Append(new base::StringValue("test1")); | 55 in_value->Append(new base::StringValue("test1")); |
| 56 in_value->Append(new base::StringValue("test2,")); | 56 in_value->Append(new base::StringValue("test2,")); |
| 57 PolicyMap policy; | 57 PolicyMap policy; |
| 58 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 58 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, |
| 59 POLICY_SCOPE_USER, in_value, NULL); | 59 POLICY_SCOPE_USER, in_value, NULL); |
| 60 UpdateProviderPolicy(policy); | 60 UpdateProviderPolicy(policy); |
| 61 const base::Value* value = NULL; | 61 const base::Value* value = NULL; |
| 62 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); | 62 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); |
| 63 ASSERT_TRUE(value); | 63 ASSERT_TRUE(value); |
| 64 EXPECT_TRUE(in_value->Equals(value)); | 64 EXPECT_TRUE(in_value->Equals(value)); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // Test cases for string-valued policy settings. | 67 // Test cases for string-valued policy settings. |
| 68 class ConfigurationPolicyPrefStoreStringTest | 68 class ConfigurationPolicyPrefStoreStringTest |
| 69 : public ConfigurationPolicyPrefStoreTest { | 69 : public ConfigurationPolicyPrefStoreTest { |
| 70 virtual void SetUp() override { | 70 void SetUp() override { |
| 71 handler_list_.AddHandler( | 71 handler_list_.AddHandler( |
| 72 make_scoped_ptr<ConfigurationPolicyHandler>(new SimplePolicyHandler( | 72 make_scoped_ptr<ConfigurationPolicyHandler>(new SimplePolicyHandler( |
| 73 kTestPolicy, kTestPref, base::Value::TYPE_STRING))); | 73 kTestPolicy, kTestPref, base::Value::TYPE_STRING))); |
| 74 } | 74 } |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 TEST_F(ConfigurationPolicyPrefStoreStringTest, GetDefault) { | 77 TEST_F(ConfigurationPolicyPrefStoreStringTest, GetDefault) { |
| 78 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); | 78 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 TEST_F(ConfigurationPolicyPrefStoreStringTest, SetValue) { | 81 TEST_F(ConfigurationPolicyPrefStoreStringTest, SetValue) { |
| 82 PolicyMap policy; | 82 PolicyMap policy; |
| 83 policy.Set(kTestPolicy, | 83 policy.Set(kTestPolicy, |
| 84 POLICY_LEVEL_MANDATORY, | 84 POLICY_LEVEL_MANDATORY, |
| 85 POLICY_SCOPE_USER, | 85 POLICY_SCOPE_USER, |
| 86 new base::StringValue("http://chromium.org"), | 86 new base::StringValue("http://chromium.org"), |
| 87 NULL); | 87 NULL); |
| 88 UpdateProviderPolicy(policy); | 88 UpdateProviderPolicy(policy); |
| 89 const base::Value* value = NULL; | 89 const base::Value* value = NULL; |
| 90 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); | 90 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); |
| 91 ASSERT_TRUE(value); | 91 ASSERT_TRUE(value); |
| 92 EXPECT_TRUE(base::StringValue("http://chromium.org").Equals(value)); | 92 EXPECT_TRUE(base::StringValue("http://chromium.org").Equals(value)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 // Test cases for boolean-valued policy settings. | 95 // Test cases for boolean-valued policy settings. |
| 96 class ConfigurationPolicyPrefStoreBooleanTest | 96 class ConfigurationPolicyPrefStoreBooleanTest |
| 97 : public ConfigurationPolicyPrefStoreTest { | 97 : public ConfigurationPolicyPrefStoreTest { |
| 98 virtual void SetUp() override { | 98 void SetUp() override { |
| 99 handler_list_.AddHandler( | 99 handler_list_.AddHandler( |
| 100 make_scoped_ptr<ConfigurationPolicyHandler>(new SimplePolicyHandler( | 100 make_scoped_ptr<ConfigurationPolicyHandler>(new SimplePolicyHandler( |
| 101 kTestPolicy, kTestPref, base::Value::TYPE_BOOLEAN))); | 101 kTestPolicy, kTestPref, base::Value::TYPE_BOOLEAN))); |
| 102 } | 102 } |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 TEST_F(ConfigurationPolicyPrefStoreBooleanTest, GetDefault) { | 105 TEST_F(ConfigurationPolicyPrefStoreBooleanTest, GetDefault) { |
| 106 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); | 106 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); |
| 107 } | 107 } |
| 108 | 108 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 132 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); | 132 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); |
| 133 boolean_value = false; | 133 boolean_value = false; |
| 134 result = value->GetAsBoolean(&boolean_value); | 134 result = value->GetAsBoolean(&boolean_value); |
| 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 virtual void SetUp() override { | 142 void SetUp() override { |
| 143 handler_list_.AddHandler( | 143 handler_list_.AddHandler( |
| 144 make_scoped_ptr<ConfigurationPolicyHandler>(new SimplePolicyHandler( | 144 make_scoped_ptr<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, | 155 policy.Set(kTestPolicy, |
| 156 POLICY_LEVEL_MANDATORY, | 156 POLICY_LEVEL_MANDATORY, |
| 157 POLICY_SCOPE_USER, | 157 POLICY_SCOPE_USER, |
| 158 new base::FundamentalValue(2), | 158 new base::FundamentalValue(2), |
| 159 NULL); | 159 NULL); |
| 160 UpdateProviderPolicy(policy); | 160 UpdateProviderPolicy(policy); |
| 161 const base::Value* value = NULL; | 161 const base::Value* value = NULL; |
| 162 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); | 162 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); |
| 163 EXPECT_TRUE(base::FundamentalValue(2).Equals(value)); | 163 EXPECT_TRUE(base::FundamentalValue(2).Equals(value)); |
| 164 } | 164 } |
| 165 | 165 |
| 166 // Exercises the policy refresh mechanism. | 166 // Exercises the policy refresh mechanism. |
| 167 class ConfigurationPolicyPrefStoreRefreshTest | 167 class ConfigurationPolicyPrefStoreRefreshTest |
| 168 : public ConfigurationPolicyPrefStoreTest { | 168 : public ConfigurationPolicyPrefStoreTest { |
| 169 protected: | 169 protected: |
| 170 virtual void SetUp() override { | 170 void SetUp() override { |
| 171 ConfigurationPolicyPrefStoreTest::SetUp(); | 171 ConfigurationPolicyPrefStoreTest::SetUp(); |
| 172 store_->AddObserver(&observer_); | 172 store_->AddObserver(&observer_); |
| 173 handler_list_.AddHandler( | 173 handler_list_.AddHandler( |
| 174 make_scoped_ptr<ConfigurationPolicyHandler>(new SimplePolicyHandler( | 174 make_scoped_ptr<ConfigurationPolicyHandler>(new SimplePolicyHandler( |
| 175 kTestPolicy, kTestPref, base::Value::TYPE_STRING))); | 175 kTestPolicy, kTestPref, base::Value::TYPE_STRING))); |
| 176 } | 176 } |
| 177 | 177 |
| 178 virtual void TearDown() override { | 178 void TearDown() override { |
| 179 store_->RemoveObserver(&observer_); | 179 store_->RemoveObserver(&observer_); |
| 180 ConfigurationPolicyPrefStoreTest::TearDown(); | 180 ConfigurationPolicyPrefStoreTest::TearDown(); |
| 181 } | 181 } |
| 182 | 182 |
| 183 PrefStoreObserverMock observer_; | 183 PrefStoreObserverMock observer_; |
| 184 }; | 184 }; |
| 185 | 185 |
| 186 TEST_F(ConfigurationPolicyPrefStoreRefreshTest, Refresh) { | 186 TEST_F(ConfigurationPolicyPrefStoreRefreshTest, Refresh) { |
| 187 const base::Value* value = NULL; | 187 const base::Value* value = NULL; |
| 188 EXPECT_FALSE(store_->GetValue(kTestPolicy, NULL)); | 188 EXPECT_FALSE(store_->GetValue(kTestPolicy, NULL)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 213 .WillRepeatedly(Return(true)); | 213 .WillRepeatedly(Return(true)); |
| 214 PolicyMap policy; | 214 PolicyMap policy; |
| 215 UpdateProviderPolicy(policy); | 215 UpdateProviderPolicy(policy); |
| 216 EXPECT_TRUE(observer_.initialized); | 216 EXPECT_TRUE(observer_.initialized); |
| 217 EXPECT_TRUE(observer_.initialization_success); | 217 EXPECT_TRUE(observer_.initialization_success); |
| 218 Mock::VerifyAndClearExpectations(&observer_); | 218 Mock::VerifyAndClearExpectations(&observer_); |
| 219 EXPECT_TRUE(store_->IsInitializationComplete()); | 219 EXPECT_TRUE(store_->IsInitializationComplete()); |
| 220 } | 220 } |
| 221 | 221 |
| 222 } // namespace policy | 222 } // namespace policy |
| OLD | NEW |