Chromium Code Reviews| Index: chrome/common/extensions/feature_switch_unittest.cc |
| diff --git a/chrome/common/extensions/feature_switch_unittest.cc b/chrome/common/extensions/feature_switch_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..032a4104676eb09a66a484edcc56e7e33321085f |
| --- /dev/null |
| +++ b/chrome/common/extensions/feature_switch_unittest.cc |
| @@ -0,0 +1,134 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/common/extensions/feature_switch.h" |
| + |
| +#include "base/command_line.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using extensions::FeatureSwitch; |
| + |
| +namespace { |
| + |
| +const char kSwitchName[] = "test-switch"; |
| + |
| +template<FeatureSwitch::DefaultValue T> |
| +class FeatureSwitchTest : public testing::Test { |
| + public: |
| + FeatureSwitchTest() |
| + : command_line_(CommandLine::NO_PROGRAM), |
| + feature_(&command_line_, kSwitchName, T) { |
| + } |
| + protected: |
| + CommandLine command_line_; |
| + FeatureSwitch feature_; |
| +}; |
| + |
| +typedef FeatureSwitchTest<FeatureSwitch::DEFAULT_DISABLED> |
| + FeatureSwitchDisabledTest; |
| +typedef FeatureSwitchTest<FeatureSwitch::DEFAULT_ENABLED> |
| + FeatureSwitchEnabledTest; |
| + |
| +} // namespace |
| + |
| +TEST_F(FeatureSwitchDisabledTest, DefaultDisabled1) { |
|
Jeffrey Yasskin
2012/10/02 00:26:31
Please give tests names associated with what they'
Aaron Boodman
2012/10/02 01:28:52
Done.
|
| + EXPECT_FALSE(feature_.IsEnabled()); |
| +} |
| + |
| +TEST_F(FeatureSwitchDisabledTest, DefaultDisabled2) { |
| + command_line_.AppendSwitchASCII(kSwitchName, "0"); |
| + EXPECT_FALSE(feature_.IsEnabled()); |
| +} |
| + |
| +TEST_F(FeatureSwitchDisabledTest, DefaultDisabled3) { |
| + command_line_.AppendSwitchASCII(kSwitchName, "monkey"); |
| + EXPECT_FALSE(feature_.IsEnabled()); |
| +} |
| + |
| +TEST_F(FeatureSwitchDisabledTest, DefaultDisabled4) { |
| + { |
| + FeatureSwitch::ScopedOverride override(feature_.Override(false)); |
| + EXPECT_FALSE(feature_.IsEnabled()); |
| + } |
| + EXPECT_FALSE(feature_.IsEnabled()); |
| + |
| + { |
| + FeatureSwitch::ScopedOverride override(feature_.Override(true)); |
| + EXPECT_TRUE(feature_.IsEnabled()); |
| + } |
| + EXPECT_FALSE(feature_.IsEnabled()); |
| +} |
| + |
| +TEST_F(FeatureSwitchDisabledTest, DefaultDisabled5) { |
| + command_line_.AppendSwitchASCII(kSwitchName, "1"); |
| + EXPECT_TRUE(feature_.IsEnabled()); |
| + |
| + { |
| + FeatureSwitch::ScopedOverride override(feature_.Override(false)); |
| + EXPECT_FALSE(feature_.IsEnabled()); |
| + } |
| + EXPECT_TRUE(feature_.IsEnabled()); |
| + |
| + { |
| + FeatureSwitch::ScopedOverride override(feature_.Override(true)); |
| + EXPECT_TRUE(feature_.IsEnabled()); |
| + } |
| + EXPECT_TRUE(feature_.IsEnabled()); |
| +} |
| + |
| +TEST_F(FeatureSwitchDisabledTest, DefaultDisabled6) { |
| + command_line_.AppendSwitchASCII(kSwitchName, " \t 1\n "); |
| + EXPECT_TRUE(feature_.IsEnabled()); |
| +} |
| + |
| +TEST_F(FeatureSwitchEnabledTest, DefaultEnabled1) { |
| + EXPECT_TRUE(feature_.IsEnabled()); |
| +} |
| + |
| +TEST_F(FeatureSwitchEnabledTest, DefaultEnabled2) { |
| + command_line_.AppendSwitchASCII(kSwitchName, "1"); |
| + EXPECT_TRUE(feature_.IsEnabled()); |
| +} |
| + |
| +TEST_F(FeatureSwitchEnabledTest, DefaultEnabled3) { |
| + command_line_.AppendSwitchASCII(kSwitchName, "monkey"); |
| + EXPECT_TRUE(feature_.IsEnabled()); |
| +} |
| + |
| +TEST_F(FeatureSwitchEnabledTest, DefaultEnabled4) { |
| + { |
| + FeatureSwitch::ScopedOverride override(feature_.Override(true)); |
| + EXPECT_TRUE(feature_.IsEnabled()); |
| + } |
| + EXPECT_TRUE(feature_.IsEnabled()); |
| + |
| + { |
| + FeatureSwitch::ScopedOverride override(feature_.Override(false)); |
| + EXPECT_FALSE(feature_.IsEnabled()); |
| + } |
| + EXPECT_TRUE(feature_.IsEnabled()); |
| +} |
| + |
| +TEST_F(FeatureSwitchEnabledTest, DefaultEnabled5) { |
| + command_line_.AppendSwitchASCII(kSwitchName, "0"); |
| + EXPECT_FALSE(feature_.IsEnabled()); |
| + |
| + { |
| + FeatureSwitch::ScopedOverride override(feature_.Override(true)); |
| + EXPECT_TRUE(feature_.IsEnabled()); |
| + } |
| + EXPECT_FALSE(feature_.IsEnabled()); |
| + |
| + { |
| + FeatureSwitch::ScopedOverride override(feature_.Override(false)); |
| + EXPECT_FALSE(feature_.IsEnabled()); |
| + } |
| + EXPECT_FALSE(feature_.IsEnabled()); |
| +} |
| + |
| +TEST_F(FeatureSwitchEnabledTest, DefaultEnabled6) { |
| + command_line_.AppendSwitchASCII(kSwitchName, "\t\t 0 \n"); |
| + EXPECT_FALSE(feature_.IsEnabled()); |
| +} |