OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "net/proxy/proxy_config_service_linux.h" | 9 #include "net/proxy/proxy_config_service_linux.h" |
10 | 10 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 ~SynchConfigGetter() { | 247 ~SynchConfigGetter() { |
248 // Let the config service post a destroy message to the IO thread | 248 // Let the config service post a destroy message to the IO thread |
249 // before cleaning up that thread. | 249 // before cleaning up that thread. |
250 delete config_service_; | 250 delete config_service_; |
251 // Clean up the IO thread. | 251 // Clean up the IO thread. |
252 io_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 252 io_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
253 this, &SynchConfigGetter::Cleanup)); | 253 this, &SynchConfigGetter::Cleanup)); |
254 Wait(); | 254 Wait(); |
255 } | 255 } |
256 | 256 |
257 // Does a reset, gconf setup and initial fetch of the proxy config, | 257 // Does gconf setup and initial fetch of the proxy config, |
258 // all on the calling thread (meant to be the thread with the | 258 // all on the calling thread (meant to be the thread with the |
259 // default glib main loop, which is the UI thread). | 259 // default glib main loop, which is the UI thread). |
260 void SetupAndInitialFetch() { | 260 void SetupAndInitialFetch() { |
261 MessageLoop* file_loop = io_thread_.message_loop(); | 261 MessageLoop* file_loop = io_thread_.message_loop(); |
262 DCHECK_EQ(MessageLoop::TYPE_IO, file_loop->type()); | 262 DCHECK_EQ(MessageLoop::TYPE_IO, file_loop->type()); |
263 config_service_->Reset(); | |
264 // We pass the mock IO thread as both the IO and file threads. | 263 // We pass the mock IO thread as both the IO and file threads. |
265 config_service_->SetupAndFetchInitialConfig( | 264 config_service_->SetupAndFetchInitialConfig( |
266 MessageLoop::current(), io_thread_.message_loop(), | 265 MessageLoop::current(), io_thread_.message_loop(), |
267 static_cast<MessageLoopForIO*>(file_loop)); | 266 static_cast<MessageLoopForIO*>(file_loop)); |
268 } | 267 } |
269 // Synchronously gets the proxy config. | 268 // Synchronously gets the proxy config. |
270 int SyncGetProxyConfig(net::ProxyConfig* config) { | 269 int SyncGetProxyConfig(net::ProxyConfig* config) { |
271 io_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 270 io_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
272 this, &SynchConfigGetter::GetConfigOnIOThread)); | 271 this, &SynchConfigGetter::GetConfigOnIOThread)); |
273 Wait(); | 272 Wait(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 } | 342 } |
344 | 343 |
345 FilePath kde_home_; | 344 FilePath kde_home_; |
346 FilePath kioslaverc_; | 345 FilePath kioslaverc_; |
347 }; | 346 }; |
348 | 347 |
349 // Builds an identifier for each test in an array. | 348 // Builds an identifier for each test in an array. |
350 #define TEST_DESC(desc) StringPrintf("at line %d <%s>", __LINE__, desc) | 349 #define TEST_DESC(desc) StringPrintf("at line %d <%s>", __LINE__, desc) |
351 | 350 |
352 TEST_F(ProxyConfigServiceLinuxTest, BasicGConfTest) { | 351 TEST_F(ProxyConfigServiceLinuxTest, BasicGConfTest) { |
353 MockEnvironmentVariableGetter* env_getter = | |
354 new MockEnvironmentVariableGetter; | |
355 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; | |
356 SynchConfigGetter sync_config_getter( | |
357 new ProxyConfigServiceLinux(env_getter, gconf_getter)); | |
358 | |
359 std::vector<std::string> empty_ignores; | 352 std::vector<std::string> empty_ignores; |
360 | 353 |
361 std::vector<std::string> google_ignores; | 354 std::vector<std::string> google_ignores; |
362 google_ignores.push_back("*.google.com"); | 355 google_ignores.push_back("*.google.com"); |
363 | 356 |
364 // Inspired from proxy_config_service_win_unittest.cc. | 357 // Inspired from proxy_config_service_win_unittest.cc. |
365 // Very neat, but harder to track down failures though. | 358 // Very neat, but harder to track down failures though. |
366 const struct { | 359 const struct { |
367 // Short description to identify the test | 360 // Short description to identify the test |
368 std::string description; | 361 std::string description; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 false, // auto_detect | 580 false, // auto_detect |
588 GURL(), // pac_url | 581 GURL(), // pac_url |
589 MakeSingleProxyRules("www.google.com"), // proxy_rules | 582 MakeSingleProxyRules("www.google.com"), // proxy_rules |
590 "*.google.com\n", // proxy_bypass_list | 583 "*.google.com\n", // proxy_bypass_list |
591 false, // bypass_local_names | 584 false, // bypass_local_names |
592 }, | 585 }, |
593 }; | 586 }; |
594 | 587 |
595 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 588 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
596 SCOPED_TRACE(StringPrintf("Test[%d] %s", i, tests[i].description.c_str())); | 589 SCOPED_TRACE(StringPrintf("Test[%d] %s", i, tests[i].description.c_str())); |
| 590 MockEnvironmentVariableGetter* env_getter = |
| 591 new MockEnvironmentVariableGetter; |
| 592 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; |
| 593 SynchConfigGetter sync_config_getter( |
| 594 new ProxyConfigServiceLinux(env_getter, gconf_getter)); |
597 ProxyConfig config; | 595 ProxyConfig config; |
598 gconf_getter->values = tests[i].values; | 596 gconf_getter->values = tests[i].values; |
599 sync_config_getter.SetupAndInitialFetch(); | 597 sync_config_getter.SetupAndInitialFetch(); |
600 sync_config_getter.SyncGetProxyConfig(&config); | 598 sync_config_getter.SyncGetProxyConfig(&config); |
601 | 599 |
602 EXPECT_EQ(tests[i].auto_detect, config.auto_detect); | 600 EXPECT_EQ(tests[i].auto_detect, config.auto_detect); |
603 EXPECT_EQ(tests[i].pac_url, config.pac_url); | 601 EXPECT_EQ(tests[i].pac_url, config.pac_url); |
604 EXPECT_EQ(tests[i].proxy_bypass_list, | 602 EXPECT_EQ(tests[i].proxy_bypass_list, |
605 FlattenProxyBypass(config.proxy_bypass)); | 603 FlattenProxyBypass(config.proxy_bypass)); |
606 EXPECT_EQ(tests[i].bypass_local_names, config.proxy_bypass_local_names); | 604 EXPECT_EQ(tests[i].bypass_local_names, config.proxy_bypass_local_names); |
607 EXPECT_EQ(tests[i].proxy_rules, config.proxy_rules); | 605 EXPECT_EQ(tests[i].proxy_rules, config.proxy_rules); |
608 } | 606 } |
609 } | 607 } |
610 | 608 |
611 TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) { | 609 TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) { |
612 MockEnvironmentVariableGetter* env_getter = | |
613 new MockEnvironmentVariableGetter; | |
614 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; | |
615 SynchConfigGetter sync_config_getter( | |
616 new ProxyConfigServiceLinux(env_getter, gconf_getter)); | |
617 | |
618 // Inspired from proxy_config_service_win_unittest.cc. | 610 // Inspired from proxy_config_service_win_unittest.cc. |
619 const struct { | 611 const struct { |
620 // Short description to identify the test | 612 // Short description to identify the test |
621 std::string description; | 613 std::string description; |
622 | 614 |
623 // Input. | 615 // Input. |
624 EnvVarValues values; | 616 EnvVarValues values; |
625 | 617 |
626 // Expected outputs (fields of the ProxyConfig). | 618 // Expected outputs (fields of the ProxyConfig). |
627 bool auto_detect; | 619 bool auto_detect; |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 GURL(), // pac_url | 859 GURL(), // pac_url |
868 MakeSingleProxyRules("www.google.com"), // proxy_rules | 860 MakeSingleProxyRules("www.google.com"), // proxy_rules |
869 // proxy_bypass_list | 861 // proxy_bypass_list |
870 "*.google.com\n*foo.com:99\n1.2.3.4:22\n127.0.0.1/8\n", | 862 "*.google.com\n*foo.com:99\n1.2.3.4:22\n127.0.0.1/8\n", |
871 false, // bypass_local_names | 863 false, // bypass_local_names |
872 }, | 864 }, |
873 }; | 865 }; |
874 | 866 |
875 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 867 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
876 SCOPED_TRACE(StringPrintf("Test[%d] %s", i, tests[i].description.c_str())); | 868 SCOPED_TRACE(StringPrintf("Test[%d] %s", i, tests[i].description.c_str())); |
| 869 MockEnvironmentVariableGetter* env_getter = |
| 870 new MockEnvironmentVariableGetter; |
| 871 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; |
| 872 SynchConfigGetter sync_config_getter( |
| 873 new ProxyConfigServiceLinux(env_getter, gconf_getter)); |
877 ProxyConfig config; | 874 ProxyConfig config; |
878 env_getter->values = tests[i].values; | 875 env_getter->values = tests[i].values; |
879 sync_config_getter.SetupAndInitialFetch(); | 876 sync_config_getter.SetupAndInitialFetch(); |
880 sync_config_getter.SyncGetProxyConfig(&config); | 877 sync_config_getter.SyncGetProxyConfig(&config); |
881 | 878 |
882 EXPECT_EQ(tests[i].auto_detect, config.auto_detect); | 879 EXPECT_EQ(tests[i].auto_detect, config.auto_detect); |
883 EXPECT_EQ(tests[i].pac_url, config.pac_url); | 880 EXPECT_EQ(tests[i].pac_url, config.pac_url); |
884 EXPECT_EQ(tests[i].proxy_bypass_list, | 881 EXPECT_EQ(tests[i].proxy_bypass_list, |
885 FlattenProxyBypass(config.proxy_bypass)); | 882 FlattenProxyBypass(config.proxy_bypass)); |
886 EXPECT_EQ(tests[i].bypass_local_names, config.proxy_bypass_local_names); | 883 EXPECT_EQ(tests[i].bypass_local_names, config.proxy_bypass_local_names); |
(...skipping 18 matching lines...) Expand all Loading... |
905 | 902 |
906 // Now set to auto-detect. | 903 // Now set to auto-detect. |
907 gconf_getter->values.mode = "auto"; | 904 gconf_getter->values.mode = "auto"; |
908 // Simulate gconf notification callback. | 905 // Simulate gconf notification callback. |
909 service->OnCheckProxyConfigSettings(); | 906 service->OnCheckProxyConfigSettings(); |
910 sync_config_getter.SyncGetProxyConfig(&config); | 907 sync_config_getter.SyncGetProxyConfig(&config); |
911 EXPECT_TRUE(config.auto_detect); | 908 EXPECT_TRUE(config.auto_detect); |
912 } | 909 } |
913 | 910 |
914 TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { | 911 TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { |
915 MockEnvironmentVariableGetter* env_getter = | |
916 new MockEnvironmentVariableGetter; | |
917 // Force the KDE getter to be used and tell it where the test is. | |
918 env_getter->values.DESKTOP_SESSION = "kde"; | |
919 env_getter->values.KDE_HOME = kde_home_.value().c_str(); | |
920 SynchConfigGetter sync_config_getter(new ProxyConfigServiceLinux(env_getter)); | |
921 | |
922 // One of the tests below needs a worst-case long line prefix. We build it | 912 // One of the tests below needs a worst-case long line prefix. We build it |
923 // programmatically so that it will always be the right size. | 913 // programmatically so that it will always be the right size. |
924 std::string long_line; | 914 std::string long_line; |
925 size_t limit = ProxyConfigServiceLinux::GConfSettingGetter::BUFFER_SIZE - 1; | 915 size_t limit = ProxyConfigServiceLinux::GConfSettingGetter::BUFFER_SIZE - 1; |
926 for (size_t i = 0; i < limit; ++i) | 916 for (size_t i = 0; i < limit; ++i) |
927 long_line += "-"; | 917 long_line += "-"; |
928 | 918 |
929 // Inspired from proxy_config_service_win_unittest.cc. | 919 // Inspired from proxy_config_service_win_unittest.cc. |
930 const struct { | 920 const struct { |
931 // Short description to identify the test | 921 // Short description to identify the test |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 GURL(), // pac_url | 1180 GURL(), // pac_url |
1191 MakeProxyPerSchemeRules("www.google.com", | 1181 MakeProxyPerSchemeRules("www.google.com", |
1192 "", "ftp.foo.com"), // proxy_rules | 1182 "", "ftp.foo.com"), // proxy_rules |
1193 "", // proxy_bypass_list | 1183 "", // proxy_bypass_list |
1194 false, // bypass_local_names | 1184 false, // bypass_local_names |
1195 }, | 1185 }, |
1196 }; | 1186 }; |
1197 | 1187 |
1198 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1188 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
1199 SCOPED_TRACE(StringPrintf("Test[%d] %s", i, tests[i].description.c_str())); | 1189 SCOPED_TRACE(StringPrintf("Test[%d] %s", i, tests[i].description.c_str())); |
| 1190 MockEnvironmentVariableGetter* env_getter = |
| 1191 new MockEnvironmentVariableGetter; |
| 1192 // Force the KDE getter to be used and tell it where the test is. |
| 1193 env_getter->values.DESKTOP_SESSION = "kde"; |
| 1194 env_getter->values.KDE_HOME = kde_home_.value().c_str(); |
| 1195 SynchConfigGetter sync_config_getter( |
| 1196 new ProxyConfigServiceLinux(env_getter)); |
1200 ProxyConfig config; | 1197 ProxyConfig config; |
1201 // Overwrite the kioslaverc file. | 1198 // Overwrite the kioslaverc file. |
1202 file_util::WriteFile(kioslaverc_, tests[i].kioslaverc.c_str(), | 1199 file_util::WriteFile(kioslaverc_, tests[i].kioslaverc.c_str(), |
1203 tests[i].kioslaverc.length()); | 1200 tests[i].kioslaverc.length()); |
1204 sync_config_getter.SetupAndInitialFetch(); | 1201 sync_config_getter.SetupAndInitialFetch(); |
1205 sync_config_getter.SyncGetProxyConfig(&config); | 1202 sync_config_getter.SyncGetProxyConfig(&config); |
1206 | 1203 |
1207 EXPECT_EQ(tests[i].auto_detect, config.auto_detect); | 1204 EXPECT_EQ(tests[i].auto_detect, config.auto_detect); |
1208 EXPECT_EQ(tests[i].pac_url, config.pac_url); | 1205 EXPECT_EQ(tests[i].pac_url, config.pac_url); |
1209 EXPECT_EQ(tests[i].proxy_bypass_list, | 1206 EXPECT_EQ(tests[i].proxy_bypass_list, |
1210 FlattenProxyBypass(config.proxy_bypass)); | 1207 FlattenProxyBypass(config.proxy_bypass)); |
1211 EXPECT_EQ(tests[i].bypass_local_names, config.proxy_bypass_local_names); | 1208 EXPECT_EQ(tests[i].bypass_local_names, config.proxy_bypass_local_names); |
1212 EXPECT_EQ(tests[i].proxy_rules, config.proxy_rules); | 1209 EXPECT_EQ(tests[i].proxy_rules, config.proxy_rules); |
1213 } | 1210 } |
1214 } | 1211 } |
1215 | 1212 |
1216 } // namespace net | 1213 } // namespace net |
OLD | NEW |