Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: net/proxy/proxy_service_mojo_unittest.cc

Issue 2351513002: net: rename BoundNetLog to NetLogWithSource (Closed)
Patch Set: one more fix, content bound_net_log_ Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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());
176 proxy_service_.reset(); 176 proxy_service_.reset();
177 on_delete_closure_.WaitForResult(); 177 on_delete_closure_.WaitForResult();
178 } 178 }
179 179
180 TEST_F(ProxyServiceMojoTest, DnsResolution) { 180 TEST_F(ProxyServiceMojoTest, DnsResolution) {
181 ProxyInfo info; 181 ProxyInfo info;
182 TestCompletionCallback callback; 182 TestCompletionCallback callback;
183 BoundTestNetLog bound_net_log; 183 BoundTestNetLog test_net_log;
184 EXPECT_EQ(ERR_IO_PENDING, 184 EXPECT_EQ(ERR_IO_PENDING,
185 proxy_service_->ResolveProxy(GURL("http://foo"), std::string(), 185 proxy_service_->ResolveProxy(GURL("http://foo"), std::string(),
186 &info, callback.callback(), nullptr, 186 &info, callback.callback(), nullptr,
187 nullptr, bound_net_log.bound())); 187 nullptr, test_net_log.bound()));
188 188
189 // Proxy script fetcher should have a fetch triggered by the first 189 // Proxy script fetcher should have a fetch triggered by the first
190 // |ResolveProxy()| request. 190 // |ResolveProxy()| request.
191 EXPECT_TRUE(fetcher_->has_pending_request()); 191 EXPECT_TRUE(fetcher_->has_pending_request());
192 EXPECT_EQ(GURL(kPacUrl), fetcher_->pending_request_url()); 192 EXPECT_EQ(GURL(kPacUrl), fetcher_->pending_request_url());
193 fetcher_->NotifyFetchCompletion(OK, kDnsResolvePacScript); 193 fetcher_->NotifyFetchCompletion(OK, kDnsResolvePacScript);
194 194
195 EXPECT_THAT(callback.WaitForResult(), IsOk()); 195 EXPECT_THAT(callback.WaitForResult(), IsOk());
196 EXPECT_EQ("QUIC bar:4321", info.ToPacString()); 196 EXPECT_EQ("QUIC bar:4321", info.ToPacString());
197 EXPECT_EQ(1u, mock_host_resolver_.num_resolve()); 197 EXPECT_EQ(1u, mock_host_resolver_.num_resolve());
198 proxy_service_.reset(); 198 proxy_service_.reset();
199 on_delete_closure_.WaitForResult(); 199 on_delete_closure_.WaitForResult();
200 200
201 TestNetLogEntry::List entries; 201 TestNetLogEntry::List entries;
202 bound_net_log.GetEntries(&entries); 202 test_net_log.GetEntries(&entries);
203 // There should be one entry with type TYPE_HOST_RESOLVER_IMPL_JOB. 203 // There should be one entry with type TYPE_HOST_RESOLVER_IMPL_JOB.
204 EXPECT_EQ(1, std::count_if(entries.begin(), entries.end(), 204 EXPECT_EQ(1, std::count_if(entries.begin(), entries.end(),
205 [](const TestNetLogEntry& entry) { 205 [](const TestNetLogEntry& entry) {
206 return entry.type == 206 return entry.type ==
207 NetLogEventType::HOST_RESOLVER_IMPL_JOB; 207 NetLogEventType::HOST_RESOLVER_IMPL_JOB;
208 })); 208 }));
209 } 209 }
210 210
211 TEST_F(ProxyServiceMojoTest, Error) { 211 TEST_F(ProxyServiceMojoTest, Error) {
212 ProxyInfo info; 212 ProxyInfo info;
213 TestCompletionCallback callback; 213 TestCompletionCallback callback;
214 BoundTestNetLog bound_net_log; 214 BoundTestNetLog test_net_log;
215 EXPECT_EQ(ERR_IO_PENDING, 215 EXPECT_EQ(ERR_IO_PENDING,
216 proxy_service_->ResolveProxy(GURL("http://foo"), std::string(), 216 proxy_service_->ResolveProxy(GURL("http://foo"), std::string(),
217 &info, callback.callback(), nullptr, 217 &info, callback.callback(), nullptr,
218 nullptr, bound_net_log.bound())); 218 nullptr, test_net_log.bound()));
219 219
220 // Proxy script fetcher should have a fetch triggered by the first 220 // Proxy script fetcher should have a fetch triggered by the first
221 // |ResolveProxy()| request. 221 // |ResolveProxy()| request.
222 EXPECT_TRUE(fetcher_->has_pending_request()); 222 EXPECT_TRUE(fetcher_->has_pending_request());
223 EXPECT_EQ(GURL(kPacUrl), fetcher_->pending_request_url()); 223 EXPECT_EQ(GURL(kPacUrl), fetcher_->pending_request_url());
224 fetcher_->NotifyFetchCompletion(OK, kThrowingPacScript); 224 fetcher_->NotifyFetchCompletion(OK, kThrowingPacScript);
225 225
226 network_delegate_.event_waiter().WaitForEvent( 226 network_delegate_.event_waiter().WaitForEvent(
227 TestNetworkDelegate::PAC_SCRIPT_ERROR); 227 TestNetworkDelegate::PAC_SCRIPT_ERROR);
228 228
229 EXPECT_THAT(callback.WaitForResult(), IsOk()); 229 EXPECT_THAT(callback.WaitForResult(), IsOk());
230 EXPECT_EQ("DIRECT", info.ToPacString()); 230 EXPECT_EQ("DIRECT", info.ToPacString());
231 EXPECT_EQ(0u, mock_host_resolver_.num_resolve()); 231 EXPECT_EQ(0u, mock_host_resolver_.num_resolve());
232 232
233 TestNetLogEntry::List entries; 233 TestNetLogEntry::List entries;
234 bound_net_log.GetEntries(&entries); 234 test_net_log.GetEntries(&entries);
235 CheckCapturedNetLogEntries(entries); 235 CheckCapturedNetLogEntries(entries);
236 entries.clear(); 236 entries.clear();
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698