| 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_android.h" | 5 #include "net/proxy/proxy_config_service_android.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" |
| 14 #include "net/proxy/proxy_config.h" | 15 #include "net/proxy/proxy_config.h" |
| 15 #include "net/proxy/proxy_info.h" | 16 #include "net/proxy/proxy_info.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 namespace net { | 19 namespace net { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 class TestObserver : public ProxyConfigService::Observer { | 23 class TestObserver : public ProxyConfigService::Observer { |
| 23 public: | 24 public: |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 message_loop_(base::MessageLoop::current()), | 58 message_loop_(base::MessageLoop::current()), |
| 58 service_(message_loop_->task_runner(), | 59 service_(message_loop_->task_runner(), |
| 59 message_loop_->task_runner(), | 60 message_loop_->task_runner(), |
| 60 base::Bind(&ProxyConfigServiceAndroidTestBase::GetProperty, | 61 base::Bind(&ProxyConfigServiceAndroidTestBase::GetProperty, |
| 61 base::Unretained(this))) {} | 62 base::Unretained(this))) {} |
| 62 | 63 |
| 63 ~ProxyConfigServiceAndroidTestBase() override {} | 64 ~ProxyConfigServiceAndroidTestBase() override {} |
| 64 | 65 |
| 65 // testing::Test: | 66 // testing::Test: |
| 66 void SetUp() override { | 67 void SetUp() override { |
| 67 message_loop_->RunUntilIdle(); | 68 base::RunLoop().RunUntilIdle(); |
| 68 service_.AddObserver(&observer_); | 69 service_.AddObserver(&observer_); |
| 69 } | 70 } |
| 70 | 71 |
| 71 void TearDown() override { service_.RemoveObserver(&observer_); } | 72 void TearDown() override { service_.RemoveObserver(&observer_); } |
| 72 | 73 |
| 73 void ClearConfiguration() { | 74 void ClearConfiguration() { |
| 74 configuration_.clear(); | 75 configuration_.clear(); |
| 75 } | 76 } |
| 76 | 77 |
| 77 void AddProperty(const std::string& key, const std::string& value) { | 78 void AddProperty(const std::string& key, const std::string& value) { |
| 78 configuration_[key] = value; | 79 configuration_[key] = value; |
| 79 } | 80 } |
| 80 | 81 |
| 81 std::string GetProperty(const std::string& key) { | 82 std::string GetProperty(const std::string& key) { |
| 82 StringMap::const_iterator it = configuration_.find(key); | 83 StringMap::const_iterator it = configuration_.find(key); |
| 83 if (it == configuration_.end()) | 84 if (it == configuration_.end()) |
| 84 return std::string(); | 85 return std::string(); |
| 85 return it->second; | 86 return it->second; |
| 86 } | 87 } |
| 87 | 88 |
| 88 void ProxySettingsChanged() { | 89 void ProxySettingsChanged() { |
| 89 service_.ProxySettingsChanged(); | 90 service_.ProxySettingsChanged(); |
| 90 message_loop_->RunUntilIdle(); | 91 base::RunLoop().RunUntilIdle(); |
| 91 } | 92 } |
| 92 | 93 |
| 93 void TestMapping(const std::string& url, const std::string& expected) { | 94 void TestMapping(const std::string& url, const std::string& expected) { |
| 94 ProxyConfigService::ConfigAvailability availability; | 95 ProxyConfigService::ConfigAvailability availability; |
| 95 ProxyConfig proxy_config; | 96 ProxyConfig proxy_config; |
| 96 availability = service_.GetLatestProxyConfig(&proxy_config); | 97 availability = service_.GetLatestProxyConfig(&proxy_config); |
| 97 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, availability); | 98 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, availability); |
| 98 ProxyInfo proxy_info; | 99 ProxyInfo proxy_info; |
| 99 proxy_config.proxy_rules().Apply(GURL(url), &proxy_info); | 100 proxy_config.proxy_rules().Apply(GURL(url), &proxy_info); |
| 100 EXPECT_EQ(expected, proxy_info.ToPacString()); | 101 EXPECT_EQ(expected, proxy_info.ToPacString()); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 TEST_F(ProxyConfigServiceAndroidTest, HttpProxySupercedesSocks) { | 343 TEST_F(ProxyConfigServiceAndroidTest, HttpProxySupercedesSocks) { |
| 343 // SOCKS proxy is ignored if default HTTP proxy defined. | 344 // SOCKS proxy is ignored if default HTTP proxy defined. |
| 344 AddProperty("proxyHost", "defaultproxy.com"); | 345 AddProperty("proxyHost", "defaultproxy.com"); |
| 345 AddProperty("socksProxyHost", "socksproxy.com"); | 346 AddProperty("socksProxyHost", "socksproxy.com"); |
| 346 AddProperty("socksProxyPort", "9000"); | 347 AddProperty("socksProxyPort", "9000"); |
| 347 ProxySettingsChanged(); | 348 ProxySettingsChanged(); |
| 348 TestMapping("http://example.com/", "PROXY defaultproxy.com:80"); | 349 TestMapping("http://example.com/", "PROXY defaultproxy.com:80"); |
| 349 } | 350 } |
| 350 | 351 |
| 351 } // namespace net | 352 } // namespace net |
| OLD | NEW |