Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: net/proxy/proxy_config_service_linux_unittest.cc

Issue 7033040: Linux: split ProxyConfigServiceLinux::SettingGetter::Setting into several enums. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/proxy/proxy_config_service_linux.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "net/proxy/proxy_config_service_linux.h" 5 #include "net/proxy/proxy_config_service_linux.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // integers 56 // integers
57 int http_port, secure_port, ftp_port, socks_port; 57 int http_port, secure_port, ftp_port, socks_port;
58 // booleans 58 // booleans
59 BoolSettingValue use_proxy, same_proxy, use_auth; 59 BoolSettingValue use_proxy, same_proxy, use_auth;
60 // string list 60 // string list
61 std::vector<std::string> ignore_hosts; 61 std::vector<std::string> ignore_hosts;
62 }; 62 };
63 63
64 // Mapping from a setting name to the location of the corresponding 64 // Mapping from a setting name to the location of the corresponding
65 // value (inside a EnvVarValues or GConfValues struct). 65 // value (inside a EnvVarValues or GConfValues struct).
66 template<typename value_type> 66 template<typename key_type, typename value_type>
67 struct SettingsTable { 67 struct SettingsTable {
68 typedef ProxyConfigServiceLinux::SettingGetter::Setting Setting; 68 typedef std::map<key_type, value_type*> map_type;
69 typedef std::map<Setting, value_type*> map_type;
70 69
71 // Gets the value from its location 70 // Gets the value from its location
72 value_type Get(Setting key) { 71 value_type Get(key_type key) {
73 typename map_type::const_iterator it = settings.find(key); 72 typename map_type::const_iterator it = settings.find(key);
74 // In case there's a typo or the unittest becomes out of sync. 73 // In case there's a typo or the unittest becomes out of sync.
75 CHECK(it != settings.end()) << "key " << key << " not found"; 74 CHECK(it != settings.end()) << "key " << key << " not found";
76 value_type* value_ptr = it->second; 75 value_type* value_ptr = it->second;
77 return *value_ptr; 76 return *value_ptr;
78 } 77 }
79 78
80 map_type settings; 79 map_type settings;
81 }; 80 };
82 81
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 185 }
187 186
188 virtual MessageLoop* GetNotificationLoop() { 187 virtual MessageLoop* GetNotificationLoop() {
189 return NULL; 188 return NULL;
190 } 189 }
191 190
192 virtual const char* GetDataSource() { 191 virtual const char* GetDataSource() {
193 return "test"; 192 return "test";
194 } 193 }
195 194
196 virtual bool GetString(Setting key, std::string* result) { 195 virtual bool GetString(StringSetting key, std::string* result) {
197 const char* value = strings_table.Get(key); 196 const char* value = strings_table.Get(key);
198 if (value) { 197 if (value) {
199 *result = value; 198 *result = value;
200 return true; 199 return true;
201 } 200 }
202 return false; 201 return false;
203 } 202 }
204 203
205 virtual bool GetInt(Setting key, int* result) { 204 virtual bool GetBool(BoolSetting key, bool* result) {
206 // We don't bother to distinguish unset keys from 0 values.
207 *result = ints_table.Get(key);
208 return true;
209 }
210
211 virtual bool GetBool(Setting key, bool* result) {
212 BoolSettingValue value = bools_table.Get(key); 205 BoolSettingValue value = bools_table.Get(key);
213 switch (value) { 206 switch (value) {
214 case UNSET: 207 case UNSET:
215 return false; 208 return false;
216 case TRUE: 209 case TRUE:
217 *result = true; 210 *result = true;
218 break; 211 break;
219 case FALSE: 212 case FALSE:
220 *result = false; 213 *result = false;
221 } 214 }
222 return true; 215 return true;
223 } 216 }
224 217
225 virtual bool GetStringList(Setting key, std::vector<std::string>* result) { 218 virtual bool GetInt(IntSetting key, int* result) {
219 // We don't bother to distinguish unset keys from 0 values.
220 *result = ints_table.Get(key);
221 return true;
222 }
223
224 virtual bool GetStringList(StringListSetting key,
225 std::vector<std::string>* result) {
226 *result = string_lists_table.Get(key); 226 *result = string_lists_table.Get(key);
227 // We don't bother to distinguish unset keys from empty lists. 227 // We don't bother to distinguish unset keys from empty lists.
228 return !result->empty(); 228 return !result->empty();
229 } 229 }
230 230
231 virtual bool BypassListIsReversed() { 231 virtual bool BypassListIsReversed() {
232 return false; 232 return false;
233 } 233 }
234 234
235 virtual bool MatchHostsUsingSuffixMatching() { 235 virtual bool MatchHostsUsingSuffixMatching() {
236 return false; 236 return false;
237 } 237 }
238 238
239 // Intentionally public, for convenience when setting up a test. 239 // Intentionally public, for convenience when setting up a test.
240 GConfValues values; 240 GConfValues values;
241 241
242 private: 242 private:
243 SettingsTable<const char*> strings_table; 243 SettingsTable<StringSetting, const char*> strings_table;
244 SettingsTable<int> ints_table; 244 SettingsTable<BoolSetting, BoolSettingValue> bools_table;
245 SettingsTable<BoolSettingValue> bools_table; 245 SettingsTable<IntSetting, int> ints_table;
246 SettingsTable<std::vector<std::string> > string_lists_table; 246 SettingsTable<StringListSetting,
247 std::vector<std::string> > string_lists_table;
247 }; 248 };
248 249
249 } // namespace 250 } // namespace
250 } // namespace net 251 } // namespace net
251 252
252 // This helper class runs ProxyConfigServiceLinux::GetLatestProxyConfig() on 253 // This helper class runs ProxyConfigServiceLinux::GetLatestProxyConfig() on
253 // the IO thread and synchronously waits for the result. 254 // the IO thread and synchronously waits for the result.
254 // Some code duplicated from proxy_script_fetcher_unittest.cc. 255 // Some code duplicated from proxy_script_fetcher_unittest.cc.
255 class SynchConfigGetter { 256 class SynchConfigGetter {
256 public: 257 public:
(...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 ProxyConfig config; 1539 ProxyConfig config;
1539 sync_config_getter.SetupAndInitialFetch(); 1540 sync_config_getter.SetupAndInitialFetch();
1540 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, 1541 EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
1541 sync_config_getter.SyncGetLatestProxyConfig(&config)); 1542 sync_config_getter.SyncGetLatestProxyConfig(&config));
1542 EXPECT_TRUE(config.auto_detect()); 1543 EXPECT_TRUE(config.auto_detect());
1543 EXPECT_EQ(GURL(), config.pac_url()); 1544 EXPECT_EQ(GURL(), config.pac_url());
1544 } 1545 }
1545 } 1546 }
1546 1547
1547 } // namespace net 1548 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_config_service_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698