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

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

Issue 10496013: Implement the mac policy provider based on the AsyncPolicyLoader. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: addressed comments Created 8 years, 6 months 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
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/mac/scoped_cftyperef.h" 8 #include "base/mac/scoped_cftyperef.h"
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/policy/asynchronous_policy_test_base.h" 11 #include "chrome/browser/policy/async_policy_provider.h"
12 #include "chrome/browser/policy/configuration_policy_provider_mac.h"
13 #include "chrome/browser/policy/configuration_policy_provider_test.h" 12 #include "chrome/browser/policy/configuration_policy_provider_test.h"
14 #include "chrome/browser/policy/policy_bundle.h" 13 #include "chrome/browser/policy/policy_bundle.h"
14 #include "chrome/browser/policy/policy_loader_mac.h"
15 #include "chrome/browser/policy/policy_map.h" 15 #include "chrome/browser/policy/policy_map.h"
16 #include "chrome/browser/preferences_mock_mac.h" 16 #include "chrome/browser/preferences_mock_mac.h"
17 #include "policy/policy_constants.h" 17 #include "policy/policy_constants.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 using base::mac::ScopedCFTypeRef; 20 using base::mac::ScopedCFTypeRef;
21 21
22 namespace policy { 22 namespace policy {
23 23
24 namespace { 24 namespace {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 return NULL; 116 return NULL;
117 } 117 }
118 118
119 class TestHarness : public PolicyProviderTestHarness { 119 class TestHarness : public PolicyProviderTestHarness {
120 public: 120 public:
121 TestHarness(); 121 TestHarness();
122 virtual ~TestHarness(); 122 virtual ~TestHarness();
123 123
124 virtual void SetUp() OVERRIDE; 124 virtual void SetUp() OVERRIDE;
125 125
126 virtual AsynchronousPolicyProvider* CreateProvider( 126 virtual ConfigurationPolicyProvider* CreateProvider(
127 const PolicyDefinitionList* policy_definition_list) OVERRIDE; 127 const PolicyDefinitionList* policy_definition_list) OVERRIDE;
128 128
129 virtual void InstallEmptyPolicy() OVERRIDE; 129 virtual void InstallEmptyPolicy() OVERRIDE;
130 virtual void InstallStringPolicy(const std::string& policy_name, 130 virtual void InstallStringPolicy(const std::string& policy_name,
131 const std::string& policy_value) OVERRIDE; 131 const std::string& policy_value) OVERRIDE;
132 virtual void InstallIntegerPolicy(const std::string& policy_name, 132 virtual void InstallIntegerPolicy(const std::string& policy_name,
133 int policy_value) OVERRIDE; 133 int policy_value) OVERRIDE;
134 virtual void InstallBooleanPolicy(const std::string& policy_name, 134 virtual void InstallBooleanPolicy(const std::string& policy_name,
135 bool policy_value) OVERRIDE; 135 bool policy_value) OVERRIDE;
136 virtual void InstallStringListPolicy( 136 virtual void InstallStringListPolicy(
(...skipping 11 matching lines...) Expand all
148 DISALLOW_COPY_AND_ASSIGN(TestHarness); 148 DISALLOW_COPY_AND_ASSIGN(TestHarness);
149 }; 149 };
150 150
151 TestHarness::TestHarness() 151 TestHarness::TestHarness()
152 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER) {} 152 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER) {}
153 153
154 TestHarness::~TestHarness() {} 154 TestHarness::~TestHarness() {}
155 155
156 void TestHarness::SetUp() {} 156 void TestHarness::SetUp() {}
157 157
158 AsynchronousPolicyProvider* TestHarness::CreateProvider( 158 ConfigurationPolicyProvider* TestHarness::CreateProvider(
159 const PolicyDefinitionList* policy_definition_list) { 159 const PolicyDefinitionList* policy_list) {
160 prefs_ = new MockPreferences(); 160 prefs_ = new MockPreferences();
161 return new ConfigurationPolicyProviderMac(policy_definition_list, prefs_); 161 scoped_ptr<AsyncPolicyLoader> loader(
162 new MacPolicyLoader(policy_list, prefs_));
163 return new AsyncPolicyProvider(policy_list, loader.Pass());
162 } 164 }
163 165
164 void TestHarness::InstallEmptyPolicy() {} 166 void TestHarness::InstallEmptyPolicy() {}
165 167
166 void TestHarness::InstallStringPolicy(const std::string& policy_name, 168 void TestHarness::InstallStringPolicy(const std::string& policy_name,
167 const std::string& policy_value) { 169 const std::string& policy_value) {
168 ScopedCFTypeRef<CFStringRef> name(base::SysUTF8ToCFStringRef(policy_name)); 170 ScopedCFTypeRef<CFStringRef> name(base::SysUTF8ToCFStringRef(policy_name));
169 ScopedCFTypeRef<CFStringRef> value(base::SysUTF8ToCFStringRef(policy_value)); 171 ScopedCFTypeRef<CFStringRef> value(base::SysUTF8ToCFStringRef(policy_value));
170 prefs_->AddTestItem(name, value, true); 172 prefs_->AddTestItem(name, value, true);
171 } 173 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 209
208 // static 210 // static
209 PolicyProviderTestHarness* TestHarness::Create() { 211 PolicyProviderTestHarness* TestHarness::Create() {
210 return new TestHarness(); 212 return new TestHarness();
211 } 213 }
212 214
213 } // namespace 215 } // namespace
214 216
215 // Instantiate abstract test case for basic policy reading tests. 217 // Instantiate abstract test case for basic policy reading tests.
216 INSTANTIATE_TEST_CASE_P( 218 INSTANTIATE_TEST_CASE_P(
217 ConfigurationPolicyProviderMacTest, 219 MacPolicyProviderTest,
218 ConfigurationPolicyProviderTest, 220 ConfigurationPolicyProviderTest,
219 testing::Values(TestHarness::Create)); 221 testing::Values(TestHarness::Create));
220 222
221 // Special test cases for some mac preferences details. 223 // Special test cases for some mac preferences details.
222 class ConfigurationPolicyProviderMacTest : public AsynchronousPolicyTestBase { 224 class MacPolicyLoaderTest : public PolicyTestBase {
223 protected: 225 protected:
224 ConfigurationPolicyProviderMacTest() 226 MacPolicyLoaderTest()
225 : prefs_(new MockPreferences()), 227 : prefs_(new MockPreferences()),
226 provider_(&test_policy_definitions::kList, prefs_) {} 228 loader_(new MacPolicyLoader(&test_policy_definitions::kList, prefs_)),
227 virtual ~ConfigurationPolicyProviderMacTest() {} 229 provider_(&test_policy_definitions::kList,
230 scoped_ptr<AsyncPolicyLoader>(loader_)) {}
Mattias Nissler (ping if slow) 2012/06/05 11:55:59 Essentially, we could rewrite these tests now with
231 virtual ~MacPolicyLoaderTest() {}
228 232
229 MockPreferences* prefs_; 233 MockPreferences* prefs_;
230 ConfigurationPolicyProviderMac provider_; 234 MacPolicyLoader* loader_;
235 AsyncPolicyProvider provider_;
231 }; 236 };
232 237
233 TEST_F(ConfigurationPolicyProviderMacTest, Invalid) { 238 TEST_F(MacPolicyLoaderTest, Invalid) {
234 ScopedCFTypeRef<CFStringRef> name( 239 ScopedCFTypeRef<CFStringRef> name(
235 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString)); 240 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString));
236 const char buffer[] = "binary \xde\xad\xbe\xef data"; 241 const char buffer[] = "binary \xde\xad\xbe\xef data";
237 ScopedCFTypeRef<CFDataRef> invalid_data( 242 ScopedCFTypeRef<CFDataRef> invalid_data(
238 CFDataCreate(kCFAllocatorDefault, 243 CFDataCreate(kCFAllocatorDefault,
239 reinterpret_cast<const UInt8 *>(buffer), 244 reinterpret_cast<const UInt8 *>(buffer),
240 arraysize(buffer))); 245 arraysize(buffer)));
241 ASSERT_TRUE(invalid_data); 246 ASSERT_TRUE(invalid_data);
242 prefs_->AddTestItem(name, invalid_data.get(), true); 247 prefs_->AddTestItem(name, invalid_data.get(), true);
243 prefs_->AddTestItem(name, invalid_data.get(), false); 248 prefs_->AddTestItem(name, invalid_data.get(), false);
244 249
245 // Make the provider read the updated |prefs_|. 250 // Make the provider read the updated |prefs_|.
246 provider_.RefreshPolicies(); 251 provider_.RefreshPolicies();
247 loop_.RunAllPending(); 252 loop_.RunAllPending();
248 const PolicyBundle kEmptyBundle; 253 const PolicyBundle kEmptyBundle;
249 EXPECT_TRUE(provider_.policies().Equals(kEmptyBundle)); 254 EXPECT_TRUE(provider_.policies().Equals(kEmptyBundle));
250 } 255 }
251 256
252 TEST_F(ConfigurationPolicyProviderMacTest, TestNonForcedValue) { 257 TEST_F(MacPolicyLoaderTest, TestNonForcedValue) {
253 ScopedCFTypeRef<CFStringRef> name( 258 ScopedCFTypeRef<CFStringRef> name(
254 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString)); 259 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString));
255 ScopedCFTypeRef<CFPropertyListRef> test_value( 260 ScopedCFTypeRef<CFPropertyListRef> test_value(
256 base::SysUTF8ToCFStringRef("string value")); 261 base::SysUTF8ToCFStringRef("string value"));
257 ASSERT_TRUE(test_value.get()); 262 ASSERT_TRUE(test_value.get());
258 prefs_->AddTestItem(name, test_value.get(), false); 263 prefs_->AddTestItem(name, test_value.get(), false);
259 264
260 // Make the provider read the updated |prefs_|. 265 // Make the provider read the updated |prefs_|.
261 provider_.RefreshPolicies(); 266 provider_.RefreshPolicies();
262 loop_.RunAllPending(); 267 loop_.RunAllPending();
263 PolicyBundle expected_bundle; 268 PolicyBundle expected_bundle;
264 expected_bundle.Get(POLICY_DOMAIN_CHROME, "") 269 expected_bundle.Get(POLICY_DOMAIN_CHROME, "")
265 .Set(test_policy_definitions::kKeyString, POLICY_LEVEL_RECOMMENDED, 270 .Set(test_policy_definitions::kKeyString, POLICY_LEVEL_RECOMMENDED,
266 POLICY_SCOPE_USER, base::Value::CreateStringValue("string value")); 271 POLICY_SCOPE_USER, base::Value::CreateStringValue("string value"));
267 EXPECT_TRUE(provider_.policies().Equals(expected_bundle)); 272 EXPECT_TRUE(provider_.policies().Equals(expected_bundle));
268 } 273 }
269 274
270 TEST_F(ConfigurationPolicyProviderMacTest, TestConversions) { 275 TEST_F(MacPolicyLoaderTest, TestConversions) {
271 base::DictionaryValue root; 276 base::DictionaryValue root;
272 277
273 // base::Value::TYPE_NULL 278 // base::Value::TYPE_NULL
274 root.Set("null", base::Value::CreateNullValue()); 279 root.Set("null", base::Value::CreateNullValue());
275 280
276 // base::Value::TYPE_BOOLEAN 281 // base::Value::TYPE_BOOLEAN
277 root.SetBoolean("false", false); 282 root.SetBoolean("false", false);
278 root.SetBoolean("true", true); 283 root.SetBoolean("true", true);
279 284
280 // base::Value::TYPE_INTEGER 285 // base::Value::TYPE_INTEGER
(...skipping 19 matching lines...) Expand all
300 305
301 // base::Value::TYPE_DICTIONARY 306 // base::Value::TYPE_DICTIONARY
302 base::DictionaryValue dict; 307 base::DictionaryValue dict;
303 root.Set("emptyd", dict.DeepCopy()); 308 root.Set("emptyd", dict.DeepCopy());
304 // Very meta. 309 // Very meta.
305 root.Set("dict", root.DeepCopy()); 310 root.Set("dict", root.DeepCopy());
306 311
307 ScopedCFTypeRef<CFPropertyListRef> property(CreatePropertyFromValue(&root)); 312 ScopedCFTypeRef<CFPropertyListRef> property(CreatePropertyFromValue(&root));
308 ASSERT_TRUE(property); 313 ASSERT_TRUE(property);
309 scoped_ptr<base::Value> value( 314 scoped_ptr<base::Value> value(
310 MacPreferencesPolicyProviderDelegate::CreateValueFromProperty(property)); 315 MacPolicyLoader::CreateValueFromProperty(property));
311 ASSERT_TRUE(value.get()); 316 ASSERT_TRUE(value.get());
312 317
313 EXPECT_TRUE(root.Equals(value.get())); 318 EXPECT_TRUE(root.Equals(value.get()));
314 } 319 }
315 320
316 } // namespace policy 321 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698