OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/variations_seed_processor.h" | 5 #include "components/variations/variations_seed_processor.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
12 #include <utility> | 12 #include <utility> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/feature_list.h" | 17 #include "base/feature_list.h" |
18 #include "base/format_macros.h" | 18 #include "base/format_macros.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
21 #include "base/strings/string_split.h" | 21 #include "base/strings/string_split.h" |
22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
24 #include "base/test/mock_entropy_provider.h" | 24 #include "base/test/mock_entropy_provider.h" |
25 #include "base/test/scoped_feature_list.h" | 25 #include "base/test/scoped_feature_list.h" |
| 26 #include "components/variations/client_filterable_state.h" |
26 #include "components/variations/processed_study.h" | 27 #include "components/variations/processed_study.h" |
27 #include "components/variations/study_filtering.h" | 28 #include "components/variations/study_filtering.h" |
28 #include "components/variations/variations_associated_data.h" | 29 #include "components/variations/variations_associated_data.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
30 | 31 |
31 namespace variations { | 32 namespace variations { |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 // Converts |time| to Study proto format. | 36 // Converts |time| to Study proto format. |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 study1->set_default_experiment_name("Default"); | 256 study1->set_default_experiment_name("Default"); |
256 AddExperiment(kGroup1Name, 100, study1); | 257 AddExperiment(kGroup1Name, 100, study1); |
257 AddExperiment("Default", 0, study1); | 258 AddExperiment("Default", 0, study1); |
258 Study* study2 = seed.add_study(); | 259 Study* study2 = seed.add_study(); |
259 *study2 = *study1; | 260 *study2 = *study1; |
260 ASSERT_EQ(seed.study(0).name(), seed.study(1).name()); | 261 ASSERT_EQ(seed.study(0).name(), seed.study(1).name()); |
261 | 262 |
262 const base::Time year_ago = | 263 const base::Time year_ago = |
263 base::Time::Now() - base::TimeDelta::FromDays(365); | 264 base::Time::Now() - base::TimeDelta::FromDays(365); |
264 | 265 |
265 const base::Version version("20.0.0.0"); | 266 ClientFilterableState client_state; |
| 267 client_state.locale = "en-CA"; |
| 268 client_state.reference_date = base::Time::Now(); |
| 269 client_state.version = base::Version("20.0.0.0"); |
| 270 client_state.channel = Study::STABLE; |
| 271 client_state.form_factor = Study::DESKTOP; |
| 272 client_state.platform = Study::PLATFORM_ANDROID; |
266 | 273 |
267 // Check that adding [expired, non-expired] activates the non-expired one. | 274 // Check that adding [expired, non-expired] activates the non-expired one. |
268 ASSERT_EQ(std::string(), base::FieldTrialList::FindFullName(kTrialName)); | 275 ASSERT_EQ(std::string(), base::FieldTrialList::FindFullName(kTrialName)); |
269 { | 276 { |
270 base::FeatureList feature_list; | 277 base::FeatureList feature_list; |
271 base::FieldTrialList field_trial_list(nullptr); | 278 base::FieldTrialList field_trial_list(nullptr); |
272 study1->set_expiry_date(TimeToProtoTime(year_ago)); | 279 study1->set_expiry_date(TimeToProtoTime(year_ago)); |
273 seed_processor.CreateTrialsFromSeed( | 280 seed_processor.CreateTrialsFromSeed(seed, client_state, |
274 seed, "en-CA", base::Time::Now(), version, Study_Channel_STABLE, | 281 override_callback_.callback(), nullptr, |
275 Study_FormFactor_DESKTOP, "", "", "", override_callback_.callback(), | 282 &feature_list); |
276 nullptr, &feature_list); | |
277 EXPECT_EQ(kGroup1Name, base::FieldTrialList::FindFullName(kTrialName)); | 283 EXPECT_EQ(kGroup1Name, base::FieldTrialList::FindFullName(kTrialName)); |
278 } | 284 } |
279 | 285 |
280 // Check that adding [non-expired, expired] activates the non-expired one. | 286 // Check that adding [non-expired, expired] activates the non-expired one. |
281 ASSERT_EQ(std::string(), base::FieldTrialList::FindFullName(kTrialName)); | 287 ASSERT_EQ(std::string(), base::FieldTrialList::FindFullName(kTrialName)); |
282 { | 288 { |
283 base::FeatureList feature_list; | 289 base::FeatureList feature_list; |
284 base::FieldTrialList field_trial_list(nullptr); | 290 base::FieldTrialList field_trial_list(nullptr); |
285 study1->clear_expiry_date(); | 291 study1->clear_expiry_date(); |
286 study2->set_expiry_date(TimeToProtoTime(year_ago)); | 292 study2->set_expiry_date(TimeToProtoTime(year_ago)); |
287 seed_processor.CreateTrialsFromSeed( | 293 seed_processor.CreateTrialsFromSeed(seed, client_state, |
288 seed, "en-CA", base::Time::Now(), version, Study_Channel_STABLE, | 294 override_callback_.callback(), nullptr, |
289 Study_FormFactor_DESKTOP, "", "", "", override_callback_.callback(), | 295 &feature_list); |
290 nullptr, &feature_list); | |
291 EXPECT_EQ(kGroup1Name, base::FieldTrialList::FindFullName(kTrialName)); | 296 EXPECT_EQ(kGroup1Name, base::FieldTrialList::FindFullName(kTrialName)); |
292 } | 297 } |
293 } | 298 } |
294 | 299 |
295 TEST_F(VariationsSeedProcessorTest, OverrideUIStrings) { | 300 TEST_F(VariationsSeedProcessorTest, OverrideUIStrings) { |
296 base::FieldTrialList field_trial_list(nullptr); | 301 base::FieldTrialList field_trial_list(nullptr); |
297 | 302 |
298 Study study; | 303 Study study; |
299 study.set_name("Study1"); | 304 study.set_name("Study1"); |
300 study.set_default_experiment_name("B"); | 305 study.set_default_experiment_name("B"); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 AddExperiment("Default", 0, study2); | 530 AddExperiment("Default", 0, study2); |
526 study2->set_activation_type(Study_ActivationType_ACTIVATION_AUTO); | 531 study2->set_activation_type(Study_ActivationType_ACTIVATION_AUTO); |
527 | 532 |
528 Study* study3 = seed.add_study(); | 533 Study* study3 = seed.add_study(); |
529 study3->set_name("C"); | 534 study3->set_name("C"); |
530 study3->set_default_experiment_name("Default"); | 535 study3->set_default_experiment_name("Default"); |
531 AddExperiment("CC", 100, study3); | 536 AddExperiment("CC", 100, study3); |
532 AddExperiment("Default", 0, study3); | 537 AddExperiment("Default", 0, study3); |
533 study3->set_activation_type(Study_ActivationType_ACTIVATION_EXPLICIT); | 538 study3->set_activation_type(Study_ActivationType_ACTIVATION_EXPLICIT); |
534 | 539 |
| 540 ClientFilterableState client_state; |
| 541 client_state.locale = "en-CA"; |
| 542 client_state.reference_date = base::Time::Now(); |
| 543 client_state.version = base::Version("20.0.0.0"); |
| 544 client_state.channel = Study::STABLE; |
| 545 client_state.form_factor = Study::DESKTOP; |
| 546 client_state.platform = Study::PLATFORM_ANDROID; |
| 547 |
535 VariationsSeedProcessor seed_processor; | 548 VariationsSeedProcessor seed_processor; |
536 seed_processor.CreateTrialsFromSeed( | 549 seed_processor.CreateTrialsFromSeed(seed, client_state, |
537 seed, "en-CA", base::Time::Now(), base::Version("20.0.0.0"), | 550 override_callback_.callback(), nullptr, |
538 Study_Channel_STABLE, Study_FormFactor_DESKTOP, "", "", "", | 551 &feature_list_); |
539 override_callback_.callback(), nullptr, &feature_list_); | |
540 | 552 |
541 // Non-specified and ACTIVATION_EXPLICIT should not start active, but | 553 // Non-specified and ACTIVATION_EXPLICIT should not start active, but |
542 // ACTIVATION_AUTO should. | 554 // ACTIVATION_AUTO should. |
543 EXPECT_FALSE(base::FieldTrialList::IsTrialActive("A")); | 555 EXPECT_FALSE(base::FieldTrialList::IsTrialActive("A")); |
544 EXPECT_TRUE(base::FieldTrialList::IsTrialActive("B")); | 556 EXPECT_TRUE(base::FieldTrialList::IsTrialActive("B")); |
545 EXPECT_FALSE(base::FieldTrialList::IsTrialActive("C")); | 557 EXPECT_FALSE(base::FieldTrialList::IsTrialActive("C")); |
546 | 558 |
547 EXPECT_EQ("AA", base::FieldTrialList::FindFullName("A")); | 559 EXPECT_EQ("AA", base::FieldTrialList::FindFullName("A")); |
548 EXPECT_EQ("BB", base::FieldTrialList::FindFullName("B")); | 560 EXPECT_EQ("BB", base::FieldTrialList::FindFullName("B")); |
549 EXPECT_EQ("CC", base::FieldTrialList::FindFullName("C")); | 561 EXPECT_EQ("CC", base::FieldTrialList::FindFullName("C")); |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 // Since no experiment in study1 sends experiment IDs, it will use the high | 968 // Since no experiment in study1 sends experiment IDs, it will use the high |
957 // entropy provider, which selects the non-default group. | 969 // entropy provider, which selects the non-default group. |
958 EXPECT_EQ(kGroup1Name, base::FieldTrialList::FindFullName(kTrial1Name)); | 970 EXPECT_EQ(kGroup1Name, base::FieldTrialList::FindFullName(kTrial1Name)); |
959 | 971 |
960 // Since an experiment in study2 has google_web_experiment_id set, it will use | 972 // Since an experiment in study2 has google_web_experiment_id set, it will use |
961 // the low entropy provider, which selects the default group. | 973 // the low entropy provider, which selects the default group. |
962 EXPECT_EQ(kDefaultName, base::FieldTrialList::FindFullName(kTrial2Name)); | 974 EXPECT_EQ(kDefaultName, base::FieldTrialList::FindFullName(kTrial2Name)); |
963 } | 975 } |
964 | 976 |
965 } // namespace variations | 977 } // namespace variations |
OLD | NEW |