Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: components/variations/service/variations_service_unittest.cc

Issue 1903593002: Allows to manually change the stored permanent country in Variations from the translate-internals d… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/variations/service/variations_service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..edbb8ccd5a62a81a2d907a5f5e013bcd64b933df 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, OverrideStoredPermanentCountry) {
+ const std::string kTestVersion = version_info::GetVersionNumber();
+ const std::string kPrefCa = version_info::GetVersionNumber() + ",ca";
+ const std::string kPrefUs = version_info::GetVersionNumber() + ",us";
+
+ struct {
+ // Comma separated list, empty string if the pref isn't set initially.
+ const std::string pref_value_before;
+ const std::string country_code_override;
+ // Comma separated list.
+ const 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.OverrideStoredPermanentCountry(
+ 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
« no previous file with comments | « components/variations/service/variations_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698