| 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> |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 EXPECT_EQ(3, line_number); | 108 EXPECT_EQ(3, line_number); |
| 109 } | 109 } |
| 110 | 110 |
| 111 class LoggingMockHostResolver : public MockHostResolver { | 111 class LoggingMockHostResolver : public MockHostResolver { |
| 112 public: | 112 public: |
| 113 int Resolve(const RequestInfo& info, | 113 int Resolve(const RequestInfo& info, |
| 114 RequestPriority priority, | 114 RequestPriority priority, |
| 115 AddressList* addresses, | 115 AddressList* addresses, |
| 116 const CompletionCallback& callback, | 116 const CompletionCallback& callback, |
| 117 std::unique_ptr<Request>* out_req, | 117 std::unique_ptr<Request>* out_req, |
| 118 const BoundNetLog& net_log) override { | 118 const NetLogWithSource& net_log) override { |
| 119 net_log.AddEvent(NetLogEventType::HOST_RESOLVER_IMPL_JOB); | 119 net_log.AddEvent(NetLogEventType::HOST_RESOLVER_IMPL_JOB); |
| 120 return MockHostResolver::Resolve(info, priority, addresses, callback, | 120 return MockHostResolver::Resolve(info, priority, addresses, callback, |
| 121 out_req, net_log); | 121 out_req, net_log); |
| 122 } | 122 } |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 } // namespace | 125 } // namespace |
| 126 | 126 |
| 127 class ProxyServiceMojoTest : public testing::Test, | 127 class ProxyServiceMojoTest : public testing::Test, |
| 128 public MojoProxyResolverFactory { | 128 public MojoProxyResolverFactory { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 155 TestClosure on_delete_closure_; | 155 TestClosure on_delete_closure_; |
| 156 std::unique_ptr<ProxyService> proxy_service_; | 156 std::unique_ptr<ProxyService> proxy_service_; |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 TEST_F(ProxyServiceMojoTest, Basic) { | 159 TEST_F(ProxyServiceMojoTest, Basic) { |
| 160 ProxyInfo info; | 160 ProxyInfo info; |
| 161 TestCompletionCallback callback; | 161 TestCompletionCallback callback; |
| 162 EXPECT_EQ(ERR_IO_PENDING, | 162 EXPECT_EQ(ERR_IO_PENDING, |
| 163 proxy_service_->ResolveProxy(GURL("http://foo"), std::string(), | 163 proxy_service_->ResolveProxy(GURL("http://foo"), std::string(), |
| 164 &info, callback.callback(), nullptr, | 164 &info, callback.callback(), nullptr, |
| 165 nullptr, BoundNetLog())); | 165 nullptr, NetLogWithSource())); |
| 166 | 166 |
| 167 // Proxy script fetcher should have a fetch triggered by the first | 167 // Proxy script fetcher should have a fetch triggered by the first |
| 168 // |ResolveProxy()| request. | 168 // |ResolveProxy()| request. |
| 169 EXPECT_TRUE(fetcher_->has_pending_request()); | 169 EXPECT_TRUE(fetcher_->has_pending_request()); |
| 170 EXPECT_EQ(GURL(kPacUrl), fetcher_->pending_request_url()); | 170 EXPECT_EQ(GURL(kPacUrl), fetcher_->pending_request_url()); |
| 171 fetcher_->NotifyFetchCompletion(OK, kSimplePacScript); | 171 fetcher_->NotifyFetchCompletion(OK, kSimplePacScript); |
| 172 | 172 |
| 173 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 173 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 174 EXPECT_EQ("PROXY foo:1234", info.ToPacString()); | 174 EXPECT_EQ("PROXY foo:1234", info.ToPacString()); |
| 175 EXPECT_EQ(0u, mock_host_resolver_.num_resolve()); | 175 EXPECT_EQ(0u, mock_host_resolver_.num_resolve()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 net_log_.GetEntries(&entries); | 237 net_log_.GetEntries(&entries); |
| 238 CheckCapturedNetLogEntries(entries); | 238 CheckCapturedNetLogEntries(entries); |
| 239 } | 239 } |
| 240 | 240 |
| 241 TEST_F(ProxyServiceMojoTest, ErrorOnInitialization) { | 241 TEST_F(ProxyServiceMojoTest, ErrorOnInitialization) { |
| 242 ProxyInfo info; | 242 ProxyInfo info; |
| 243 TestCompletionCallback callback; | 243 TestCompletionCallback callback; |
| 244 EXPECT_EQ(ERR_IO_PENDING, | 244 EXPECT_EQ(ERR_IO_PENDING, |
| 245 proxy_service_->ResolveProxy(GURL("http://foo"), std::string(), | 245 proxy_service_->ResolveProxy(GURL("http://foo"), std::string(), |
| 246 &info, callback.callback(), nullptr, | 246 &info, callback.callback(), nullptr, |
| 247 nullptr, BoundNetLog())); | 247 nullptr, NetLogWithSource())); |
| 248 | 248 |
| 249 // Proxy script fetcher should have a fetch triggered by the first | 249 // Proxy script fetcher should have a fetch triggered by the first |
| 250 // |ResolveProxy()| request. | 250 // |ResolveProxy()| request. |
| 251 EXPECT_TRUE(fetcher_->has_pending_request()); | 251 EXPECT_TRUE(fetcher_->has_pending_request()); |
| 252 EXPECT_EQ(GURL(kPacUrl), fetcher_->pending_request_url()); | 252 EXPECT_EQ(GURL(kPacUrl), fetcher_->pending_request_url()); |
| 253 fetcher_->NotifyFetchCompletion(OK, kThrowingOnLoadPacScript); | 253 fetcher_->NotifyFetchCompletion(OK, kThrowingOnLoadPacScript); |
| 254 | 254 |
| 255 network_delegate_.event_waiter().WaitForEvent( | 255 network_delegate_.event_waiter().WaitForEvent( |
| 256 TestNetworkDelegate::PAC_SCRIPT_ERROR); | 256 TestNetworkDelegate::PAC_SCRIPT_ERROR); |
| 257 | 257 |
| 258 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 258 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 259 EXPECT_EQ("DIRECT", info.ToPacString()); | 259 EXPECT_EQ("DIRECT", info.ToPacString()); |
| 260 EXPECT_EQ(0u, mock_host_resolver_.num_resolve()); | 260 EXPECT_EQ(0u, mock_host_resolver_.num_resolve()); |
| 261 | 261 |
| 262 TestNetLogEntry::List entries; | 262 TestNetLogEntry::List entries; |
| 263 net_log_.GetEntries(&entries); | 263 net_log_.GetEntries(&entries); |
| 264 CheckCapturedNetLogEntries(entries); | 264 CheckCapturedNetLogEntries(entries); |
| 265 } | 265 } |
| 266 | 266 |
| 267 } // namespace net | 267 } // namespace net |
| OLD | NEW |