| 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 "base/run_loop.h" |
| 15 #include "jni/AndroidProxyConfigServiceTestUtil_jni.h" |
| 15 #include "net/proxy/proxy_config.h" | 16 #include "net/proxy/proxy_config.h" |
| 16 #include "net/proxy/proxy_info.h" | 17 #include "net/proxy/proxy_info.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 class TestObserver : public ProxyConfigService::Observer { | 24 class TestObserver : public ProxyConfigService::Observer { |
| 24 public: | 25 public: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 38 | 39 |
| 39 const ProxyConfig& config() const { | 40 const ProxyConfig& config() const { |
| 40 return config_; | 41 return config_; |
| 41 } | 42 } |
| 42 | 43 |
| 43 private: | 44 private: |
| 44 ProxyConfig config_; | 45 ProxyConfig config_; |
| 45 ProxyConfigService::ConfigAvailability availability_; | 46 ProxyConfigService::ConfigAvailability availability_; |
| 46 }; | 47 }; |
| 47 | 48 |
| 49 // Helper class that simply prepares Java's Looper on construction. |
| 50 class JavaLooperPreparer { |
| 51 public: |
| 52 JavaLooperPreparer() { |
| 53 Java_AndroidProxyConfigServiceTestUtil_prepareLooper( |
| 54 base::android::AttachCurrentThread()); |
| 55 } |
| 56 }; |
| 57 |
| 48 } // namespace | 58 } // namespace |
| 49 | 59 |
| 50 typedef std::map<std::string, std::string> StringMap; | 60 typedef std::map<std::string, std::string> StringMap; |
| 51 | 61 |
| 52 class ProxyConfigServiceAndroidTestBase : public testing::Test { | 62 class ProxyConfigServiceAndroidTestBase : public testing::Test { |
| 53 protected: | 63 protected: |
| 54 // Note that the current thread's message loop is initialized by the test | 64 // Note that the current thread's message loop is initialized by the test |
| 55 // suite (see net/test/net_test_suite.cc). | 65 // suite (see net/test/net_test_suite.cc). |
| 56 ProxyConfigServiceAndroidTestBase(const StringMap& initial_configuration) | 66 ProxyConfigServiceAndroidTestBase(const StringMap& initial_configuration) |
| 57 : configuration_(initial_configuration), | 67 : configuration_(initial_configuration), |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 availability = service_.GetLatestProxyConfig(&proxy_config); | 107 availability = service_.GetLatestProxyConfig(&proxy_config); |
| 98 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, availability); | 108 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, availability); |
| 99 ProxyInfo proxy_info; | 109 ProxyInfo proxy_info; |
| 100 proxy_config.proxy_rules().Apply(GURL(url), &proxy_info); | 110 proxy_config.proxy_rules().Apply(GURL(url), &proxy_info); |
| 101 EXPECT_EQ(expected, proxy_info.ToPacString()); | 111 EXPECT_EQ(expected, proxy_info.ToPacString()); |
| 102 } | 112 } |
| 103 | 113 |
| 104 StringMap configuration_; | 114 StringMap configuration_; |
| 105 TestObserver observer_; | 115 TestObserver observer_; |
| 106 base::MessageLoop* const message_loop_; | 116 base::MessageLoop* const message_loop_; |
| 117 // |java_looper_preparer_| appears before |service_| so that Java's Looper is |
| 118 // prepared before constructing |service_| as it creates a ProxyChangeListener |
| 119 // which requires a Looper. |
| 120 JavaLooperPreparer java_looper_preparer_; |
| 107 ProxyConfigServiceAndroid service_; | 121 ProxyConfigServiceAndroid service_; |
| 108 }; | 122 }; |
| 109 | 123 |
| 110 class ProxyConfigServiceAndroidTest : public ProxyConfigServiceAndroidTestBase { | 124 class ProxyConfigServiceAndroidTest : public ProxyConfigServiceAndroidTestBase { |
| 111 public: | 125 public: |
| 112 ProxyConfigServiceAndroidTest() | 126 ProxyConfigServiceAndroidTest() |
| 113 : ProxyConfigServiceAndroidTestBase(StringMap()) {} | 127 : ProxyConfigServiceAndroidTestBase(StringMap()) {} |
| 114 }; | 128 }; |
| 115 | 129 |
| 116 class ProxyConfigServiceAndroidWithInitialConfigTest | 130 class ProxyConfigServiceAndroidWithInitialConfigTest |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 TEST_F(ProxyConfigServiceAndroidTest, HttpProxySupercedesSocks) { | 357 TEST_F(ProxyConfigServiceAndroidTest, HttpProxySupercedesSocks) { |
| 344 // SOCKS proxy is ignored if default HTTP proxy defined. | 358 // SOCKS proxy is ignored if default HTTP proxy defined. |
| 345 AddProperty("proxyHost", "defaultproxy.com"); | 359 AddProperty("proxyHost", "defaultproxy.com"); |
| 346 AddProperty("socksProxyHost", "socksproxy.com"); | 360 AddProperty("socksProxyHost", "socksproxy.com"); |
| 347 AddProperty("socksProxyPort", "9000"); | 361 AddProperty("socksProxyPort", "9000"); |
| 348 ProxySettingsChanged(); | 362 ProxySettingsChanged(); |
| 349 TestMapping("http://example.com/", "PROXY defaultproxy.com:80"); | 363 TestMapping("http://example.com/", "PROXY defaultproxy.com:80"); |
| 350 } | 364 } |
| 351 | 365 |
| 352 } // namespace net | 366 } // namespace net |
| OLD | NEW |