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

Side by Side Diff: chrome/browser/policy/cloud/cloud_policy_invalidator_unittest.cc

Issue 19733003: Implement cloud policy invalidations using the invalidation service framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/basictypes.h"
6 #include "base/bind.h"
7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/histogram.h"
10 #include "base/metrics/histogram_samples.h"
11 #include "base/metrics/sample_map.h"
12 #include "base/metrics/statistics_recorder.h"
13 #include "base/test/test_simple_task_runner.h"
14 #include "base/time/time.h"
15 #include "base/values.h"
16 #include "chrome/browser/invalidation/fake_invalidation_service.h"
17 #include "chrome/browser/policy/cloud/cloud_policy_core.h"
18 #include "chrome/browser/policy/cloud/cloud_policy_invalidator.h"
19 #include "chrome/browser/policy/cloud/cloud_policy_service.h"
20 #include "chrome/browser/policy/cloud/enterprise_metrics.h"
21 #include "chrome/browser/policy/cloud/mock_cloud_policy_client.h"
22 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h"
23 #include "chrome/browser/policy/policy_types.h"
24 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
25 #include "policy/policy_constants.h"
26 #include "sync/notifier/invalidation_util.h"
27 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h"
29
30 namespace policy {
31
32 class CloudPolicyInvalidatorTest : public testing::Test {
33 protected:
34 // Policy objects which can be used in tests.
35 enum PolicyObject {
36 POLICY_OBJECT_NONE,
37 POLICY_OBJECT_A,
38 POLICY_OBJECT_B
39 };
40
41 CloudPolicyInvalidatorTest();
42
43 virtual void SetUp() OVERRIDE;
44
45 virtual void TearDown() OVERRIDE;
46
47 // Starts the invalidator which will be tested.
48 void StartInvalidator();
49
50 // Unregister the invalidator.
51 void UnregisterInvalidator();
52
53 // Simulates storing a new policy to the policy store.
54 // |object| determines which policy object the store will report the
55 // invalidator should register for. May be POLICY_OBJECT_NONE for no object.
56 // |invalidation_version| determines what invalidation the store will report.
57 // |policy_changed| determines whether the store will report that the
58 // policy changed.
59 // |timestamp| determines the response timestamp the store will report.
60 void StorePolicy(
61 PolicyObject object,
62 int64 invalidation_version,
63 bool policy_changed,
64 int64 timestamp);
65 void StorePolicy(
66 PolicyObject object,
67 int64 invalidation_version,
68 bool policy_changed) {
69 StorePolicy(object, invalidation_version, policy_changed, ++timestamp_);
70 }
71 void StorePolicy(PolicyObject object, int64 invalidation_version) {
72 StorePolicy(object, invalidation_version, false);
73 }
74 void StorePolicy(PolicyObject object) {
75 StorePolicy(object, 0);
76 }
77
78 // Causes the invalidation service to fire an invalidation. Returns an ack
79 // handle which be used to verify that the invalidation was acknowledged.
80 syncer::AckHandle FireInvalidation(
81 PolicyObject object,
82 int64 version,
83 const std::string& payload);
84
85 // Causes the invalidation service to fire an invalidation with unknown
86 // version. Returns an ack handle which be used to verify that the
87 // invalidation was acknowledged.
88 syncer::AckHandle FireInvalidation(PolicyObject object);
89
90 // Verifies expectations of the current invalidation info on the policy
91 // client object.
92 void ExpectClientInvalidationInfo(int64 version, const std::string& payload);
93
94 // Verifies expectation that the invalidate callback was not called.
95 void ExpectInvalidateNotCalled();
96
97 // Verifies expectation that the invalidate callback was called within an
98 // appropriate timeframe depending on whether the invalidation had unknown
99 // version.
100 void ExpectInvalidateCalled(bool unknown_version);
101 void ExpectInvalidateCalled() {
102 ExpectInvalidateCalled(true);
103 }
104
105 // Determines if the invalidation with the given ack handle has been
106 // acknowledged.
107 bool IsInvalidationAcknowledged(const syncer::AckHandle& ack_handle);
108
109 // Get the current count for the given metric.
110 base::HistogramBase::Count GetCount(MetricPolicyRefresh metric);
111 base::HistogramBase::Count GetCount(MetricPolicyInvalidations metric);
112
113 private:
114 // The invalidate callback used for testing.
115 void Invalidate();
116
117 // Returns the object id of the given policy object.
118 const invalidation::ObjectId& GetPolicyObjectId(PolicyObject object) const;
119
120 // Get histogram samples for the given histogram.
121 scoped_ptr<base::HistogramSamples> GetHistogramSamples(
122 const std::string& name) const;
123
124 // Objects the invalidator depends on.
125 invalidation::FakeInvalidationService invalidation_service_;
126 MockCloudPolicyClient client_;
127 MockCloudPolicyStore store_;
128 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
129
130 // The invalidator which will be tested.
131 scoped_ptr<CloudPolicyInvalidator> invalidator_;
132
133 // Object ids for the test policy objects.
134 invalidation::ObjectId object_id_a_;
135 invalidation::ObjectId object_id_b_;
136
137 // Increasing policy timestamp.
138 int64 timestamp_;
139
140 // Stores how many times the invalidate callback was called.
141 int invalidate_callback_count_;
142
143 // Stores starting histogram counts for kMetricPolicyRefresh.
144 scoped_ptr<base::HistogramSamples> refresh_samples_;
145
146 // Stores starting histogram counts for kMetricPolicyInvalidations.
147 scoped_ptr<base::HistogramSamples> invalidations_samples_;
148 };
149
150 CloudPolicyInvalidatorTest::CloudPolicyInvalidatorTest()
151 : task_runner_(new base::TestSimpleTaskRunner()),
152 object_id_a_(135, "asdf"),
153 object_id_b_(246, "zxcv"),
154 timestamp_(123456),
155 invalidate_callback_count_(0) {}
156
157 void CloudPolicyInvalidatorTest::SetUp() {
158 base::StatisticsRecorder::Initialize();
159 refresh_samples_ = GetHistogramSamples(kMetricPolicyRefresh);
160 invalidations_samples_ = GetHistogramSamples(kMetricPolicyInvalidations);
161 }
162
163 void CloudPolicyInvalidatorTest::TearDown() {
164 EXPECT_FALSE(invalidation_service_.ReceivedInvalidAcknowledgement());
165 }
166
167 void CloudPolicyInvalidatorTest::StartInvalidator() {
168 invalidator_.reset(new CloudPolicyInvalidator(
169 &invalidation_service_,
170 &client_,
171 &store_,
172 task_runner_,
173 base::Bind(
174 &CloudPolicyInvalidatorTest::Invalidate,
175 base::Unretained(this))));
176 }
177
178 void CloudPolicyInvalidatorTest::UnregisterInvalidator() {
179 invalidator_->Unregister();
180 }
181
182 void CloudPolicyInvalidatorTest::StorePolicy(
183 PolicyObject object,
184 int64 invalidation_version,
185 bool policy_changed,
186 int64 timestamp) {
187 enterprise_management::PolicyData* data =
188 new enterprise_management::PolicyData();
189 if (object != POLICY_OBJECT_NONE) {
190 data->set_invalidation_source(GetPolicyObjectId(object).source());
191 data->set_invalidation_name(GetPolicyObjectId(object).name());
192 }
193 data->set_timestamp(timestamp);
194 store_.set_invalidation_version(invalidation_version);
195 store_.SetPolicyChanged(policy_changed);
196 store_.policy_.reset(data);
197 base::DictionaryValue policies;
198 policies.SetInteger(
199 key::kMaxInvalidationFetchDelay,
200 CloudPolicyInvalidator::kMaxFetchDelayMin);
201 store_.policy_map_.LoadFrom(
202 &policies,
203 POLICY_LEVEL_MANDATORY,
204 POLICY_SCOPE_MACHINE);
205 store_.NotifyStoreLoaded();
206 }
207
208 syncer::AckHandle CloudPolicyInvalidatorTest::FireInvalidation(
209 PolicyObject object,
210 int64 version,
211 const std::string& payload) {
212 return invalidation_service_.EmitInvalidationForTest(
213 GetPolicyObjectId(object),
214 version,
215 payload);
216 }
217
218 syncer::AckHandle CloudPolicyInvalidatorTest::FireInvalidation(
219 PolicyObject object) {
220 return invalidation_service_.EmitInvalidationForTest(
221 GetPolicyObjectId(object),
222 syncer::Invalidation::kUnknownVersion,
223 std::string());
224 }
225
226 void CloudPolicyInvalidatorTest::ExpectClientInvalidationInfo(
227 int64 version,
228 const std::string& payload) {
229 EXPECT_EQ(version, client_.invalidation_version_);
230 EXPECT_EQ(payload, client_.invalidation_payload_);
231 }
232
233 void CloudPolicyInvalidatorTest::ExpectInvalidateNotCalled() {
234 EXPECT_EQ(0, invalidate_callback_count_);
235 task_runner_->RunUntilIdle();
236 EXPECT_EQ(0, invalidate_callback_count_);
237 }
238
239 void CloudPolicyInvalidatorTest::ExpectInvalidateCalled(bool unknown_version) {
240 base::TimeDelta min_delay;
241 base::TimeDelta max_delay = base::TimeDelta::FromMilliseconds(
242 CloudPolicyInvalidator::kMaxFetchDelayMin);
243 if (unknown_version) {
244 base::TimeDelta additional_delay = base::TimeDelta::FromMinutes(
245 CloudPolicyInvalidator::kMissingPayloadDelay);
246 min_delay += additional_delay;
247 max_delay += additional_delay;
248 }
249
250 ASSERT_FALSE(task_runner_->GetPendingTasks().empty());
251 base::TimeDelta actual_delay = task_runner_->GetPendingTasks().back().delay;
252 EXPECT_GE(actual_delay, min_delay);
253 EXPECT_LE(actual_delay, max_delay);
254
255 EXPECT_EQ(0, invalidate_callback_count_);
256 task_runner_->RunUntilIdle();
257 EXPECT_EQ(1, invalidate_callback_count_);
258 invalidate_callback_count_ = 0;
259 }
260
261 bool CloudPolicyInvalidatorTest::IsInvalidationAcknowledged(
262 const syncer::AckHandle& ack_handle) {
263 return invalidation_service_.IsInvalidationAcknowledged(ack_handle);
264 }
265
266 base::HistogramBase::Count CloudPolicyInvalidatorTest::GetCount(
267 MetricPolicyRefresh metric) {
268 return GetHistogramSamples(kMetricPolicyRefresh)->GetCount(metric) -
269 refresh_samples_->GetCount(metric);
270 }
271
272 base::HistogramBase::Count CloudPolicyInvalidatorTest::GetCount(
273 MetricPolicyInvalidations metric) {
274 return GetHistogramSamples(kMetricPolicyInvalidations)->GetCount(metric) -
275 invalidations_samples_->GetCount(metric);
276 }
277
278 void CloudPolicyInvalidatorTest::Invalidate() {
279 ++invalidate_callback_count_;
280 }
281
282 const invalidation::ObjectId& CloudPolicyInvalidatorTest::GetPolicyObjectId(
283 PolicyObject object) const {
284 EXPECT_TRUE(object == POLICY_OBJECT_A || object == POLICY_OBJECT_B);
285 return object == POLICY_OBJECT_A ? object_id_a_ : object_id_b_;
286 }
287
288 scoped_ptr<base::HistogramSamples>
289 CloudPolicyInvalidatorTest::GetHistogramSamples(
290 const std::string& name) const {
291 base::HistogramBase* histogram =
292 base::StatisticsRecorder::FindHistogram(name);
293 if (!histogram)
294 return scoped_ptr<base::HistogramSamples>(new base::SampleMap());
295 return histogram->SnapshotSamples();
296 }
297
298 TEST_F(CloudPolicyInvalidatorTest, RegisterOnStoreLoaded) {
299 // No registration when store is not loaded.
300 StartInvalidator();
301 FireInvalidation(POLICY_OBJECT_A);
302 FireInvalidation(POLICY_OBJECT_B);
303 ExpectInvalidateNotCalled();
304
305 // No registration when store is loaded with no invalidation object id.
306 StorePolicy(POLICY_OBJECT_NONE);
307 FireInvalidation(POLICY_OBJECT_A);
308 FireInvalidation(POLICY_OBJECT_B);
309 ExpectInvalidateNotCalled();
310
311 // Check registration when store is loaded for object A.
312 StorePolicy(POLICY_OBJECT_A);
313 FireInvalidation(POLICY_OBJECT_A);
314 ExpectInvalidateCalled();
315 FireInvalidation(POLICY_OBJECT_B);
316 ExpectInvalidateNotCalled();
317 }
318
319 TEST_F(CloudPolicyInvalidatorTest, ChangeRegistration) {
320 // Register for object A.
321 StartInvalidator();
322 StorePolicy(POLICY_OBJECT_A);
323 FireInvalidation(POLICY_OBJECT_A);
324 ExpectInvalidateCalled();
325 FireInvalidation(POLICY_OBJECT_B);
326 ExpectInvalidateNotCalled();
327 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A);
328
329 // Check re-registration for object B. Make sure the pending invalidation for
330 // object A is acknowledged without making the callback.
331 StorePolicy(POLICY_OBJECT_B);
332 EXPECT_TRUE(IsInvalidationAcknowledged(ack));
333 ExpectInvalidateNotCalled();
334
335 // Make sure future invalidations for object A are ignored and for object B
336 // are processed.
337 FireInvalidation(POLICY_OBJECT_A);
338 ExpectInvalidateNotCalled();
339 FireInvalidation(POLICY_OBJECT_B);
340 ExpectInvalidateCalled();
341 }
342
343 TEST_F(CloudPolicyInvalidatorTest, UnregisterOnStoreLoaded) {
344 // Register for object A.
345 StartInvalidator();
346 StorePolicy(POLICY_OBJECT_A);
347 FireInvalidation(POLICY_OBJECT_A);
348 ExpectInvalidateCalled();
349
350 // Check unregistration when store is loaded with no invalidation object id.
351 StorePolicy(POLICY_OBJECT_NONE);
352 FireInvalidation(POLICY_OBJECT_A);
353 FireInvalidation(POLICY_OBJECT_B);
354 ExpectInvalidateNotCalled();
355
356 // Check re-registration for object B.
357 StorePolicy(POLICY_OBJECT_B);
358 FireInvalidation(POLICY_OBJECT_B);
359 ExpectInvalidateCalled();
360 }
361
362 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidation) {
363 // Register and fire invalidation
364 StorePolicy(POLICY_OBJECT_A);
365 StartInvalidator();
366 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A, 12, "test_payload");
367
368 // Make sure client info is set as soon as the invalidation is received.
369 ExpectClientInvalidationInfo(12, "test_payload");
370 ExpectInvalidateCalled(false /* unknown_version */);
371
372 // Make sure invalidation is not acknowledged until the store is loaded.
373 EXPECT_FALSE(IsInvalidationAcknowledged(ack));
374 ExpectClientInvalidationInfo(12, "test_payload");
375 StorePolicy(POLICY_OBJECT_A, 12);
376 EXPECT_TRUE(IsInvalidationAcknowledged(ack));
377 ExpectClientInvalidationInfo(0, std::string());
378 }
379
380 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidationWithUnknownVersion) {
381 // Register and fire invalidation with unknown version.
382 StorePolicy(POLICY_OBJECT_A);
383 StartInvalidator();
384 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A);
385
386 // Make sure client info is not set until after the invalidation callback is
387 // made.
388 ExpectClientInvalidationInfo(0, std::string());
389 ExpectInvalidateCalled();
390 ExpectClientInvalidationInfo(-1, std::string());
391
392 // Make sure invalidation is not acknowledged until the store is loaded.
393 EXPECT_FALSE(IsInvalidationAcknowledged(ack));
394 StorePolicy(POLICY_OBJECT_A, -1);
395 EXPECT_TRUE(IsInvalidationAcknowledged(ack));
396 ExpectClientInvalidationInfo(0, std::string());
397 }
398
399 TEST_F(CloudPolicyInvalidatorTest, Unregister) {
400 StorePolicy(POLICY_OBJECT_A);
401 StartInvalidator();
402 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A);
403
404 // Make sure invalidation is acknowledged when Unregister is called, even
405 // if the store hasn't been reloaded.
406 EXPECT_FALSE(IsInvalidationAcknowledged(ack));
407 UnregisterInvalidator();
408 EXPECT_TRUE(IsInvalidationAcknowledged(ack));
409
410 // Make sure that the invalidate callback is not made.
411 ExpectInvalidateNotCalled();
412 }
413
414 TEST_F(CloudPolicyInvalidatorTest, HandleMultipleInvalidations) {
415 // Generate multiple invalidations.
416 StorePolicy(POLICY_OBJECT_A);
417 StartInvalidator();
418 syncer::AckHandle ack1 = FireInvalidation(POLICY_OBJECT_A, 1, "test1");
419 ExpectClientInvalidationInfo(1, "test1");
420 syncer::AckHandle ack2 = FireInvalidation(POLICY_OBJECT_A, 2, "test2");
421 ExpectClientInvalidationInfo(2, "test2");
422 syncer::AckHandle ack3= FireInvalidation(POLICY_OBJECT_A, 3, "test3");
423 ExpectClientInvalidationInfo(3, "test3");
424
425 // Make sure the replaced invalidations are acknowledged.
426 EXPECT_TRUE(IsInvalidationAcknowledged(ack1));
427 EXPECT_TRUE(IsInvalidationAcknowledged(ack2));
428
429 // Make sure the invalidate callback is called once.
430 ExpectInvalidateCalled(false /* unknown_version */);
431
432 // Make sure that the last invalidation is only acknowledged after the store
433 // is loaded with the latest version.
434 StorePolicy(POLICY_OBJECT_A, 1);
435 EXPECT_FALSE(IsInvalidationAcknowledged(ack3));
436 StorePolicy(POLICY_OBJECT_A, 2);
437 EXPECT_FALSE(IsInvalidationAcknowledged(ack3));
438 StorePolicy(POLICY_OBJECT_A, 3);
439 EXPECT_TRUE(IsInvalidationAcknowledged(ack3));
440 }
441
442 TEST_F(CloudPolicyInvalidatorTest,
443 HandleMultipleInvalidationsWithUnknownVersion) {
444 // Validate that multiple invalidations with unknown version each generate
445 // unique invalidation version numbers.
446 StorePolicy(POLICY_OBJECT_A);
447 StartInvalidator();
448 syncer::AckHandle ack1 = FireInvalidation(POLICY_OBJECT_A);
449 ExpectClientInvalidationInfo(0, std::string());
450 ExpectInvalidateCalled();
451 ExpectClientInvalidationInfo(-1, std::string());
452 syncer::AckHandle ack2 = FireInvalidation(POLICY_OBJECT_A);
453 ExpectClientInvalidationInfo(0, std::string());
454 ExpectInvalidateCalled();
455 ExpectClientInvalidationInfo(-2, std::string());
456 syncer::AckHandle ack3 = FireInvalidation(POLICY_OBJECT_A);
457 ExpectClientInvalidationInfo(0, std::string());
458 ExpectInvalidateCalled();
459 ExpectClientInvalidationInfo(-3, std::string());
460
461 // Make sure the replaced invalidations are acknowledged.
462 EXPECT_TRUE(IsInvalidationAcknowledged(ack1));
463 EXPECT_TRUE(IsInvalidationAcknowledged(ack2));
464
465 // Make sure that the last invalidation is only acknowledged after the store
466 // is loaded with the last unknown version.
467 StorePolicy(POLICY_OBJECT_A, -1);
468 EXPECT_FALSE(IsInvalidationAcknowledged(ack3));
469 StorePolicy(POLICY_OBJECT_A, -2);
470 EXPECT_FALSE(IsInvalidationAcknowledged(ack3));
471 StorePolicy(POLICY_OBJECT_A, -3);
472 EXPECT_TRUE(IsInvalidationAcknowledged(ack3));
473 }
474
475 TEST_F(CloudPolicyInvalidatorTest, AcknowledgeBeforeInvalidateCallback) {
476 // Generate an invalidation.
477 StorePolicy(POLICY_OBJECT_A);
478 StartInvalidator();
479 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A, 3, "test");
480
481 // Ensure that the invalidate callback is not made and the invalidation is
482 // acknowledged if the store is loaded with the latest version before the
483 // callback is invoked.
484 StorePolicy(POLICY_OBJECT_A, 3);
485 EXPECT_TRUE(IsInvalidationAcknowledged(ack));
486 ExpectInvalidateNotCalled();
487 }
488
489 TEST_F(CloudPolicyInvalidatorTest, RefreshMetricsUnregistered) {
490 // Store loads occurring before invalidation registration are not counted.
491 StartInvalidator();
492 StorePolicy(POLICY_OBJECT_NONE, 0, false /* policy_changed */);
493 StorePolicy(POLICY_OBJECT_NONE, 0, true /* policy_changed */);
494 EXPECT_EQ(0, GetCount(kMetricPolicyRefreshChanged));
495 EXPECT_EQ(0, GetCount(kMetricPolicyRefreshUnchanged));
496 EXPECT_EQ(0, GetCount(kMetricPolicyRefreshInvalidatedChanged));
497 EXPECT_EQ(0, GetCount(kMetricPolicyRefreshInvalidatedUnchanged));
498 }
499
500 TEST_F(CloudPolicyInvalidatorTest, RefreshMetricsStoreSameTimestamp) {
501 // Store loads with the same timestamp as the load which causes registration
502 // are not counted.
503 StartInvalidator();
504 StorePolicy(
505 POLICY_OBJECT_A, 0, false /* policy_changed */, 12 /* timestamp */);
506 StorePolicy(
507 POLICY_OBJECT_A, 0, false /* policy_changed */, 12 /* timestamp */);
508 StorePolicy(
509 POLICY_OBJECT_A, 0, true /* policy_changed */, 12 /* timestamp */);
510
511 // The next load with a different timestamp counts.
512 StorePolicy(
513 POLICY_OBJECT_A, 0, true /* policy_changed */, 13 /* timestamp */);
514
515 EXPECT_EQ(1, GetCount(kMetricPolicyRefreshChanged));
516 EXPECT_EQ(0, GetCount(kMetricPolicyRefreshUnchanged));
517 EXPECT_EQ(0, GetCount(kMetricPolicyRefreshInvalidatedChanged));
518 EXPECT_EQ(0, GetCount(kMetricPolicyRefreshInvalidatedUnchanged));
519 }
520
521 TEST_F(CloudPolicyInvalidatorTest, RefreshMetricsInvalidation) {
522 // Store loads after an invalidation are counted as invalidated, even if
523 // the loads do not result in the invalidation being acknowledged.
524 StartInvalidator();
525 StorePolicy(POLICY_OBJECT_A);
526 FireInvalidation(POLICY_OBJECT_A, 5, "test");
527 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */);
528 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */);
529 StorePolicy(POLICY_OBJECT_A, 5, true /* policy_changed */);
530
531 // Store loads after the invalidation is complete are not counted as
532 // invalidated.
533 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */);
534 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */);
535 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */);
536 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */);
537 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */);
538 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */);
539 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */);
540
541 EXPECT_EQ(3, GetCount(kMetricPolicyRefreshChanged));
542 EXPECT_EQ(4, GetCount(kMetricPolicyRefreshUnchanged));
543 EXPECT_EQ(2, GetCount(kMetricPolicyRefreshInvalidatedChanged));
544 EXPECT_EQ(1, GetCount(kMetricPolicyRefreshInvalidatedUnchanged));
545 }
546
547 TEST_F(CloudPolicyInvalidatorTest, InvalidationMetrics) {
548 // Generate a mix of versioned and unknown-version invalidations.
549 StorePolicy(POLICY_OBJECT_A);
550 StartInvalidator();
551 FireInvalidation(POLICY_OBJECT_B);
552 FireInvalidation(POLICY_OBJECT_A);
553 FireInvalidation(POLICY_OBJECT_B, 1, "test");
554 FireInvalidation(POLICY_OBJECT_A, 1, "test");
555 FireInvalidation(POLICY_OBJECT_A, 2, "test");
556 FireInvalidation(POLICY_OBJECT_A);
557 FireInvalidation(POLICY_OBJECT_A);
558 FireInvalidation(POLICY_OBJECT_A, 3, "test");
559 FireInvalidation(POLICY_OBJECT_A, 4, "test");
560
561 // Verify that received invalidations metrics are correct.
562 EXPECT_EQ(3, GetCount(kMetricPolicyInvalidationsNoPayload));
563 EXPECT_EQ(4, GetCount(kMetricPolicyInvalidationsPayload));
564 }
565
566 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698