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

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

Issue 10656046: Use a schema to decode 3rd party policy on windows, when present. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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 "chrome/browser/policy/configuration_policy_provider_test.h" 5 #include "chrome/browser/policy/configuration_policy_provider_test.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/policy/configuration_policy_provider.h" 10 #include "chrome/browser/policy/configuration_policy_provider.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 PolicyProviderTestHarness::~PolicyProviderTestHarness() {} 59 PolicyProviderTestHarness::~PolicyProviderTestHarness() {}
60 60
61 PolicyLevel PolicyProviderTestHarness::policy_level() const { 61 PolicyLevel PolicyProviderTestHarness::policy_level() const {
62 return level_; 62 return level_;
63 } 63 }
64 64
65 PolicyScope PolicyProviderTestHarness::policy_scope() const { 65 PolicyScope PolicyProviderTestHarness::policy_scope() const {
66 return scope_; 66 return scope_;
67 } 67 }
68 68
69 void PolicyProviderTestHarness::Install3rdPartyPolicy(
70 const base::DictionaryValue* policies) {
71 FAIL();
72 }
73
69 ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest() {} 74 ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest() {}
70 75
71 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {} 76 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {}
72 77
73 void ConfigurationPolicyProviderTest::SetUp() { 78 void ConfigurationPolicyProviderTest::SetUp() {
74 PolicyTestBase::SetUp(); 79 PolicyTestBase::SetUp();
75 80
76 test_harness_.reset((*GetParam())()); 81 test_harness_.reset((*GetParam())());
77 test_harness_->SetUp(); 82 test_harness_->SetUp();
78 83
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 254
250 PolicyBundle expected_bundle; 255 PolicyBundle expected_bundle;
251 base::DictionaryValue* expected_value = new base::DictionaryValue(); 256 base::DictionaryValue* expected_value = new base::DictionaryValue();
252 expected_value->SetInteger(key::kProxyServerMode, 3); 257 expected_value->SetInteger(key::kProxyServerMode, 3);
253 expected_bundle.Get(POLICY_DOMAIN_CHROME, "") 258 expected_bundle.Get(POLICY_DOMAIN_CHROME, "")
254 .Set(key::kProxySettings, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 259 .Set(key::kProxySettings, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
255 expected_value); 260 expected_value);
256 EXPECT_TRUE(provider.policies().Equals(expected_bundle)); 261 EXPECT_TRUE(provider.policies().Equals(expected_bundle));
257 } 262 }
258 263
264 Configuration3rdPartyPolicyProviderTest::
265 Configuration3rdPartyPolicyProviderTest() {}
266
267 Configuration3rdPartyPolicyProviderTest::
268 ~Configuration3rdPartyPolicyProviderTest() {}
269
270 TEST_P(Configuration3rdPartyPolicyProviderTest, Load3rdParty) {
271 base::DictionaryValue policy_dict;
272 policy_dict.SetBoolean("bool", true);
273 policy_dict.SetDouble("double", 123.456);
274 policy_dict.SetInteger("int", 789);
275 policy_dict.SetString("str", "string value");
276
277 base::ListValue* list = new base::ListValue();
278 for (int i = 0; i < 5; ++i) {
Mattias Nissler (ping if slow) 2012/06/27 12:07:17 two should be enough?
Joao da Silva 2012/06/27 14:31:15 Done.
279 base::DictionaryValue* dict = new base::DictionaryValue();
280 dict->SetInteger("subdictindex", i);
281 dict->Set("subdict", policy_dict.DeepCopy());
282 list->Append(dict);
283 }
284 policy_dict.Set("list", list);
285 policy_dict.Set("dict", policy_dict.DeepCopy());
286
287 // Install these policies as a Chrome policy.
288 test_harness_->InstallDictionaryPolicy(
289 test_policy_definitions::kKeyDictionary, &policy_dict);
290 // Install them as 3rd party policies too.
291 base::DictionaryValue policy_3rdparty;
292 policy_3rdparty.Set("extensions.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
293 policy_dict.DeepCopy());
294 policy_3rdparty.Set("extensions.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
295 policy_dict.DeepCopy());
296 // Install invalid 3rd party policies that shouldn't be loaded. These also
297 // help detecting memory leaks in the code paths that detect invalid input.
298 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy());
299 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc",
300 base::Value::CreateStringValue("invalid-value"));
301 test_harness_->Install3rdPartyPolicy(&policy_3rdparty);
302
303 provider_->RefreshPolicies();
304 loop_.RunAllPending();
305
306 PolicyMap expected_policy;
307 expected_policy.Set(test_policy_definitions::kKeyDictionary,
308 test_harness_->policy_level(),
309 test_harness_->policy_scope(),
310 policy_dict.DeepCopy());
311 PolicyBundle expected_bundle;
312 expected_bundle.Get(POLICY_DOMAIN_CHROME, "").CopyFrom(expected_policy);
313 expected_policy.Clear();
314 expected_policy.LoadFrom(&policy_dict,
315 test_harness_->policy_level(),
316 test_harness_->policy_scope());
317 expected_bundle.Get(POLICY_DOMAIN_EXTENSIONS,
318 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
319 .CopyFrom(expected_policy);
320 expected_bundle.Get(POLICY_DOMAIN_EXTENSIONS,
321 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
322 .CopyFrom(expected_policy);
323 EXPECT_TRUE(provider_->policies().Equals(expected_bundle));
324 }
325
259 } // namespace policy 326 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698