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

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

Issue 2358723002: Convert FieldTrialList to Accept a std::unique_ptr (Closed)
Patch Set: Change Comment nullptr to null Created 4 years, 2 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
OLDNEW
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/strings/string_split.h" 21 #include "base/strings/string_split.h"
21 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
22 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
23 #include "base/test/mock_entropy_provider.h" 24 #include "base/test/mock_entropy_provider.h"
24 #include "base/test/scoped_feature_list.h" 25 #include "base/test/scoped_feature_list.h"
25 #include "components/variations/processed_study.h" 26 #include "components/variations/processed_study.h"
26 #include "components/variations/study_filtering.h" 27 #include "components/variations/study_filtering.h"
27 #include "components/variations/variations_associated_data.h" 28 #include "components/variations/variations_associated_data.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 30
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 Study* study2 = seed.add_study(); 861 Study* study2 = seed.add_study();
861 study2->set_name(kTrial2Name); 862 study2->set_name(kTrial2Name);
862 study2->set_consistency(variations::Study_Consistency_PERMANENT); 863 study2->set_consistency(variations::Study_Consistency_PERMANENT);
863 study2->set_default_experiment_name(kDefaultName); 864 study2->set_default_experiment_name(kDefaultName);
864 AddExperiment(kGroup1Name, 50, study2); 865 AddExperiment(kGroup1Name, 50, study2);
865 AddExperiment(kDefaultName, 50, study2); 866 AddExperiment(kDefaultName, 50, study2);
866 study2->mutable_experiment(0)->set_google_web_experiment_id(kExperimentId); 867 study2->mutable_experiment(0)->set_google_web_experiment_id(kExperimentId);
867 868
868 // An entorpy value of 0.1 will cause the AA group to be chosen, since AA is 869 // An entorpy value of 0.1 will cause the AA group to be chosen, since AA is
869 // the only non-default group, and has a probability percent above 0.1. 870 // the only non-default group, and has a probability percent above 0.1.
870 base::MockEntropyProvider* mock_high_entropy_provider = 871 base::FieldTrialList field_trial_list(
871 new base::MockEntropyProvider(0.1); 872 base::MakeUnique<base::MockEntropyProvider>(0.1));
872
873 // The field trial list takes ownership of the provider.
874 base::FieldTrialList field_trial_list(mock_high_entropy_provider);
875 873
876 // Use a stack instance, since nothing takes ownership of this provider. 874 // Use a stack instance, since nothing takes ownership of this provider.
877 // This entropy value will cause the default group to be chosen since it's a 875 // This entropy value will cause the default group to be chosen since it's a
878 // 50/50 trial. 876 // 50/50 trial.
879 base::MockEntropyProvider mock_low_entropy_provider(0.9); 877 base::MockEntropyProvider mock_low_entropy_provider(0.9);
880 878
881 EXPECT_TRUE(CreateTrialFromStudyWithEntropyOverride( 879 EXPECT_TRUE(CreateTrialFromStudyWithEntropyOverride(
882 *study1, &mock_low_entropy_provider)); 880 *study1, &mock_low_entropy_provider));
883 EXPECT_TRUE(CreateTrialFromStudyWithEntropyOverride( 881 EXPECT_TRUE(CreateTrialFromStudyWithEntropyOverride(
884 *study2, &mock_low_entropy_provider)); 882 *study2, &mock_low_entropy_provider));
885 883
886 // Since no experiment in study1 sends experiment IDs, it will use the high 884 // Since no experiment in study1 sends experiment IDs, it will use the high
887 // entropy provider, which selects the non-default group. 885 // entropy provider, which selects the non-default group.
888 EXPECT_EQ(kGroup1Name, base::FieldTrialList::FindFullName(kTrial1Name)); 886 EXPECT_EQ(kGroup1Name, base::FieldTrialList::FindFullName(kTrial1Name));
889 887
890 // Since an experiment in study2 has google_web_experiment_id set, it will use 888 // Since an experiment in study2 has google_web_experiment_id set, it will use
891 // the low entropy provider, which selects the default group. 889 // the low entropy provider, which selects the default group.
892 EXPECT_EQ(kDefaultName, base::FieldTrialList::FindFullName(kTrial2Name)); 890 EXPECT_EQ(kDefaultName, base::FieldTrialList::FindFullName(kTrial2Name));
893 } 891 }
894 892
895 } // namespace variations 893 } // namespace variations
OLDNEW
« no previous file with comments | « components/variations/entropy_provider_unittest.cc ('k') | content/browser/loader/resource_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698