| 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.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 rv = resolver.SetPacScript( | 269 rv = resolver.SetPacScript( |
| 270 ProxyResolverScriptData::FromUTF8("pac script bytes"), | 270 ProxyResolverScriptData::FromUTF8("pac script bytes"), |
| 271 set_script_callback.callback()); | 271 set_script_callback.callback()); |
| 272 EXPECT_EQ(ERR_IO_PENDING, rv); | 272 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 273 EXPECT_EQ(OK, set_script_callback.WaitForResult()); | 273 EXPECT_EQ(OK, set_script_callback.WaitForResult()); |
| 274 EXPECT_EQ(ASCIIToUTF16("pac script bytes"), | 274 EXPECT_EQ(ASCIIToUTF16("pac script bytes"), |
| 275 mock->last_script_data()->utf16()); | 275 mock->last_script_data()->utf16()); |
| 276 | 276 |
| 277 // Start request 0. | 277 // Start request 0. |
| 278 TestCompletionCallback callback0; | 278 TestCompletionCallback callback0; |
| 279 CapturingBoundNetLog log0(CapturingNetLog::kUnbounded); | 279 CapturingBoundNetLog log0; |
| 280 ProxyInfo results0; | 280 ProxyInfo results0; |
| 281 rv = resolver.GetProxyForURL(GURL("http://request0"), &results0, | 281 rv = resolver.GetProxyForURL(GURL("http://request0"), &results0, |
| 282 callback0.callback(), NULL, log0.bound()); | 282 callback0.callback(), NULL, log0.bound()); |
| 283 EXPECT_EQ(ERR_IO_PENDING, rv); | 283 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 284 | 284 |
| 285 // Wait for request 0 to finish. | 285 // Wait for request 0 to finish. |
| 286 rv = callback0.WaitForResult(); | 286 rv = callback0.WaitForResult(); |
| 287 EXPECT_EQ(0, rv); | 287 EXPECT_EQ(0, rv); |
| 288 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); | 288 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); |
| 289 | 289 |
| 290 // The mock proxy resolver should have written 1 log entry. And | 290 // The mock proxy resolver should have written 1 log entry. And |
| 291 // on completion, this should have been copied into |log0|. | 291 // on completion, this should have been copied into |log0|. |
| 292 // We also have 1 log entry that was emitted by the | 292 // We also have 1 log entry that was emitted by the |
| 293 // MultiThreadedProxyResolver. | 293 // MultiThreadedProxyResolver. |
| 294 net::CapturingNetLog::CapturedEntryList entries0; | 294 CapturingNetLog::CapturedEntryList entries0; |
| 295 log0.GetEntries(&entries0); | 295 log0.GetEntries(&entries0); |
| 296 | 296 |
| 297 ASSERT_EQ(2u, entries0.size()); | 297 ASSERT_EQ(2u, entries0.size()); |
| 298 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, entries0[0].type); | 298 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, entries0[0].type); |
| 299 | 299 |
| 300 // Start 3 more requests (request1 to request3). | 300 // Start 3 more requests (request1 to request3). |
| 301 | 301 |
| 302 TestCompletionCallback callback1; | 302 TestCompletionCallback callback1; |
| 303 ProxyInfo results1; | 303 ProxyInfo results1; |
| 304 rv = resolver.GetProxyForURL(GURL("http://request1"), &results1, | 304 rv = resolver.GetProxyForURL(GURL("http://request1"), &results1, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 init_callback.callback()); | 363 init_callback.callback()); |
| 364 EXPECT_EQ(OK, init_callback.WaitForResult()); | 364 EXPECT_EQ(OK, init_callback.WaitForResult()); |
| 365 | 365 |
| 366 // Block the proxy resolver, so no request can complete. | 366 // Block the proxy resolver, so no request can complete. |
| 367 mock->Block(); | 367 mock->Block(); |
| 368 | 368 |
| 369 // Start request 0. | 369 // Start request 0. |
| 370 ProxyResolver::RequestHandle request0; | 370 ProxyResolver::RequestHandle request0; |
| 371 TestCompletionCallback callback0; | 371 TestCompletionCallback callback0; |
| 372 ProxyInfo results0; | 372 ProxyInfo results0; |
| 373 CapturingBoundNetLog log0(CapturingNetLog::kUnbounded); | 373 CapturingBoundNetLog log0; |
| 374 rv = resolver.GetProxyForURL(GURL("http://request0"), &results0, | 374 rv = resolver.GetProxyForURL(GURL("http://request0"), &results0, |
| 375 callback0.callback(), &request0, log0.bound()); | 375 callback0.callback(), &request0, log0.bound()); |
| 376 EXPECT_EQ(ERR_IO_PENDING, rv); | 376 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 377 | 377 |
| 378 // Start 2 more requests (request1 and request2). | 378 // Start 2 more requests (request1 and request2). |
| 379 | 379 |
| 380 TestCompletionCallback callback1; | 380 TestCompletionCallback callback1; |
| 381 ProxyInfo results1; | 381 ProxyInfo results1; |
| 382 CapturingBoundNetLog log1(CapturingNetLog::kUnbounded); | 382 CapturingBoundNetLog log1; |
| 383 rv = resolver.GetProxyForURL(GURL("http://request1"), &results1, | 383 rv = resolver.GetProxyForURL(GURL("http://request1"), &results1, |
| 384 callback1.callback(), NULL, log1.bound()); | 384 callback1.callback(), NULL, log1.bound()); |
| 385 EXPECT_EQ(ERR_IO_PENDING, rv); | 385 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 386 | 386 |
| 387 ProxyResolver::RequestHandle request2; | 387 ProxyResolver::RequestHandle request2; |
| 388 TestCompletionCallback callback2; | 388 TestCompletionCallback callback2; |
| 389 ProxyInfo results2; | 389 ProxyInfo results2; |
| 390 CapturingBoundNetLog log2(CapturingNetLog::kUnbounded); | 390 CapturingBoundNetLog log2; |
| 391 rv = resolver.GetProxyForURL(GURL("http://request2"), &results2, | 391 rv = resolver.GetProxyForURL(GURL("http://request2"), &results2, |
| 392 callback2.callback(), &request2, log2.bound()); | 392 callback2.callback(), &request2, log2.bound()); |
| 393 EXPECT_EQ(ERR_IO_PENDING, rv); | 393 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 394 | 394 |
| 395 // Unblock the worker thread so the requests can continue running. | 395 // Unblock the worker thread so the requests can continue running. |
| 396 mock->WaitUntilBlocked(); | 396 mock->WaitUntilBlocked(); |
| 397 mock->Unblock(); | 397 mock->Unblock(); |
| 398 | 398 |
| 399 // Check that request 0 completed as expected. | 399 // Check that request 0 completed as expected. |
| 400 // The NetLog has 1 entry that came from the MultiThreadedProxyResolver, and | 400 // The NetLog has 1 entry that came from the MultiThreadedProxyResolver, and |
| 401 // 1 entry from the mock proxy resolver. | 401 // 1 entry from the mock proxy resolver. |
| 402 EXPECT_EQ(0, callback0.WaitForResult()); | 402 EXPECT_EQ(0, callback0.WaitForResult()); |
| 403 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); | 403 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); |
| 404 | 404 |
| 405 net::CapturingNetLog::CapturedEntryList entries0; | 405 CapturingNetLog::CapturedEntryList entries0; |
| 406 log0.GetEntries(&entries0); | 406 log0.GetEntries(&entries0); |
| 407 | 407 |
| 408 ASSERT_EQ(2u, entries0.size()); | 408 ASSERT_EQ(2u, entries0.size()); |
| 409 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, | 409 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, |
| 410 entries0[0].type); | 410 entries0[0].type); |
| 411 | 411 |
| 412 // Check that request 1 completed as expected. | 412 // Check that request 1 completed as expected. |
| 413 EXPECT_EQ(1, callback1.WaitForResult()); | 413 EXPECT_EQ(1, callback1.WaitForResult()); |
| 414 EXPECT_EQ("PROXY request1:80", results1.ToPacString()); | 414 EXPECT_EQ("PROXY request1:80", results1.ToPacString()); |
| 415 | 415 |
| 416 net::CapturingNetLog::CapturedEntryList entries1; | 416 CapturingNetLog::CapturedEntryList entries1; |
| 417 log1.GetEntries(&entries1); | 417 log1.GetEntries(&entries1); |
| 418 | 418 |
| 419 ASSERT_EQ(4u, entries1.size()); | 419 ASSERT_EQ(4u, entries1.size()); |
| 420 EXPECT_TRUE(LogContainsBeginEvent( | 420 EXPECT_TRUE(LogContainsBeginEvent( |
| 421 entries1, 0, | 421 entries1, 0, |
| 422 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); | 422 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); |
| 423 EXPECT_TRUE(LogContainsEndEvent( | 423 EXPECT_TRUE(LogContainsEndEvent( |
| 424 entries1, 1, | 424 entries1, 1, |
| 425 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); | 425 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); |
| 426 | 426 |
| 427 // Check that request 2 completed as expected. | 427 // Check that request 2 completed as expected. |
| 428 EXPECT_EQ(2, callback2.WaitForResult()); | 428 EXPECT_EQ(2, callback2.WaitForResult()); |
| 429 EXPECT_EQ("PROXY request2:80", results2.ToPacString()); | 429 EXPECT_EQ("PROXY request2:80", results2.ToPacString()); |
| 430 | 430 |
| 431 net::CapturingNetLog::CapturedEntryList entries2; | 431 CapturingNetLog::CapturedEntryList entries2; |
| 432 log2.GetEntries(&entries2); | 432 log2.GetEntries(&entries2); |
| 433 | 433 |
| 434 ASSERT_EQ(4u, entries2.size()); | 434 ASSERT_EQ(4u, entries2.size()); |
| 435 EXPECT_TRUE(LogContainsBeginEvent( | 435 EXPECT_TRUE(LogContainsBeginEvent( |
| 436 entries2, 0, | 436 entries2, 0, |
| 437 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); | 437 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); |
| 438 EXPECT_TRUE(LogContainsEndEvent( | 438 EXPECT_TRUE(LogContainsEndEvent( |
| 439 entries2, 1, | 439 entries2, 1, |
| 440 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); | 440 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); |
| 441 } | 441 } |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 // All in all, the first thread should have seen just 1 request. And the | 789 // All in all, the first thread should have seen just 1 request. And the |
| 790 // second thread 3 requests. | 790 // second thread 3 requests. |
| 791 ASSERT_EQ(2u, factory->resolvers().size()); | 791 ASSERT_EQ(2u, factory->resolvers().size()); |
| 792 EXPECT_EQ(1, factory->resolvers()[0]->request_count()); | 792 EXPECT_EQ(1, factory->resolvers()[0]->request_count()); |
| 793 EXPECT_EQ(3, factory->resolvers()[1]->request_count()); | 793 EXPECT_EQ(3, factory->resolvers()[1]->request_count()); |
| 794 } | 794 } |
| 795 | 795 |
| 796 } // namespace | 796 } // namespace |
| 797 | 797 |
| 798 } // namespace net | 798 } // namespace net |
| OLD | NEW |