| 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 "components/variations/service/variations_service.h" | 5 #include "components/variations/service/variations_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 private: | 265 private: |
| 266 base::MessageLoop message_loop_; | 266 base::MessageLoop message_loop_; |
| 267 | 267 |
| 268 DISALLOW_COPY_AND_ASSIGN(VariationsServiceTest); | 268 DISALLOW_COPY_AND_ASSIGN(VariationsServiceTest); |
| 269 }; | 269 }; |
| 270 | 270 |
| 271 TEST_F(VariationsServiceTest, CreateTrialsFromSeed) { | 271 TEST_F(VariationsServiceTest, CreateTrialsFromSeed) { |
| 272 TestingPrefServiceSimple prefs; | 272 TestingPrefServiceSimple prefs; |
| 273 VariationsService::RegisterPrefs(prefs.registry()); | 273 VariationsService::RegisterPrefs(prefs.registry()); |
| 274 | 274 |
| 275 // Setup base::FeatureList. | |
| 276 base::FeatureList::ClearInstanceForTesting(); | |
| 277 base::FeatureList::SetInstance(base::WrapUnique(new base::FeatureList())); | |
| 278 | |
| 279 // Create a local base::FieldTrialList, to hold the field trials created in | 275 // Create a local base::FieldTrialList, to hold the field trials created in |
| 280 // this test. | 276 // this test. |
| 281 base::FieldTrialList field_trial_list(nullptr); | 277 base::FieldTrialList field_trial_list(nullptr); |
| 282 | 278 |
| 283 // Create a variations service. | 279 // Create a variations service. |
| 284 TestVariationsService service( | 280 TestVariationsService service( |
| 285 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), | 281 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), |
| 286 &prefs); | 282 &prefs); |
| 287 service.SetCreateTrialsFromSeedCalledForTesting(false); | 283 service.SetCreateTrialsFromSeedCalledForTesting(false); |
| 288 | 284 |
| 289 // Store a seed. | 285 // Store a seed. |
| 290 service.StoreSeed(SerializeSeed(CreateTestSeed()), std::string(), | 286 service.StoreSeed(SerializeSeed(CreateTestSeed()), std::string(), |
| 291 std::string(), base::Time::Now(), false, false); | 287 std::string(), base::Time::Now(), false, false); |
| 292 prefs.SetInt64(prefs::kVariationsLastFetchTime, | 288 prefs.SetInt64(prefs::kVariationsLastFetchTime, |
| 293 base::Time::Now().ToInternalValue()); | 289 base::Time::Now().ToInternalValue()); |
| 294 | 290 |
| 295 // Check that field trials are created from the seed. Since the test study has | 291 // Check that field trials are created from the seed. Since the test study has |
| 296 // only 1 experiment with 100% probability weight, we must be part of it. | 292 // only 1 experiment with 100% probability weight, we must be part of it. |
| 297 EXPECT_TRUE(service.CreateTrialsFromSeed(base::FeatureList::GetInstance())); | 293 EXPECT_TRUE(service.CreateTrialsFromSeed(base::FeatureList::GetInstance())); |
| 298 EXPECT_EQ(kTestSeedExperimentName, | 294 EXPECT_EQ(kTestSeedExperimentName, |
| 299 base::FieldTrialList::FindFullName(kTestSeedStudyName)); | 295 base::FieldTrialList::FindFullName(kTestSeedStudyName)); |
| 300 } | 296 } |
| 301 | 297 |
| 302 TEST_F(VariationsServiceTest, CreateTrialsFromSeedNoLastFetchTime) { | 298 TEST_F(VariationsServiceTest, CreateTrialsFromSeedNoLastFetchTime) { |
| 303 TestingPrefServiceSimple prefs; | 299 TestingPrefServiceSimple prefs; |
| 304 VariationsService::RegisterPrefs(prefs.registry()); | 300 VariationsService::RegisterPrefs(prefs.registry()); |
| 305 | 301 |
| 306 // Setup base::FeatureList. | |
| 307 base::FeatureList::ClearInstanceForTesting(); | |
| 308 base::FeatureList::SetInstance(base::WrapUnique(new base::FeatureList())); | |
| 309 | |
| 310 // Create a local base::FieldTrialList, to hold the field trials created in | 302 // Create a local base::FieldTrialList, to hold the field trials created in |
| 311 // this test. | 303 // this test. |
| 312 base::FieldTrialList field_trial_list(nullptr); | 304 base::FieldTrialList field_trial_list(nullptr); |
| 313 | 305 |
| 314 // Create a variations service | 306 // Create a variations service |
| 315 TestVariationsService service( | 307 TestVariationsService service( |
| 316 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), | 308 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), |
| 317 &prefs); | 309 &prefs); |
| 318 service.SetCreateTrialsFromSeedCalledForTesting(false); | 310 service.SetCreateTrialsFromSeedCalledForTesting(false); |
| 319 | 311 |
| 320 // Store a seed. To simulate a first run, |prefs::kVariationsLastFetchTime| | 312 // Store a seed. To simulate a first run, |prefs::kVariationsLastFetchTime| |
| 321 // is left empty. | 313 // is left empty. |
| 322 service.StoreSeed(SerializeSeed(CreateTestSeed()), std::string(), | 314 service.StoreSeed(SerializeSeed(CreateTestSeed()), std::string(), |
| 323 std::string(), base::Time::Now(), false, false); | 315 std::string(), base::Time::Now(), false, false); |
| 324 EXPECT_EQ(0, prefs.GetInt64(prefs::kVariationsLastFetchTime)); | 316 EXPECT_EQ(0, prefs.GetInt64(prefs::kVariationsLastFetchTime)); |
| 325 | 317 |
| 326 // Check that field trials are created from the seed. Since the test study has | 318 // Check that field trials are created from the seed. Since the test study has |
| 327 // only 1 experiment with 100% probability weight, we must be part of it. | 319 // only 1 experiment with 100% probability weight, we must be part of it. |
| 328 EXPECT_TRUE(service.CreateTrialsFromSeed(base::FeatureList::GetInstance())); | 320 EXPECT_TRUE(service.CreateTrialsFromSeed(base::FeatureList::GetInstance())); |
| 329 EXPECT_EQ(base::FieldTrialList::FindFullName(kTestSeedStudyName), | 321 EXPECT_EQ(base::FieldTrialList::FindFullName(kTestSeedStudyName), |
| 330 kTestSeedExperimentName); | 322 kTestSeedExperimentName); |
| 331 } | 323 } |
| 332 | 324 |
| 333 TEST_F(VariationsServiceTest, CreateTrialsFromOutdatedSeed) { | 325 TEST_F(VariationsServiceTest, CreateTrialsFromOutdatedSeed) { |
| 334 TestingPrefServiceSimple prefs; | 326 TestingPrefServiceSimple prefs; |
| 335 VariationsService::RegisterPrefs(prefs.registry()); | 327 VariationsService::RegisterPrefs(prefs.registry()); |
| 336 | 328 |
| 337 // Setup base::FeatureList. | |
| 338 base::FeatureList::ClearInstanceForTesting(); | |
| 339 base::FeatureList::SetInstance(base::WrapUnique(new base::FeatureList())); | |
| 340 | |
| 341 // Create a local base::FieldTrialList, to hold the field trials created in | 329 // Create a local base::FieldTrialList, to hold the field trials created in |
| 342 // this test. | 330 // this test. |
| 343 base::FieldTrialList field_trial_list(nullptr); | 331 base::FieldTrialList field_trial_list(nullptr); |
| 344 | 332 |
| 345 // Create a variations service. | 333 // Create a variations service. |
| 346 TestVariationsService service( | 334 TestVariationsService service( |
| 347 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), | 335 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), |
| 348 &prefs); | 336 &prefs); |
| 349 service.SetCreateTrialsFromSeedCalledForTesting(false); | 337 service.SetCreateTrialsFromSeedCalledForTesting(false); |
| 350 | 338 |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 } | 778 } |
| 791 const base::ListValue* pref_value = | 779 const base::ListValue* pref_value = |
| 792 prefs.GetList(prefs::kVariationsPermanentConsistencyCountry); | 780 prefs.GetList(prefs::kVariationsPermanentConsistencyCountry); |
| 793 EXPECT_EQ(ListValueToString(expected_list_value), | 781 EXPECT_EQ(ListValueToString(expected_list_value), |
| 794 ListValueToString(*pref_value)) | 782 ListValueToString(*pref_value)) |
| 795 << test.pref_value_before << ", " << test.country_code_override; | 783 << test.pref_value_before << ", " << test.country_code_override; |
| 796 } | 784 } |
| 797 } | 785 } |
| 798 | 786 |
| 799 } // namespace variations | 787 } // namespace variations |
| OLD | NEW |