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