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

Side by Side Diff: components/variations/field_trial_config/field_trial_util_unittest.cc

Issue 2484613002: Migrate more tests to ScopedFeatureList. (Closed)
Patch Set: rebase 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/field_trial_config/field_trial_util.h" 5 #include "components/variations/field_trial_config/field_trial_util.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/feature_list.h"
12 #include "base/macros.h" 11 #include "base/macros.h"
13 #include "base/metrics/field_trial.h" 12 #include "base/metrics/field_trial.h"
13 #include "base/test/scoped_feature_list.h"
14 #include "components/variations/field_trial_config/fieldtrial_testing_config.h" 14 #include "components/variations/field_trial_config/fieldtrial_testing_config.h"
15 #include "components/variations/variations_associated_data.h" 15 #include "components/variations/variations_associated_data.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace variations { 18 namespace variations {
19 19
20 namespace { 20 namespace {
21 21
22 class FieldTrialUtilTest : public ::testing::Test { 22 class FieldTrialUtilTest : public ::testing::Test {
23 public: 23 public:
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 const FieldTrialTestingStudy array_kFieldTrialConfig_studies[] = { 121 const FieldTrialTestingStudy array_kFieldTrialConfig_studies[] = {
122 {"TestTrial1", array_kFieldTrialConfig_experiments_0, 1}, 122 {"TestTrial1", array_kFieldTrialConfig_experiments_0, 1},
123 {"TestTrial2", array_kFieldTrialConfig_experiments_1, 2}, 123 {"TestTrial2", array_kFieldTrialConfig_experiments_1, 2},
124 }; 124 };
125 125
126 const FieldTrialTestingConfig kConfig = { 126 const FieldTrialTestingConfig kConfig = {
127 array_kFieldTrialConfig_studies, 2 127 array_kFieldTrialConfig_studies, 2
128 }; 128 };
129 129
130 base::FeatureList::ClearInstanceForTesting();
131 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 130 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
132 AssociateParamsFromFieldTrialConfig(kConfig, feature_list.get()); 131 AssociateParamsFromFieldTrialConfig(kConfig, feature_list.get());
133 base::FeatureList::SetInstance(std::move(feature_list)); 132 base::test::ScopedFeatureList scoped_feature_list;
133 scoped_feature_list.InitWithFeatureList(std::move(feature_list));
134 134
135 // Check the resulting feature and field trial states. Trials should not be 135 // Check the resulting feature and field trial states. Trials should not be
136 // active until their associated features are queried. 136 // active until their associated features are queried.
137 EXPECT_FALSE(base::FieldTrialList::IsTrialActive("TestTrial1")); 137 EXPECT_FALSE(base::FieldTrialList::IsTrialActive("TestTrial1"));
138 EXPECT_TRUE(base::FeatureList::IsEnabled(kFeatureA)); 138 EXPECT_TRUE(base::FeatureList::IsEnabled(kFeatureA));
139 EXPECT_TRUE(base::FeatureList::IsEnabled(kFeatureB)); 139 EXPECT_TRUE(base::FeatureList::IsEnabled(kFeatureB));
140 EXPECT_TRUE(base::FieldTrialList::IsTrialActive("TestTrial1")); 140 EXPECT_TRUE(base::FieldTrialList::IsTrialActive("TestTrial1"));
141 141
142 EXPECT_FALSE(base::FieldTrialList::IsTrialActive("TestTrial2")); 142 EXPECT_FALSE(base::FieldTrialList::IsTrialActive("TestTrial2"));
143 EXPECT_FALSE(base::FeatureList::IsEnabled(kFeatureC)); 143 EXPECT_FALSE(base::FeatureList::IsEnabled(kFeatureC));
(...skipping 28 matching lines...) Expand all
172 172
173 base::FeatureList feature_list; 173 base::FeatureList feature_list;
174 AssociateParamsFromFieldTrialConfig(kConfig, &feature_list); 174 AssociateParamsFromFieldTrialConfig(kConfig, &feature_list);
175 175
176 EXPECT_EQ("TestGroup1", base::FieldTrialList::FindFullName("TestTrial1")); 176 EXPECT_EQ("TestGroup1", base::FieldTrialList::FindFullName("TestTrial1"));
177 EXPECT_EQ("ForcedGroup2", base::FieldTrialList::FindFullName("TestTrial2")); 177 EXPECT_EQ("ForcedGroup2", base::FieldTrialList::FindFullName("TestTrial2"));
178 EXPECT_EQ("ForcedGroup3", base::FieldTrialList::FindFullName("TestTrial3")); 178 EXPECT_EQ("ForcedGroup3", base::FieldTrialList::FindFullName("TestTrial3"));
179 } 179 }
180 180
181 } // namespace variations 181 } // namespace variations
OLDNEW
« no previous file with comments | « components/variations/field_trial_config/BUILD.gn ('k') | content/browser/loader/async_resource_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698