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" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/policy/async_policy_provider.h" | 13 #include "chrome/browser/policy/async_policy_provider.h" |
14 #include "chrome/browser/policy/configuration_policy_provider_test.h" | 14 #include "chrome/browser/policy/configuration_policy_provider_test.h" |
15 #include "chrome/browser/policy/external_data_fetcher.h" | 15 #include "chrome/browser/policy/external_data_fetcher.h" |
16 #include "chrome/browser/policy/policy_bundle.h" | 16 #include "chrome/browser/policy/policy_bundle.h" |
17 #include "chrome/browser/policy/policy_loader_mac.h" | 17 #include "chrome/browser/policy/policy_loader_mac.h" |
18 #include "chrome/browser/policy/policy_map.h" | 18 #include "chrome/browser/policy/policy_map.h" |
19 #include "chrome/browser/policy/preferences_mock_mac.h" | 19 #include "chrome/browser/policy/preferences_mock_mac.h" |
20 #include "policy/policy_constants.h" | 20 #include "policy/policy_constants.h" |
bartfab (slow)
2013/11/05 18:18:33
Nit: Is this still used?
Joao da Silva
2013/11/07 20:27:27
Good catch, removed
| |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 using base::ScopedCFTypeRef; | 23 using base::ScopedCFTypeRef; |
24 | 24 |
25 namespace policy { | 25 namespace policy { |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // Converts a base::Value to the equivalent CFPropertyListRef. | 29 // Converts a base::Value to the equivalent CFPropertyListRef. |
30 // The returned value is owned by the caller. | 30 // The returned value is owned by the caller. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 SchemaRegistry* registry, |
131 scoped_refptr<base::SequencedTaskRunner> task_runner, | 131 scoped_refptr<base::SequencedTaskRunner> task_runner) OVERRIDE; |
132 const PolicyDefinitionList* policy_definition_list) OVERRIDE; | |
133 | 132 |
134 virtual void InstallEmptyPolicy() OVERRIDE; | 133 virtual void InstallEmptyPolicy() OVERRIDE; |
135 virtual void InstallStringPolicy(const std::string& policy_name, | 134 virtual void InstallStringPolicy(const std::string& policy_name, |
136 const std::string& policy_value) OVERRIDE; | 135 const std::string& policy_value) OVERRIDE; |
137 virtual void InstallIntegerPolicy(const std::string& policy_name, | 136 virtual void InstallIntegerPolicy(const std::string& policy_name, |
138 int policy_value) OVERRIDE; | 137 int policy_value) OVERRIDE; |
139 virtual void InstallBooleanPolicy(const std::string& policy_name, | 138 virtual void InstallBooleanPolicy(const std::string& policy_name, |
140 bool policy_value) OVERRIDE; | 139 bool policy_value) OVERRIDE; |
141 virtual void InstallStringListPolicy( | 140 virtual void InstallStringListPolicy( |
142 const std::string& policy_name, | 141 const std::string& policy_name, |
(...skipping 12 matching lines...) Expand all Loading... | |
155 | 154 |
156 TestHarness::TestHarness() | 155 TestHarness::TestHarness() |
157 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER) {} | 156 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER) {} |
158 | 157 |
159 TestHarness::~TestHarness() {} | 158 TestHarness::~TestHarness() {} |
160 | 159 |
161 void TestHarness::SetUp() {} | 160 void TestHarness::SetUp() {} |
162 | 161 |
163 ConfigurationPolicyProvider* TestHarness::CreateProvider( | 162 ConfigurationPolicyProvider* TestHarness::CreateProvider( |
164 SchemaRegistry* registry, | 163 SchemaRegistry* registry, |
165 scoped_refptr<base::SequencedTaskRunner> task_runner, | 164 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
166 const PolicyDefinitionList* policy_definition_list) { | |
167 prefs_ = new MockPreferences(); | 165 prefs_ = new MockPreferences(); |
168 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderMac( | 166 scoped_ptr<AsyncPolicyLoader> loader( |
169 task_runner, policy_definition_list, base::FilePath(), prefs_)); | 167 new PolicyLoaderMac(task_runner, base::FilePath(), prefs_)); |
170 return new AsyncPolicyProvider(registry, loader.Pass()); | 168 return new AsyncPolicyProvider(registry, loader.Pass()); |
171 } | 169 } |
172 | 170 |
173 void TestHarness::InstallEmptyPolicy() {} | 171 void TestHarness::InstallEmptyPolicy() {} |
174 | 172 |
175 void TestHarness::InstallStringPolicy(const std::string& policy_name, | 173 void TestHarness::InstallStringPolicy(const std::string& policy_name, |
176 const std::string& policy_value) { | 174 const std::string& policy_value) { |
177 ScopedCFTypeRef<CFStringRef> name(base::SysUTF8ToCFStringRef(policy_name)); | 175 ScopedCFTypeRef<CFStringRef> name(base::SysUTF8ToCFStringRef(policy_name)); |
178 ScopedCFTypeRef<CFStringRef> value(base::SysUTF8ToCFStringRef(policy_value)); | 176 ScopedCFTypeRef<CFStringRef> value(base::SysUTF8ToCFStringRef(policy_value)); |
179 prefs_->AddTestItem(name, value, true); | 177 prefs_->AddTestItem(name, value, true); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 | 230 |
233 // Special test cases for some mac preferences details. | 231 // Special test cases for some mac preferences details. |
234 class PolicyLoaderMacTest : public PolicyTestBase { | 232 class PolicyLoaderMacTest : public PolicyTestBase { |
235 protected: | 233 protected: |
236 PolicyLoaderMacTest() | 234 PolicyLoaderMacTest() |
237 : prefs_(new MockPreferences()) {} | 235 : prefs_(new MockPreferences()) {} |
238 virtual ~PolicyLoaderMacTest() {} | 236 virtual ~PolicyLoaderMacTest() {} |
239 | 237 |
240 virtual void SetUp() OVERRIDE { | 238 virtual void SetUp() OVERRIDE { |
241 PolicyTestBase::SetUp(); | 239 PolicyTestBase::SetUp(); |
242 scoped_ptr<AsyncPolicyLoader> loader( | 240 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderMac( |
243 new PolicyLoaderMac(loop_.message_loop_proxy(), | 241 loop_.message_loop_proxy(), base::FilePath(), prefs_)); |
244 &test_policy_definitions::kList, | |
245 base::FilePath(), | |
246 prefs_)); | |
247 provider_.reset(new AsyncPolicyProvider(&schema_registry_, loader.Pass())); | 242 provider_.reset(new AsyncPolicyProvider(&schema_registry_, loader.Pass())); |
248 provider_->Init(&schema_registry_); | 243 provider_->Init(&schema_registry_); |
249 } | 244 } |
250 | 245 |
251 virtual void TearDown() OVERRIDE { | 246 virtual void TearDown() OVERRIDE { |
252 provider_->Shutdown(); | 247 provider_->Shutdown(); |
253 PolicyTestBase::TearDown(); | 248 PolicyTestBase::TearDown(); |
254 } | 249 } |
255 | 250 |
256 MockPreferences* prefs_; | 251 MockPreferences* prefs_; |
257 scoped_ptr<AsyncPolicyProvider> provider_; | 252 scoped_ptr<AsyncPolicyProvider> provider_; |
258 }; | 253 }; |
259 | 254 |
260 TEST_F(PolicyLoaderMacTest, Invalid) { | 255 TEST_F(PolicyLoaderMacTest, Invalid) { |
261 ScopedCFTypeRef<CFStringRef> name( | 256 ScopedCFTypeRef<CFStringRef> name( |
262 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString)); | 257 base::SysUTF8ToCFStringRef(test_keys::kKeyString)); |
263 const char buffer[] = "binary \xde\xad\xbe\xef data"; | 258 const char buffer[] = "binary \xde\xad\xbe\xef data"; |
264 ScopedCFTypeRef<CFDataRef> invalid_data( | 259 ScopedCFTypeRef<CFDataRef> invalid_data( |
265 CFDataCreate(kCFAllocatorDefault, | 260 CFDataCreate(kCFAllocatorDefault, |
266 reinterpret_cast<const UInt8 *>(buffer), | 261 reinterpret_cast<const UInt8 *>(buffer), |
267 arraysize(buffer))); | 262 arraysize(buffer))); |
268 ASSERT_TRUE(invalid_data); | 263 ASSERT_TRUE(invalid_data); |
269 prefs_->AddTestItem(name, invalid_data.get(), true); | 264 prefs_->AddTestItem(name, invalid_data.get(), true); |
270 prefs_->AddTestItem(name, invalid_data.get(), false); | 265 prefs_->AddTestItem(name, invalid_data.get(), false); |
271 | 266 |
272 // Make the provider read the updated |prefs_|. | 267 // Make the provider read the updated |prefs_|. |
273 provider_->RefreshPolicies(); | 268 provider_->RefreshPolicies(); |
274 loop_.RunUntilIdle(); | 269 loop_.RunUntilIdle(); |
275 const PolicyBundle kEmptyBundle; | 270 const PolicyBundle kEmptyBundle; |
276 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); | 271 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); |
277 } | 272 } |
278 | 273 |
279 TEST_F(PolicyLoaderMacTest, TestNonForcedValue) { | 274 TEST_F(PolicyLoaderMacTest, TestNonForcedValue) { |
280 ScopedCFTypeRef<CFStringRef> name( | 275 ScopedCFTypeRef<CFStringRef> name( |
281 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString)); | 276 base::SysUTF8ToCFStringRef(test_keys::kKeyString)); |
282 ScopedCFTypeRef<CFPropertyListRef> test_value( | 277 ScopedCFTypeRef<CFPropertyListRef> test_value( |
283 base::SysUTF8ToCFStringRef("string value")); | 278 base::SysUTF8ToCFStringRef("string value")); |
284 ASSERT_TRUE(test_value.get()); | 279 ASSERT_TRUE(test_value.get()); |
285 prefs_->AddTestItem(name, test_value.get(), false); | 280 prefs_->AddTestItem(name, test_value.get(), false); |
286 | 281 |
287 // Make the provider read the updated |prefs_|. | 282 // Make the provider read the updated |prefs_|. |
288 provider_->RefreshPolicies(); | 283 provider_->RefreshPolicies(); |
289 loop_.RunUntilIdle(); | 284 loop_.RunUntilIdle(); |
290 PolicyBundle expected_bundle; | 285 PolicyBundle expected_bundle; |
291 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 286 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
292 .Set(test_policy_definitions::kKeyString, | 287 .Set(test_keys::kKeyString, |
293 POLICY_LEVEL_RECOMMENDED, | 288 POLICY_LEVEL_RECOMMENDED, |
294 POLICY_SCOPE_USER, | 289 POLICY_SCOPE_USER, |
295 base::Value::CreateStringValue("string value"), | 290 base::Value::CreateStringValue("string value"), |
296 NULL); | 291 NULL); |
297 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); | 292 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); |
298 } | 293 } |
299 | 294 |
300 TEST_F(PolicyLoaderMacTest, TestConversions) { | 295 TEST_F(PolicyLoaderMacTest, TestConversions) { |
301 base::DictionaryValue root; | 296 base::DictionaryValue root; |
302 | 297 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 ScopedCFTypeRef<CFPropertyListRef> property(CreatePropertyFromValue(&root)); | 332 ScopedCFTypeRef<CFPropertyListRef> property(CreatePropertyFromValue(&root)); |
338 ASSERT_TRUE(property); | 333 ASSERT_TRUE(property); |
339 scoped_ptr<base::Value> value( | 334 scoped_ptr<base::Value> value( |
340 PolicyLoaderMac::CreateValueFromProperty(property)); | 335 PolicyLoaderMac::CreateValueFromProperty(property)); |
341 ASSERT_TRUE(value.get()); | 336 ASSERT_TRUE(value.get()); |
342 | 337 |
343 EXPECT_TRUE(root.Equals(value.get())); | 338 EXPECT_TRUE(root.Equals(value.get())); |
344 } | 339 } |
345 | 340 |
346 } // namespace policy | 341 } // namespace policy |
OLD | NEW |