| 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 "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 |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/format_macros.h" | 13 #include "base/format_macros.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/stringprintf.h" |
| 16 #include "base/task.h" | 17 #include "base/task.h" |
| 17 #include "base/thread.h" | 18 #include "base/thread.h" |
| 18 #include "base/waitable_event.h" | 19 #include "base/waitable_event.h" |
| 19 #include "net/proxy/proxy_config.h" | 20 #include "net/proxy/proxy_config.h" |
| 20 #include "net/proxy/proxy_config_service_common_unittest.h" | 21 #include "net/proxy/proxy_config_service_common_unittest.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "testing/platform_test.h" | 23 #include "testing/platform_test.h" |
| 23 | 24 |
| 24 namespace net { | 25 namespace net { |
| 25 namespace { | 26 namespace { |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 // KDE3 paths. | 370 // KDE3 paths. |
| 370 FilePath kde_home_; | 371 FilePath kde_home_; |
| 371 FilePath kioslaverc_; | 372 FilePath kioslaverc_; |
| 372 // KDE4 paths. | 373 // KDE4 paths. |
| 373 FilePath kde4_home_; | 374 FilePath kde4_home_; |
| 374 FilePath kde4_config_; | 375 FilePath kde4_config_; |
| 375 FilePath kioslaverc4_; | 376 FilePath kioslaverc4_; |
| 376 }; | 377 }; |
| 377 | 378 |
| 378 // Builds an identifier for each test in an array. | 379 // Builds an identifier for each test in an array. |
| 379 #define TEST_DESC(desc) StringPrintf("at line %d <%s>", __LINE__, desc) | 380 #define TEST_DESC(desc) base::StringPrintf("at line %d <%s>", __LINE__, desc) |
| 380 | 381 |
| 381 TEST_F(ProxyConfigServiceLinuxTest, BasicGConfTest) { | 382 TEST_F(ProxyConfigServiceLinuxTest, BasicGConfTest) { |
| 382 std::vector<std::string> empty_ignores; | 383 std::vector<std::string> empty_ignores; |
| 383 | 384 |
| 384 std::vector<std::string> google_ignores; | 385 std::vector<std::string> google_ignores; |
| 385 google_ignores.push_back("*.google.com"); | 386 google_ignores.push_back("*.google.com"); |
| 386 | 387 |
| 387 // Inspired from proxy_config_service_win_unittest.cc. | 388 // Inspired from proxy_config_service_win_unittest.cc. |
| 388 // Very neat, but harder to track down failures though. | 389 // Very neat, but harder to track down failures though. |
| 389 const struct { | 390 const struct { |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 | 599 |
| 599 false, // auto_detect | 600 false, // auto_detect |
| 600 GURL(), // pac_url | 601 GURL(), // pac_url |
| 601 ProxyRulesExpectation::Single( | 602 ProxyRulesExpectation::Single( |
| 602 "www.google.com:80", // single proxy | 603 "www.google.com:80", // single proxy |
| 603 "*.google.com"), // bypass rules | 604 "*.google.com"), // bypass rules |
| 604 }, | 605 }, |
| 605 }; | 606 }; |
| 606 | 607 |
| 607 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 608 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 608 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, | 609 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i, |
| 609 tests[i].description.c_str())); | 610 tests[i].description.c_str())); |
| 610 MockEnvironment* env = new MockEnvironment; | 611 MockEnvironment* env = new MockEnvironment; |
| 611 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; | 612 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; |
| 612 SynchConfigGetter sync_config_getter( | 613 SynchConfigGetter sync_config_getter( |
| 613 new ProxyConfigServiceLinux(env, gconf_getter)); | 614 new ProxyConfigServiceLinux(env, gconf_getter)); |
| 614 ProxyConfig config; | 615 ProxyConfig config; |
| 615 gconf_getter->values = tests[i].values; | 616 gconf_getter->values = tests[i].values; |
| 616 sync_config_getter.SetupAndInitialFetch(); | 617 sync_config_getter.SetupAndInitialFetch(); |
| 617 sync_config_getter.SyncGetLatestProxyConfig(&config); | 618 sync_config_getter.SyncGetLatestProxyConfig(&config); |
| 618 | 619 |
| 619 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); | 620 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 | 889 |
| 889 false, // auto_detect | 890 false, // auto_detect |
| 890 GURL(), // pac_url | 891 GURL(), // pac_url |
| 891 ProxyRulesExpectation::Single( | 892 ProxyRulesExpectation::Single( |
| 892 "www.google.com:80", | 893 "www.google.com:80", |
| 893 "*.google.com,*foo.com:99,1.2.3.4:22,127.0.0.1/8"), | 894 "*.google.com,*foo.com:99,1.2.3.4:22,127.0.0.1/8"), |
| 894 }, | 895 }, |
| 895 }; | 896 }; |
| 896 | 897 |
| 897 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 898 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 898 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, | 899 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i, |
| 899 tests[i].description.c_str())); | 900 tests[i].description.c_str())); |
| 900 MockEnvironment* env = new MockEnvironment; | 901 MockEnvironment* env = new MockEnvironment; |
| 901 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; | 902 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; |
| 902 SynchConfigGetter sync_config_getter( | 903 SynchConfigGetter sync_config_getter( |
| 903 new ProxyConfigServiceLinux(env, gconf_getter)); | 904 new ProxyConfigServiceLinux(env, gconf_getter)); |
| 904 ProxyConfig config; | 905 ProxyConfig config; |
| 905 env->values = tests[i].values; | 906 env->values = tests[i].values; |
| 906 sync_config_getter.SetupAndInitialFetch(); | 907 sync_config_getter.SetupAndInitialFetch(); |
| 907 sync_config_getter.SyncGetLatestProxyConfig(&config); | 908 sync_config_getter.SyncGetLatestProxyConfig(&config); |
| 908 | 909 |
| 909 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); | 910 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 ProxyRulesExpectation::PerScheme( | 1286 ProxyRulesExpectation::PerScheme( |
| 1286 "www.normal.com:80", // http | 1287 "www.normal.com:80", // http |
| 1287 "www.secure.com:80", // https | 1288 "www.secure.com:80", // https |
| 1288 "ftp.foo.com:80", // ftp | 1289 "ftp.foo.com:80", // ftp |
| 1289 "*.google.com,*.kde.org"), // bypass rules | 1290 "*.google.com,*.kde.org"), // bypass rules |
| 1290 }, | 1291 }, |
| 1291 | 1292 |
| 1292 }; | 1293 }; |
| 1293 | 1294 |
| 1294 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1295 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 1295 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, | 1296 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i, |
| 1296 tests[i].description.c_str())); | 1297 tests[i].description.c_str())); |
| 1297 MockEnvironment* env = new MockEnvironment; | 1298 MockEnvironment* env = new MockEnvironment; |
| 1298 env->values = tests[i].env_values; | 1299 env->values = tests[i].env_values; |
| 1299 // Force the KDE getter to be used and tell it where the test is. | 1300 // Force the KDE getter to be used and tell it where the test is. |
| 1300 env->values.DESKTOP_SESSION = "kde4"; | 1301 env->values.DESKTOP_SESSION = "kde4"; |
| 1301 env->values.KDEHOME = kde_home_.value().c_str(); | 1302 env->values.KDEHOME = kde_home_.value().c_str(); |
| 1302 SynchConfigGetter sync_config_getter( | 1303 SynchConfigGetter sync_config_getter( |
| 1303 new ProxyConfigServiceLinux(env)); | 1304 new ProxyConfigServiceLinux(env)); |
| 1304 ProxyConfig config; | 1305 ProxyConfig config; |
| 1305 // Overwrite the kioslaverc file. | 1306 // Overwrite the kioslaverc file. |
| 1306 file_util::WriteFile(kioslaverc_, tests[i].kioslaverc.c_str(), | 1307 file_util::WriteFile(kioslaverc_, tests[i].kioslaverc.c_str(), |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 new ProxyConfigServiceLinux(env)); | 1401 new ProxyConfigServiceLinux(env)); |
| 1401 ProxyConfig config; | 1402 ProxyConfig config; |
| 1402 sync_config_getter.SetupAndInitialFetch(); | 1403 sync_config_getter.SetupAndInitialFetch(); |
| 1403 sync_config_getter.SyncGetLatestProxyConfig(&config); | 1404 sync_config_getter.SyncGetLatestProxyConfig(&config); |
| 1404 EXPECT_TRUE(config.auto_detect()); | 1405 EXPECT_TRUE(config.auto_detect()); |
| 1405 EXPECT_EQ(GURL(), config.pac_url()); | 1406 EXPECT_EQ(GURL(), config.pac_url()); |
| 1406 } | 1407 } |
| 1407 } | 1408 } |
| 1408 | 1409 |
| 1409 } // namespace net | 1410 } // namespace net |
| OLD | NEW |