OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <gtest/gtest.h> | 5 #include <gtest/gtest.h> |
6 | 6 |
7 #include "app/app_switches.h" | 7 #include "app/app_switches.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/net/pref_proxy_config_service.h" | |
11 #include "chrome/browser/prefs/command_line_pref_store.h" | 12 #include "chrome/browser/prefs/command_line_pref_store.h" |
12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 class TestCommandLinePrefStore : public CommandLinePrefStore { | 18 class TestCommandLinePrefStore : public CommandLinePrefStore { |
18 public: | 19 public: |
19 explicit TestCommandLinePrefStore(CommandLine* cl) | 20 explicit TestCommandLinePrefStore(CommandLine* cl) |
20 : CommandLinePrefStore(cl) {} | 21 : CommandLinePrefStore(cl) {} |
(...skipping 22 matching lines...) Expand all Loading... | |
43 EXPECT_EQ("hi-MOM", result); | 44 EXPECT_EQ("hi-MOM", result); |
44 } | 45 } |
45 | 46 |
46 // Tests a simple boolean pref on the command line. | 47 // Tests a simple boolean pref on the command line. |
47 TEST(CommandLinePrefStoreTest, SimpleBooleanPref) { | 48 TEST(CommandLinePrefStoreTest, SimpleBooleanPref) { |
48 CommandLine cl(CommandLine::NO_PROGRAM); | 49 CommandLine cl(CommandLine::NO_PROGRAM); |
49 cl.AppendSwitch(switches::kNoProxyServer); | 50 cl.AppendSwitch(switches::kNoProxyServer); |
50 CommandLinePrefStore store(&cl); | 51 CommandLinePrefStore store(&cl); |
51 | 52 |
52 Value* actual = NULL; | 53 Value* actual = NULL; |
53 ASSERT_EQ(PrefStore::READ_OK, store.GetValue(prefs::kNoProxyServer, &actual)); | 54 ASSERT_EQ(PrefStore::READ_OK, |
54 bool result; | 55 store.GetValue(prefs::kProxyServerMode, &actual)); |
55 EXPECT_TRUE(actual->GetAsBoolean(&result)); | 56 int result = -1; |
56 EXPECT_TRUE(result); | 57 EXPECT_TRUE(actual->GetAsInteger(&result)); |
58 EXPECT_EQ(PrefProxyConfigService::DISABLED, result); | |
57 } | 59 } |
58 | 60 |
59 // Tests a command line with no recognized prefs. | 61 // Tests a command line with no recognized prefs. |
60 TEST(CommandLinePrefStoreTest, NoPrefs) { | 62 TEST(CommandLinePrefStoreTest, NoPrefs) { |
61 CommandLine cl(CommandLine::NO_PROGRAM); | 63 CommandLine cl(CommandLine::NO_PROGRAM); |
62 cl.AppendSwitch(unknown_string); | 64 cl.AppendSwitch(unknown_string); |
63 cl.AppendSwitchASCII(unknown_bool, "a value"); | 65 cl.AppendSwitchASCII(unknown_bool, "a value"); |
64 CommandLinePrefStore store(&cl); | 66 CommandLinePrefStore store(&cl); |
65 | 67 |
66 Value* actual = NULL; | 68 Value* actual = NULL; |
67 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_bool, &actual)); | 69 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_bool, &actual)); |
68 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_string, &actual)); | 70 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_string, &actual)); |
69 } | 71 } |
70 | 72 |
71 // Tests a complex command line with multiple known and unknown switches. | 73 // Tests a complex command line with multiple known and unknown switches. |
72 TEST(CommandLinePrefStoreTest, MultipleSwitches) { | 74 TEST(CommandLinePrefStoreTest, MultipleSwitches) { |
73 CommandLine cl(CommandLine::NO_PROGRAM); | 75 CommandLine cl(CommandLine::NO_PROGRAM); |
74 cl.AppendSwitch(unknown_string); | 76 cl.AppendSwitch(unknown_string); |
75 cl.AppendSwitch(switches::kProxyAutoDetect); | 77 cl.AppendSwitch(switches::kProxyAutoDetect); |
76 cl.AppendSwitchASCII(switches::kProxyServer, "proxy"); | 78 cl.AppendSwitchASCII(switches::kProxyServer, "proxy"); |
77 cl.AppendSwitchASCII(switches::kProxyBypassList, "list"); | 79 cl.AppendSwitchASCII(switches::kProxyBypassList, "list"); |
78 cl.AppendSwitchASCII(unknown_bool, "a value"); | 80 cl.AppendSwitchASCII(unknown_bool, "a value"); |
79 CommandLinePrefStore store(&cl); | 81 CommandLinePrefStore store(&cl); |
80 | 82 |
81 Value* actual = NULL; | 83 Value* actual = NULL; |
82 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_bool, &actual)); | 84 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_bool, &actual)); |
83 ASSERT_EQ(PrefStore::READ_OK, | 85 ASSERT_EQ(PrefStore::READ_OK, |
84 store.GetValue(prefs::kProxyAutoDetect, &actual)); | 86 store.GetValue(prefs::kProxyServerMode, &actual)); |
85 bool bool_result = false; | 87 int int_result = -1; |
86 EXPECT_TRUE(actual->GetAsBoolean(&bool_result)); | 88 EXPECT_TRUE(actual->GetAsInteger(&int_result)); |
87 EXPECT_TRUE(bool_result); | 89 EXPECT_EQ(PrefProxyConfigService::AUTO_DETECT, int_result); |
danno
2010/12/14 12:48:17
You should also have a test for MANUAL, I don't se
gfeher
2010/12/16 10:42:04
Done.
| |
88 | 90 |
89 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_string, &actual)); | 91 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_string, &actual)); |
90 std::string string_result = ""; | 92 std::string string_result = ""; |
91 ASSERT_EQ(PrefStore::READ_OK, store.GetValue(prefs::kProxyServer, &actual)); | 93 ASSERT_EQ(PrefStore::READ_OK, store.GetValue(prefs::kProxyServer, &actual)); |
92 EXPECT_TRUE(actual->GetAsString(&string_result)); | 94 EXPECT_TRUE(actual->GetAsString(&string_result)); |
93 EXPECT_EQ("proxy", string_result); | 95 EXPECT_EQ("proxy", string_result); |
94 ASSERT_EQ(PrefStore::READ_OK, | 96 ASSERT_EQ(PrefStore::READ_OK, |
95 store.GetValue(prefs::kProxyBypassList, &actual)); | 97 store.GetValue(prefs::kProxyBypassList, &actual)); |
96 EXPECT_TRUE(actual->GetAsString(&string_result)); | 98 EXPECT_TRUE(actual->GetAsString(&string_result)); |
97 EXPECT_EQ("list", string_result); | 99 EXPECT_EQ("list", string_result); |
(...skipping 19 matching lines...) Expand all Loading... | |
117 | 119 |
118 // All proxy switches except no-proxy. | 120 // All proxy switches except no-proxy. |
119 CommandLine cl2(CommandLine::NO_PROGRAM); | 121 CommandLine cl2(CommandLine::NO_PROGRAM); |
120 cl2.AppendSwitch(switches::kProxyAutoDetect); | 122 cl2.AppendSwitch(switches::kProxyAutoDetect); |
121 cl2.AppendSwitchASCII(switches::kProxyServer, "server"); | 123 cl2.AppendSwitchASCII(switches::kProxyServer, "server"); |
122 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "url"); | 124 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "url"); |
123 cl2.AppendSwitchASCII(switches::kProxyBypassList, "list"); | 125 cl2.AppendSwitchASCII(switches::kProxyBypassList, "list"); |
124 TestCommandLinePrefStore store4(&cl2); | 126 TestCommandLinePrefStore store4(&cl2); |
125 EXPECT_TRUE(store4.ProxySwitchesAreValid()); | 127 EXPECT_TRUE(store4.ProxySwitchesAreValid()); |
126 } | 128 } |
OLD | NEW |