OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_service_mojo.h" | 5 #include "net/proxy/proxy_service_mojo.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/memory/singleton.h" | |
15 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
16 #include "base/values.h" | 15 #include "base/values.h" |
17 #include "mojo/public/cpp/bindings/strong_binding.h" | |
18 #include "net/base/network_delegate_impl.h" | 16 #include "net/base/network_delegate_impl.h" |
19 #include "net/base/test_completion_callback.h" | 17 #include "net/base/test_completion_callback.h" |
20 #include "net/dns/mock_host_resolver.h" | 18 #include "net/dns/mock_host_resolver.h" |
21 #include "net/log/net_log_event_type.h" | 19 #include "net/log/net_log_event_type.h" |
22 #include "net/log/net_log_with_source.h" | 20 #include "net/log/net_log_with_source.h" |
23 #include "net/log/test_net_log.h" | 21 #include "net/log/test_net_log.h" |
24 #include "net/log/test_net_log_entry.h" | 22 #include "net/log/test_net_log_entry.h" |
25 #include "net/proxy/dhcp_proxy_script_fetcher.h" | 23 #include "net/proxy/dhcp_proxy_script_fetcher.h" |
26 #include "net/proxy/mock_proxy_script_fetcher.h" | 24 #include "net/proxy/mock_proxy_script_fetcher.h" |
27 #include "net/proxy/mojo_proxy_resolver_factory.h" | 25 #include "net/proxy/mojo_proxy_resolver_factory.h" |
28 #include "net/proxy/mojo_proxy_resolver_factory_impl.h" | |
29 #include "net/proxy/proxy_config_service_fixed.h" | 26 #include "net/proxy/proxy_config_service_fixed.h" |
30 #include "net/proxy/proxy_service.h" | 27 #include "net/proxy/proxy_service.h" |
| 28 #include "net/proxy/test_mojo_proxy_resolver_factory.h" |
31 #include "net/test/event_waiter.h" | 29 #include "net/test/event_waiter.h" |
32 #include "net/test/gtest_util.h" | 30 #include "net/test/gtest_util.h" |
33 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
35 #include "url/gurl.h" | 33 #include "url/gurl.h" |
36 | 34 |
37 using net::test::IsOk; | 35 using net::test::IsOk; |
38 | 36 |
39 namespace net { | 37 namespace net { |
40 | 38 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 AddressList* addresses, | 115 AddressList* addresses, |
118 const CompletionCallback& callback, | 116 const CompletionCallback& callback, |
119 std::unique_ptr<Request>* out_req, | 117 std::unique_ptr<Request>* out_req, |
120 const NetLogWithSource& net_log) override { | 118 const NetLogWithSource& net_log) override { |
121 net_log.AddEvent(NetLogEventType::HOST_RESOLVER_IMPL_JOB); | 119 net_log.AddEvent(NetLogEventType::HOST_RESOLVER_IMPL_JOB); |
122 return MockHostResolver::Resolve(info, priority, addresses, callback, | 120 return MockHostResolver::Resolve(info, priority, addresses, callback, |
123 out_req, net_log); | 121 out_req, net_log); |
124 } | 122 } |
125 }; | 123 }; |
126 | 124 |
127 class InProcessMojoProxyResolverFactory : public MojoProxyResolverFactory { | |
128 public: | |
129 static InProcessMojoProxyResolverFactory* GetInstance() { | |
130 return base::Singleton<InProcessMojoProxyResolverFactory>::get(); | |
131 } | |
132 | |
133 // Overridden from MojoProxyResolverFactory: | |
134 std::unique_ptr<base::ScopedClosureRunner> CreateResolver( | |
135 const std::string& pac_script, | |
136 mojo::InterfaceRequest<interfaces::ProxyResolver> req, | |
137 interfaces::ProxyResolverFactoryRequestClientPtr client) override { | |
138 factory_->CreateResolver(pac_script, std::move(req), std::move(client)); | |
139 return nullptr; | |
140 } | |
141 | |
142 private: | |
143 InProcessMojoProxyResolverFactory() { | |
144 mojo::MakeStrongBinding(base::MakeUnique<MojoProxyResolverFactoryImpl>(), | |
145 mojo::MakeRequest(&factory_)); | |
146 } | |
147 ~InProcessMojoProxyResolverFactory() override = default; | |
148 friend struct base::DefaultSingletonTraits<InProcessMojoProxyResolverFactory>; | |
149 | |
150 interfaces::ProxyResolverFactoryPtr factory_; | |
151 | |
152 DISALLOW_COPY_AND_ASSIGN(InProcessMojoProxyResolverFactory); | |
153 }; | |
154 | |
155 } // namespace | 125 } // namespace |
156 | 126 |
157 class ProxyServiceMojoTest : public testing::Test, | 127 class ProxyServiceMojoTest : public testing::Test, |
158 public MojoProxyResolverFactory { | 128 public MojoProxyResolverFactory { |
159 protected: | 129 protected: |
160 void SetUp() override { | 130 void SetUp() override { |
161 mock_host_resolver_.rules()->AddRule("example.com", "1.2.3.4"); | 131 mock_host_resolver_.rules()->AddRule("example.com", "1.2.3.4"); |
162 | 132 |
163 fetcher_ = new MockProxyScriptFetcher; | 133 fetcher_ = new MockProxyScriptFetcher; |
164 proxy_service_ = CreateProxyServiceUsingMojoFactory( | 134 proxy_service_ = CreateProxyServiceUsingMojoFactory( |
165 this, base::MakeUnique<ProxyConfigServiceFixed>( | 135 this, base::MakeUnique<ProxyConfigServiceFixed>( |
166 ProxyConfig::CreateFromCustomPacURL(GURL(kPacUrl))), | 136 ProxyConfig::CreateFromCustomPacURL(GURL(kPacUrl))), |
167 fetcher_, base::MakeUnique<DoNothingDhcpProxyScriptFetcher>(), | 137 fetcher_, base::MakeUnique<DoNothingDhcpProxyScriptFetcher>(), |
168 &mock_host_resolver_, &net_log_, &network_delegate_); | 138 &mock_host_resolver_, &net_log_, &network_delegate_); |
169 } | 139 } |
170 | 140 |
171 std::unique_ptr<base::ScopedClosureRunner> CreateResolver( | 141 std::unique_ptr<base::ScopedClosureRunner> CreateResolver( |
172 const std::string& pac_script, | 142 const std::string& pac_script, |
173 mojo::InterfaceRequest<interfaces::ProxyResolver> req, | 143 mojo::InterfaceRequest<interfaces::ProxyResolver> req, |
174 interfaces::ProxyResolverFactoryRequestClientPtr client) override { | 144 interfaces::ProxyResolverFactoryRequestClientPtr client) override { |
175 InProcessMojoProxyResolverFactory::GetInstance()->CreateResolver( | 145 TestMojoProxyResolverFactory::GetInstance()->CreateResolver( |
176 pac_script, std::move(req), std::move(client)); | 146 pac_script, std::move(req), std::move(client)); |
177 return base::MakeUnique<base::ScopedClosureRunner>( | 147 return base::MakeUnique<base::ScopedClosureRunner>( |
178 on_delete_closure_.closure()); | 148 on_delete_closure_.closure()); |
179 } | 149 } |
180 | 150 |
181 TestNetworkDelegate network_delegate_; | 151 TestNetworkDelegate network_delegate_; |
182 LoggingMockHostResolver mock_host_resolver_; | 152 LoggingMockHostResolver mock_host_resolver_; |
183 MockProxyScriptFetcher* fetcher_; // Owned by |proxy_service_|. | 153 MockProxyScriptFetcher* fetcher_; // Owned by |proxy_service_|. |
184 TestNetLog net_log_; | 154 TestNetLog net_log_; |
185 TestClosure on_delete_closure_; | 155 TestClosure on_delete_closure_; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 258 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
289 EXPECT_EQ("DIRECT", info.ToPacString()); | 259 EXPECT_EQ("DIRECT", info.ToPacString()); |
290 EXPECT_EQ(0u, mock_host_resolver_.num_resolve()); | 260 EXPECT_EQ(0u, mock_host_resolver_.num_resolve()); |
291 | 261 |
292 TestNetLogEntry::List entries; | 262 TestNetLogEntry::List entries; |
293 net_log_.GetEntries(&entries); | 263 net_log_.GetEntries(&entries); |
294 CheckCapturedNetLogEntries(entries); | 264 CheckCapturedNetLogEntries(entries); |
295 } | 265 } |
296 | 266 |
297 } // namespace net | 267 } // namespace net |
OLD | NEW |