Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / common / extensions / feature_switch_unittest.cc
blob537794810143a93383d36a60a12e1109b2043527
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.
5 #include "extensions/common/feature_switch.h"
7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 using extensions::FeatureSwitch;
13 namespace {
15 const char kSwitchName[] = "test-switch";
17 template<FeatureSwitch::DefaultValue T>
18 class FeatureSwitchTest : public testing::Test {
19 public:
20 FeatureSwitchTest()
21 : command_line_(base::CommandLine::NO_PROGRAM),
22 feature_(&command_line_, kSwitchName, T) {}
23 protected:
24 base::CommandLine command_line_;
25 FeatureSwitch feature_;
28 typedef FeatureSwitchTest<FeatureSwitch::DEFAULT_DISABLED>
29 FeatureSwitchDisabledTest;
30 typedef FeatureSwitchTest<FeatureSwitch::DEFAULT_ENABLED>
31 FeatureSwitchEnabledTest;
33 } // namespace
35 TEST_F(FeatureSwitchDisabledTest, NoSwitchValue) {
36 EXPECT_FALSE(feature_.IsEnabled());
39 TEST_F(FeatureSwitchDisabledTest, FalseSwitchValue) {
40 command_line_.AppendSwitchASCII(kSwitchName, "0");
41 EXPECT_FALSE(feature_.IsEnabled());
44 TEST_F(FeatureSwitchDisabledTest, GibberishSwitchValue) {
45 command_line_.AppendSwitchASCII(kSwitchName, "monkey");
46 EXPECT_FALSE(feature_.IsEnabled());
49 TEST_F(FeatureSwitchDisabledTest, Override) {
51 FeatureSwitch::ScopedOverride override(&feature_, false);
52 EXPECT_FALSE(feature_.IsEnabled());
54 EXPECT_FALSE(feature_.IsEnabled());
57 FeatureSwitch::ScopedOverride override(&feature_, true);
58 EXPECT_TRUE(feature_.IsEnabled());
60 EXPECT_FALSE(feature_.IsEnabled());
63 TEST_F(FeatureSwitchDisabledTest, TrueSwitchValue) {
64 command_line_.AppendSwitchASCII(kSwitchName, "1");
65 EXPECT_TRUE(feature_.IsEnabled());
68 FeatureSwitch::ScopedOverride override(&feature_, false);
69 EXPECT_FALSE(feature_.IsEnabled());
71 EXPECT_TRUE(feature_.IsEnabled());
74 FeatureSwitch::ScopedOverride override(&feature_, true);
75 EXPECT_TRUE(feature_.IsEnabled());
77 EXPECT_TRUE(feature_.IsEnabled());
80 TEST_F(FeatureSwitchDisabledTest, TrimSwitchValue) {
81 command_line_.AppendSwitchASCII(kSwitchName, " \t 1\n ");
82 EXPECT_TRUE(feature_.IsEnabled());
85 TEST_F(FeatureSwitchEnabledTest, NoSwitchValue) {
86 EXPECT_TRUE(feature_.IsEnabled());
89 TEST_F(FeatureSwitchEnabledTest, TrueSwitchValue) {
90 command_line_.AppendSwitchASCII(kSwitchName, "1");
91 EXPECT_TRUE(feature_.IsEnabled());
94 TEST_F(FeatureSwitchEnabledTest, GibberishSwitchValue) {
95 command_line_.AppendSwitchASCII(kSwitchName, "monkey");
96 EXPECT_TRUE(feature_.IsEnabled());
99 TEST_F(FeatureSwitchEnabledTest, Override) {
101 FeatureSwitch::ScopedOverride override(&feature_, true);
102 EXPECT_TRUE(feature_.IsEnabled());
104 EXPECT_TRUE(feature_.IsEnabled());
107 FeatureSwitch::ScopedOverride override(&feature_, false);
108 EXPECT_FALSE(feature_.IsEnabled());
110 EXPECT_TRUE(feature_.IsEnabled());
113 TEST_F(FeatureSwitchEnabledTest, FalseSwitchValue) {
114 command_line_.AppendSwitchASCII(kSwitchName, "0");
115 EXPECT_FALSE(feature_.IsEnabled());
118 FeatureSwitch::ScopedOverride override(&feature_, true);
119 EXPECT_TRUE(feature_.IsEnabled());
121 EXPECT_FALSE(feature_.IsEnabled());
124 FeatureSwitch::ScopedOverride override(&feature_, false);
125 EXPECT_FALSE(feature_.IsEnabled());
127 EXPECT_FALSE(feature_.IsEnabled());
130 TEST_F(FeatureSwitchEnabledTest, TrimSwitchValue) {
131 command_line_.AppendSwitchASCII(kSwitchName, "\t\t 0 \n");
132 EXPECT_FALSE(feature_.IsEnabled());