OLD | NEW |
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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "components/variations/processed_study.h" | 10 #include "components/variations/processed_study.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 {"en-US", true, false, false}, | 132 {"en-US", true, false, false}, |
133 {"en-US,en-CA,fr", true, true, true}, | 133 {"en-US,en-CA,fr", true, true, true}, |
134 {"en-US,en-CA,en-GB", true, true, false}, | 134 {"en-US,en-CA,en-GB", true, true, false}, |
135 {"en-GB,en-CA,en-US", true, true, false}, | 135 {"en-GB,en-CA,en-US", true, true, false}, |
136 {"ja,kr,vi", false, false, false}, | 136 {"ja,kr,vi", false, false, false}, |
137 {"fr-CA", false, false, false}, | 137 {"fr-CA", false, false, false}, |
138 {"", true, true, true}, | 138 {"", true, true, true}, |
139 }; | 139 }; |
140 | 140 |
141 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 141 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
142 std::vector<std::string> filter_locales; | |
143 Study_Filter filter; | 142 Study_Filter filter; |
144 base::SplitString(test_cases[i].filter_locales, ',', &filter_locales); | 143 for (const std::string& locale : base::SplitString( |
145 for (size_t j = 0; j < filter_locales.size(); ++j) | 144 test_cases[i].filter_locales, ",", |
146 filter.add_locale(filter_locales[j]); | 145 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) |
| 146 filter.add_locale(locale); |
147 EXPECT_EQ(test_cases[i].en_us_result, | 147 EXPECT_EQ(test_cases[i].en_us_result, |
148 internal::CheckStudyLocale(filter, "en-US")); | 148 internal::CheckStudyLocale(filter, "en-US")); |
149 EXPECT_EQ(test_cases[i].en_ca_result, | 149 EXPECT_EQ(test_cases[i].en_ca_result, |
150 internal::CheckStudyLocale(filter, "en-CA")); | 150 internal::CheckStudyLocale(filter, "en-CA")); |
151 EXPECT_EQ(test_cases[i].fr_result, | 151 EXPECT_EQ(test_cases[i].fr_result, |
152 internal::CheckStudyLocale(filter, "fr")); | 152 internal::CheckStudyLocale(filter, "fr")); |
153 } | 153 } |
154 } | 154 } |
155 | 155 |
156 TEST(VariationsStudyFilteringTest, CheckStudyPlatform) { | 156 TEST(VariationsStudyFilteringTest, CheckStudyPlatform) { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 {"", "apple,pear,orange", "fancy INTEL SNapple device", false}, | 348 {"", "apple,pear,orange", "fancy INTEL SNapple device", false}, |
349 // Empty. | 349 // Empty. |
350 {"", "apple,pear,orange", "", true}, | 350 {"", "apple,pear,orange", "", true}, |
351 | 351 |
352 // Not testing when both are set as it should never occur and should be | 352 // Not testing when both are set as it should never occur and should be |
353 // considered undefined. | 353 // considered undefined. |
354 }; | 354 }; |
355 | 355 |
356 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 356 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
357 Study_Filter filter; | 357 Study_Filter filter; |
358 std::vector<std::string> hardware_class; | 358 for (const std::string& cur : base::SplitString( |
359 base::SplitString(test_cases[i].hardware_class, ',', &hardware_class); | 359 test_cases[i].hardware_class, ",", |
360 for (size_t j = 0; j < hardware_class.size(); ++j) | 360 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) |
361 filter.add_hardware_class(hardware_class[j]); | 361 filter.add_hardware_class(cur); |
362 | 362 |
363 std::vector<std::string> exclude_hardware_class; | 363 for (const std::string& cur : base::SplitString( |
364 base::SplitString(test_cases[i].exclude_hardware_class, ',', | 364 test_cases[i].exclude_hardware_class, ",", |
365 &exclude_hardware_class); | 365 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) |
366 for (size_t j = 0; j < exclude_hardware_class.size(); ++j) | 366 filter.add_exclude_hardware_class(cur); |
367 filter.add_exclude_hardware_class(exclude_hardware_class[j]); | |
368 | 367 |
369 EXPECT_EQ(test_cases[i].expected_result, | 368 EXPECT_EQ(test_cases[i].expected_result, |
370 internal::CheckStudyHardwareClass( | 369 internal::CheckStudyHardwareClass( |
371 filter, test_cases[i].actual_hardware_class)); | 370 filter, test_cases[i].actual_hardware_class)); |
372 } | 371 } |
373 } | 372 } |
374 | 373 |
375 TEST(VariationsStudyFilteringTest, CheckStudyCountry) { | 374 TEST(VariationsStudyFilteringTest, CheckStudyCountry) { |
376 struct { | 375 struct { |
377 const char* country; | 376 const char* country; |
(...skipping 21 matching lines...) Expand all Loading... |
399 // Empty, which is what would happen if no country was returned from the | 398 // Empty, which is what would happen if no country was returned from the |
400 // server. | 399 // server. |
401 {"", "br,ca,us", "", true}, | 400 {"", "br,ca,us", "", true}, |
402 | 401 |
403 // Not testing when both are set as it should never occur and should be | 402 // Not testing when both are set as it should never occur and should be |
404 // considered undefined. | 403 // considered undefined. |
405 }; | 404 }; |
406 | 405 |
407 for (const auto& test : test_cases) { | 406 for (const auto& test : test_cases) { |
408 Study_Filter filter; | 407 Study_Filter filter; |
409 std::vector<std::string> countries; | 408 for (const std::string& country : base::SplitString( |
410 base::SplitString(test.country, ',', &countries); | 409 test.country, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) |
411 for (const std::string& country : countries) | |
412 filter.add_country(country); | 410 filter.add_country(country); |
413 | 411 |
414 std::vector<std::string> exclude_countries; | 412 for (const std::string& exclude_country : base::SplitString( |
415 base::SplitString(test.exclude_country, ',', &exclude_countries); | 413 test.exclude_country, ",", |
416 for (const std::string& exclude_country : exclude_countries) | 414 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) |
417 filter.add_exclude_country(exclude_country); | 415 filter.add_exclude_country(exclude_country); |
418 | 416 |
419 EXPECT_EQ(test.expected_result, | 417 EXPECT_EQ(test.expected_result, |
420 internal::CheckStudyCountry(filter, test.actual_country)); | 418 internal::CheckStudyCountry(filter, test.actual_country)); |
421 } | 419 } |
422 } | 420 } |
423 | 421 |
424 TEST(VariationsStudyFilteringTest, FilterAndValidateStudies) { | 422 TEST(VariationsStudyFilteringTest, FilterAndValidateStudies) { |
425 const std::string kTrial1Name = "A"; | 423 const std::string kTrial1Name = "A"; |
426 const std::string kGroup1Name = "Group1"; | 424 const std::string kGroup1Name = "Group1"; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 | 569 |
572 default_group->set_name("def"); | 570 default_group->set_name("def"); |
573 EXPECT_TRUE(processed_study.Init(&study, false)); | 571 EXPECT_TRUE(processed_study.Init(&study, false)); |
574 Study_Experiment* repeated_group = study.add_experiment(); | 572 Study_Experiment* repeated_group = study.add_experiment(); |
575 repeated_group->set_name("abc"); | 573 repeated_group->set_name("abc"); |
576 repeated_group->set_probability_weight(1); | 574 repeated_group->set_probability_weight(1); |
577 EXPECT_FALSE(processed_study.Init(&study, false)); | 575 EXPECT_FALSE(processed_study.Init(&study, false)); |
578 } | 576 } |
579 | 577 |
580 } // namespace variations | 578 } // namespace variations |
OLD | NEW |