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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « components/variations/service/variations_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, OverrideStoredPermanentCountry) {
732 const std::string kTestVersion = version_info::GetVersionNumber();
733 const std::string kPrefCa = version_info::GetVersionNumber() + ",ca";
734 const std::string kPrefUs = version_info::GetVersionNumber() + ",us";
735
736 struct {
737 // Comma separated list, empty string if the pref isn't set initially.
738 const std::string pref_value_before;
739 const std::string country_code_override;
740 // Comma separated list.
741 const 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.OverrideStoredPermanentCountry(
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
OLDNEW
« 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