Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/spdy/spdy_proxy_client_socket.h" | 5 #include "net/spdy/spdy_proxy_client_socket.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 // Create the SPDY Stream | 192 // Create the SPDY Stream |
| 193 ASSERT_EQ( | 193 ASSERT_EQ( |
| 194 OK, | 194 OK, |
| 195 spdy_session_->CreateStream(url_, LOWEST, &spdy_stream_, BoundNetLog(), | 195 spdy_session_->CreateStream(url_, LOWEST, &spdy_stream_, BoundNetLog(), |
| 196 CompletionCallback())); | 196 CompletionCallback())); |
| 197 | 197 |
| 198 // Create the SpdyProxyClientSocket | 198 // Create the SpdyProxyClientSocket |
| 199 sock_.reset( | 199 sock_.reset( |
| 200 new SpdyProxyClientSocket(spdy_stream_, user_agent_, | 200 new SpdyProxyClientSocket(spdy_stream_, user_agent_, |
| 201 endpoint_host_port_pair_, url_, | 201 endpoint_host_port_pair_, url_, |
| 202 proxy_host_port_, session_->http_auth_cache(), | 202 proxy_host_port_, |
| 203 session_->http_auth_handler_factory())); | 203 new HttpAuthController( |
| 204 HttpAuth::AUTH_PROXY, | |
| 205 GURL(kProxyUrl), | |
| 206 session_->http_auth_cache(), | |
| 207 session_->http_auth_handler_factory()))); | |
| 204 } | 208 } |
| 205 | 209 |
| 206 scoped_refptr<IOBufferWithSize> SpdyProxyClientSocketTest::CreateBuffer( | 210 scoped_refptr<IOBufferWithSize> SpdyProxyClientSocketTest::CreateBuffer( |
| 207 const char* data, int size) { | 211 const char* data, int size) { |
| 208 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(size)); | 212 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(size)); |
| 209 memcpy(buf->data(), data, size); | 213 memcpy(buf->data(), data, size); |
| 210 return buf; | 214 return buf; |
| 211 } | 215 } |
| 212 | 216 |
| 213 void SpdyProxyClientSocketTest::AssertConnectSucceeds() { | 217 void SpdyProxyClientSocketTest::AssertConnectSucceeds() { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 | 433 |
| 430 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 434 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 431 | 435 |
| 432 ASSERT_FALSE(sock_->IsConnected()); | 436 ASSERT_FALSE(sock_->IsConnected()); |
| 433 | 437 |
| 434 AssertConnectSucceeds(); | 438 AssertConnectSucceeds(); |
| 435 | 439 |
| 436 AssertConnectionEstablished(); | 440 AssertConnectionEstablished(); |
| 437 } | 441 } |
| 438 | 442 |
| 439 TEST_F(SpdyProxyClientSocketTest, ConnectWithAuthRequested) { | 443 TEST_F(SpdyProxyClientSocketTest, ConnectWithAuthRequested) { |
|
vandebo (ex-Chrome)
2012/01/20 20:49:29
Is this test now redundant to ConenctWithAuthResta
Ryan Hamilton
2012/01/20 21:51:35
Done.
| |
| 440 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 444 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
| 441 MockWrite writes[] = { | 445 MockWrite writes[] = { |
| 442 CreateMockWrite(*conn, 0, false), | 446 CreateMockWrite(*conn, 0, false), |
| 443 }; | 447 }; |
| 444 | 448 |
| 445 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectAuthReplyFrame()); | 449 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectAuthReplyFrame()); |
| 446 MockRead reads[] = { | 450 MockRead reads[] = { |
| 447 CreateMockRead(*resp, 1, true), | 451 CreateMockRead(*resp, 1, true), |
| 448 MockRead(true, 0, 3), // EOF | 452 MockRead(true, 0, 3), // EOF |
| 449 }; | 453 }; |
| 450 | 454 |
| 451 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 455 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 452 | 456 |
| 453 AssertConnectFails(ERR_TUNNEL_CONNECTION_FAILED); | 457 AssertConnectFails(ERR_PROXY_AUTH_REQUESTED); |
| 454 | 458 |
| 455 const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); | 459 const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); |
| 456 ASSERT_TRUE(response != NULL); | 460 ASSERT_TRUE(response != NULL); |
| 457 ASSERT_EQ(407, response->headers->response_code()); | 461 ASSERT_EQ(407, response->headers->response_code()); |
| 458 ASSERT_EQ("Proxy Authentication Required", | 462 ASSERT_EQ("Proxy Authentication Required", |
| 459 response->headers->GetStatusText()); | 463 response->headers->GetStatusText()); |
| 460 } | 464 } |
| 461 | 465 |
| 462 TEST_F(SpdyProxyClientSocketTest, ConnectWithAuthCredentials) { | 466 TEST_F(SpdyProxyClientSocketTest, ConnectWithAuthCredentials) { |
| 463 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectAuthRequestFrame()); | 467 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectAuthRequestFrame()); |
| 464 MockWrite writes[] = { | 468 MockWrite writes[] = { |
| 465 CreateMockWrite(*conn, 0, false), | 469 CreateMockWrite(*conn, 0, false), |
| 466 }; | 470 }; |
| 467 | 471 |
| 468 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 472 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
| 469 MockRead reads[] = { | 473 MockRead reads[] = { |
| 470 CreateMockRead(*resp, 1, true), | 474 CreateMockRead(*resp, 1, true), |
| 471 MockRead(true, 0, 3), // EOF | 475 MockRead(true, 0, 3), // EOF |
| 472 }; | 476 }; |
| 473 | 477 |
| 474 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 478 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 475 AddAuthToCache(); | 479 AddAuthToCache(); |
| 476 | 480 |
| 477 AssertConnectSucceeds(); | 481 AssertConnectSucceeds(); |
| 478 | 482 |
| 479 AssertConnectionEstablished(); | 483 AssertConnectionEstablished(); |
| 480 } | 484 } |
| 481 | 485 |
| 486 TEST_F(SpdyProxyClientSocketTest, ConnectWithAuthRestart) { | |
| 487 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | |
| 488 scoped_ptr<spdy::SpdyFrame> auth(ConstructConnectAuthRequestFrame()); | |
| 489 MockWrite writes[] = { | |
| 490 CreateMockWrite(*conn, 0, false), | |
| 491 }; | |
| 492 | |
| 493 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectAuthReplyFrame()); | |
| 494 scoped_ptr<spdy::SpdyFrame> auth_resp(ConstructConnectReplyFrame()); | |
| 495 MockRead reads[] = { | |
| 496 CreateMockRead(*resp, 1, true), | |
| 497 MockRead(true, 0, 3), // EOF | |
| 498 }; | |
| 499 | |
| 500 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | |
| 501 | |
| 502 AssertConnectFails(ERR_PROXY_AUTH_REQUESTED); | |
| 503 | |
| 504 const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); | |
| 505 ASSERT_TRUE(response != NULL); | |
| 506 ASSERT_EQ(407, response->headers->response_code()); | |
| 507 ASSERT_EQ("Proxy Authentication Required", | |
| 508 response->headers->GetStatusText()); | |
| 509 | |
| 510 AddAuthToCache(); | |
| 511 | |
| 512 ASSERT_EQ(ERR_NO_KEEP_ALIVE_ON_AUTH_RESTART, | |
| 513 sock_->RestartWithAuth(read_callback_.callback())); | |
| 514 // A SpdyProxyClientSocket sits on a single SPDY stream which can | |
| 515 // only be used for a single request/response. | |
| 516 ASSERT_FALSE(sock_->IsConnectedAndIdle()); | |
| 517 } | |
| 518 | |
|
vandebo (ex-Chrome)
2012/01/20 20:49:29
Can you add a test that requests non-basic, non-di
Ryan Hamilton
2012/01/20 21:51:35
Done. Though now that I think about it, I wonder
vandebo (ex-Chrome)
2012/01/20 21:58:20
SGTM
Ryan Hamilton
2012/01/23 18:37:27
Done.
| |
| 482 TEST_F(SpdyProxyClientSocketTest, ConnectFails) { | 519 TEST_F(SpdyProxyClientSocketTest, ConnectFails) { |
| 483 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 520 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
| 484 MockWrite writes[] = { | 521 MockWrite writes[] = { |
| 485 CreateMockWrite(*conn, 0, false), | 522 CreateMockWrite(*conn, 0, false), |
| 486 }; | 523 }; |
| 487 | 524 |
| 488 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 525 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
| 489 MockRead reads[] = { | 526 MockRead reads[] = { |
| 490 MockRead(true, 0, 1), // EOF | 527 MockRead(true, 0, 1), // EOF |
| 491 }; | 528 }; |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 824 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 861 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
| 825 MockRead reads[] = { | 862 MockRead reads[] = { |
| 826 CreateMockRead(*resp, 1, true), | 863 CreateMockRead(*resp, 1, true), |
| 827 CreateMockRead(*msg1, 2, true), | 864 CreateMockRead(*msg1, 2, true), |
| 828 CreateMockRead(*msg2, 3, true), | 865 CreateMockRead(*msg2, 3, true), |
| 829 MockRead(true, 0, 4), // EOF | 866 MockRead(true, 0, 4), // EOF |
| 830 }; | 867 }; |
| 831 | 868 |
| 832 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 869 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 833 | 870 |
| 834 AssertConnectFails(ERR_TUNNEL_CONNECTION_FAILED); | 871 AssertConnectFails(ERR_PROXY_AUTH_REQUESTED); |
| 835 | 872 |
| 836 Run(2); // SpdySession consumes the next two reads and sends then to | 873 Run(2); // SpdySession consumes the next two reads and sends then to |
| 837 // sock_ to be buffered. | 874 // sock_ to be buffered. |
| 838 AssertSyncReadEquals(kMsg1, kLen1); | 875 AssertSyncReadEquals(kMsg1, kLen1); |
| 839 AssertSyncReadEquals(kMsg2, kLen2); | 876 AssertSyncReadEquals(kMsg2, kLen2); |
| 840 } | 877 } |
| 841 | 878 |
| 842 TEST_F(SpdyProxyClientSocketTest, ReadErrorResponseBody) { | 879 TEST_F(SpdyProxyClientSocketTest, ReadErrorResponseBody) { |
| 843 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 880 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
| 844 MockWrite writes[] = { | 881 MockWrite writes[] = { |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1291 write_callback_.callback())); | 1328 write_callback_.callback())); |
| 1292 | 1329 |
| 1293 Run(2); | 1330 Run(2); |
| 1294 | 1331 |
| 1295 EXPECT_FALSE(sock_.get()); | 1332 EXPECT_FALSE(sock_.get()); |
| 1296 EXPECT_TRUE(read_callback.have_result()); | 1333 EXPECT_TRUE(read_callback.have_result()); |
| 1297 EXPECT_FALSE(write_callback_.have_result()); | 1334 EXPECT_FALSE(write_callback_.have_result()); |
| 1298 } | 1335 } |
| 1299 | 1336 |
| 1300 } // namespace net | 1337 } // namespace net |
| OLD | NEW |