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

Side by Side Diff: components/variations/study_filtering_unittest.cc

Issue 2488173005: Adding support for exclude locales to variations. (Closed)
Patch Set: fix typo in comment Created 4 years, 1 month 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/study_filtering.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/study_filtering.h" 5 #include "components/variations/study_filtering.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string.h> 9 #include <string.h>
10 10
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 const int index = arraysize(form_factors) - i - 1; 123 const int index = arraysize(form_factors) - i - 1;
124 filter.add_form_factor(form_factors[index]); 124 filter.add_form_factor(form_factors[index]);
125 form_factor_added[index] = true; 125 form_factor_added[index] = true;
126 } 126 }
127 } 127 }
128 } 128 }
129 129
130 TEST(VariationsStudyFilteringTest, CheckStudyLocale) { 130 TEST(VariationsStudyFilteringTest, CheckStudyLocale) {
131 struct { 131 struct {
132 const char* filter_locales; 132 const char* filter_locales;
133 const char* exclude_locales;
133 bool en_us_result; 134 bool en_us_result;
134 bool en_ca_result; 135 bool en_ca_result;
135 bool fr_result; 136 bool fr_result;
136 } test_cases[] = { 137 } test_cases[] = {
137 {"en-US", true, false, false}, 138 {"en-US", "", true, false, false},
138 {"en-US,en-CA,fr", true, true, true}, 139 // Tests that locale overrides exclude_locale, when both are given. This
139 {"en-US,en-CA,en-GB", true, true, false}, 140 // should not occur in practice though.
140 {"en-GB,en-CA,en-US", true, true, false}, 141 {"en-US", "en-US", true, false, false},
141 {"ja,kr,vi", false, false, false}, 142 {"en-US,en-CA,fr", "", true, true, true},
142 {"fr-CA", false, false, false}, 143 {"en-US,en-CA,en-GB", "", true, true, false},
143 {"", true, true, true}, 144 {"en-GB,en-CA,en-US", "", true, true, false},
145 {"ja,kr,vi", "", false, false, false},
146 {"fr-CA", "", false, false, false},
147 {"", "", true, true, true},
148 {"", "en-US", false, true, true},
149 {"", "en-US,en-CA,fr", false, false, false},
150 {"", "en-US,en-CA,en-GB", false, false, true},
151 {"", "en-GB,en-CA,en-US", false, false, true},
152 {"", "ja,kr,vi", true, true, true},
153 {"", "fr-CA", true, true, true},
144 }; 154 };
145 155
146 for (size_t i = 0; i < arraysize(test_cases); ++i) { 156 for (size_t i = 0; i < arraysize(test_cases); ++i) {
147 Study_Filter filter; 157 Study_Filter filter;
148 for (const std::string& locale : base::SplitString( 158 for (const std::string& locale : base::SplitString(
149 test_cases[i].filter_locales, ",", 159 test_cases[i].filter_locales, ",",
150 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) 160 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL))
151 filter.add_locale(locale); 161 filter.add_locale(locale);
162 for (const std::string& exclude_locale :
163 base::SplitString(test_cases[i].exclude_locales, ",",
164 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL))
165 filter.add_exclude_locale(exclude_locale);
152 EXPECT_EQ(test_cases[i].en_us_result, 166 EXPECT_EQ(test_cases[i].en_us_result,
153 internal::CheckStudyLocale(filter, "en-US")); 167 internal::CheckStudyLocale(filter, "en-US"));
154 EXPECT_EQ(test_cases[i].en_ca_result, 168 EXPECT_EQ(test_cases[i].en_ca_result,
155 internal::CheckStudyLocale(filter, "en-CA")); 169 internal::CheckStudyLocale(filter, "en-CA"));
156 EXPECT_EQ(test_cases[i].fr_result, 170 EXPECT_EQ(test_cases[i].fr_result,
157 internal::CheckStudyLocale(filter, "fr")); 171 internal::CheckStudyLocale(filter, "fr"));
158 } 172 }
159 } 173 }
160 174
161 TEST(VariationsStudyFilteringTest, CheckStudyPlatform) { 175 TEST(VariationsStudyFilteringTest, CheckStudyPlatform) {
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 585
572 default_group->set_name("def"); 586 default_group->set_name("def");
573 EXPECT_TRUE(processed_study.Init(&study, false)); 587 EXPECT_TRUE(processed_study.Init(&study, false));
574 Study_Experiment* repeated_group = study.add_experiment(); 588 Study_Experiment* repeated_group = study.add_experiment();
575 repeated_group->set_name("abc"); 589 repeated_group->set_name("abc");
576 repeated_group->set_probability_weight(1); 590 repeated_group->set_probability_weight(1);
577 EXPECT_FALSE(processed_study.Init(&study, false)); 591 EXPECT_FALSE(processed_study.Init(&study, false));
578 } 592 }
579 593
580 } // namespace variations 594 } // namespace variations
OLDNEW
« no previous file with comments | « components/variations/study_filtering.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698