Chromium Code Reviews| Index: components/variations/service/variations_service_unittest.cc |
| diff --git a/components/variations/service/variations_service_unittest.cc b/components/variations/service/variations_service_unittest.cc |
| index aea08e39f8a39c053d6c389bbb168c1a9af58751..eac5703153a007ebda8ebfc3bb3975ab0fab3a4b 100644 |
| --- a/components/variations/service/variations_service_unittest.cc |
| +++ b/components/variations/service/variations_service_unittest.cc |
| @@ -728,4 +728,64 @@ TEST_F(VariationsServiceTest, LoadPermanentConsistencyCountry) { |
| } |
| } |
| +TEST_F(VariationsServiceTest, ForceSetStoredPermanentCountry) { |
| + std::string kTestVersion = version_info::GetVersionNumber(); |
| + std::string kPrefCa = version_info::GetVersionNumber() + ",ca"; |
| + std::string kPrefUs = version_info::GetVersionNumber() + ",us"; |
|
hajimehoshi
2016/04/22 07:22:57
const
hamelphi
2016/04/22 17:20:05
Done.
|
| + |
| + struct { |
| + // Comma separated list, empty string if the pref isn't set initially. |
| + std::string pref_value_before; |
| + std::string country_code_override; |
| + // Comma separated list. |
| + std::string expected_pref_value_after; |
| + // Is the pref expected to be updated or not. |
| + const bool has_updated; |
| + } test_cases[] = { |
| + {kPrefUs, "ca", kPrefCa, true}, |
| + {kPrefUs, "us", kPrefUs, false}, |
| + {kPrefUs, "", kPrefUs, false}, |
| + {"", "ca", kPrefCa, true}, |
| + {"", "", "", false}, |
| + {"19.0.0.0,us", "ca", kPrefCa, true}, |
| + {"19.0.0.0,us", "us", "19.0.0.0,us", false}, |
| + }; |
| + |
| + for (const auto& test : test_cases) { |
| + TestingPrefServiceSimple prefs; |
| + VariationsService::RegisterPrefs(prefs.registry()); |
| + TestVariationsService service( |
| + make_scoped_ptr(new web_resource::TestRequestAllowedNotifier(&prefs)), |
| + &prefs); |
| + |
| + if (!test.pref_value_before.empty()) { |
| + base::ListValue list_value; |
| + for (const std::string& component : |
| + base::SplitString(test.pref_value_before, ",", base::TRIM_WHITESPACE, |
| + base::SPLIT_WANT_ALL)) { |
| + list_value.AppendString(component); |
| + } |
| + prefs.Set(prefs::kVariationsPermanentConsistencyCountry, list_value); |
| + } |
| + |
| + variations::VariationsSeed seed(CreateTestSeed()); |
| + |
| + EXPECT_EQ(test.has_updated, service.ForceSetStoredPermanentCountry( |
| + test.country_code_override)) |
| + << test.pref_value_before << ", " << test.country_code_override; |
| + |
| + base::ListValue expected_list_value; |
| + for (const std::string& component : |
| + base::SplitString(test.expected_pref_value_after, ",", |
| + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| + expected_list_value.AppendString(component); |
| + } |
| + const base::ListValue* pref_value = |
| + prefs.GetList(prefs::kVariationsPermanentConsistencyCountry); |
| + EXPECT_EQ(ListValueToString(expected_list_value), |
| + ListValueToString(*pref_value)) |
| + << test.pref_value_before << ", " << test.country_code_override; |
| + } |
| +} |
| + |
| } // namespace variations |