Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(449)

Side by Side Diff: chrome/browser/policy/policy_loader_mac_unittest.cc

Issue 58313002: Removed the PolicyDefinitionList. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome-policy-schema-10-use-registry
Patch Set: rebase Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/policy/policy_loader_mac.cc ('k') | chrome/browser/policy/policy_loader_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
21 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
22 21
23 using base::ScopedCFTypeRef; 22 using base::ScopedCFTypeRef;
24 23
25 namespace policy { 24 namespace policy {
26 25
27 namespace { 26 namespace {
28 27
29 // Converts a base::Value to the equivalent CFPropertyListRef. 28 // Converts a base::Value to the equivalent CFPropertyListRef.
30 // The returned value is owned by the caller. 29 // The returned value is owned by the caller.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 120
122 class TestHarness : public PolicyProviderTestHarness { 121 class TestHarness : public PolicyProviderTestHarness {
123 public: 122 public:
124 TestHarness(); 123 TestHarness();
125 virtual ~TestHarness(); 124 virtual ~TestHarness();
126 125
127 virtual void SetUp() OVERRIDE; 126 virtual void SetUp() OVERRIDE;
128 127
129 virtual ConfigurationPolicyProvider* CreateProvider( 128 virtual ConfigurationPolicyProvider* CreateProvider(
130 SchemaRegistry* registry, 129 SchemaRegistry* registry,
131 scoped_refptr<base::SequencedTaskRunner> task_runner, 130 scoped_refptr<base::SequencedTaskRunner> task_runner) OVERRIDE;
132 const PolicyDefinitionList* policy_definition_list) OVERRIDE;
133 131
134 virtual void InstallEmptyPolicy() OVERRIDE; 132 virtual void InstallEmptyPolicy() OVERRIDE;
135 virtual void InstallStringPolicy(const std::string& policy_name, 133 virtual void InstallStringPolicy(const std::string& policy_name,
136 const std::string& policy_value) OVERRIDE; 134 const std::string& policy_value) OVERRIDE;
137 virtual void InstallIntegerPolicy(const std::string& policy_name, 135 virtual void InstallIntegerPolicy(const std::string& policy_name,
138 int policy_value) OVERRIDE; 136 int policy_value) OVERRIDE;
139 virtual void InstallBooleanPolicy(const std::string& policy_name, 137 virtual void InstallBooleanPolicy(const std::string& policy_name,
140 bool policy_value) OVERRIDE; 138 bool policy_value) OVERRIDE;
141 virtual void InstallStringListPolicy( 139 virtual void InstallStringListPolicy(
142 const std::string& policy_name, 140 const std::string& policy_name,
(...skipping 12 matching lines...) Expand all
155 153
156 TestHarness::TestHarness() 154 TestHarness::TestHarness()
157 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER) {} 155 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER) {}
158 156
159 TestHarness::~TestHarness() {} 157 TestHarness::~TestHarness() {}
160 158
161 void TestHarness::SetUp() {} 159 void TestHarness::SetUp() {}
162 160
163 ConfigurationPolicyProvider* TestHarness::CreateProvider( 161 ConfigurationPolicyProvider* TestHarness::CreateProvider(
164 SchemaRegistry* registry, 162 SchemaRegistry* registry,
165 scoped_refptr<base::SequencedTaskRunner> task_runner, 163 scoped_refptr<base::SequencedTaskRunner> task_runner) {
166 const PolicyDefinitionList* policy_definition_list) {
167 prefs_ = new MockPreferences(); 164 prefs_ = new MockPreferences();
168 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderMac( 165 scoped_ptr<AsyncPolicyLoader> loader(
169 task_runner, policy_definition_list, base::FilePath(), prefs_)); 166 new PolicyLoaderMac(task_runner, base::FilePath(), prefs_));
170 return new AsyncPolicyProvider(registry, loader.Pass()); 167 return new AsyncPolicyProvider(registry, loader.Pass());
171 } 168 }
172 169
173 void TestHarness::InstallEmptyPolicy() {} 170 void TestHarness::InstallEmptyPolicy() {}
174 171
175 void TestHarness::InstallStringPolicy(const std::string& policy_name, 172 void TestHarness::InstallStringPolicy(const std::string& policy_name,
176 const std::string& policy_value) { 173 const std::string& policy_value) {
177 ScopedCFTypeRef<CFStringRef> name(base::SysUTF8ToCFStringRef(policy_name)); 174 ScopedCFTypeRef<CFStringRef> name(base::SysUTF8ToCFStringRef(policy_name));
178 ScopedCFTypeRef<CFStringRef> value(base::SysUTF8ToCFStringRef(policy_value)); 175 ScopedCFTypeRef<CFStringRef> value(base::SysUTF8ToCFStringRef(policy_value));
179 prefs_->AddTestItem(name, value, true); 176 prefs_->AddTestItem(name, value, true);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 229
233 // Special test cases for some mac preferences details. 230 // Special test cases for some mac preferences details.
234 class PolicyLoaderMacTest : public PolicyTestBase { 231 class PolicyLoaderMacTest : public PolicyTestBase {
235 protected: 232 protected:
236 PolicyLoaderMacTest() 233 PolicyLoaderMacTest()
237 : prefs_(new MockPreferences()) {} 234 : prefs_(new MockPreferences()) {}
238 virtual ~PolicyLoaderMacTest() {} 235 virtual ~PolicyLoaderMacTest() {}
239 236
240 virtual void SetUp() OVERRIDE { 237 virtual void SetUp() OVERRIDE {
241 PolicyTestBase::SetUp(); 238 PolicyTestBase::SetUp();
242 scoped_ptr<AsyncPolicyLoader> loader( 239 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderMac(
243 new PolicyLoaderMac(loop_.message_loop_proxy(), 240 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())); 241 provider_.reset(new AsyncPolicyProvider(&schema_registry_, loader.Pass()));
248 provider_->Init(&schema_registry_); 242 provider_->Init(&schema_registry_);
249 } 243 }
250 244
251 virtual void TearDown() OVERRIDE { 245 virtual void TearDown() OVERRIDE {
252 provider_->Shutdown(); 246 provider_->Shutdown();
253 PolicyTestBase::TearDown(); 247 PolicyTestBase::TearDown();
254 } 248 }
255 249
256 MockPreferences* prefs_; 250 MockPreferences* prefs_;
257 scoped_ptr<AsyncPolicyProvider> provider_; 251 scoped_ptr<AsyncPolicyProvider> provider_;
258 }; 252 };
259 253
260 TEST_F(PolicyLoaderMacTest, Invalid) { 254 TEST_F(PolicyLoaderMacTest, Invalid) {
261 ScopedCFTypeRef<CFStringRef> name( 255 ScopedCFTypeRef<CFStringRef> name(
262 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString)); 256 base::SysUTF8ToCFStringRef(test_keys::kKeyString));
263 const char buffer[] = "binary \xde\xad\xbe\xef data"; 257 const char buffer[] = "binary \xde\xad\xbe\xef data";
264 ScopedCFTypeRef<CFDataRef> invalid_data( 258 ScopedCFTypeRef<CFDataRef> invalid_data(
265 CFDataCreate(kCFAllocatorDefault, 259 CFDataCreate(kCFAllocatorDefault,
266 reinterpret_cast<const UInt8 *>(buffer), 260 reinterpret_cast<const UInt8 *>(buffer),
267 arraysize(buffer))); 261 arraysize(buffer)));
268 ASSERT_TRUE(invalid_data); 262 ASSERT_TRUE(invalid_data);
269 prefs_->AddTestItem(name, invalid_data.get(), true); 263 prefs_->AddTestItem(name, invalid_data.get(), true);
270 prefs_->AddTestItem(name, invalid_data.get(), false); 264 prefs_->AddTestItem(name, invalid_data.get(), false);
271 265
272 // Make the provider read the updated |prefs_|. 266 // Make the provider read the updated |prefs_|.
273 provider_->RefreshPolicies(); 267 provider_->RefreshPolicies();
274 loop_.RunUntilIdle(); 268 loop_.RunUntilIdle();
275 const PolicyBundle kEmptyBundle; 269 const PolicyBundle kEmptyBundle;
276 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); 270 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle));
277 } 271 }
278 272
279 TEST_F(PolicyLoaderMacTest, TestNonForcedValue) { 273 TEST_F(PolicyLoaderMacTest, TestNonForcedValue) {
280 ScopedCFTypeRef<CFStringRef> name( 274 ScopedCFTypeRef<CFStringRef> name(
281 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString)); 275 base::SysUTF8ToCFStringRef(test_keys::kKeyString));
282 ScopedCFTypeRef<CFPropertyListRef> test_value( 276 ScopedCFTypeRef<CFPropertyListRef> test_value(
283 base::SysUTF8ToCFStringRef("string value")); 277 base::SysUTF8ToCFStringRef("string value"));
284 ASSERT_TRUE(test_value.get()); 278 ASSERT_TRUE(test_value.get());
285 prefs_->AddTestItem(name, test_value.get(), false); 279 prefs_->AddTestItem(name, test_value.get(), false);
286 280
287 // Make the provider read the updated |prefs_|. 281 // Make the provider read the updated |prefs_|.
288 provider_->RefreshPolicies(); 282 provider_->RefreshPolicies();
289 loop_.RunUntilIdle(); 283 loop_.RunUntilIdle();
290 PolicyBundle expected_bundle; 284 PolicyBundle expected_bundle;
291 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 285 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
292 .Set(test_policy_definitions::kKeyString, 286 .Set(test_keys::kKeyString,
293 POLICY_LEVEL_RECOMMENDED, 287 POLICY_LEVEL_RECOMMENDED,
294 POLICY_SCOPE_USER, 288 POLICY_SCOPE_USER,
295 base::Value::CreateStringValue("string value"), 289 base::Value::CreateStringValue("string value"),
296 NULL); 290 NULL);
297 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); 291 EXPECT_TRUE(provider_->policies().Equals(expected_bundle));
298 } 292 }
299 293
300 TEST_F(PolicyLoaderMacTest, TestConversions) { 294 TEST_F(PolicyLoaderMacTest, TestConversions) {
301 base::DictionaryValue root; 295 base::DictionaryValue root;
302 296
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 ScopedCFTypeRef<CFPropertyListRef> property(CreatePropertyFromValue(&root)); 331 ScopedCFTypeRef<CFPropertyListRef> property(CreatePropertyFromValue(&root));
338 ASSERT_TRUE(property); 332 ASSERT_TRUE(property);
339 scoped_ptr<base::Value> value( 333 scoped_ptr<base::Value> value(
340 PolicyLoaderMac::CreateValueFromProperty(property)); 334 PolicyLoaderMac::CreateValueFromProperty(property));
341 ASSERT_TRUE(value.get()); 335 ASSERT_TRUE(value.get());
342 336
343 EXPECT_TRUE(root.Equals(value.get())); 337 EXPECT_TRUE(root.Equals(value.get()));
344 } 338 }
345 339
346 } // namespace policy 340 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_loader_mac.cc ('k') | chrome/browser/policy/policy_loader_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698