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

Side by Side Diff: base/test/scoped_feature_list.cc

Issue 2226063002: Add a ScopedFeatureList class for testing and start using it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix issue in previous patchset. Created 4 years, 4 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/test/scoped_feature_list.h"
6
7 namespace base {
8 namespace test {
9
10 ScopedFeatureList::ScopedFeatureList() {}
11
12 ScopedFeatureList::~ScopedFeatureList() {
13 if (original_feature_list_) {
14 base::FeatureList::ClearInstanceForTesting();
15 base::FeatureList::RestoreInstanceForTesting(
16 std::move(original_feature_list_));
17 }
18 }
19
20 void ScopedFeatureList::Init() {
21 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
22 feature_list->InitializeFromCommandLine(std::string(), std::string());
23 InitWithFeatureList(std::move(feature_list));
24 }
25
26 void ScopedFeatureList::InitWithFeatureList(
27 std::unique_ptr<FeatureList> feature_list) {
28 DCHECK(!original_feature_list_);
29 original_feature_list_ = base::FeatureList::ClearInstanceForTesting();
30 base::FeatureList::SetInstance(std::move(feature_list));
31 }
32
33 void ScopedFeatureList::InitFromCommandLine(
34 const std::string& enable_features,
35 const std::string& disable_features) {
36 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
37 feature_list->InitializeFromCommandLine(enable_features, disable_features);
38 InitWithFeatureList(std::move(feature_list));
39 }
40
41 void ScopedFeatureList::InitAndEnableFeature(const base::Feature& feature) {
42 InitFromCommandLine(feature.name, std::string());
43 }
44
45 void ScopedFeatureList::InitAndDisableFeature(const base::Feature& feature) {
46 InitFromCommandLine(std::string(), feature.name);
47 }
48
49 } // namespace test
50 } // namespace base
OLDNEW
« no previous file with comments | « base/test/scoped_feature_list.h ('k') | chrome/browser/password_manager/chrome_password_manager_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698