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

Side by Side Diff: base/metrics/feature_list_unittest.cc

Issue 1278403003: Initial implementation of FeatureList in base/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More comments addressed. Created 5 years, 3 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 2015 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/metrics/feature_list.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace base {
10
11 namespace {
12
13 const char kFeatureOnName[] = "Example1";
Ilya Sherman 2015/09/01 03:55:26 I think the tests would be easier to follow if thi
Alexei Svitkine (slow) 2015/09/01 15:53:44 Done.
14 struct Feature kExampleFeatureOn {
15 kFeatureOnName, true
16 };
17
18 const char kFeatureOffName[] = "Example2";
19 struct Feature kExampleFeatureOff {
20 kFeatureOffName, false
21 };
22
23 class FeatureListTest : public testing::Test {
Ilya Sherman 2015/09/01 03:55:26 nit: The test harness class should be declared out
Alexei Svitkine (slow) 2015/09/01 15:53:44 Done.
24 public:
25 FeatureListTest() : feature_list_(new FeatureList) {
26 RegisterFeatureListInstance();
27 }
28 ~FeatureListTest() override { ClearFeatureListInstance(); }
29
30 void RegisterFeatureListInstance() {
31 FeatureList::SetInstance(make_scoped_ptr(feature_list_));
32 }
Ilya Sherman 2015/09/01 03:55:26 This doesn't make much sense as a public method if
Alexei Svitkine (slow) 2015/09/01 15:53:44 Done.
33 void ClearFeatureListInstance() { FeatureList::ClearInstanceForTesting(); }
34
35 FeatureList* feature_list() { return feature_list_; }
Ilya Sherman 2015/09/01 03:55:26 This can return a pointer to freed memory if Clear
Alexei Svitkine (slow) 2015/09/01 15:53:44 Done.
36
37 private:
38 // Weak. Owned by the FeatureList::SetInstance().
39 FeatureList* feature_list_;
40
41 DISALLOW_COPY_AND_ASSIGN(FeatureListTest);
42 };
43
44 } // namespace
45
46 TEST_F(FeatureListTest, DefaultStates) {
47 EXPECT_TRUE(FeatureList::IsEnabled(kExampleFeatureOn));
48 EXPECT_FALSE(FeatureList::IsEnabled(kExampleFeatureOff));
49 }
50
51 TEST_F(FeatureListTest, InitializeFromCommandLine) {
52 struct {
53 const char* enable_features;
54 const char* disable_features;
55 bool expected_feature_on_state;
56 bool expected_feature_off_state;
57 } test_cases[] = {
58 {"", "", true, false},
59 {"Example2", "", true, true},
60 {"Example2", "Example1", false, true},
61 {"Example1,Example2", "", true, true},
62 {"", "Example1,Example2", false, false},
63 // In the case an entry is both, disable takes precedence.
64 {"Example1", "Example1,Example2", false, false},
65 };
66
67 for (size_t i = 0; i < arraysize(test_cases); i++) {
Ilya Sherman 2015/09/01 03:55:26 nit: ++i
Alexei Svitkine (slow) 2015/09/01 15:53:44 Done.
68 const auto& test_case = test_cases[i];
69
70 FeatureList feature_list;
71 feature_list.InitializeFromCommandLine(test_case.enable_features,
72 test_case.disable_features);
73 feature_list.FinalizeInitialization();
Ilya Sherman 2015/09/01 03:55:26 It seems more appropriate to set the singleton, an
Alexei Svitkine (slow) 2015/09/01 15:53:44 Done. I was originally thinking to keep the class
74
75 EXPECT_EQ(test_case.expected_feature_on_state,
76 feature_list.IsFeatureEnabled(kExampleFeatureOn))
77 << i;
78 EXPECT_EQ(test_case.expected_feature_off_state,
79 feature_list.IsFeatureEnabled(kExampleFeatureOff))
80 << i;
81 }
82 }
83
84 TEST_F(FeatureListTest, CheckFeatureIdentity) {
Ilya Sherman 2015/09/01 03:55:26 This purpose of this test is not immediately obvio
Alexei Svitkine (slow) 2015/09/01 15:53:44 I don't think a test using the public API is possi
Ilya Sherman 2015/09/01 20:17:17 I was thinking we could use a gtest Death Test: [
Alexei Svitkine (slow) 2015/09/01 21:18:38 Right, then the test would have to only be enabled
85 EXPECT_TRUE(feature_list()->CheckFeatureIdentity(kExampleFeatureOn));
86 EXPECT_TRUE(feature_list()->CheckFeatureIdentity(kExampleFeatureOn));
87 EXPECT_TRUE(feature_list()->CheckFeatureIdentity(kExampleFeatureOff));
88 EXPECT_TRUE(feature_list()->CheckFeatureIdentity(kExampleFeatureOff));
Ilya Sherman 2015/09/01 03:55:26 Why are these lines written twice each?
Alexei Svitkine (slow) 2015/09/01 15:53:44 The first time would register it and the second ti
89
90 struct Feature kExampleFeatureOn2 {
91 kFeatureOnName, true
92 };
93 EXPECT_FALSE(feature_list()->CheckFeatureIdentity(kExampleFeatureOn2));
94 }
95
96 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698