OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/multi_threaded_proxy_resolver.h" | 5 #include "net/proxy/multi_threaded_proxy_resolver.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 rv = resolver.SetPacScript( | 187 rv = resolver.SetPacScript( |
188 ProxyResolverScriptData::FromUTF8("pac script bytes"), | 188 ProxyResolverScriptData::FromUTF8("pac script bytes"), |
189 set_script_callback.callback()); | 189 set_script_callback.callback()); |
190 EXPECT_EQ(ERR_IO_PENDING, rv); | 190 EXPECT_EQ(ERR_IO_PENDING, rv); |
191 EXPECT_EQ(OK, set_script_callback.WaitForResult()); | 191 EXPECT_EQ(OK, set_script_callback.WaitForResult()); |
192 EXPECT_EQ(ASCIIToUTF16("pac script bytes"), | 192 EXPECT_EQ(ASCIIToUTF16("pac script bytes"), |
193 mock->last_script_data()->utf16()); | 193 mock->last_script_data()->utf16()); |
194 | 194 |
195 // Start request 0. | 195 // Start request 0. |
196 TestCompletionCallback callback0; | 196 TestCompletionCallback callback0; |
197 CapturingBoundNetLog log0; | 197 BoundTestNetLog log0; |
198 ProxyInfo results0; | 198 ProxyInfo results0; |
199 rv = resolver.GetProxyForURL(GURL("http://request0"), &results0, | 199 rv = resolver.GetProxyForURL(GURL("http://request0"), &results0, |
200 callback0.callback(), NULL, log0.bound()); | 200 callback0.callback(), NULL, log0.bound()); |
201 EXPECT_EQ(ERR_IO_PENDING, rv); | 201 EXPECT_EQ(ERR_IO_PENDING, rv); |
202 | 202 |
203 // Wait for request 0 to finish. | 203 // Wait for request 0 to finish. |
204 rv = callback0.WaitForResult(); | 204 rv = callback0.WaitForResult(); |
205 EXPECT_EQ(0, rv); | 205 EXPECT_EQ(0, rv); |
206 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); | 206 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); |
207 | 207 |
208 // The mock proxy resolver should have written 1 log entry. And | 208 // The mock proxy resolver should have written 1 log entry. And |
209 // on completion, this should have been copied into |log0|. | 209 // on completion, this should have been copied into |log0|. |
210 // We also have 1 log entry that was emitted by the | 210 // We also have 1 log entry that was emitted by the |
211 // MultiThreadedProxyResolver. | 211 // MultiThreadedProxyResolver. |
212 CapturingNetLog::CapturedEntryList entries0; | 212 TestNetLog::CapturedEntryList entries0; |
213 log0.GetEntries(&entries0); | 213 log0.GetEntries(&entries0); |
214 | 214 |
215 ASSERT_EQ(2u, entries0.size()); | 215 ASSERT_EQ(2u, entries0.size()); |
216 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, entries0[0].type); | 216 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, entries0[0].type); |
217 | 217 |
218 // Start 3 more requests (request1 to request3). | 218 // Start 3 more requests (request1 to request3). |
219 | 219 |
220 TestCompletionCallback callback1; | 220 TestCompletionCallback callback1; |
221 ProxyInfo results1; | 221 ProxyInfo results1; |
222 rv = resolver.GetProxyForURL(GURL("http://request1"), &results1, | 222 rv = resolver.GetProxyForURL(GURL("http://request1"), &results1, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 init_callback.callback()); | 268 init_callback.callback()); |
269 EXPECT_EQ(OK, init_callback.WaitForResult()); | 269 EXPECT_EQ(OK, init_callback.WaitForResult()); |
270 | 270 |
271 // Block the proxy resolver, so no request can complete. | 271 // Block the proxy resolver, so no request can complete. |
272 mock->Block(); | 272 mock->Block(); |
273 | 273 |
274 // Start request 0. | 274 // Start request 0. |
275 ProxyResolver::RequestHandle request0; | 275 ProxyResolver::RequestHandle request0; |
276 TestCompletionCallback callback0; | 276 TestCompletionCallback callback0; |
277 ProxyInfo results0; | 277 ProxyInfo results0; |
278 CapturingBoundNetLog log0; | 278 BoundTestNetLog log0; |
279 rv = resolver.GetProxyForURL(GURL("http://request0"), &results0, | 279 rv = resolver.GetProxyForURL(GURL("http://request0"), &results0, |
280 callback0.callback(), &request0, log0.bound()); | 280 callback0.callback(), &request0, log0.bound()); |
281 EXPECT_EQ(ERR_IO_PENDING, rv); | 281 EXPECT_EQ(ERR_IO_PENDING, rv); |
282 | 282 |
283 // Start 2 more requests (request1 and request2). | 283 // Start 2 more requests (request1 and request2). |
284 | 284 |
285 TestCompletionCallback callback1; | 285 TestCompletionCallback callback1; |
286 ProxyInfo results1; | 286 ProxyInfo results1; |
287 CapturingBoundNetLog log1; | 287 BoundTestNetLog log1; |
288 rv = resolver.GetProxyForURL(GURL("http://request1"), &results1, | 288 rv = resolver.GetProxyForURL(GURL("http://request1"), &results1, |
289 callback1.callback(), NULL, log1.bound()); | 289 callback1.callback(), NULL, log1.bound()); |
290 EXPECT_EQ(ERR_IO_PENDING, rv); | 290 EXPECT_EQ(ERR_IO_PENDING, rv); |
291 | 291 |
292 ProxyResolver::RequestHandle request2; | 292 ProxyResolver::RequestHandle request2; |
293 TestCompletionCallback callback2; | 293 TestCompletionCallback callback2; |
294 ProxyInfo results2; | 294 ProxyInfo results2; |
295 CapturingBoundNetLog log2; | 295 BoundTestNetLog log2; |
296 rv = resolver.GetProxyForURL(GURL("http://request2"), &results2, | 296 rv = resolver.GetProxyForURL(GURL("http://request2"), &results2, |
297 callback2.callback(), &request2, log2.bound()); | 297 callback2.callback(), &request2, log2.bound()); |
298 EXPECT_EQ(ERR_IO_PENDING, rv); | 298 EXPECT_EQ(ERR_IO_PENDING, rv); |
299 | 299 |
300 // Unblock the worker thread so the requests can continue running. | 300 // Unblock the worker thread so the requests can continue running. |
301 mock->WaitUntilBlocked(); | 301 mock->WaitUntilBlocked(); |
302 mock->Unblock(); | 302 mock->Unblock(); |
303 | 303 |
304 // Check that request 0 completed as expected. | 304 // Check that request 0 completed as expected. |
305 // The NetLog has 1 entry that came from the MultiThreadedProxyResolver, and | 305 // The NetLog has 1 entry that came from the MultiThreadedProxyResolver, and |
306 // 1 entry from the mock proxy resolver. | 306 // 1 entry from the mock proxy resolver. |
307 EXPECT_EQ(0, callback0.WaitForResult()); | 307 EXPECT_EQ(0, callback0.WaitForResult()); |
308 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); | 308 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); |
309 | 309 |
310 CapturingNetLog::CapturedEntryList entries0; | 310 TestNetLog::CapturedEntryList entries0; |
311 log0.GetEntries(&entries0); | 311 log0.GetEntries(&entries0); |
312 | 312 |
313 ASSERT_EQ(2u, entries0.size()); | 313 ASSERT_EQ(2u, entries0.size()); |
314 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, | 314 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, |
315 entries0[0].type); | 315 entries0[0].type); |
316 | 316 |
317 // Check that request 1 completed as expected. | 317 // Check that request 1 completed as expected. |
318 EXPECT_EQ(1, callback1.WaitForResult()); | 318 EXPECT_EQ(1, callback1.WaitForResult()); |
319 EXPECT_EQ("PROXY request1:80", results1.ToPacString()); | 319 EXPECT_EQ("PROXY request1:80", results1.ToPacString()); |
320 | 320 |
321 CapturingNetLog::CapturedEntryList entries1; | 321 TestNetLog::CapturedEntryList entries1; |
322 log1.GetEntries(&entries1); | 322 log1.GetEntries(&entries1); |
323 | 323 |
324 ASSERT_EQ(4u, entries1.size()); | 324 ASSERT_EQ(4u, entries1.size()); |
325 EXPECT_TRUE(LogContainsBeginEvent( | 325 EXPECT_TRUE(LogContainsBeginEvent( |
326 entries1, 0, | 326 entries1, 0, |
327 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); | 327 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); |
328 EXPECT_TRUE(LogContainsEndEvent( | 328 EXPECT_TRUE(LogContainsEndEvent( |
329 entries1, 1, | 329 entries1, 1, |
330 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); | 330 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); |
331 | 331 |
332 // Check that request 2 completed as expected. | 332 // Check that request 2 completed as expected. |
333 EXPECT_EQ(2, callback2.WaitForResult()); | 333 EXPECT_EQ(2, callback2.WaitForResult()); |
334 EXPECT_EQ("PROXY request2:80", results2.ToPacString()); | 334 EXPECT_EQ("PROXY request2:80", results2.ToPacString()); |
335 | 335 |
336 CapturingNetLog::CapturedEntryList entries2; | 336 TestNetLog::CapturedEntryList entries2; |
337 log2.GetEntries(&entries2); | 337 log2.GetEntries(&entries2); |
338 | 338 |
339 ASSERT_EQ(4u, entries2.size()); | 339 ASSERT_EQ(4u, entries2.size()); |
340 EXPECT_TRUE(LogContainsBeginEvent( | 340 EXPECT_TRUE(LogContainsBeginEvent( |
341 entries2, 0, | 341 entries2, 0, |
342 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); | 342 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); |
343 EXPECT_TRUE(LogContainsEndEvent( | 343 EXPECT_TRUE(LogContainsEndEvent( |
344 entries2, 1, | 344 entries2, 1, |
345 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); | 345 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); |
346 } | 346 } |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 // All in all, the first thread should have seen just 1 request. And the | 694 // All in all, the first thread should have seen just 1 request. And the |
695 // second thread 3 requests. | 695 // second thread 3 requests. |
696 ASSERT_EQ(2u, factory->resolvers().size()); | 696 ASSERT_EQ(2u, factory->resolvers().size()); |
697 EXPECT_EQ(1, factory->resolvers()[0]->request_count()); | 697 EXPECT_EQ(1, factory->resolvers()[0]->request_count()); |
698 EXPECT_EQ(3, factory->resolvers()[1]->request_count()); | 698 EXPECT_EQ(3, factory->resolvers()[1]->request_count()); |
699 } | 699 } |
700 | 700 |
701 } // namespace | 701 } // namespace |
702 | 702 |
703 } // namespace net | 703 } // namespace net |
OLD | NEW |