OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include <stddef.h> | 6 #include <stddef.h> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/prefs/command_line_pref_store.h" | 13 #include "chrome/browser/prefs/chrome_command_line_pref_store.h" |
14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "components/proxy_config/proxy_config_dictionary.h" | 16 #include "components/proxy_config/proxy_config_dictionary.h" |
17 #include "components/proxy_config/proxy_config_pref_names.h" | 17 #include "components/proxy_config/proxy_config_pref_names.h" |
18 #include "components/ssl_config/ssl_config_prefs.h" | 18 #include "components/ssl_config/ssl_config_prefs.h" |
19 #include "ui/base/ui_base_switches.h" | 19 #include "ui/base/ui_base_switches.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const char unknown_bool[] = "unknown_switch"; | 23 const char unknown_bool[] = "unknown_switch"; |
24 const char unknown_string[] = "unknown_other_switch"; | 24 const char unknown_string[] = "unknown_other_switch"; |
25 | 25 |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 class TestCommandLinePrefStore : public CommandLinePrefStore { | 28 class TestCommandLinePrefStore : public ChromeCommandLinePrefStore { |
29 public: | 29 public: |
30 explicit TestCommandLinePrefStore(base::CommandLine* cl) | 30 explicit TestCommandLinePrefStore(base::CommandLine* cl) |
31 : CommandLinePrefStore(cl) {} | 31 : ChromeCommandLinePrefStore(cl) {} |
32 | 32 |
33 bool ProxySwitchesAreValid() { | 33 bool ProxySwitchesAreValid() { |
34 return ValidateProxySwitches(); | 34 return ValidateProxySwitches(); |
35 } | 35 } |
36 | 36 |
37 void VerifyProxyMode(ProxyPrefs::ProxyMode expected_mode) { | 37 void VerifyProxyMode(ProxyPrefs::ProxyMode expected_mode) { |
38 const base::Value* value = NULL; | 38 const base::Value* value = NULL; |
39 ASSERT_TRUE(GetValue(proxy_config::prefs::kProxy, &value)); | 39 ASSERT_TRUE(GetValue(proxy_config::prefs::kProxy, &value)); |
40 ASSERT_EQ(base::Value::TYPE_DICTIONARY, value->GetType()); | 40 ASSERT_EQ(base::Value::TYPE_DICTIONARY, value->GetType()); |
41 ProxyConfigDictionary dict( | 41 ProxyConfigDictionary dict( |
(...skipping 18 matching lines...) Expand all Loading... |
60 ASSERT_TRUE((*it)->GetAsString(&cipher_string)); | 60 ASSERT_TRUE((*it)->GetAsString(&cipher_string)); |
61 EXPECT_EQ(*ciphers, cipher_string); | 61 EXPECT_EQ(*ciphers, cipher_string); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 private: | 65 private: |
66 ~TestCommandLinePrefStore() override {} | 66 ~TestCommandLinePrefStore() override {} |
67 }; | 67 }; |
68 | 68 |
69 // Tests a simple string pref on the command line. | 69 // Tests a simple string pref on the command line. |
70 TEST(CommandLinePrefStoreTest, SimpleStringPref) { | 70 TEST(ChromeCommandLinePrefStoreTest, SimpleStringPref) { |
71 base::CommandLine cl(base::CommandLine::NO_PROGRAM); | 71 base::CommandLine cl(base::CommandLine::NO_PROGRAM); |
72 cl.AppendSwitchASCII(switches::kLang, "hi-MOM"); | 72 cl.AppendSwitchASCII(switches::kLang, "hi-MOM"); |
73 scoped_refptr<CommandLinePrefStore> store = new CommandLinePrefStore(&cl); | 73 scoped_refptr<ChromeCommandLinePrefStore> store = |
| 74 new ChromeCommandLinePrefStore(&cl); |
74 | 75 |
75 const base::Value* actual = NULL; | 76 const base::Value* actual = NULL; |
76 EXPECT_TRUE(store->GetValue(prefs::kApplicationLocale, &actual)); | 77 EXPECT_TRUE(store->GetValue(prefs::kApplicationLocale, &actual)); |
77 std::string result; | 78 std::string result; |
78 EXPECT_TRUE(actual->GetAsString(&result)); | 79 EXPECT_TRUE(actual->GetAsString(&result)); |
79 EXPECT_EQ("hi-MOM", result); | 80 EXPECT_EQ("hi-MOM", result); |
80 } | 81 } |
81 | 82 |
82 // Tests a simple boolean pref on the command line. | 83 // Tests a simple boolean pref on the command line. |
83 TEST(CommandLinePrefStoreTest, SimpleBooleanPref) { | 84 TEST(ChromeCommandLinePrefStoreTest, SimpleBooleanPref) { |
84 base::CommandLine cl(base::CommandLine::NO_PROGRAM); | 85 base::CommandLine cl(base::CommandLine::NO_PROGRAM); |
85 cl.AppendSwitch(switches::kNoProxyServer); | 86 cl.AppendSwitch(switches::kNoProxyServer); |
86 scoped_refptr<TestCommandLinePrefStore> store = | 87 scoped_refptr<TestCommandLinePrefStore> store = |
87 new TestCommandLinePrefStore(&cl); | 88 new TestCommandLinePrefStore(&cl); |
88 | 89 |
89 store->VerifyProxyMode(ProxyPrefs::MODE_DIRECT); | 90 store->VerifyProxyMode(ProxyPrefs::MODE_DIRECT); |
90 } | 91 } |
91 | 92 |
92 // Tests a command line with no recognized prefs. | 93 // Tests a command line with no recognized prefs. |
93 TEST(CommandLinePrefStoreTest, NoPrefs) { | 94 TEST(ChromeCommandLinePrefStoreTest, NoPrefs) { |
94 base::CommandLine cl(base::CommandLine::NO_PROGRAM); | 95 base::CommandLine cl(base::CommandLine::NO_PROGRAM); |
95 cl.AppendSwitch(unknown_string); | 96 cl.AppendSwitch(unknown_string); |
96 cl.AppendSwitchASCII(unknown_bool, "a value"); | 97 cl.AppendSwitchASCII(unknown_bool, "a value"); |
97 scoped_refptr<CommandLinePrefStore> store = new CommandLinePrefStore(&cl); | 98 scoped_refptr<ChromeCommandLinePrefStore> store = |
| 99 new ChromeCommandLinePrefStore(&cl); |
98 | 100 |
99 const base::Value* actual = NULL; | 101 const base::Value* actual = NULL; |
100 EXPECT_FALSE(store->GetValue(unknown_bool, &actual)); | 102 EXPECT_FALSE(store->GetValue(unknown_bool, &actual)); |
101 EXPECT_FALSE(store->GetValue(unknown_string, &actual)); | 103 EXPECT_FALSE(store->GetValue(unknown_string, &actual)); |
102 } | 104 } |
103 | 105 |
104 // Tests a complex command line with multiple known and unknown switches. | 106 // Tests a complex command line with multiple known and unknown switches. |
105 TEST(CommandLinePrefStoreTest, MultipleSwitches) { | 107 TEST(ChromeCommandLinePrefStoreTest, MultipleSwitches) { |
106 base::CommandLine cl(base::CommandLine::NO_PROGRAM); | 108 base::CommandLine cl(base::CommandLine::NO_PROGRAM); |
107 cl.AppendSwitch(unknown_string); | 109 cl.AppendSwitch(unknown_string); |
108 cl.AppendSwitchASCII(switches::kProxyServer, "proxy"); | 110 cl.AppendSwitchASCII(switches::kProxyServer, "proxy"); |
109 cl.AppendSwitchASCII(switches::kProxyBypassList, "list"); | 111 cl.AppendSwitchASCII(switches::kProxyBypassList, "list"); |
110 cl.AppendSwitchASCII(unknown_bool, "a value"); | 112 cl.AppendSwitchASCII(unknown_bool, "a value"); |
111 scoped_refptr<TestCommandLinePrefStore> store = | 113 scoped_refptr<TestCommandLinePrefStore> store = |
112 new TestCommandLinePrefStore(&cl); | 114 new TestCommandLinePrefStore(&cl); |
113 | 115 |
114 const base::Value* actual = NULL; | 116 const base::Value* actual = NULL; |
115 EXPECT_FALSE(store->GetValue(unknown_bool, &actual)); | 117 EXPECT_FALSE(store->GetValue(unknown_bool, &actual)); |
116 EXPECT_FALSE(store->GetValue(unknown_string, &actual)); | 118 EXPECT_FALSE(store->GetValue(unknown_string, &actual)); |
117 | 119 |
118 store->VerifyProxyMode(ProxyPrefs::MODE_FIXED_SERVERS); | 120 store->VerifyProxyMode(ProxyPrefs::MODE_FIXED_SERVERS); |
119 | 121 |
120 const base::Value* value = NULL; | 122 const base::Value* value = NULL; |
121 ASSERT_TRUE(store->GetValue(proxy_config::prefs::kProxy, &value)); | 123 ASSERT_TRUE(store->GetValue(proxy_config::prefs::kProxy, &value)); |
122 ASSERT_EQ(base::Value::TYPE_DICTIONARY, value->GetType()); | 124 ASSERT_EQ(base::Value::TYPE_DICTIONARY, value->GetType()); |
123 ProxyConfigDictionary dict(static_cast<const base::DictionaryValue*>(value)); | 125 ProxyConfigDictionary dict(static_cast<const base::DictionaryValue*>(value)); |
124 | 126 |
125 std::string string_result; | 127 std::string string_result; |
126 | 128 |
127 ASSERT_TRUE(dict.GetProxyServer(&string_result)); | 129 ASSERT_TRUE(dict.GetProxyServer(&string_result)); |
128 EXPECT_EQ("proxy", string_result); | 130 EXPECT_EQ("proxy", string_result); |
129 | 131 |
130 ASSERT_TRUE(dict.GetBypassList(&string_result)); | 132 ASSERT_TRUE(dict.GetBypassList(&string_result)); |
131 EXPECT_EQ("list", string_result); | 133 EXPECT_EQ("list", string_result); |
132 } | 134 } |
133 | 135 |
134 // Tests proxy switch validation. | 136 // Tests proxy switch validation. |
135 TEST(CommandLinePrefStoreTest, ProxySwitchValidation) { | 137 TEST(ChromeCommandLinePrefStoreTest, ProxySwitchValidation) { |
136 base::CommandLine cl(base::CommandLine::NO_PROGRAM); | 138 base::CommandLine cl(base::CommandLine::NO_PROGRAM); |
137 | 139 |
138 // No switches. | 140 // No switches. |
139 scoped_refptr<TestCommandLinePrefStore> store = | 141 scoped_refptr<TestCommandLinePrefStore> store = |
140 new TestCommandLinePrefStore(&cl); | 142 new TestCommandLinePrefStore(&cl); |
141 EXPECT_TRUE(store->ProxySwitchesAreValid()); | 143 EXPECT_TRUE(store->ProxySwitchesAreValid()); |
142 | 144 |
143 // Only no-proxy. | 145 // Only no-proxy. |
144 cl.AppendSwitch(switches::kNoProxyServer); | 146 cl.AppendSwitch(switches::kNoProxyServer); |
145 scoped_refptr<TestCommandLinePrefStore> store2 = | 147 scoped_refptr<TestCommandLinePrefStore> store2 = |
(...skipping 10 matching lines...) Expand all Loading... |
156 base::CommandLine cl2(base::CommandLine::NO_PROGRAM); | 158 base::CommandLine cl2(base::CommandLine::NO_PROGRAM); |
157 cl2.AppendSwitch(switches::kProxyAutoDetect); | 159 cl2.AppendSwitch(switches::kProxyAutoDetect); |
158 cl2.AppendSwitchASCII(switches::kProxyServer, "server"); | 160 cl2.AppendSwitchASCII(switches::kProxyServer, "server"); |
159 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "url"); | 161 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "url"); |
160 cl2.AppendSwitchASCII(switches::kProxyBypassList, "list"); | 162 cl2.AppendSwitchASCII(switches::kProxyBypassList, "list"); |
161 scoped_refptr<TestCommandLinePrefStore> store4 = | 163 scoped_refptr<TestCommandLinePrefStore> store4 = |
162 new TestCommandLinePrefStore(&cl2); | 164 new TestCommandLinePrefStore(&cl2); |
163 EXPECT_TRUE(store4->ProxySwitchesAreValid()); | 165 EXPECT_TRUE(store4->ProxySwitchesAreValid()); |
164 } | 166 } |
165 | 167 |
166 TEST(CommandLinePrefStoreTest, ManualProxyModeInference) { | 168 TEST(ChromeCommandLinePrefStoreTest, ManualProxyModeInference) { |
167 base::CommandLine cl1(base::CommandLine::NO_PROGRAM); | 169 base::CommandLine cl1(base::CommandLine::NO_PROGRAM); |
168 cl1.AppendSwitch(unknown_string); | 170 cl1.AppendSwitch(unknown_string); |
169 cl1.AppendSwitchASCII(switches::kProxyServer, "proxy"); | 171 cl1.AppendSwitchASCII(switches::kProxyServer, "proxy"); |
170 scoped_refptr<TestCommandLinePrefStore> store1 = | 172 scoped_refptr<TestCommandLinePrefStore> store1 = |
171 new TestCommandLinePrefStore(&cl1); | 173 new TestCommandLinePrefStore(&cl1); |
172 store1->VerifyProxyMode(ProxyPrefs::MODE_FIXED_SERVERS); | 174 store1->VerifyProxyMode(ProxyPrefs::MODE_FIXED_SERVERS); |
173 | 175 |
174 base::CommandLine cl2(base::CommandLine::NO_PROGRAM); | 176 base::CommandLine cl2(base::CommandLine::NO_PROGRAM); |
175 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "proxy"); | 177 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "proxy"); |
176 scoped_refptr<TestCommandLinePrefStore> store2 = | 178 scoped_refptr<TestCommandLinePrefStore> store2 = |
177 new TestCommandLinePrefStore(&cl2); | 179 new TestCommandLinePrefStore(&cl2); |
178 store2->VerifyProxyMode(ProxyPrefs::MODE_PAC_SCRIPT); | 180 store2->VerifyProxyMode(ProxyPrefs::MODE_PAC_SCRIPT); |
179 | 181 |
180 base::CommandLine cl3(base::CommandLine::NO_PROGRAM); | 182 base::CommandLine cl3(base::CommandLine::NO_PROGRAM); |
181 cl3.AppendSwitchASCII(switches::kProxyServer, std::string()); | 183 cl3.AppendSwitchASCII(switches::kProxyServer, std::string()); |
182 scoped_refptr<TestCommandLinePrefStore> store3 = | 184 scoped_refptr<TestCommandLinePrefStore> store3 = |
183 new TestCommandLinePrefStore(&cl3); | 185 new TestCommandLinePrefStore(&cl3); |
184 store3->VerifyProxyMode(ProxyPrefs::MODE_DIRECT); | 186 store3->VerifyProxyMode(ProxyPrefs::MODE_DIRECT); |
185 } | 187 } |
186 | 188 |
187 TEST(CommandLinePrefStoreTest, DisableSSLCipherSuites) { | 189 TEST(ChromeCommandLinePrefStoreTest, DisableSSLCipherSuites) { |
188 base::CommandLine cl1(base::CommandLine::NO_PROGRAM); | 190 base::CommandLine cl1(base::CommandLine::NO_PROGRAM); |
189 cl1.AppendSwitchASCII(switches::kCipherSuiteBlacklist, | 191 cl1.AppendSwitchASCII(switches::kCipherSuiteBlacklist, |
190 "0x0004,0x0005"); | 192 "0x0004,0x0005"); |
191 scoped_refptr<TestCommandLinePrefStore> store1 = | 193 scoped_refptr<TestCommandLinePrefStore> store1 = |
192 new TestCommandLinePrefStore(&cl1); | 194 new TestCommandLinePrefStore(&cl1); |
193 const char* const expected_ciphers1[] = { | 195 const char* const expected_ciphers1[] = { |
194 "0x0004", | 196 "0x0004", |
195 "0x0005", | 197 "0x0005", |
196 }; | 198 }; |
197 store1->VerifySSLCipherSuites(expected_ciphers1, | 199 store1->VerifySSLCipherSuites(expected_ciphers1, |
(...skipping 16 matching lines...) Expand all Loading... |
214 cl3.AppendSwitchASCII(switches::kCipherSuiteBlacklist, | 216 cl3.AppendSwitchASCII(switches::kCipherSuiteBlacklist, |
215 "0x0004;MOAR;0x0005"); | 217 "0x0004;MOAR;0x0005"); |
216 scoped_refptr<TestCommandLinePrefStore> store3 = | 218 scoped_refptr<TestCommandLinePrefStore> store3 = |
217 new TestCommandLinePrefStore(&cl3); | 219 new TestCommandLinePrefStore(&cl3); |
218 const char* const expected_ciphers3[] = { | 220 const char* const expected_ciphers3[] = { |
219 "0x0004;MOAR;0x0005" | 221 "0x0004;MOAR;0x0005" |
220 }; | 222 }; |
221 store3->VerifySSLCipherSuites(expected_ciphers3, | 223 store3->VerifySSLCipherSuites(expected_ciphers3, |
222 arraysize(expected_ciphers3)); | 224 arraysize(expected_ciphers3)); |
223 } | 225 } |
OLD | NEW |