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

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

Issue 9911029: Refactored the CloudPolicyProvider so that it becomes initialized once and stays initialized. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Using mock caches in the unittest Created 8 years, 8 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/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/memory/scoped_ptr.h"
9 #include "base/message_loop.h"
10 #include "base/time.h"
Mattias Nissler (ping if slow) 2012/03/30 11:46:35 needed?
Joao da Silva 2012/03/30 16:36:58 No, cleaned up.
8 #include "base/values.h" 11 #include "base/values.h"
9 #include "chrome/browser/policy/browser_policy_connector.h" 12 #include "chrome/browser/policy/browser_policy_connector.h"
10 #include "chrome/browser/policy/cloud_policy_cache_base.h" 13 #include "chrome/browser/policy/cloud_policy_cache_base.h"
11 #include "chrome/browser/policy/cloud_policy_provider_impl.h" 14 #include "chrome/browser/policy/cloud_policy_provider.h"
12 #include "chrome/browser/policy/configuration_policy_provider.h"
13 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 15 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
16 #include "content/test/test_browser_thread.h"
14 #include "policy/policy_constants.h" 17 #include "policy/policy_constants.h"
15 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h"
16 20
17 using testing::Mock; 21 using testing::Mock;
18 using testing::_;
19 22
20 namespace em = enterprise_management; 23 namespace em = enterprise_management;
21 24
22 namespace policy { 25 namespace policy {
23 26
24 namespace {
25
26 // Utility function for tests.
27 void SetPolicy(PolicyMap* map, const char* policy, Value* value) {
28 map->Set(policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, value);
29 }
30
31 } // namespace
32
33 class MockCloudPolicyCache : public CloudPolicyCacheBase { 27 class MockCloudPolicyCache : public CloudPolicyCacheBase {
34 public: 28 public:
35 MockCloudPolicyCache() {} 29 MockCloudPolicyCache() {}
36 virtual ~MockCloudPolicyCache() {} 30 virtual ~MockCloudPolicyCache() {}
37 31
38 // CloudPolicyCacheBase implementation. 32 virtual void Load() OVERRIDE {}
39 void Load() OVERRIDE {} 33
40 bool SetPolicy(const em::PolicyFetchResponse& policy) OVERRIDE { 34 virtual bool SetPolicy(const em::PolicyFetchResponse& policy) OVERRIDE {
41 return true;
42 }
43 bool DecodePolicyData(const em::PolicyData& policy_data,
44 PolicyMap* policies) OVERRIDE {
45 return true; 35 return true;
46 } 36 }
47 37
48 void SetUnmanaged() OVERRIDE { 38 virtual void SetUnmanaged() OVERRIDE {
49 is_unmanaged_ = true; 39 is_unmanaged_ = true;
50 } 40 }
51 41
42 virtual bool DecodePolicyData(const em::PolicyData& policy_data,
43 PolicyMap* policies) OVERRIDE {
44 return true;
45 }
46
52 PolicyMap* mutable_policy() { 47 PolicyMap* mutable_policy() {
53 return &policies_; 48 return &policies_;
54 } 49 }
55 50
56 void set_initialized(bool initialized) { 51 // Make this method public.
57 initialization_complete_ = initialized; 52 using CloudPolicyCacheBase::SetReady;
58 }
59
60 void Set(const char *name, Value* value) {
61 policies_.Set(name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, value);
62 }
63 53
64 private: 54 private:
65 DISALLOW_COPY_AND_ASSIGN(MockCloudPolicyCache); 55 DISALLOW_COPY_AND_ASSIGN(MockCloudPolicyCache);
66 }; 56 };
67 57
68 class CloudPolicyProviderTest : public testing::Test { 58 class CloudPolicyProviderTest : public testing::Test {
69 protected: 59 protected:
70 void CreateCloudPolicyProvider() { 60 CloudPolicyProviderTest()
61 : message_loop_(MessageLoop::TYPE_UI),
62 ui_thread_(content::BrowserThread::UI, &message_loop_),
63 file_thread_(content::BrowserThread::FILE, &message_loop_) {}
Mattias Nissler (ping if slow) 2012/03/30 11:46:35 Does this test actually need the loop?
Joao da Silva 2012/03/30 16:36:58 No, cleaned up.
64
65 void ResetProvider() {
Mattias Nissler (ping if slow) 2012/03/30 11:46:35 This is only ever called on test startup. Merge in
Joao da Silva 2012/03/30 16:36:58 Done.
66 registrar_.reset();
67 cloud_policy_provider_.reset();
68 message_loop_.RunAllPending();
69
71 cloud_policy_provider_.reset( 70 cloud_policy_provider_.reset(
72 new CloudPolicyProviderImpl(&browser_policy_connector_, 71 new CloudPolicyProvider(&browser_policy_connector_,
73 GetChromePolicyDefinitionList(), 72 GetChromePolicyDefinitionList(),
74 POLICY_LEVEL_MANDATORY)); 73 POLICY_LEVEL_MANDATORY));
75 } 74 registrar_.reset(new ConfigurationPolicyObserverRegistrar());
76 75 registrar_->Init(cloud_policy_provider_.get(), &observer_);
77 // Appends the caches to a provider and then provides the policies to 76 }
78 // |result|. 77
79 void RunCachesThroughProvider(MockCloudPolicyCache caches[], int n, 78 void AddUserCache() {
80 PolicyMap* result) { 79 user_policy_cache_.reset(new MockCloudPolicyCache());
81 CloudPolicyProviderImpl provider( 80 EXPECT_CALL(observer_, OnUpdatePolicy(cloud_policy_provider_.get()));
82 &browser_policy_connector_, 81 cloud_policy_provider_->SetUserPolicyCache(user_policy_cache_.get());
83 GetChromePolicyDefinitionList(), 82 Mock::VerifyAndClearExpectations(&observer_);
84 POLICY_LEVEL_MANDATORY); 83 }
85 for (int i = 0; i < n; i++) { 84
86 provider.AppendCache(&caches[i]); 85 void AddDeviceCache() {
87 } 86 #if defined(OS_CHROMEOS)
88 provider.Provide(result); 87 device_policy_cache_.reset(new MockCloudPolicyCache());
89 } 88 EXPECT_CALL(observer_, OnUpdatePolicy(cloud_policy_provider_.get()));
90 89 cloud_policy_provider_->SetDevicePolicyCache(device_policy_cache_.get());
91 void CombineTwoPolicyMaps(const PolicyMap& base, 90 Mock::VerifyAndClearExpectations(&observer_);
92 const PolicyMap& overlay, 91 #endif
93 PolicyMap* out_map) { 92 }
94 MockCloudPolicyCache caches[2]; 93
95 caches[0].mutable_policy()->CopyFrom(base); 94 void SetUserCacheReady() {
96 caches[0].set_initialized(true); 95 EXPECT_CALL(observer_, OnUpdatePolicy(cloud_policy_provider_.get()));
97 caches[1].mutable_policy()->CopyFrom(overlay); 96 user_policy_cache_->SetReady();
98 caches[1].set_initialized(true); 97 Mock::VerifyAndClearExpectations(&observer_);
99 RunCachesThroughProvider(caches, 2, out_map); 98 EXPECT_TRUE(user_policy_cache_->IsReady());
100 } 99 }
101 100
102 void FixDeprecatedPolicies(PolicyMap* policies) { 101 void SetDeviceCacheReady() {
103 CloudPolicyProviderImpl::FixDeprecatedPolicies(policies); 102 #if defined(OS_CHROMEOS)
104 } 103 EXPECT_CALL(observer_, OnUpdatePolicy(cloud_policy_provider_.get()));
105 104 device_policy_cache_->SetReady();
106 scoped_ptr<CloudPolicyProviderImpl> cloud_policy_provider_; 105 Mock::VerifyAndClearExpectations(&observer_);
107 106 EXPECT_TRUE(device_policy_cache_->IsReady());
108 private: 107 #endif
108 }
109
110 MessageLoop message_loop_;
111 content::TestBrowserThread ui_thread_;
112 content::TestBrowserThread file_thread_;
113
109 BrowserPolicyConnector browser_policy_connector_; 114 BrowserPolicyConnector browser_policy_connector_;
115
116 scoped_ptr<MockCloudPolicyCache> user_policy_cache_;
Mattias Nissler (ping if slow) 2012/03/30 11:46:35 Any reason the caches need to be wrapped in scoped
Joao da Silva 2012/03/30 16:36:58 Done.
117 #if defined(OS_CHROMEOS)
118 scoped_ptr<MockCloudPolicyCache> device_policy_cache_;
119 #endif
120
121 scoped_ptr<CloudPolicyProvider> cloud_policy_provider_;
122 MockConfigurationPolicyObserver observer_;
123 scoped_ptr<ConfigurationPolicyObserverRegistrar> registrar_;
110 }; 124 };
111 125
112 // Proxy setting distributed over multiple caches. 126 TEST_F(CloudPolicyProviderTest, Initialization) {
113 TEST_F(CloudPolicyProviderTest, 127 ResetProvider();
114 ProxySettingDistributedOverMultipleCaches) { 128 EXPECT_FALSE(cloud_policy_provider_->IsInitializationComplete());
115 // There are proxy_policy_count()+1 = 6 caches and they are mixed together by 129
116 // one instance of CloudPolicyProvider. The first cache has some policies but 130 // The provider only becomes initialized when it has all caches, and the
117 // no proxy-related ones. The following caches have each one proxy-policy set. 131 // caches are ready too.
118 const int n = 6; 132 AddDeviceCache();
119 MockCloudPolicyCache caches[n]; 133 EXPECT_FALSE(cloud_policy_provider_->IsInitializationComplete());
120 134 SetDeviceCacheReady();
121 // Prepare |cache[0]| to serve some non-proxy policies. 135 EXPECT_FALSE(cloud_policy_provider_->IsInitializationComplete());
122 caches[0].Set(key::kShowHomeButton, Value::CreateBooleanValue(true)); 136 AddUserCache();
123 caches[0].Set(key::kIncognitoEnabled, Value::CreateBooleanValue(true)); 137 EXPECT_FALSE(user_policy_cache_->IsReady());
124 caches[0].Set(key::kTranslateEnabled, Value::CreateBooleanValue(true)); 138 EXPECT_FALSE(cloud_policy_provider_->IsInitializationComplete());
125 caches[0].set_initialized(true); 139
126 140 PolicyMap policy;
127 // Prepare the other caches to serve one proxy-policy each. 141 EXPECT_TRUE(cloud_policy_provider_->Provide(&policy));
128 caches[1].Set(key::kProxyMode, Value::CreateStringValue("cache 1")); 142 EXPECT_TRUE(policy.empty());
129 caches[1].set_initialized(true); 143
130 caches[2].Set(key::kProxyServerMode, Value::CreateIntegerValue(2)); 144 SetUserCacheReady();
131 caches[2].set_initialized(true); 145 EXPECT_TRUE(cloud_policy_provider_->IsInitializationComplete());
132 caches[3].Set(key::kProxyServer, Value::CreateStringValue("cache 3")); 146 EXPECT_TRUE(cloud_policy_provider_->Provide(&policy));
133 caches[3].set_initialized(true); 147 EXPECT_TRUE(policy.empty());
134 caches[4].Set(key::kProxyPacUrl, Value::CreateStringValue("cache 4")); 148
135 caches[4].set_initialized(true); 149 const std::string kUrl("http://chromium.org");
136 caches[5].Set(key::kProxyMode, Value::CreateStringValue("cache 5")); 150 user_policy_cache_->mutable_policy()->Set(key::kHomepageLocation,
137 caches[5].set_initialized(true); 151 POLICY_LEVEL_MANDATORY,
138 152 POLICY_SCOPE_USER,
139 PolicyMap policies; 153 Value::CreateStringValue(kUrl));
140 RunCachesThroughProvider(caches, n, &policies); 154 EXPECT_CALL(observer_, OnUpdatePolicy(cloud_policy_provider_.get()));
141 155 user_policy_cache_->SetReady();
Mattias Nissler (ping if slow) 2012/03/30 11:46:35 So this is just to notify the observers? If so, pl
Joao da Silva 2012/03/30 16:36:58 Done.
142 // Verify expectations. 156 Mock::VerifyAndClearExpectations(&observer_);
143 EXPECT_TRUE(policies.Get(key::kProxyMode) == NULL); 157 EXPECT_TRUE(cloud_policy_provider_->Provide(&policy));
144 EXPECT_TRUE(policies.Get(key::kProxyServerMode) == NULL); 158
145 EXPECT_TRUE(policies.Get(key::kProxyServer) == NULL); 159 PolicyMap expected;
146 EXPECT_TRUE(policies.Get(key::kProxyPacUrl) == NULL); 160 expected.Set(key::kHomepageLocation,
147 161 POLICY_LEVEL_MANDATORY,
148 const Value* value = policies.GetValue(key::kProxySettings); 162 POLICY_SCOPE_USER,
149 ASSERT_TRUE(value != NULL); 163 Value::CreateStringValue(kUrl));
150 ASSERT_TRUE(value->IsType(Value::TYPE_DICTIONARY)); 164 EXPECT_TRUE(policy.Equals(expected));
151 const DictionaryValue* settings = static_cast<const DictionaryValue*>(value); 165 }
166
167 TEST_F(CloudPolicyProviderTest, RefreshPolicies) {
168 // OnUpdatePolicy is called when the provider doesn't have any caches.
169 ResetProvider();
170 EXPECT_CALL(observer_, OnUpdatePolicy(cloud_policy_provider_.get())).Times(1);
171 cloud_policy_provider_->RefreshPolicies();
172 Mock::VerifyAndClearExpectations(&observer_);
173
174 // OnUpdatePolicy is called when all the caches have updated.
175 AddUserCache();
176
177 EXPECT_CALL(observer_, OnUpdatePolicy(cloud_policy_provider_.get())).Times(0);
178 cloud_policy_provider_->RefreshPolicies();
179 Mock::VerifyAndClearExpectations(&observer_);
180
181 EXPECT_CALL(observer_, OnUpdatePolicy(cloud_policy_provider_.get())).Times(1);
182 cloud_policy_provider_->OnCacheUpdate(user_policy_cache_.get());
183 Mock::VerifyAndClearExpectations(&observer_);
184
185 #if defined(OS_CHROMEOS)
186 AddDeviceCache();
187
188 EXPECT_CALL(observer_, OnUpdatePolicy(cloud_policy_provider_.get())).Times(0);
189 cloud_policy_provider_->RefreshPolicies();
190 Mock::VerifyAndClearExpectations(&observer_);
191
192 // Updating one of the caches is not enough, both must be updated.
193 EXPECT_CALL(observer_, OnUpdatePolicy(cloud_policy_provider_.get())).Times(0);
194 cloud_policy_provider_->OnCacheUpdate(user_policy_cache_.get());
195 Mock::VerifyAndClearExpectations(&observer_);
196
197 // If a cache refreshes more than once, the provider should still wait for
198 // the others before firing the update.
199 EXPECT_CALL(observer_, OnUpdatePolicy(cloud_policy_provider_.get())).Times(0);
200 cloud_policy_provider_->OnCacheUpdate(user_policy_cache_.get());
201 Mock::VerifyAndClearExpectations(&observer_);
202
203 EXPECT_CALL(observer_, OnUpdatePolicy(cloud_policy_provider_.get())).Times(1);
204 cloud_policy_provider_->OnCacheUpdate(device_policy_cache_.get());
205 Mock::VerifyAndClearExpectations(&observer_);
206 #endif
207 }
208
209 #if defined(OS_CHROMEOS)
210 TEST_F(CloudPolicyProviderTest, MergeProxyPolicies) {
211 ResetProvider();
212 AddDeviceCache();
213 AddUserCache();
214 SetDeviceCacheReady();
215 SetUserCacheReady();
216 EXPECT_TRUE(cloud_policy_provider_->IsInitializationComplete());
217 PolicyMap policy;
218 EXPECT_TRUE(cloud_policy_provider_->Provide(&policy));
219 EXPECT_TRUE(policy.empty());
220
221 // User policy takes precedence over device policy.
222 EXPECT_CALL(observer_, OnUpdatePolicy(cloud_policy_provider_.get()));
223 device_policy_cache_->mutable_policy()->Set(
224 key::kProxyMode, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE,
225 Value::CreateStringValue("device mode"));
226 device_policy_cache_->SetReady();
227 Mock::VerifyAndClearExpectations(&observer_);
228
229 EXPECT_CALL(observer_, OnUpdatePolicy(cloud_policy_provider_.get()));
230 user_policy_cache_->mutable_policy()->Set(
231 key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
232 Value::CreateStringValue("user mode"));
233 user_policy_cache_->SetReady();
234 Mock::VerifyAndClearExpectations(&observer_);
235
236 EXPECT_TRUE(cloud_policy_provider_->Provide(&policy));
237
238 // The deprecated proxy policies are converted to the new ProxySettings.
239 EXPECT_TRUE(policy.Get(key::kProxyMode) == NULL);
240 EXPECT_TRUE(policy.Get(key::kProxyServerMode) == NULL);
241 EXPECT_TRUE(policy.Get(key::kProxyServer) == NULL);
242 EXPECT_TRUE(policy.Get(key::kProxyPacUrl) == NULL);
243
244 EXPECT_EQ(1u, policy.size());
245 const PolicyMap::Entry* entry = policy.Get(key::kProxySettings);
246 ASSERT_TRUE(entry != NULL);
247 ASSERT_TRUE(entry->value != NULL);
248 EXPECT_EQ(POLICY_LEVEL_MANDATORY, entry->level);
249 EXPECT_EQ(POLICY_SCOPE_USER, entry->scope);
250 const DictionaryValue* settings;
251 ASSERT_TRUE(entry->value->GetAsDictionary(&settings));
152 std::string mode; 252 std::string mode;
153 EXPECT_TRUE(settings->GetString(key::kProxyMode, &mode)); 253 EXPECT_TRUE(settings->GetString(key::kProxyMode, &mode));
154 EXPECT_EQ("cache 1", mode); 254 EXPECT_EQ("user mode", mode);
155
156 base::FundamentalValue expected(true);
157 EXPECT_TRUE(base::Value::Equals(&expected,
158 policies.GetValue(key::kShowHomeButton)));
159 EXPECT_TRUE(base::Value::Equals(&expected,
160 policies.GetValue(key::kIncognitoEnabled)));
161 EXPECT_TRUE(base::Value::Equals(&expected,
162 policies.GetValue(key::kTranslateEnabled)));
163 } 255 }
164 256 #endif
165 // Combining two PolicyMaps.
166 TEST_F(CloudPolicyProviderTest, CombineTwoPolicyMapsSame) {
167 PolicyMap A, B, C;
168 SetPolicy(&A, key::kHomepageLocation,
169 Value::CreateStringValue("http://www.chromium.org"));
170 SetPolicy(&B, key::kHomepageLocation,
171 Value::CreateStringValue("http://www.google.com"));
172 SetPolicy(&A, key::kApplicationLocaleValue, Value::CreateStringValue("hu"));
173 SetPolicy(&B, key::kApplicationLocaleValue, Value::CreateStringValue("us"));
174 SetPolicy(&A, key::kDevicePolicyRefreshRate, new base::FundamentalValue(100));
175 SetPolicy(&B, key::kDevicePolicyRefreshRate, new base::FundamentalValue(200));
176 CombineTwoPolicyMaps(A, B, &C);
177 EXPECT_TRUE(A.Equals(C));
178 }
179
180 TEST_F(CloudPolicyProviderTest, CombineTwoPolicyMapsEmpty) {
181 PolicyMap A, B, C;
182 CombineTwoPolicyMaps(A, B, &C);
183 EXPECT_TRUE(C.empty());
184 }
185
186 TEST_F(CloudPolicyProviderTest, CombineTwoPolicyMapsPartial) {
187 PolicyMap A, B, C;
188
189 SetPolicy(&A, key::kHomepageLocation,
190 Value::CreateStringValue("http://www.chromium.org"));
191 SetPolicy(&B, key::kHomepageLocation,
192 Value::CreateStringValue("http://www.google.com"));
193 SetPolicy(&B, key::kApplicationLocaleValue, Value::CreateStringValue("us"));
194 SetPolicy(&A, key::kDevicePolicyRefreshRate, new base::FundamentalValue(100));
195 SetPolicy(&B, key::kDevicePolicyRefreshRate, new base::FundamentalValue(200));
196 CombineTwoPolicyMaps(A, B, &C);
197
198 const Value* value;
199 std::string string_value;
200 int int_value;
201 value = C.GetValue(key::kHomepageLocation);
202 ASSERT_TRUE(NULL != value);
203 EXPECT_TRUE(value->GetAsString(&string_value));
204 EXPECT_EQ("http://www.chromium.org", string_value);
205 value = C.GetValue(key::kApplicationLocaleValue);
206 ASSERT_TRUE(NULL != value);
207 EXPECT_TRUE(value->GetAsString(&string_value));
208 EXPECT_EQ("us", string_value);
209 value = C.GetValue(key::kDevicePolicyRefreshRate);
210 ASSERT_TRUE(NULL != value);
211 EXPECT_TRUE(value->GetAsInteger(&int_value));
212 EXPECT_EQ(100, int_value);
213 }
214
215 TEST_F(CloudPolicyProviderTest, CombineTwoPolicyMapsProxies) {
216 const int a_value = 1;
217 const int b_value = -1;
218 PolicyMap A, B, C;
219
220 SetPolicy(&A, key::kProxyMode, Value::CreateIntegerValue(a_value));
221 SetPolicy(&B, key::kProxyServerMode, Value::CreateIntegerValue(b_value));
222 SetPolicy(&B, key::kProxyServer, Value::CreateIntegerValue(b_value));
223 SetPolicy(&B, key::kProxyPacUrl, Value::CreateIntegerValue(b_value));
224 SetPolicy(&B, key::kProxyBypassList, Value::CreateIntegerValue(b_value));
225
226 CombineTwoPolicyMaps(A, B, &C);
227
228 FixDeprecatedPolicies(&A);
229 FixDeprecatedPolicies(&B);
230 EXPECT_TRUE(A.Equals(C));
231 EXPECT_FALSE(B.Equals(C));
232 }
233
234 TEST_F(CloudPolicyProviderTest, RefreshPolicies) {
235 CreateCloudPolicyProvider();
236 MockCloudPolicyCache cache0;
237 MockCloudPolicyCache cache1;
238 MockCloudPolicyCache cache2;
239 MockConfigurationPolicyObserver observer;
240 ConfigurationPolicyObserverRegistrar registrar;
241 registrar.Init(cloud_policy_provider_.get(), &observer);
242
243 // OnUpdatePolicy is called when the provider doesn't have any caches.
244 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(1);
245 cloud_policy_provider_->RefreshPolicies();
246 Mock::VerifyAndClearExpectations(&observer);
247
248 // OnUpdatePolicy is called when all the caches have updated.
249 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(2);
250 cloud_policy_provider_->AppendCache(&cache0);
251 cloud_policy_provider_->AppendCache(&cache1);
252 Mock::VerifyAndClearExpectations(&observer);
253
254 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(0);
255 cloud_policy_provider_->RefreshPolicies();
256 Mock::VerifyAndClearExpectations(&observer);
257
258 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(0);
259 // Updating just one of the caches is not enough.
260 cloud_policy_provider_->OnCacheUpdate(&cache0);
261 Mock::VerifyAndClearExpectations(&observer);
262
263 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(0);
264 // This cache wasn't available when RefreshPolicies was called, so it isn't
265 // required to fire the update.
266 cloud_policy_provider_->AppendCache(&cache2);
267 Mock::VerifyAndClearExpectations(&observer);
268
269 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(1);
270 cloud_policy_provider_->OnCacheUpdate(&cache1);
271 Mock::VerifyAndClearExpectations(&observer);
272
273 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(0);
274 cloud_policy_provider_->RefreshPolicies();
275 Mock::VerifyAndClearExpectations(&observer);
276
277 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(0);
278 cloud_policy_provider_->OnCacheUpdate(&cache0);
279 cloud_policy_provider_->OnCacheUpdate(&cache1);
280 Mock::VerifyAndClearExpectations(&observer);
281
282 // If a cache refreshes more than once, the provider should still wait for
283 // the others before firing the update.
284 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(0);
285 cloud_policy_provider_->OnCacheUpdate(&cache0);
286 Mock::VerifyAndClearExpectations(&observer);
287
288 // Fire updates if one of the required caches goes away while waiting.
289 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(1);
290 cloud_policy_provider_->OnCacheGoingAway(&cache2);
291 Mock::VerifyAndClearExpectations(&observer);
292 }
293 257
294 } // namespace policy 258 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698