OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <CoreFoundation/CoreFoundation.h> | 5 #include <CoreFoundation/CoreFoundation.h> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 } | 120 } |
121 | 121 |
122 class TestHarness : public PolicyProviderTestHarness { | 122 class TestHarness : public PolicyProviderTestHarness { |
123 public: | 123 public: |
124 TestHarness(); | 124 TestHarness(); |
125 virtual ~TestHarness(); | 125 virtual ~TestHarness(); |
126 | 126 |
127 virtual void SetUp() OVERRIDE; | 127 virtual void SetUp() OVERRIDE; |
128 | 128 |
129 virtual ConfigurationPolicyProvider* CreateProvider( | 129 virtual ConfigurationPolicyProvider* CreateProvider( |
| 130 SchemaRegistry* registry, |
130 scoped_refptr<base::SequencedTaskRunner> task_runner, | 131 scoped_refptr<base::SequencedTaskRunner> task_runner, |
131 const PolicyDefinitionList* policy_definition_list) OVERRIDE; | 132 const PolicyDefinitionList* policy_definition_list) OVERRIDE; |
132 | 133 |
133 virtual void InstallEmptyPolicy() OVERRIDE; | 134 virtual void InstallEmptyPolicy() OVERRIDE; |
134 virtual void InstallStringPolicy(const std::string& policy_name, | 135 virtual void InstallStringPolicy(const std::string& policy_name, |
135 const std::string& policy_value) OVERRIDE; | 136 const std::string& policy_value) OVERRIDE; |
136 virtual void InstallIntegerPolicy(const std::string& policy_name, | 137 virtual void InstallIntegerPolicy(const std::string& policy_name, |
137 int policy_value) OVERRIDE; | 138 int policy_value) OVERRIDE; |
138 virtual void InstallBooleanPolicy(const std::string& policy_name, | 139 virtual void InstallBooleanPolicy(const std::string& policy_name, |
139 bool policy_value) OVERRIDE; | 140 bool policy_value) OVERRIDE; |
(...skipping 13 matching lines...) Expand all Loading... |
153 }; | 154 }; |
154 | 155 |
155 TestHarness::TestHarness() | 156 TestHarness::TestHarness() |
156 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER) {} | 157 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER) {} |
157 | 158 |
158 TestHarness::~TestHarness() {} | 159 TestHarness::~TestHarness() {} |
159 | 160 |
160 void TestHarness::SetUp() {} | 161 void TestHarness::SetUp() {} |
161 | 162 |
162 ConfigurationPolicyProvider* TestHarness::CreateProvider( | 163 ConfigurationPolicyProvider* TestHarness::CreateProvider( |
| 164 SchemaRegistry* registry, |
163 scoped_refptr<base::SequencedTaskRunner> task_runner, | 165 scoped_refptr<base::SequencedTaskRunner> task_runner, |
164 const PolicyDefinitionList* policy_definition_list) { | 166 const PolicyDefinitionList* policy_definition_list) { |
165 prefs_ = new MockPreferences(); | 167 prefs_ = new MockPreferences(); |
166 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderMac( | 168 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderMac( |
167 task_runner, policy_definition_list, base::FilePath(), prefs_)); | 169 task_runner, policy_definition_list, base::FilePath(), prefs_)); |
168 return new AsyncPolicyProvider(loader.Pass()); | 170 return new AsyncPolicyProvider(registry, loader.Pass()); |
169 } | 171 } |
170 | 172 |
171 void TestHarness::InstallEmptyPolicy() {} | 173 void TestHarness::InstallEmptyPolicy() {} |
172 | 174 |
173 void TestHarness::InstallStringPolicy(const std::string& policy_name, | 175 void TestHarness::InstallStringPolicy(const std::string& policy_name, |
174 const std::string& policy_value) { | 176 const std::string& policy_value) { |
175 ScopedCFTypeRef<CFStringRef> name(base::SysUTF8ToCFStringRef(policy_name)); | 177 ScopedCFTypeRef<CFStringRef> name(base::SysUTF8ToCFStringRef(policy_name)); |
176 ScopedCFTypeRef<CFStringRef> value(base::SysUTF8ToCFStringRef(policy_value)); | 178 ScopedCFTypeRef<CFStringRef> value(base::SysUTF8ToCFStringRef(policy_value)); |
177 prefs_->AddTestItem(name, value, true); | 179 prefs_->AddTestItem(name, value, true); |
178 } | 180 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 ConfigurationPolicyProviderTest, | 227 ConfigurationPolicyProviderTest, |
226 testing::Values(TestHarness::Create)); | 228 testing::Values(TestHarness::Create)); |
227 | 229 |
228 // TODO(joaodasilva): instantiate Configuration3rdPartyPolicyProviderTest too | 230 // TODO(joaodasilva): instantiate Configuration3rdPartyPolicyProviderTest too |
229 // once the mac loader supports 3rd party policy. http://crbug.com/108995 | 231 // once the mac loader supports 3rd party policy. http://crbug.com/108995 |
230 | 232 |
231 // Special test cases for some mac preferences details. | 233 // Special test cases for some mac preferences details. |
232 class PolicyLoaderMacTest : public PolicyTestBase { | 234 class PolicyLoaderMacTest : public PolicyTestBase { |
233 protected: | 235 protected: |
234 PolicyLoaderMacTest() | 236 PolicyLoaderMacTest() |
235 : prefs_(new MockPreferences()), | 237 : prefs_(new MockPreferences()) {} |
236 loader_(new PolicyLoaderMac(loop_.message_loop_proxy(), | |
237 &test_policy_definitions::kList, | |
238 base::FilePath(), | |
239 prefs_)), | |
240 provider_(scoped_ptr<AsyncPolicyLoader>(loader_)) {} | |
241 virtual ~PolicyLoaderMacTest() {} | 238 virtual ~PolicyLoaderMacTest() {} |
242 | 239 |
243 virtual void SetUp() OVERRIDE { | 240 virtual void SetUp() OVERRIDE { |
244 PolicyTestBase::SetUp(); | 241 PolicyTestBase::SetUp(); |
245 provider_.Init(); | 242 scoped_ptr<AsyncPolicyLoader> loader( |
| 243 new PolicyLoaderMac(loop_.message_loop_proxy(), |
| 244 &test_policy_definitions::kList, |
| 245 base::FilePath(), |
| 246 prefs_)); |
| 247 provider_.reset(new AsyncPolicyProvider(&schema_registry_, loader.Pass())); |
| 248 provider_->Init(&schema_registry_); |
246 } | 249 } |
247 | 250 |
248 virtual void TearDown() OVERRIDE { | 251 virtual void TearDown() OVERRIDE { |
249 provider_.Shutdown(); | 252 provider_->Shutdown(); |
250 PolicyTestBase::TearDown(); | 253 PolicyTestBase::TearDown(); |
251 } | 254 } |
252 | 255 |
253 MockPreferences* prefs_; | 256 MockPreferences* prefs_; |
254 PolicyLoaderMac* loader_; | 257 scoped_ptr<AsyncPolicyProvider> provider_; |
255 AsyncPolicyProvider provider_; | |
256 }; | 258 }; |
257 | 259 |
258 TEST_F(PolicyLoaderMacTest, Invalid) { | 260 TEST_F(PolicyLoaderMacTest, Invalid) { |
259 ScopedCFTypeRef<CFStringRef> name( | 261 ScopedCFTypeRef<CFStringRef> name( |
260 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString)); | 262 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString)); |
261 const char buffer[] = "binary \xde\xad\xbe\xef data"; | 263 const char buffer[] = "binary \xde\xad\xbe\xef data"; |
262 ScopedCFTypeRef<CFDataRef> invalid_data( | 264 ScopedCFTypeRef<CFDataRef> invalid_data( |
263 CFDataCreate(kCFAllocatorDefault, | 265 CFDataCreate(kCFAllocatorDefault, |
264 reinterpret_cast<const UInt8 *>(buffer), | 266 reinterpret_cast<const UInt8 *>(buffer), |
265 arraysize(buffer))); | 267 arraysize(buffer))); |
266 ASSERT_TRUE(invalid_data); | 268 ASSERT_TRUE(invalid_data); |
267 prefs_->AddTestItem(name, invalid_data.get(), true); | 269 prefs_->AddTestItem(name, invalid_data.get(), true); |
268 prefs_->AddTestItem(name, invalid_data.get(), false); | 270 prefs_->AddTestItem(name, invalid_data.get(), false); |
269 | 271 |
270 // Make the provider read the updated |prefs_|. | 272 // Make the provider read the updated |prefs_|. |
271 provider_.RefreshPolicies(); | 273 provider_->RefreshPolicies(); |
272 loop_.RunUntilIdle(); | 274 loop_.RunUntilIdle(); |
273 const PolicyBundle kEmptyBundle; | 275 const PolicyBundle kEmptyBundle; |
274 EXPECT_TRUE(provider_.policies().Equals(kEmptyBundle)); | 276 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); |
275 } | 277 } |
276 | 278 |
277 TEST_F(PolicyLoaderMacTest, TestNonForcedValue) { | 279 TEST_F(PolicyLoaderMacTest, TestNonForcedValue) { |
278 ScopedCFTypeRef<CFStringRef> name( | 280 ScopedCFTypeRef<CFStringRef> name( |
279 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString)); | 281 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString)); |
280 ScopedCFTypeRef<CFPropertyListRef> test_value( | 282 ScopedCFTypeRef<CFPropertyListRef> test_value( |
281 base::SysUTF8ToCFStringRef("string value")); | 283 base::SysUTF8ToCFStringRef("string value")); |
282 ASSERT_TRUE(test_value.get()); | 284 ASSERT_TRUE(test_value.get()); |
283 prefs_->AddTestItem(name, test_value.get(), false); | 285 prefs_->AddTestItem(name, test_value.get(), false); |
284 | 286 |
285 // Make the provider read the updated |prefs_|. | 287 // Make the provider read the updated |prefs_|. |
286 provider_.RefreshPolicies(); | 288 provider_->RefreshPolicies(); |
287 loop_.RunUntilIdle(); | 289 loop_.RunUntilIdle(); |
288 PolicyBundle expected_bundle; | 290 PolicyBundle expected_bundle; |
289 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 291 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
290 .Set(test_policy_definitions::kKeyString, | 292 .Set(test_policy_definitions::kKeyString, |
291 POLICY_LEVEL_RECOMMENDED, | 293 POLICY_LEVEL_RECOMMENDED, |
292 POLICY_SCOPE_USER, | 294 POLICY_SCOPE_USER, |
293 base::Value::CreateStringValue("string value"), | 295 base::Value::CreateStringValue("string value"), |
294 NULL); | 296 NULL); |
295 EXPECT_TRUE(provider_.policies().Equals(expected_bundle)); | 297 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); |
296 } | 298 } |
297 | 299 |
298 TEST_F(PolicyLoaderMacTest, TestConversions) { | 300 TEST_F(PolicyLoaderMacTest, TestConversions) { |
299 base::DictionaryValue root; | 301 base::DictionaryValue root; |
300 | 302 |
301 // base::Value::TYPE_NULL | 303 // base::Value::TYPE_NULL |
302 root.Set("null", base::Value::CreateNullValue()); | 304 root.Set("null", base::Value::CreateNullValue()); |
303 | 305 |
304 // base::Value::TYPE_BOOLEAN | 306 // base::Value::TYPE_BOOLEAN |
305 root.SetBoolean("false", false); | 307 root.SetBoolean("false", false); |
(...skipping 29 matching lines...) Expand all Loading... |
335 ScopedCFTypeRef<CFPropertyListRef> property(CreatePropertyFromValue(&root)); | 337 ScopedCFTypeRef<CFPropertyListRef> property(CreatePropertyFromValue(&root)); |
336 ASSERT_TRUE(property); | 338 ASSERT_TRUE(property); |
337 scoped_ptr<base::Value> value( | 339 scoped_ptr<base::Value> value( |
338 PolicyLoaderMac::CreateValueFromProperty(property)); | 340 PolicyLoaderMac::CreateValueFromProperty(property)); |
339 ASSERT_TRUE(value.get()); | 341 ASSERT_TRUE(value.get()); |
340 | 342 |
341 EXPECT_TRUE(root.Equals(value.get())); | 343 EXPECT_TRUE(root.Equals(value.get())); |
342 } | 344 } |
343 | 345 |
344 } // namespace policy | 346 } // namespace policy |
OLD | NEW |