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), |
58 message_loop_(base::MessageLoop::current()), | 68 message_loop_(base::MessageLoop::current()), |
69 // Prepare Java's Looper before constructing |service_| as it creates | |
70 // ProxyChangeListener which requires a Looper. | |
71 java_looper_preparer_(), | |
xunjieli
2017/04/13 18:44:54
hmm.. I guess this isn't safe to omit? I'd assume
pauljensen
2017/05/01 15:35:53
You're right, I think I put it here so the comment
| |
59 service_(message_loop_->task_runner(), | 72 service_(message_loop_->task_runner(), |
60 message_loop_->task_runner(), | 73 message_loop_->task_runner(), |
61 base::Bind(&ProxyConfigServiceAndroidTestBase::GetProperty, | 74 base::Bind(&ProxyConfigServiceAndroidTestBase::GetProperty, |
62 base::Unretained(this))) {} | 75 base::Unretained(this))) {} |
63 | 76 |
64 ~ProxyConfigServiceAndroidTestBase() override {} | 77 ~ProxyConfigServiceAndroidTestBase() override {} |
65 | 78 |
66 // testing::Test: | 79 // testing::Test: |
67 void SetUp() override { | 80 void SetUp() override { |
68 base::RunLoop().RunUntilIdle(); | 81 base::RunLoop().RunUntilIdle(); |
(...skipping 28 matching lines...) Expand all Loading... | |
97 availability = service_.GetLatestProxyConfig(&proxy_config); | 110 availability = service_.GetLatestProxyConfig(&proxy_config); |
98 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, availability); | 111 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, availability); |
99 ProxyInfo proxy_info; | 112 ProxyInfo proxy_info; |
100 proxy_config.proxy_rules().Apply(GURL(url), &proxy_info); | 113 proxy_config.proxy_rules().Apply(GURL(url), &proxy_info); |
101 EXPECT_EQ(expected, proxy_info.ToPacString()); | 114 EXPECT_EQ(expected, proxy_info.ToPacString()); |
102 } | 115 } |
103 | 116 |
104 StringMap configuration_; | 117 StringMap configuration_; |
105 TestObserver observer_; | 118 TestObserver observer_; |
106 base::MessageLoop* const message_loop_; | 119 base::MessageLoop* const message_loop_; |
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 |