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

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

Issue 669813003: Update from chromium https://crrev.com/301725/ (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « net/proxy/proxy_config_service_linux.cc ('k') | net/proxy/proxy_config_service_win.cc » ('j') | 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) 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 "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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 Reset(); 100 Reset();
101 } 101 }
102 102
103 // Zeroes all environment values. 103 // Zeroes all environment values.
104 void Reset() { 104 void Reset() {
105 EnvVarValues zero_values = { 0 }; 105 EnvVarValues zero_values = { 0 };
106 values = zero_values; 106 values = zero_values;
107 } 107 }
108 108
109 // Begin base::Environment implementation. 109 // Begin base::Environment implementation.
110 virtual bool GetVar(const char* variable_name, std::string* result) override { 110 bool GetVar(const char* variable_name, std::string* result) override {
111 std::map<std::string, const char**>::iterator it = 111 std::map<std::string, const char**>::iterator it =
112 table.find(variable_name); 112 table.find(variable_name);
113 if (it != table.end() && *(it->second) != NULL) { 113 if (it != table.end() && *(it->second) != NULL) {
114 // Note that the variable may be defined but empty. 114 // Note that the variable may be defined but empty.
115 *result = *(it->second); 115 *result = *(it->second);
116 return true; 116 return true;
117 } 117 }
118 return false; 118 return false;
119 } 119 }
120 120
121 virtual bool SetVar(const char* variable_name, const std::string& new_value) 121 bool SetVar(const char* variable_name,
122 override { 122 const std::string& new_value) override {
123 ADD_FAILURE(); 123 ADD_FAILURE();
124 return false; 124 return false;
125 } 125 }
126 126
127 virtual bool UnSetVar(const char* variable_name) override { 127 bool UnSetVar(const char* variable_name) override {
128 ADD_FAILURE(); 128 ADD_FAILURE();
129 return false; 129 return false;
130 } 130 }
131 // End base::Environment implementation. 131 // End base::Environment implementation.
132 132
133 // Intentionally public, for convenience when setting up a test. 133 // Intentionally public, for convenience when setting up a test.
134 EnvVarValues values; 134 EnvVarValues values;
135 135
136 private: 136 private:
137 std::map<std::string, const char**> table; 137 std::map<std::string, const char**> table;
(...skipping 30 matching lines...) Expand all
168 &values.ignore_hosts; 168 &values.ignore_hosts;
169 Reset(); 169 Reset();
170 } 170 }
171 171
172 // Zeros all environment values. 172 // Zeros all environment values.
173 void Reset() { 173 void Reset() {
174 GConfValues zero_values = { 0 }; 174 GConfValues zero_values = { 0 };
175 values = zero_values; 175 values = zero_values;
176 } 176 }
177 177
178 virtual bool Init( 178 bool Init(const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner,
179 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, 179 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner)
180 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner)
181 override { 180 override {
182 task_runner_ = glib_task_runner; 181 task_runner_ = glib_task_runner;
183 return true; 182 return true;
184 } 183 }
185 184
186 virtual void ShutDown() override {} 185 void ShutDown() override {}
187 186
188 virtual bool SetUpNotifications(ProxyConfigServiceLinux::Delegate* delegate) 187 bool SetUpNotifications(
189 override { 188 ProxyConfigServiceLinux::Delegate* delegate) override {
190 return true; 189 return true;
191 } 190 }
192 191
193 virtual const scoped_refptr<base::SingleThreadTaskRunner>& 192 const scoped_refptr<base::SingleThreadTaskRunner>& GetNotificationTaskRunner()
194 GetNotificationTaskRunner() override { 193 override {
195 return task_runner_; 194 return task_runner_;
196 } 195 }
197 196
198 virtual ProxyConfigSource GetConfigSource() override { 197 ProxyConfigSource GetConfigSource() override {
199 return PROXY_CONFIG_SOURCE_TEST; 198 return PROXY_CONFIG_SOURCE_TEST;
200 } 199 }
201 200
202 virtual bool GetString(StringSetting key, std::string* result) override { 201 bool GetString(StringSetting key, std::string* result) override {
203 const char* value = strings_table.Get(key); 202 const char* value = strings_table.Get(key);
204 if (value) { 203 if (value) {
205 *result = value; 204 *result = value;
206 return true; 205 return true;
207 } 206 }
208 return false; 207 return false;
209 } 208 }
210 209
211 virtual bool GetBool(BoolSetting key, bool* result) override { 210 bool GetBool(BoolSetting key, bool* result) override {
212 BoolSettingValue value = bools_table.Get(key); 211 BoolSettingValue value = bools_table.Get(key);
213 switch (value) { 212 switch (value) {
214 case UNSET: 213 case UNSET:
215 return false; 214 return false;
216 case TRUE: 215 case TRUE:
217 *result = true; 216 *result = true;
218 break; 217 break;
219 case FALSE: 218 case FALSE:
220 *result = false; 219 *result = false;
221 } 220 }
222 return true; 221 return true;
223 } 222 }
224 223
225 virtual bool GetInt(IntSetting key, int* result) override { 224 bool GetInt(IntSetting key, int* result) override {
226 // We don't bother to distinguish unset keys from 0 values. 225 // We don't bother to distinguish unset keys from 0 values.
227 *result = ints_table.Get(key); 226 *result = ints_table.Get(key);
228 return true; 227 return true;
229 } 228 }
230 229
231 virtual bool GetStringList(StringListSetting key, 230 bool GetStringList(StringListSetting key,
232 std::vector<std::string>* result) override { 231 std::vector<std::string>* result) override {
233 *result = string_lists_table.Get(key); 232 *result = string_lists_table.Get(key);
234 // We don't bother to distinguish unset keys from empty lists. 233 // We don't bother to distinguish unset keys from empty lists.
235 return !result->empty(); 234 return !result->empty();
236 } 235 }
237 236
238 virtual bool BypassListIsReversed() override { 237 bool BypassListIsReversed() override { return false; }
239 return false;
240 }
241 238
242 virtual bool MatchHostsUsingSuffixMatching() override { 239 bool MatchHostsUsingSuffixMatching() override { return false; }
243 return false;
244 }
245 240
246 // Intentionally public, for convenience when setting up a test. 241 // Intentionally public, for convenience when setting up a test.
247 GConfValues values; 242 GConfValues values;
248 243
249 private: 244 private:
250 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 245 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
251 SettingsTable<StringSetting, const char*> strings_table; 246 SettingsTable<StringSetting, const char*> strings_table;
252 SettingsTable<BoolSetting, BoolSettingValue> bools_table; 247 SettingsTable<BoolSetting, BoolSettingValue> bools_table;
253 SettingsTable<IntSetting, int> ints_table; 248 SettingsTable<IntSetting, int> ints_table;
254 SettingsTable<StringListSetting, 249 SettingsTable<StringListSetting,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 net::ProxyConfigService::ConfigAvailability get_latest_config_result_; 343 net::ProxyConfigService::ConfigAvailability get_latest_config_result_;
349 }; 344 };
350 345
351 namespace net { 346 namespace net {
352 347
353 // This test fixture is only really needed for the KDEConfigParser test case, 348 // This test fixture is only really needed for the KDEConfigParser test case,
354 // but all the test cases with the same prefix ("ProxyConfigServiceLinuxTest") 349 // but all the test cases with the same prefix ("ProxyConfigServiceLinuxTest")
355 // must use the same test fixture class (also "ProxyConfigServiceLinuxTest"). 350 // must use the same test fixture class (also "ProxyConfigServiceLinuxTest").
356 class ProxyConfigServiceLinuxTest : public PlatformTest { 351 class ProxyConfigServiceLinuxTest : public PlatformTest {
357 protected: 352 protected:
358 virtual void SetUp() override { 353 void SetUp() override {
359 PlatformTest::SetUp(); 354 PlatformTest::SetUp();
360 // Set up a temporary KDE home directory. 355 // Set up a temporary KDE home directory.
361 std::string prefix("ProxyConfigServiceLinuxTest_user_home"); 356 std::string prefix("ProxyConfigServiceLinuxTest_user_home");
362 base::CreateNewTempDirectory(prefix, &user_home_); 357 base::CreateNewTempDirectory(prefix, &user_home_);
363 kde_home_ = user_home_.Append(FILE_PATH_LITERAL(".kde")); 358 kde_home_ = user_home_.Append(FILE_PATH_LITERAL(".kde"));
364 base::FilePath path = kde_home_.Append(FILE_PATH_LITERAL("share")); 359 base::FilePath path = kde_home_.Append(FILE_PATH_LITERAL("share"));
365 path = path.Append(FILE_PATH_LITERAL("config")); 360 path = path.Append(FILE_PATH_LITERAL("config"));
366 base::CreateDirectory(path); 361 base::CreateDirectory(path);
367 kioslaverc_ = path.Append(FILE_PATH_LITERAL("kioslaverc")); 362 kioslaverc_ = path.Append(FILE_PATH_LITERAL("kioslaverc"));
368 // Set up paths but do not create the directory for .kde4. 363 // Set up paths but do not create the directory for .kde4.
369 kde4_home_ = user_home_.Append(FILE_PATH_LITERAL(".kde4")); 364 kde4_home_ = user_home_.Append(FILE_PATH_LITERAL(".kde4"));
370 path = kde4_home_.Append(FILE_PATH_LITERAL("share")); 365 path = kde4_home_.Append(FILE_PATH_LITERAL("share"));
371 kde4_config_ = path.Append(FILE_PATH_LITERAL("config")); 366 kde4_config_ = path.Append(FILE_PATH_LITERAL("config"));
372 kioslaverc4_ = kde4_config_.Append(FILE_PATH_LITERAL("kioslaverc")); 367 kioslaverc4_ = kde4_config_.Append(FILE_PATH_LITERAL("kioslaverc"));
373 } 368 }
374 369
375 virtual void TearDown() override { 370 void TearDown() override {
376 // Delete the temporary KDE home directory. 371 // Delete the temporary KDE home directory.
377 base::DeleteFile(user_home_, true); 372 base::DeleteFile(user_home_, true);
378 PlatformTest::TearDown(); 373 PlatformTest::TearDown();
379 } 374 }
380 375
381 base::FilePath user_home_; 376 base::FilePath user_home_;
382 // KDE3 paths. 377 // KDE3 paths.
383 base::FilePath kde_home_; 378 base::FilePath kde_home_;
384 base::FilePath kioslaverc_; 379 base::FilePath kioslaverc_;
385 // KDE4 paths. 380 // KDE4 paths.
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1611 ProxyConfig config; 1606 ProxyConfig config;
1612 sync_config_getter.SetupAndInitialFetch(); 1607 sync_config_getter.SetupAndInitialFetch();
1613 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, 1608 EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
1614 sync_config_getter.SyncGetLatestProxyConfig(&config)); 1609 sync_config_getter.SyncGetLatestProxyConfig(&config));
1615 EXPECT_TRUE(config.auto_detect()); 1610 EXPECT_TRUE(config.auto_detect());
1616 EXPECT_EQ(GURL(), config.pac_url()); 1611 EXPECT_EQ(GURL(), config.pac_url());
1617 } 1612 }
1618 } 1613 }
1619 1614
1620 } // namespace net 1615 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_config_service_linux.cc ('k') | net/proxy/proxy_config_service_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698