OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/waitable_event.h" | 5 #include "base/waitable_event.h" |
6 #include "googleurl/src/gurl.h" | 6 #include "googleurl/src/gurl.h" |
7 #include "net/base/net_log.h" | 7 #include "net/base/net_log.h" |
8 #include "net/base/net_log_unittest.h" | 8 #include "net/base/net_log_unittest.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 171 |
172 // The mock proxy resolver should have written 1 log entry. And | 172 // The mock proxy resolver should have written 1 log entry. And |
173 // on completion, this should have been copied into |log0|. | 173 // on completion, this should have been copied into |log0|. |
174 EXPECT_EQ(1u, log0.entries().size()); | 174 EXPECT_EQ(1u, log0.entries().size()); |
175 | 175 |
176 // Start 3 more requests (request1 to request3). | 176 // Start 3 more requests (request1 to request3). |
177 | 177 |
178 TestCompletionCallback callback1; | 178 TestCompletionCallback callback1; |
179 ProxyInfo results1; | 179 ProxyInfo results1; |
180 rv = resolver.GetProxyForURL( | 180 rv = resolver.GetProxyForURL( |
181 GURL("http://request1"), &results1, &callback1, NULL, NULL); | 181 GURL("http://request1"), &results1, &callback1, NULL, BoundNetLog()); |
182 EXPECT_EQ(ERR_IO_PENDING, rv); | 182 EXPECT_EQ(ERR_IO_PENDING, rv); |
183 | 183 |
184 TestCompletionCallback callback2; | 184 TestCompletionCallback callback2; |
185 ProxyInfo results2; | 185 ProxyInfo results2; |
186 rv = resolver.GetProxyForURL( | 186 rv = resolver.GetProxyForURL( |
187 GURL("http://request2"), &results2, &callback2, NULL, NULL); | 187 GURL("http://request2"), &results2, &callback2, NULL, BoundNetLog()); |
188 EXPECT_EQ(ERR_IO_PENDING, rv); | 188 EXPECT_EQ(ERR_IO_PENDING, rv); |
189 | 189 |
190 TestCompletionCallback callback3; | 190 TestCompletionCallback callback3; |
191 ProxyInfo results3; | 191 ProxyInfo results3; |
192 rv = resolver.GetProxyForURL( | 192 rv = resolver.GetProxyForURL( |
193 GURL("http://request3"), &results3, &callback3, NULL, NULL); | 193 GURL("http://request3"), &results3, &callback3, NULL, BoundNetLog()); |
194 EXPECT_EQ(ERR_IO_PENDING, rv); | 194 EXPECT_EQ(ERR_IO_PENDING, rv); |
195 | 195 |
196 // Wait for the requests to finish (they must finish in the order they were | 196 // Wait for the requests to finish (they must finish in the order they were |
197 // started, which is what we check for from their magic return value) | 197 // started, which is what we check for from their magic return value) |
198 | 198 |
199 rv = callback1.WaitForResult(); | 199 rv = callback1.WaitForResult(); |
200 EXPECT_EQ(1, rv); | 200 EXPECT_EQ(1, rv); |
201 EXPECT_EQ("PROXY request1:80", results1.ToPacString()); | 201 EXPECT_EQ("PROXY request1:80", results1.ToPacString()); |
202 | 202 |
203 rv = callback2.WaitForResult(); | 203 rv = callback2.WaitForResult(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 int rv; | 300 int rv; |
301 | 301 |
302 // Block the proxy resolver, so no request can complete. | 302 // Block the proxy resolver, so no request can complete. |
303 mock->Block(); | 303 mock->Block(); |
304 | 304 |
305 // Start request 0. | 305 // Start request 0. |
306 ProxyResolver::RequestHandle request0; | 306 ProxyResolver::RequestHandle request0; |
307 TestCompletionCallback callback0; | 307 TestCompletionCallback callback0; |
308 ProxyInfo results0; | 308 ProxyInfo results0; |
309 rv = resolver.GetProxyForURL( | 309 rv = resolver.GetProxyForURL( |
310 GURL("http://request0"), &results0, &callback0, &request0, NULL); | 310 GURL("http://request0"), &results0, &callback0, &request0, BoundNetLog()); |
311 EXPECT_EQ(ERR_IO_PENDING, rv); | 311 EXPECT_EQ(ERR_IO_PENDING, rv); |
312 | 312 |
313 // Wait until requests 0 reaches the worker thread. | 313 // Wait until requests 0 reaches the worker thread. |
314 mock->WaitUntilBlocked(); | 314 mock->WaitUntilBlocked(); |
315 | 315 |
316 // Start 3 more requests (request1 : request3). | 316 // Start 3 more requests (request1 : request3). |
317 | 317 |
318 TestCompletionCallback callback1; | 318 TestCompletionCallback callback1; |
319 ProxyInfo results1; | 319 ProxyInfo results1; |
320 rv = resolver.GetProxyForURL( | 320 rv = resolver.GetProxyForURL( |
321 GURL("http://request1"), &results1, &callback1, NULL, NULL); | 321 GURL("http://request1"), &results1, &callback1, NULL, BoundNetLog()); |
322 EXPECT_EQ(ERR_IO_PENDING, rv); | 322 EXPECT_EQ(ERR_IO_PENDING, rv); |
323 | 323 |
324 ProxyResolver::RequestHandle request2; | 324 ProxyResolver::RequestHandle request2; |
325 TestCompletionCallback callback2; | 325 TestCompletionCallback callback2; |
326 ProxyInfo results2; | 326 ProxyInfo results2; |
327 rv = resolver.GetProxyForURL( | 327 rv = resolver.GetProxyForURL( |
328 GURL("http://request2"), &results2, &callback2, &request2, NULL); | 328 GURL("http://request2"), &results2, &callback2, &request2, BoundNetLog()); |
329 EXPECT_EQ(ERR_IO_PENDING, rv); | 329 EXPECT_EQ(ERR_IO_PENDING, rv); |
330 | 330 |
331 TestCompletionCallback callback3; | 331 TestCompletionCallback callback3; |
332 ProxyInfo results3; | 332 ProxyInfo results3; |
333 rv = resolver.GetProxyForURL( | 333 rv = resolver.GetProxyForURL( |
334 GURL("http://request3"), &results3, &callback3, NULL, NULL); | 334 GURL("http://request3"), &results3, &callback3, NULL, BoundNetLog()); |
335 EXPECT_EQ(ERR_IO_PENDING, rv); | 335 EXPECT_EQ(ERR_IO_PENDING, rv); |
336 | 336 |
337 // Cancel request0 (inprogress) and request2 (pending). | 337 // Cancel request0 (inprogress) and request2 (pending). |
338 resolver.CancelRequest(request0); | 338 resolver.CancelRequest(request0); |
339 resolver.CancelRequest(request2); | 339 resolver.CancelRequest(request2); |
340 | 340 |
341 // Unblock the worker thread so the requests can continue running. | 341 // Unblock the worker thread so the requests can continue running. |
342 mock->Unblock(); | 342 mock->Unblock(); |
343 | 343 |
344 // Wait for requests 1 and 3 to finish. | 344 // Wait for requests 1 and 3 to finish. |
(...skipping 24 matching lines...) Expand all Loading... |
369 int rv; | 369 int rv; |
370 | 370 |
371 // Block the proxy resolver, so no request can complete. | 371 // Block the proxy resolver, so no request can complete. |
372 mock->Block(); | 372 mock->Block(); |
373 | 373 |
374 // Start 3 requests. | 374 // Start 3 requests. |
375 | 375 |
376 TestCompletionCallback callback0; | 376 TestCompletionCallback callback0; |
377 ProxyInfo results0; | 377 ProxyInfo results0; |
378 rv = resolver->GetProxyForURL( | 378 rv = resolver->GetProxyForURL( |
379 GURL("http://request0"), &results0, &callback0, NULL, NULL); | 379 GURL("http://request0"), &results0, &callback0, NULL, BoundNetLog()); |
380 EXPECT_EQ(ERR_IO_PENDING, rv); | 380 EXPECT_EQ(ERR_IO_PENDING, rv); |
381 | 381 |
382 TestCompletionCallback callback1; | 382 TestCompletionCallback callback1; |
383 ProxyInfo results1; | 383 ProxyInfo results1; |
384 rv = resolver->GetProxyForURL( | 384 rv = resolver->GetProxyForURL( |
385 GURL("http://request1"), &results1, &callback1, NULL, NULL); | 385 GURL("http://request1"), &results1, &callback1, NULL, BoundNetLog()); |
386 EXPECT_EQ(ERR_IO_PENDING, rv); | 386 EXPECT_EQ(ERR_IO_PENDING, rv); |
387 | 387 |
388 TestCompletionCallback callback2; | 388 TestCompletionCallback callback2; |
389 ProxyInfo results2; | 389 ProxyInfo results2; |
390 rv = resolver->GetProxyForURL( | 390 rv = resolver->GetProxyForURL( |
391 GURL("http://request2"), &results2, &callback2, NULL, NULL); | 391 GURL("http://request2"), &results2, &callback2, NULL, BoundNetLog()); |
392 EXPECT_EQ(ERR_IO_PENDING, rv); | 392 EXPECT_EQ(ERR_IO_PENDING, rv); |
393 | 393 |
394 // Wait until request 0 reaches the worker thread. | 394 // Wait until request 0 reaches the worker thread. |
395 mock->WaitUntilBlocked(); | 395 mock->WaitUntilBlocked(); |
396 | 396 |
397 // Add some latency, to improve the chance that when | 397 // Add some latency, to improve the chance that when |
398 // SingleThreadedProxyResolver is deleted below we are still running inside | 398 // SingleThreadedProxyResolver is deleted below we are still running inside |
399 // of the worker thread. The test will pass regardless, so this race doesn't | 399 // of the worker thread. The test will pass regardless, so this race doesn't |
400 // cause flakiness. However the destruction during execution is a more | 400 // cause flakiness. However the destruction during execution is a more |
401 // interesting case to test. | 401 // interesting case to test. |
(...skipping 21 matching lines...) Expand all Loading... |
423 int rv; | 423 int rv; |
424 | 424 |
425 // Block the proxy resolver, so no request can complete. | 425 // Block the proxy resolver, so no request can complete. |
426 mock->Block(); | 426 mock->Block(); |
427 | 427 |
428 // Start request 0. | 428 // Start request 0. |
429 ProxyResolver::RequestHandle request0; | 429 ProxyResolver::RequestHandle request0; |
430 TestCompletionCallback callback0; | 430 TestCompletionCallback callback0; |
431 ProxyInfo results0; | 431 ProxyInfo results0; |
432 rv = resolver.GetProxyForURL( | 432 rv = resolver.GetProxyForURL( |
433 GURL("http://request0"), &results0, &callback0, &request0, NULL); | 433 GURL("http://request0"), &results0, &callback0, &request0, BoundNetLog()); |
434 EXPECT_EQ(ERR_IO_PENDING, rv); | 434 EXPECT_EQ(ERR_IO_PENDING, rv); |
435 | 435 |
436 // Wait until requests 0 reaches the worker thread. | 436 // Wait until requests 0 reaches the worker thread. |
437 mock->WaitUntilBlocked(); | 437 mock->WaitUntilBlocked(); |
438 | 438 |
439 TestCompletionCallback set_pac_script_callback; | 439 TestCompletionCallback set_pac_script_callback; |
440 rv = resolver.SetPacScriptByData("data", &set_pac_script_callback); | 440 rv = resolver.SetPacScriptByData("data", &set_pac_script_callback); |
441 EXPECT_EQ(ERR_IO_PENDING, rv); | 441 EXPECT_EQ(ERR_IO_PENDING, rv); |
442 | 442 |
443 // Cancel the SetPacScriptByData request (it can't have finished yet, | 443 // Cancel the SetPacScriptByData request (it can't have finished yet, |
444 // since the single-thread is currently blocked). | 444 // since the single-thread is currently blocked). |
445 resolver.CancelSetPacScript(); | 445 resolver.CancelSetPacScript(); |
446 | 446 |
447 // Start 1 more request. | 447 // Start 1 more request. |
448 | 448 |
449 TestCompletionCallback callback1; | 449 TestCompletionCallback callback1; |
450 ProxyInfo results1; | 450 ProxyInfo results1; |
451 rv = resolver.GetProxyForURL( | 451 rv = resolver.GetProxyForURL( |
452 GURL("http://request1"), &results1, &callback1, NULL, NULL); | 452 GURL("http://request1"), &results1, &callback1, NULL, BoundNetLog()); |
453 EXPECT_EQ(ERR_IO_PENDING, rv); | 453 EXPECT_EQ(ERR_IO_PENDING, rv); |
454 | 454 |
455 // Unblock the worker thread so the requests can continue running. | 455 // Unblock the worker thread so the requests can continue running. |
456 mock->Unblock(); | 456 mock->Unblock(); |
457 | 457 |
458 // Wait for requests 0 and 1 to finish. | 458 // Wait for requests 0 and 1 to finish. |
459 | 459 |
460 rv = callback0.WaitForResult(); | 460 rv = callback0.WaitForResult(); |
461 EXPECT_EQ(0, rv); | 461 EXPECT_EQ(0, rv); |
462 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); | 462 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); |
463 | 463 |
464 rv = callback1.WaitForResult(); | 464 rv = callback1.WaitForResult(); |
465 EXPECT_EQ(1, rv); | 465 EXPECT_EQ(1, rv); |
466 EXPECT_EQ("PROXY request1:80", results1.ToPacString()); | 466 EXPECT_EQ("PROXY request1:80", results1.ToPacString()); |
467 | 467 |
468 // The SetPacScript callback should never have been completed. | 468 // The SetPacScript callback should never have been completed. |
469 EXPECT_FALSE(set_pac_script_callback.have_result()); | 469 EXPECT_FALSE(set_pac_script_callback.have_result()); |
470 } | 470 } |
471 | 471 |
472 } // namespace | 472 } // namespace |
473 } // namespace net | 473 } // namespace net |
OLD | NEW |