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 "chrome/browser/metrics/variations/variations_service.h" | 5 #include "chrome/browser/metrics/variations/variations_service.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 }; | 477 }; |
478 | 478 |
479 for (const auto& test : test_cases) { | 479 for (const auto& test : test_cases) { |
480 TestingPrefServiceSimple prefs; | 480 TestingPrefServiceSimple prefs; |
481 VariationsService::RegisterPrefs(prefs.registry()); | 481 VariationsService::RegisterPrefs(prefs.registry()); |
482 VariationsService service( | 482 VariationsService service( |
483 new web_resource::TestRequestAllowedNotifier(&prefs), &prefs, NULL); | 483 new web_resource::TestRequestAllowedNotifier(&prefs), &prefs, NULL); |
484 | 484 |
485 if (test.pref_value_before) { | 485 if (test.pref_value_before) { |
486 base::ListValue list_value; | 486 base::ListValue list_value; |
487 std::vector<std::string> list_components; | 487 for (const std::string& component : base::SplitString( |
488 base::SplitString(test.pref_value_before, ',', &list_components); | 488 test.pref_value_before, ",", |
489 for (const std::string& component : list_components) | 489 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) |
490 list_value.AppendString(component); | 490 list_value.AppendString(component); |
491 prefs.Set(prefs::kVariationsPermanentConsistencyCountry, list_value); | 491 prefs.Set(prefs::kVariationsPermanentConsistencyCountry, list_value); |
492 } | 492 } |
493 | 493 |
494 variations::VariationsSeed seed(CreateTestSeed()); | 494 variations::VariationsSeed seed(CreateTestSeed()); |
495 if (test.seed_country_code) | 495 if (test.seed_country_code) |
496 seed.set_country_code(test.seed_country_code); | 496 seed.set_country_code(test.seed_country_code); |
497 | 497 |
498 base::HistogramTester histogram_tester; | 498 base::HistogramTester histogram_tester; |
499 EXPECT_EQ(test.expected_country, service.LoadPermanentConsistencyCountry( | 499 EXPECT_EQ(test.expected_country, service.LoadPermanentConsistencyCountry( |
500 base::Version(test.version), seed)); | 500 base::Version(test.version), seed)); |
501 | 501 |
502 base::ListValue expected_list_value; | 502 base::ListValue expected_list_value; |
503 std::vector<std::string> list_components; | 503 for (const std::string& component : base::SplitString( |
504 base::SplitString(test.expected_pref_value_after, ',', &list_components); | 504 test.expected_pref_value_after, ",", |
505 for (const std::string& component : list_components) | 505 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) |
506 expected_list_value.AppendString(component); | 506 expected_list_value.AppendString(component); |
507 EXPECT_TRUE(expected_list_value.Equals( | 507 EXPECT_TRUE(expected_list_value.Equals( |
508 prefs.GetList(prefs::kVariationsPermanentConsistencyCountry))); | 508 prefs.GetList(prefs::kVariationsPermanentConsistencyCountry))); |
509 | 509 |
510 histogram_tester.ExpectUniqueSample( | 510 histogram_tester.ExpectUniqueSample( |
511 "Variations.LoadPermanentConsistencyCountryResult", | 511 "Variations.LoadPermanentConsistencyCountryResult", |
512 test.expected_result, 1); | 512 test.expected_result, 1); |
513 } | 513 } |
514 } | 514 } |
515 | 515 |
516 } // namespace chrome_variations | 516 } // namespace chrome_variations |
OLD | NEW |