Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 "chrome/common/extensions/feature_switch.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 using extensions::FeatureSwitch; | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 const char kSwitchName[] = "test-switch"; | |
| 16 | |
| 17 template<FeatureSwitch::DefaultValue T> | |
| 18 class FeatureSwitchTest : public testing::Test { | |
| 19 public: | |
| 20 FeatureSwitchTest() | |
| 21 : command_line_(CommandLine::NO_PROGRAM), | |
| 22 feature_(&command_line_, kSwitchName, T) { | |
| 23 } | |
| 24 protected: | |
| 25 CommandLine command_line_; | |
| 26 FeatureSwitch feature_; | |
| 27 }; | |
| 28 | |
| 29 typedef FeatureSwitchTest<FeatureSwitch::DEFAULT_DISABLED> | |
| 30 FeatureSwitchDisabledTest; | |
| 31 typedef FeatureSwitchTest<FeatureSwitch::DEFAULT_ENABLED> | |
| 32 FeatureSwitchEnabledTest; | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 TEST_F(FeatureSwitchDisabledTest, DefaultDisabled_NoSwitchValue) { | |
|
Jeffrey Yasskin
2012/10/02 01:45:51
Note that "Disabled" already appears in the fixtur
Aaron Boodman
2012/10/02 07:46:40
Done.
| |
| 37 EXPECT_FALSE(feature_.IsEnabled()); | |
| 38 } | |
| 39 | |
| 40 TEST_F(FeatureSwitchDisabledTest, DefaultDisabled_FalseSwitchValue) { | |
| 41 command_line_.AppendSwitchASCII(kSwitchName, "0"); | |
| 42 EXPECT_FALSE(feature_.IsEnabled()); | |
| 43 } | |
| 44 | |
| 45 TEST_F(FeatureSwitchDisabledTest, DefaultDisabled_GibberishSwitchValue) { | |
| 46 command_line_.AppendSwitchASCII(kSwitchName, "monkey"); | |
| 47 EXPECT_FALSE(feature_.IsEnabled()); | |
| 48 } | |
| 49 | |
| 50 TEST_F(FeatureSwitchDisabledTest, DefaultDisabled_Override) { | |
| 51 { | |
| 52 FeatureSwitch::ScopedOverride override(&feature_, false); | |
| 53 EXPECT_FALSE(feature_.IsEnabled()); | |
| 54 } | |
| 55 EXPECT_FALSE(feature_.IsEnabled()); | |
| 56 | |
| 57 { | |
| 58 FeatureSwitch::ScopedOverride override(&feature_, true); | |
| 59 EXPECT_TRUE(feature_.IsEnabled()); | |
| 60 } | |
| 61 EXPECT_FALSE(feature_.IsEnabled()); | |
| 62 } | |
| 63 | |
| 64 TEST_F(FeatureSwitchDisabledTest, DefaultDisabled_TrueSwitchValue) { | |
| 65 command_line_.AppendSwitchASCII(kSwitchName, "1"); | |
| 66 EXPECT_TRUE(feature_.IsEnabled()); | |
| 67 | |
| 68 { | |
| 69 FeatureSwitch::ScopedOverride override(&feature_, false); | |
| 70 EXPECT_FALSE(feature_.IsEnabled()); | |
| 71 } | |
| 72 EXPECT_TRUE(feature_.IsEnabled()); | |
| 73 | |
| 74 { | |
| 75 FeatureSwitch::ScopedOverride override(&feature_, true); | |
| 76 EXPECT_TRUE(feature_.IsEnabled()); | |
| 77 } | |
| 78 EXPECT_TRUE(feature_.IsEnabled()); | |
| 79 } | |
| 80 | |
| 81 TEST_F(FeatureSwitchDisabledTest, DefaultDisabled_TrimSwitchValue) { | |
| 82 command_line_.AppendSwitchASCII(kSwitchName, " \t 1\n "); | |
| 83 EXPECT_TRUE(feature_.IsEnabled()); | |
| 84 } | |
| 85 | |
| 86 TEST_F(FeatureSwitchEnabledTest, DefaultEnabled_NoSwitchValue) { | |
| 87 EXPECT_TRUE(feature_.IsEnabled()); | |
| 88 } | |
| 89 | |
| 90 TEST_F(FeatureSwitchEnabledTest, DefaultEnabled_TrueSwitchValue) { | |
| 91 command_line_.AppendSwitchASCII(kSwitchName, "1"); | |
| 92 EXPECT_TRUE(feature_.IsEnabled()); | |
| 93 } | |
| 94 | |
| 95 TEST_F(FeatureSwitchEnabledTest, DefaultEnabled_GibberishSwitchValue) { | |
| 96 command_line_.AppendSwitchASCII(kSwitchName, "monkey"); | |
| 97 EXPECT_TRUE(feature_.IsEnabled()); | |
| 98 } | |
| 99 | |
| 100 TEST_F(FeatureSwitchEnabledTest, DefaultEnabled_Override) { | |
| 101 { | |
| 102 FeatureSwitch::ScopedOverride override(&feature_, true); | |
| 103 EXPECT_TRUE(feature_.IsEnabled()); | |
| 104 } | |
| 105 EXPECT_TRUE(feature_.IsEnabled()); | |
| 106 | |
| 107 { | |
| 108 FeatureSwitch::ScopedOverride override(&feature_, false); | |
| 109 EXPECT_FALSE(feature_.IsEnabled()); | |
| 110 } | |
| 111 EXPECT_TRUE(feature_.IsEnabled()); | |
| 112 } | |
| 113 | |
| 114 TEST_F(FeatureSwitchEnabledTest, DefaultEnabled_FalseSwitchValue) { | |
| 115 command_line_.AppendSwitchASCII(kSwitchName, "0"); | |
| 116 EXPECT_FALSE(feature_.IsEnabled()); | |
| 117 | |
| 118 { | |
| 119 FeatureSwitch::ScopedOverride override(&feature_, true); | |
| 120 EXPECT_TRUE(feature_.IsEnabled()); | |
| 121 } | |
| 122 EXPECT_FALSE(feature_.IsEnabled()); | |
| 123 | |
| 124 { | |
| 125 FeatureSwitch::ScopedOverride override(&feature_, false); | |
| 126 EXPECT_FALSE(feature_.IsEnabled()); | |
| 127 } | |
| 128 EXPECT_FALSE(feature_.IsEnabled()); | |
| 129 } | |
| 130 | |
| 131 TEST_F(FeatureSwitchEnabledTest, DefaultEnabled_TrimSwitchValue) { | |
| 132 command_line_.AppendSwitchASCII(kSwitchName, "\t\t 0 \n"); | |
| 133 EXPECT_FALSE(feature_.IsEnabled()); | |
| 134 } | |
| OLD | NEW |