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

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: UI polishing 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
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..d766e94444511357feac78990ef95802c9a01ace 100644
--- a/components/variations/service/variations_service_unittest.cc
+++ b/components/variations/service/variations_service_unittest.cc
@@ -23,6 +23,7 @@
#include "components/variations/pref_names.h"
#include "components/variations/proto/study.pb.h"
#include "components/variations/proto/variations_seed.pb.h"
+#include "components/version_info/version_info.h"
#include "components/web_resource/resource_request_allowed_notifier_test_util.h"
#include "net/base/url_util.h"
#include "net/http/http_response_headers.h"
@@ -728,4 +729,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";
+
+ 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 != "") {
Alexei Svitkine (slow) 2016/04/20 20:30:24 Nit: !.empty()
hamelphi 2016/04/20 21:39:47 Done.
+ 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

Powered by Google App Engine
This is Rietveld 408576698