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

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

Issue 8499021: UserPolicyCache only becomes ready after policy has been fetched. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 helper.ProcessRegisterRequest(); 303 helper.ProcessRegisterRequest();
304 EXPECT_TRUE(helper.VerifyAndClearExpectations()); 304 EXPECT_TRUE(helper.VerifyAndClearExpectations());
305 EXPECT_TRUE(CheckSamples()); 305 EXPECT_TRUE(CheckSamples());
306 } 306 }
307 307
308 TEST_F(EnterpriseMetricsTest, TokenFetchOK) { 308 TEST_F(EnterpriseMetricsTest, TokenFetchOK) {
309 SetMetricName(kMetricToken); 309 SetMetricName(kMetricToken);
310 DeviceManagementBackendTestHelper helper(loop()); 310 DeviceManagementBackendTestHelper helper(loop());
311 311
312 // Test token fetcher. 312 // Test token fetcher.
313 UserPolicyCache cache(temp_dir().AppendASCII("FetchTokenTest")); 313 UserPolicyCache cache(temp_dir().AppendASCII("FetchTokenTest"), false);
314 scoped_ptr<CloudPolicyDataStore> data_store; 314 scoped_ptr<CloudPolicyDataStore> data_store;
315 data_store.reset(CloudPolicyDataStore::CreateForUserPolicies()); 315 data_store.reset(CloudPolicyDataStore::CreateForUserPolicies());
316 data_store->SetupForTesting("", "fake_device_id", "fake_user_name", 316 data_store->SetupForTesting("", "fake_device_id", "fake_user_name",
317 "fake_gaia_token", true); 317 "fake_gaia_token", true);
318 PolicyNotifier notifier; 318 PolicyNotifier notifier;
319 DeviceTokenFetcher fetcher(&helper.service(), &cache, data_store.get(), 319 DeviceTokenFetcher fetcher(&helper.service(), &cache, data_store.get(),
320 &notifier); 320 &notifier);
321 321
322 MockCloudPolicyDataStoreObserver observer; 322 MockCloudPolicyDataStoreObserver observer;
323 data_store->AddObserver(&observer); 323 data_store->AddObserver(&observer);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 ExpectSample(kMetricPolicyFetchRequested); 458 ExpectSample(kMetricPolicyFetchRequested);
459 ExpectSample(kMetricPolicyFetchResponseReceived); 459 ExpectSample(kMetricPolicyFetchResponseReceived);
460 helper.ProcessPolicyRequest(); 460 helper.ProcessPolicyRequest();
461 EXPECT_TRUE(helper.VerifyAndClearExpectations()); 461 EXPECT_TRUE(helper.VerifyAndClearExpectations());
462 EXPECT_TRUE(CheckSamples()); 462 EXPECT_TRUE(CheckSamples());
463 } 463 }
464 464
465 TEST_F(EnterpriseMetricsTest, PolicyFetchInvalidPolicy) { 465 TEST_F(EnterpriseMetricsTest, PolicyFetchInvalidPolicy) {
466 SetMetricName(kMetricPolicy); 466 SetMetricName(kMetricPolicy);
467 467
468 UserPolicyCache cache(temp_dir().AppendASCII("UserPolicyCacheTest")); 468 UserPolicyCache cache(temp_dir().AppendASCII("UserPolicyCacheTest"), false);
469 UserPolicyDiskCache::Delegate* cache_as_delegate = 469 UserPolicyDiskCache::Delegate* cache_as_delegate =
470 implicit_cast<UserPolicyDiskCache::Delegate*>(&cache); 470 implicit_cast<UserPolicyDiskCache::Delegate*>(&cache);
471 471
472 em::CachedCloudPolicyResponse response; 472 em::CachedCloudPolicyResponse response;
473 response.mutable_cloud_policy()->set_policy_data("\xff"); 473 response.mutable_cloud_policy()->set_policy_data("\xff");
474 cache_as_delegate->OnDiskCacheLoaded(UserPolicyDiskCache::LOAD_RESULT_SUCCESS, 474 cache_as_delegate->OnDiskCacheLoaded(UserPolicyDiskCache::LOAD_RESULT_SUCCESS,
475 response); 475 response);
476 ExpectSample(kMetricPolicyFetchInvalidPolicy); 476 ExpectSample(kMetricPolicyFetchInvalidPolicy);
477 EXPECT_TRUE(CheckSamples()); 477 EXPECT_TRUE(CheckSamples());
478 } 478 }
479 479
480 TEST_F(EnterpriseMetricsTest, PolicyFetchTimestampInFuture) { 480 TEST_F(EnterpriseMetricsTest, PolicyFetchTimestampInFuture) {
481 SetMetricName(kMetricPolicy); 481 SetMetricName(kMetricPolicy);
482 482
483 UserPolicyCache cache(temp_dir().AppendASCII("UserPolicyCacheTest")); 483 UserPolicyCache cache(temp_dir().AppendASCII("UserPolicyCacheTest"), false);
484 UserPolicyDiskCache::Delegate* cache_as_delegate = 484 UserPolicyDiskCache::Delegate* cache_as_delegate =
485 implicit_cast<UserPolicyDiskCache::Delegate*>(&cache); 485 implicit_cast<UserPolicyDiskCache::Delegate*>(&cache);
486 486
487 std::string data; 487 std::string data;
488 em::PolicyData policy_data; 488 em::PolicyData policy_data;
489 base::TimeDelta timestamp = 489 base::TimeDelta timestamp =
490 (base::Time::NowFromSystemTime() + base::TimeDelta::FromDays(1000)) - 490 (base::Time::NowFromSystemTime() + base::TimeDelta::FromDays(1000)) -
491 base::Time::UnixEpoch(); 491 base::Time::UnixEpoch();
492 policy_data.set_timestamp(timestamp.InMilliseconds()); 492 policy_data.set_timestamp(timestamp.InMilliseconds());
493 policy_data.SerializeToString(&data); 493 policy_data.SerializeToString(&data);
494 em::CachedCloudPolicyResponse response; 494 em::CachedCloudPolicyResponse response;
495 response.mutable_cloud_policy()->set_policy_data(data); 495 response.mutable_cloud_policy()->set_policy_data(data);
496 cache_as_delegate->OnDiskCacheLoaded(UserPolicyDiskCache::LOAD_RESULT_SUCCESS, 496 cache_as_delegate->OnDiskCacheLoaded(UserPolicyDiskCache::LOAD_RESULT_SUCCESS,
497 response); 497 response);
498 ExpectSample(kMetricPolicyFetchTimestampInFuture); 498 ExpectSample(kMetricPolicyFetchTimestampInFuture);
499 EXPECT_TRUE(CheckSamples()); 499 EXPECT_TRUE(CheckSamples());
500 } 500 }
501 501
502 TEST_F(EnterpriseMetricsTest, PolicyFetchNotModified) { 502 TEST_F(EnterpriseMetricsTest, PolicyFetchNotModified) {
503 SetMetricName(kMetricPolicy); 503 SetMetricName(kMetricPolicy);
504 504
505 UserPolicyCache cache(temp_dir().AppendASCII("UserPolicyCacheTest")); 505 UserPolicyCache cache(temp_dir().AppendASCII("UserPolicyCacheTest"), false);
506 UserPolicyDiskCache::Delegate* cache_as_delegate = 506 UserPolicyDiskCache::Delegate* cache_as_delegate =
507 implicit_cast<UserPolicyDiskCache::Delegate*>(&cache); 507 implicit_cast<UserPolicyDiskCache::Delegate*>(&cache);
508 508
509 std::string data; 509 std::string data;
510 em::PolicyData policy_data; 510 em::PolicyData policy_data;
511 policy_data.set_timestamp(0); 511 policy_data.set_timestamp(0);
512 policy_data.SerializeToString(&data); 512 policy_data.SerializeToString(&data);
513 em::CachedCloudPolicyResponse response; 513 em::CachedCloudPolicyResponse response;
514 response.mutable_cloud_policy()->set_policy_data(data); 514 response.mutable_cloud_policy()->set_policy_data(data);
515 cache_as_delegate->OnDiskCacheLoaded(UserPolicyDiskCache::LOAD_RESULT_SUCCESS, 515 cache_as_delegate->OnDiskCacheLoaded(UserPolicyDiskCache::LOAD_RESULT_SUCCESS,
516 response); 516 response);
517 ExpectSample(kMetricPolicyFetchNotModified); 517 ExpectSample(kMetricPolicyFetchNotModified);
518 EXPECT_TRUE(CheckSamples()); 518 EXPECT_TRUE(CheckSamples());
519 } 519 }
520 520
521 TEST_F(EnterpriseMetricsTest, PolicyFetchOK) { 521 TEST_F(EnterpriseMetricsTest, PolicyFetchOK) {
522 SetMetricName(kMetricPolicy); 522 SetMetricName(kMetricPolicy);
523 523
524 UserPolicyCache cache(temp_dir().AppendASCII("UserPolicyCacheTest")); 524 UserPolicyCache cache(temp_dir().AppendASCII("UserPolicyCacheTest"), false);
525 525
526 std::string data; 526 std::string data;
527 em::PolicyData policy_data; 527 em::PolicyData policy_data;
528 policy_data.set_timestamp(0); 528 policy_data.set_timestamp(0);
529 policy_data.SerializeToString(&data); 529 policy_data.SerializeToString(&data);
530 em::CachedCloudPolicyResponse response; 530 em::CachedCloudPolicyResponse response;
531 cache.SetPolicy(response.cloud_policy()); 531 cache.SetPolicy(response.cloud_policy());
532 ExpectSample(kMetricPolicyFetchOK); 532 ExpectSample(kMetricPolicyFetchOK);
533 ExpectSample(kMetricPolicyFetchNotModified); 533 ExpectSample(kMetricPolicyFetchNotModified);
534 EXPECT_TRUE(CheckSamples()); 534 EXPECT_TRUE(CheckSamples());
535 // This also triggers a store. Update the expected samples. 535 // This also triggers a store. Update the expected samples.
536 RunAllPending(); 536 RunAllPending();
537 ExpectSample(kMetricPolicyStoreSucceeded); 537 ExpectSample(kMetricPolicyStoreSucceeded);
538 EXPECT_TRUE(CheckSamples()); 538 EXPECT_TRUE(CheckSamples());
539 } 539 }
540 540
541 TEST_F(EnterpriseMetricsTest, PolicyFetchBadResponse) { 541 TEST_F(EnterpriseMetricsTest, PolicyFetchBadResponse) {
542 SetMetricName(kMetricPolicy); 542 SetMetricName(kMetricPolicy);
543 543
544 UserPolicyCache cache(temp_dir().AppendASCII("UserPolicyCacheTest")); 544 UserPolicyCache cache(temp_dir().AppendASCII("UserPolicyCacheTest"), false);
545 PolicyNotifier notifier; 545 PolicyNotifier notifier;
546 scoped_ptr<CloudPolicyDataStore> data_store; 546 scoped_ptr<CloudPolicyDataStore> data_store;
547 data_store.reset(CloudPolicyDataStore::CreateForUserPolicies()); 547 data_store.reset(CloudPolicyDataStore::CreateForUserPolicies());
548 data_store->SetupForTesting("", "fake_device_id", "fake_user_name", 548 data_store->SetupForTesting("", "fake_device_id", "fake_user_name",
549 "fake_gaia_token", true); 549 "fake_gaia_token", true);
550 CloudPolicyController controller(NULL, &cache, NULL, data_store.get(), 550 CloudPolicyController controller(NULL, &cache, NULL, data_store.get(),
551 &notifier); 551 &notifier);
552 em::DevicePolicyResponse device_policy_response; 552 em::DevicePolicyResponse device_policy_response;
553 controller.HandlePolicyResponse(device_policy_response); 553 controller.HandlePolicyResponse(device_policy_response);
554 ExpectSample(kMetricPolicyFetchBadResponse); 554 ExpectSample(kMetricPolicyFetchBadResponse);
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 helper.CompleteRetrieve(chromeos::SignedSettings::NOT_FOUND); 861 helper.CompleteRetrieve(chromeos::SignedSettings::NOT_FOUND);
862 helper.SetData("\xff"); 862 helper.SetData("\xff");
863 helper.SetPolicy(); 863 helper.SetPolicy();
864 ExpectSample(kMetricPolicyFetchInvalidPolicy); 864 ExpectSample(kMetricPolicyFetchInvalidPolicy);
865 EXPECT_TRUE(CheckSamples()); 865 EXPECT_TRUE(CheckSamples());
866 } 866 }
867 867
868 #endif 868 #endif
869 869
870 } // namespace policy 870 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698