| 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/dns/mojo_host_resolver_impl.h" | 5 #include "net/dns/mojo_host_resolver_impl.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 void SetResolveCallback(base::Closure callback) { | 99 void SetResolveCallback(base::Closure callback) { |
| 100 resolve_callback_ = callback; | 100 resolve_callback_ = callback; |
| 101 } | 101 } |
| 102 | 102 |
| 103 // Overridden from MockHostResolver. | 103 // Overridden from MockHostResolver. |
| 104 int Resolve(const RequestInfo& info, | 104 int Resolve(const RequestInfo& info, |
| 105 RequestPriority priority, | 105 RequestPriority priority, |
| 106 AddressList* addresses, | 106 AddressList* addresses, |
| 107 const CompletionCallback& callback, | 107 const CompletionCallback& callback, |
| 108 std::unique_ptr<Request>* request, | 108 std::unique_ptr<Request>* request, |
| 109 const BoundNetLog& net_log) override; | 109 const NetLogWithSource& net_log) override; |
| 110 | 110 |
| 111 private: | 111 private: |
| 112 base::Closure resolve_callback_; | 112 base::Closure resolve_callback_; |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 int CallbackMockHostResolver::Resolve(const RequestInfo& info, | 115 int CallbackMockHostResolver::Resolve(const RequestInfo& info, |
| 116 RequestPriority priority, | 116 RequestPriority priority, |
| 117 AddressList* addresses, | 117 AddressList* addresses, |
| 118 const CompletionCallback& callback, | 118 const CompletionCallback& callback, |
| 119 std::unique_ptr<Request>* request, | 119 std::unique_ptr<Request>* request, |
| 120 const BoundNetLog& net_log) { | 120 const NetLogWithSource& net_log) { |
| 121 int result = MockHostResolver::Resolve(info, priority, addresses, callback, | 121 int result = MockHostResolver::Resolve(info, priority, addresses, callback, |
| 122 request, net_log); | 122 request, net_log); |
| 123 if (!resolve_callback_.is_null()) { | 123 if (!resolve_callback_.is_null()) { |
| 124 resolve_callback_.Run(); | 124 resolve_callback_.Run(); |
| 125 resolve_callback_.Reset(); | 125 resolve_callback_.Reset(); |
| 126 } | 126 } |
| 127 return result; | 127 return result; |
| 128 } | 128 } |
| 129 | 129 |
| 130 } // namespace | 130 } // namespace |
| 131 | 131 |
| 132 class MojoHostResolverImplTest : public testing::Test { | 132 class MojoHostResolverImplTest : public testing::Test { |
| 133 protected: | 133 protected: |
| 134 void SetUp() override { | 134 void SetUp() override { |
| 135 mock_host_resolver_.rules()->AddRule("example.com", "1.2.3.4"); | 135 mock_host_resolver_.rules()->AddRule("example.com", "1.2.3.4"); |
| 136 mock_host_resolver_.rules()->AddRule("chromium.org", "8.8.8.8"); | 136 mock_host_resolver_.rules()->AddRule("chromium.org", "8.8.8.8"); |
| 137 mock_host_resolver_.rules()->AddSimulatedFailure("failure.fail"); | 137 mock_host_resolver_.rules()->AddSimulatedFailure("failure.fail"); |
| 138 | 138 |
| 139 resolver_service_.reset( | 139 resolver_service_.reset( |
| 140 new MojoHostResolverImpl(&mock_host_resolver_, BoundNetLog())); | 140 new MojoHostResolverImpl(&mock_host_resolver_, NetLogWithSource())); |
| 141 } | 141 } |
| 142 | 142 |
| 143 interfaces::HostResolverRequestInfoPtr CreateRequest(const std::string& host, | 143 interfaces::HostResolverRequestInfoPtr CreateRequest(const std::string& host, |
| 144 uint16_t port, | 144 uint16_t port, |
| 145 bool is_my_ip_address) { | 145 bool is_my_ip_address) { |
| 146 interfaces::HostResolverRequestInfoPtr request = | 146 interfaces::HostResolverRequestInfoPtr request = |
| 147 interfaces::HostResolverRequestInfo::New(); | 147 interfaces::HostResolverRequestInfo::New(); |
| 148 request->host = host; | 148 request->host = host; |
| 149 request->port = port; | 149 request->port = port; |
| 150 request->address_family = interfaces::AddressFamily::IPV4; | 150 request->address_family = interfaces::AddressFamily::IPV4; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 WaitForRequests(1); | 283 WaitForRequests(1); |
| 284 | 284 |
| 285 client.reset(); | 285 client.reset(); |
| 286 base::RunLoop().RunUntilIdle(); | 286 base::RunLoop().RunUntilIdle(); |
| 287 | 287 |
| 288 mock_host_resolver_.ResolveAllPending(); | 288 mock_host_resolver_.ResolveAllPending(); |
| 289 base::RunLoop().RunUntilIdle(); | 289 base::RunLoop().RunUntilIdle(); |
| 290 } | 290 } |
| 291 | 291 |
| 292 } // namespace net | 292 } // namespace net |
| OLD | NEW |