Chromium Code Reviews| 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 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 721 ListValueToString(*pref_value)) | 721 ListValueToString(*pref_value)) |
| 722 << test.pref_value_before << ", " << test.version << ", " | 722 << test.pref_value_before << ", " << test.version << ", " |
| 723 << test.latest_country_code; | 723 << test.latest_country_code; |
| 724 | 724 |
| 725 histogram_tester.ExpectUniqueSample( | 725 histogram_tester.ExpectUniqueSample( |
| 726 "Variations.LoadPermanentConsistencyCountryResult", | 726 "Variations.LoadPermanentConsistencyCountryResult", |
| 727 test.expected_result, 1); | 727 test.expected_result, 1); |
| 728 } | 728 } |
| 729 } | 729 } |
| 730 | 730 |
| 731 TEST_F(VariationsServiceTest, ForceSetStoredPermanentCountry) { | |
| 732 std::string kTestVersion = version_info::GetVersionNumber(); | |
| 733 std::string kPrefCa = version_info::GetVersionNumber() + ",ca"; | |
| 734 std::string kPrefUs = version_info::GetVersionNumber() + ",us"; | |
|
hajimehoshi
2016/04/22 07:22:57
const
hamelphi
2016/04/22 17:20:05
Done.
| |
| 735 | |
| 736 struct { | |
| 737 // Comma separated list, empty string if the pref isn't set initially. | |
| 738 std::string pref_value_before; | |
| 739 std::string country_code_override; | |
| 740 // Comma separated list. | |
| 741 std::string expected_pref_value_after; | |
| 742 // Is the pref expected to be updated or not. | |
| 743 const bool has_updated; | |
| 744 } test_cases[] = { | |
| 745 {kPrefUs, "ca", kPrefCa, true}, | |
| 746 {kPrefUs, "us", kPrefUs, false}, | |
| 747 {kPrefUs, "", kPrefUs, false}, | |
| 748 {"", "ca", kPrefCa, true}, | |
| 749 {"", "", "", false}, | |
| 750 {"19.0.0.0,us", "ca", kPrefCa, true}, | |
| 751 {"19.0.0.0,us", "us", "19.0.0.0,us", false}, | |
| 752 }; | |
| 753 | |
| 754 for (const auto& test : test_cases) { | |
| 755 TestingPrefServiceSimple prefs; | |
| 756 VariationsService::RegisterPrefs(prefs.registry()); | |
| 757 TestVariationsService service( | |
| 758 make_scoped_ptr(new web_resource::TestRequestAllowedNotifier(&prefs)), | |
| 759 &prefs); | |
| 760 | |
| 761 if (!test.pref_value_before.empty()) { | |
| 762 base::ListValue list_value; | |
| 763 for (const std::string& component : | |
| 764 base::SplitString(test.pref_value_before, ",", base::TRIM_WHITESPACE, | |
| 765 base::SPLIT_WANT_ALL)) { | |
| 766 list_value.AppendString(component); | |
| 767 } | |
| 768 prefs.Set(prefs::kVariationsPermanentConsistencyCountry, list_value); | |
| 769 } | |
| 770 | |
| 771 variations::VariationsSeed seed(CreateTestSeed()); | |
| 772 | |
| 773 EXPECT_EQ(test.has_updated, service.ForceSetStoredPermanentCountry( | |
| 774 test.country_code_override)) | |
| 775 << test.pref_value_before << ", " << test.country_code_override; | |
| 776 | |
| 777 base::ListValue expected_list_value; | |
| 778 for (const std::string& component : | |
| 779 base::SplitString(test.expected_pref_value_after, ",", | |
| 780 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { | |
| 781 expected_list_value.AppendString(component); | |
| 782 } | |
| 783 const base::ListValue* pref_value = | |
| 784 prefs.GetList(prefs::kVariationsPermanentConsistencyCountry); | |
| 785 EXPECT_EQ(ListValueToString(expected_list_value), | |
| 786 ListValueToString(*pref_value)) | |
| 787 << test.pref_value_before << ", " << test.country_code_override; | |
| 788 } | |
| 789 } | |
| 790 | |
| 731 } // namespace variations | 791 } // namespace variations |
| OLD | NEW |