| OLD | NEW | 
|---|
| 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 "base/base64.h" | 5 #include "base/base64.h" | 
| 6 #include "base/string_split.h" | 6 #include "base/string_split.h" | 
| 7 #include "chrome/browser/metrics/proto/study.pb.h" | 7 #include "chrome/browser/metrics/proto/study.pb.h" | 
| 8 #include "chrome/browser/metrics/variations/resource_request_allowed_notifier_te
     st_util.h" | 8 #include "chrome/browser/metrics/variations/resource_request_allowed_notifier_te
     st_util.h" | 
| 9 #include "chrome/browser/metrics/variations/variations_service.h" | 9 #include "chrome/browser/metrics/variations/variations_service.h" | 
| 10 #include "chrome/common/chrome_version_info.h" | 10 #include "chrome/common/chrome_version_info.h" | 
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 333     study.set_expiry_date(TimeToProtoTime(expiry_test_cases[i].expiry_date)); | 333     study.set_expiry_date(TimeToProtoTime(expiry_test_cases[i].expiry_date)); | 
| 334     const bool result = VariationsService::IsStudyExpired(study, now); | 334     const bool result = VariationsService::IsStudyExpired(study, now); | 
| 335     EXPECT_EQ(expiry_test_cases[i].expected_result, result) | 335     EXPECT_EQ(expiry_test_cases[i].expected_result, result) | 
| 336         << "Case " << i << " failed!"; | 336         << "Case " << i << " failed!"; | 
| 337   } | 337   } | 
| 338 } | 338 } | 
| 339 | 339 | 
| 340 TEST(VariationsServiceTest, LoadSeed) { | 340 TEST(VariationsServiceTest, LoadSeed) { | 
| 341   TestingPrefServiceSimple pref_service; | 341   TestingPrefServiceSimple pref_service; | 
| 342 | 342 | 
| 343   VariationsService::RegisterPrefs(&pref_service); | 343   VariationsService::RegisterPrefs(pref_service.registry()); | 
| 344 | 344 | 
| 345   // Store good seed data to test if loading from prefs works. | 345   // Store good seed data to test if loading from prefs works. | 
| 346   TrialsSeed seed = CreateTestSeed(); | 346   TrialsSeed seed = CreateTestSeed(); | 
| 347 | 347 | 
| 348   std::string serialized_seed; | 348   std::string serialized_seed; | 
| 349   seed.SerializeToString(&serialized_seed); | 349   seed.SerializeToString(&serialized_seed); | 
| 350   std::string base64_serialized_seed; | 350   std::string base64_serialized_seed; | 
| 351   ASSERT_TRUE(base::Base64Encode(serialized_seed, &base64_serialized_seed)); | 351   ASSERT_TRUE(base::Base64Encode(serialized_seed, &base64_serialized_seed)); | 
| 352   pref_service.SetString(prefs::kVariationsSeed, base64_serialized_seed); | 352   pref_service.SetString(prefs::kVariationsSeed, base64_serialized_seed); | 
| 353 | 353 | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 373       pref_service.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); | 373       pref_service.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); | 
| 374   EXPECT_FALSE( | 374   EXPECT_FALSE( | 
| 375       variations_service.LoadTrialsSeedFromPref(&pref_service, &loaded_seed)); | 375       variations_service.LoadTrialsSeedFromPref(&pref_service, &loaded_seed)); | 
| 376   EXPECT_TRUE( | 376   EXPECT_TRUE( | 
| 377       pref_service.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); | 377       pref_service.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); | 
| 378 } | 378 } | 
| 379 | 379 | 
| 380 TEST(VariationsServiceTest, StoreSeed) { | 380 TEST(VariationsServiceTest, StoreSeed) { | 
| 381   TestingPrefServiceSimple pref_service; | 381   TestingPrefServiceSimple pref_service; | 
| 382 | 382 | 
| 383   VariationsService::RegisterPrefs(&pref_service); | 383   VariationsService::RegisterPrefs(pref_service.registry()); | 
| 384   const base::Time now = base::Time::Now(); | 384   const base::Time now = base::Time::Now(); | 
| 385 | 385 | 
| 386   TrialsSeed seed = CreateTestSeed(); | 386   TrialsSeed seed = CreateTestSeed(); | 
| 387 | 387 | 
| 388   TestVariationsService variations_service(new TestRequestAllowedNotifier); | 388   TestVariationsService variations_service(new TestRequestAllowedNotifier); | 
| 389   std::string serialized_seed; | 389   std::string serialized_seed; | 
| 390   seed.SerializeToString(&serialized_seed); | 390   seed.SerializeToString(&serialized_seed); | 
| 391   EXPECT_TRUE( | 391   EXPECT_TRUE( | 
| 392       variations_service.StoreSeedData(serialized_seed, now, &pref_service)); | 392       variations_service.StoreSeedData(serialized_seed, now, &pref_service)); | 
| 393   // Make sure the pref was actually set. | 393   // Make sure the pref was actually set. | 
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 512   // manipulate it for this test. | 512   // manipulate it for this test. | 
| 513   TestRequestAllowedNotifier* test_notifier = new TestRequestAllowedNotifier; | 513   TestRequestAllowedNotifier* test_notifier = new TestRequestAllowedNotifier; | 
| 514   TestVariationsService test_service(test_notifier); | 514   TestVariationsService test_service(test_notifier); | 
| 515 | 515 | 
| 516   test_notifier->SetRequestsAllowedOverride(true); | 516   test_notifier->SetRequestsAllowedOverride(true); | 
| 517   test_service.StartRepeatedVariationsSeedFetch(); | 517   test_service.StartRepeatedVariationsSeedFetch(); | 
| 518   EXPECT_TRUE(test_service.fetch_attempted()); | 518   EXPECT_TRUE(test_service.fetch_attempted()); | 
| 519 } | 519 } | 
| 520 | 520 | 
| 521 }  // namespace chrome_variations | 521 }  // namespace chrome_variations | 
| OLD | NEW | 
|---|