OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/cloud_policy_provider.h" | 5 #include "chrome/browser/policy/cloud_policy_provider.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/browser_process.h" | |
10 #include "chrome/browser/policy/browser_policy_connector.h" | |
9 #include "chrome/browser/policy/cloud_policy_cache_base.h" | 11 #include "chrome/browser/policy/cloud_policy_cache_base.h" |
10 #include "chrome/browser/policy/cloud_policy_provider_impl.h" | 12 #include "chrome/browser/policy/cloud_policy_provider_impl.h" |
11 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 13 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
12 #include "policy/policy_constants.h" | 14 #include "policy/policy_constants.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
14 | 16 |
15 using testing::AnyNumber; | 17 using testing::AnyNumber; |
16 using testing::_; | 18 using testing::_; |
17 | 19 |
18 namespace policy { | 20 namespace policy { |
(...skipping 21 matching lines...) Expand all Loading... | |
40 } | 42 } |
41 | 43 |
42 PolicyMap* raw_recommended_policy() { | 44 PolicyMap* raw_recommended_policy() { |
43 return &recommended_policy_; | 45 return &recommended_policy_; |
44 } | 46 } |
45 | 47 |
46 void SetUnmanaged() { | 48 void SetUnmanaged() { |
47 is_unmanaged_ = true; | 49 is_unmanaged_ = true; |
48 } | 50 } |
49 | 51 |
50 void SetFetchingDone() { | |
51 // Implement pure virtual method. | |
52 } | |
53 | |
54 void set_initialized(bool initialized) { | 52 void set_initialized(bool initialized) { |
55 initialization_complete_ = initialized; | 53 initialization_complete_ = initialized; |
56 } | 54 } |
57 | 55 |
58 private: | 56 private: |
59 DISALLOW_COPY_AND_ASSIGN(MockCloudPolicyCache); | 57 DISALLOW_COPY_AND_ASSIGN(MockCloudPolicyCache); |
60 }; | 58 }; |
61 | 59 |
62 class CloudPolicyProviderTest : public testing::Test { | 60 class CloudPolicyProviderTest : public testing::Test { |
63 protected: | 61 protected: |
62 virtual void SetUp() OVERRIDE { | |
63 browser_policy_connector_.reset(new BrowserPolicyConnector()); | |
Mattias Nissler (ping if slow)
2011/11/18 16:14:11
No need to wrap in a scoped_ptr.
Joao da Silva
2011/11/21 14:55:04
Done.
| |
64 } | |
65 | |
64 void CreateCloudPolicyProvider(CloudPolicyCacheBase::PolicyLevel level) { | 66 void CreateCloudPolicyProvider(CloudPolicyCacheBase::PolicyLevel level) { |
65 cloud_policy_provider_.reset(new CloudPolicyProviderImpl( | 67 cloud_policy_provider_.reset( |
66 GetChromePolicyDefinitionList(), level)); | 68 new CloudPolicyProviderImpl( |
69 browser_policy_connector_.get(), | |
70 GetChromePolicyDefinitionList(), | |
71 level)); | |
67 } | 72 } |
68 | 73 |
69 // Appends the caches to a provider and then provides the policies to | 74 // Appends the caches to a provider and then provides the policies to |
70 // |policy_map_|. | 75 // |policy_map_|. |
71 void RunCachesThroughProvider(MockCloudPolicyCache caches[], int n, | 76 void RunCachesThroughProvider(MockCloudPolicyCache caches[], int n, |
72 CloudPolicyCacheBase::PolicyLevel level) { | 77 CloudPolicyCacheBase::PolicyLevel level) { |
73 CloudPolicyProviderImpl provider( | 78 CloudPolicyProviderImpl provider( |
79 g_browser_process->browser_policy_connector(), | |
74 GetChromePolicyDefinitionList(), | 80 GetChromePolicyDefinitionList(), |
75 level); | 81 level); |
76 for (int i = 0; i < n; i++) { | 82 for (int i = 0; i < n; i++) { |
77 provider.AppendCache(&caches[i]); | 83 provider.AppendCache(&caches[i]); |
78 } | 84 } |
79 policy_map_.reset(new PolicyMap()); | 85 policy_map_.reset(new PolicyMap()); |
80 provider.Provide(policy_map_.get()); | 86 provider.Provide(policy_map_.get()); |
81 } | 87 } |
82 | 88 |
83 // Checks a string policy in |policy_map_|. | 89 // Checks a string policy in |policy_map_|. |
(...skipping 20 matching lines...) Expand all Loading... | |
104 } | 110 } |
105 | 111 |
106 void CombineTwoPolicyMaps(const PolicyMap& base, | 112 void CombineTwoPolicyMaps(const PolicyMap& base, |
107 const PolicyMap& overlay, | 113 const PolicyMap& overlay, |
108 PolicyMap* out_map) { | 114 PolicyMap* out_map) { |
109 DCHECK(cloud_policy_provider_.get()); | 115 DCHECK(cloud_policy_provider_.get()); |
110 cloud_policy_provider_->CombineTwoPolicyMaps(base, overlay, out_map); | 116 cloud_policy_provider_->CombineTwoPolicyMaps(base, overlay, out_map); |
111 } | 117 } |
112 | 118 |
113 private: | 119 private: |
114 // Some tests need a list of policies that doesn't contain any proxy | 120 scoped_ptr<BrowserPolicyConnector> browser_policy_connector_; |
115 // policies. Note: these policies will be handled as if they had the | |
116 // type of Value::TYPE_INTEGER. | |
117 static const ConfigurationPolicyType simple_policies[]; | |
118 | |
119 scoped_ptr<CloudPolicyProviderImpl> cloud_policy_provider_; | 121 scoped_ptr<CloudPolicyProviderImpl> cloud_policy_provider_; |
120 scoped_ptr<PolicyMap> policy_map_; | 122 scoped_ptr<PolicyMap> policy_map_; |
121 }; | 123 }; |
122 | 124 |
123 // Proxy setting distributed over multiple caches. | 125 // Proxy setting distributed over multiple caches. |
124 TEST_F(CloudPolicyProviderTest, | 126 TEST_F(CloudPolicyProviderTest, |
125 ProxySettingDistributedOverMultipleCaches) { | 127 ProxySettingDistributedOverMultipleCaches) { |
126 // There are proxy_policy_count()+1 = 6 caches and they are mixed together by | 128 // There are proxy_policy_count()+1 = 6 caches and they are mixed together by |
127 // one instance of CloudPolicyProvider. The first cache has some policies but | 129 // one instance of CloudPolicyProvider. The first cache has some policies but |
128 // no proxy-related ones. The following caches have each one proxy-policy set. | 130 // no proxy-related ones. The following caches have each one proxy-policy set. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 B.Set(kPolicyProxyPacUrl, Value::CreateIntegerValue(b_value)); | 236 B.Set(kPolicyProxyPacUrl, Value::CreateIntegerValue(b_value)); |
235 B.Set(kPolicyProxyBypassList, Value::CreateIntegerValue(b_value)); | 237 B.Set(kPolicyProxyBypassList, Value::CreateIntegerValue(b_value)); |
236 | 238 |
237 CombineTwoPolicyMaps(A, B, &C); | 239 CombineTwoPolicyMaps(A, B, &C); |
238 | 240 |
239 EXPECT_TRUE(A.Equals(C)); | 241 EXPECT_TRUE(A.Equals(C)); |
240 EXPECT_FALSE(B.Equals(C)); | 242 EXPECT_FALSE(B.Equals(C)); |
241 } | 243 } |
242 | 244 |
243 } // namespace policy | 245 } // namespace policy |
OLD | NEW |