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 "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 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1495 tests[i].description.c_str())); | 1495 tests[i].description.c_str())); |
1496 MockEnvironment* env = new MockEnvironment; | 1496 MockEnvironment* env = new MockEnvironment; |
1497 env->values = tests[i].env_values; | 1497 env->values = tests[i].env_values; |
1498 // Force the KDE getter to be used and tell it where the test is. | 1498 // Force the KDE getter to be used and tell it where the test is. |
1499 env->values.DESKTOP_SESSION = "kde4"; | 1499 env->values.DESKTOP_SESSION = "kde4"; |
1500 env->values.KDEHOME = kde_home_.value().c_str(); | 1500 env->values.KDEHOME = kde_home_.value().c_str(); |
1501 SynchConfigGetter sync_config_getter( | 1501 SynchConfigGetter sync_config_getter( |
1502 new ProxyConfigServiceLinux(env)); | 1502 new ProxyConfigServiceLinux(env)); |
1503 ProxyConfig config; | 1503 ProxyConfig config; |
1504 // Overwrite the kioslaverc file. | 1504 // Overwrite the kioslaverc file. |
1505 file_util::WriteFile(kioslaverc_, tests[i].kioslaverc.c_str(), | 1505 base::WriteFile(kioslaverc_, tests[i].kioslaverc.c_str(), |
1506 tests[i].kioslaverc.length()); | 1506 tests[i].kioslaverc.length()); |
1507 sync_config_getter.SetupAndInitialFetch(); | 1507 sync_config_getter.SetupAndInitialFetch(); |
1508 ProxyConfigService::ConfigAvailability availability = | 1508 ProxyConfigService::ConfigAvailability availability = |
1509 sync_config_getter.SyncGetLatestProxyConfig(&config); | 1509 sync_config_getter.SyncGetLatestProxyConfig(&config); |
1510 EXPECT_EQ(tests[i].availability, availability); | 1510 EXPECT_EQ(tests[i].availability, availability); |
1511 | 1511 |
1512 if (availability == ProxyConfigService::CONFIG_VALID) { | 1512 if (availability == ProxyConfigService::CONFIG_VALID) { |
1513 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); | 1513 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); |
1514 EXPECT_EQ(tests[i].pac_url, config.pac_url()); | 1514 EXPECT_EQ(tests[i].pac_url, config.pac_url()); |
1515 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); | 1515 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); |
1516 } | 1516 } |
1517 } | 1517 } |
1518 } | 1518 } |
1519 | 1519 |
1520 TEST_F(ProxyConfigServiceLinuxTest, KDEHomePicker) { | 1520 TEST_F(ProxyConfigServiceLinuxTest, KDEHomePicker) { |
1521 // Auto detect proxy settings. | 1521 // Auto detect proxy settings. |
1522 std::string slaverc3 = "[Proxy Settings]\nProxyType=3\n"; | 1522 std::string slaverc3 = "[Proxy Settings]\nProxyType=3\n"; |
1523 // Valid PAC URL. | 1523 // Valid PAC URL. |
1524 std::string slaverc4 = "[Proxy Settings]\nProxyType=2\n" | 1524 std::string slaverc4 = "[Proxy Settings]\nProxyType=2\n" |
1525 "Proxy Config Script=http://wpad/wpad.dat\n"; | 1525 "Proxy Config Script=http://wpad/wpad.dat\n"; |
1526 GURL slaverc4_pac_url("http://wpad/wpad.dat"); | 1526 GURL slaverc4_pac_url("http://wpad/wpad.dat"); |
1527 | 1527 |
1528 // Overwrite the .kde kioslaverc file. | 1528 // Overwrite the .kde kioslaverc file. |
1529 file_util::WriteFile(kioslaverc_, slaverc3.c_str(), slaverc3.length()); | 1529 base::WriteFile(kioslaverc_, slaverc3.c_str(), slaverc3.length()); |
1530 | 1530 |
1531 // If .kde4 exists it will mess up the first test. It should not, as | 1531 // If .kde4 exists it will mess up the first test. It should not, as |
1532 // we created the directory for $HOME in the test setup. | 1532 // we created the directory for $HOME in the test setup. |
1533 CHECK(!base::DirectoryExists(kde4_home_)); | 1533 CHECK(!base::DirectoryExists(kde4_home_)); |
1534 | 1534 |
1535 { SCOPED_TRACE("KDE4, no .kde4 directory, verify fallback"); | 1535 { SCOPED_TRACE("KDE4, no .kde4 directory, verify fallback"); |
1536 MockEnvironment* env = new MockEnvironment; | 1536 MockEnvironment* env = new MockEnvironment; |
1537 env->values.DESKTOP_SESSION = "kde4"; | 1537 env->values.DESKTOP_SESSION = "kde4"; |
1538 env->values.HOME = user_home_.value().c_str(); | 1538 env->values.HOME = user_home_.value().c_str(); |
1539 SynchConfigGetter sync_config_getter( | 1539 SynchConfigGetter sync_config_getter( |
1540 new ProxyConfigServiceLinux(env)); | 1540 new ProxyConfigServiceLinux(env)); |
1541 ProxyConfig config; | 1541 ProxyConfig config; |
1542 sync_config_getter.SetupAndInitialFetch(); | 1542 sync_config_getter.SetupAndInitialFetch(); |
1543 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, | 1543 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, |
1544 sync_config_getter.SyncGetLatestProxyConfig(&config)); | 1544 sync_config_getter.SyncGetLatestProxyConfig(&config)); |
1545 EXPECT_TRUE(config.auto_detect()); | 1545 EXPECT_TRUE(config.auto_detect()); |
1546 EXPECT_EQ(GURL(), config.pac_url()); | 1546 EXPECT_EQ(GURL(), config.pac_url()); |
1547 } | 1547 } |
1548 | 1548 |
1549 // Now create .kde4 and put a kioslaverc in the config directory. | 1549 // Now create .kde4 and put a kioslaverc in the config directory. |
1550 // Note that its timestamp will be at least as new as the .kde one. | 1550 // Note that its timestamp will be at least as new as the .kde one. |
1551 base::CreateDirectory(kde4_config_); | 1551 base::CreateDirectory(kde4_config_); |
1552 file_util::WriteFile(kioslaverc4_, slaverc4.c_str(), slaverc4.length()); | 1552 base::WriteFile(kioslaverc4_, slaverc4.c_str(), slaverc4.length()); |
1553 CHECK(base::PathExists(kioslaverc4_)); | 1553 CHECK(base::PathExists(kioslaverc4_)); |
1554 | 1554 |
1555 { SCOPED_TRACE("KDE4, .kde4 directory present, use it"); | 1555 { SCOPED_TRACE("KDE4, .kde4 directory present, use it"); |
1556 MockEnvironment* env = new MockEnvironment; | 1556 MockEnvironment* env = new MockEnvironment; |
1557 env->values.DESKTOP_SESSION = "kde4"; | 1557 env->values.DESKTOP_SESSION = "kde4"; |
1558 env->values.HOME = user_home_.value().c_str(); | 1558 env->values.HOME = user_home_.value().c_str(); |
1559 SynchConfigGetter sync_config_getter( | 1559 SynchConfigGetter sync_config_getter( |
1560 new ProxyConfigServiceLinux(env)); | 1560 new ProxyConfigServiceLinux(env)); |
1561 ProxyConfig config; | 1561 ProxyConfig config; |
1562 sync_config_getter.SetupAndInitialFetch(); | 1562 sync_config_getter.SetupAndInitialFetch(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1608 ProxyConfig config; | 1608 ProxyConfig config; |
1609 sync_config_getter.SetupAndInitialFetch(); | 1609 sync_config_getter.SetupAndInitialFetch(); |
1610 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, | 1610 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, |
1611 sync_config_getter.SyncGetLatestProxyConfig(&config)); | 1611 sync_config_getter.SyncGetLatestProxyConfig(&config)); |
1612 EXPECT_TRUE(config.auto_detect()); | 1612 EXPECT_TRUE(config.auto_detect()); |
1613 EXPECT_EQ(GURL(), config.pac_url()); | 1613 EXPECT_EQ(GURL(), config.pac_url()); |
1614 } | 1614 } |
1615 } | 1615 } |
1616 | 1616 |
1617 } // namespace net | 1617 } // namespace net |
OLD | NEW |