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/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 #include <stdarg.h> | 8 #include <stdarg.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 | 157 |
158 class HttpNetworkTransactionSpdy21Test : public PlatformTest { | 158 class HttpNetworkTransactionSpdy21Test : public PlatformTest { |
159 protected: | 159 protected: |
160 struct SimpleGetHelperResult { | 160 struct SimpleGetHelperResult { |
161 int rv; | 161 int rv; |
162 std::string status_line; | 162 std::string status_line; |
163 std::string response_data; | 163 std::string response_data; |
164 }; | 164 }; |
165 | 165 |
166 virtual void SetUp() { | 166 virtual void SetUp() { |
167 SpdySession::set_default_protocol(SSLClientSocket::kProtoSPDY21); | 167 SpdySession::set_default_protocol(SSLClientSocket::kProtoSPDY21); |
mmenke
2012/03/16 18:01:15
nit: Suggest you call this "CloseIdle..."
Ryan Hamilton
2012/03/16 22:21:03
I'm not sure I understand what you are suggesting
mmenke
2012/03/16 22:25:09
Errm...Oops...Moved the comment from a previous re
Ryan Hamilton
2012/03/16 22:34:56
Good idea. Done.
| |
168 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 168 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
169 MessageLoop::current()->RunAllPending(); | 169 MessageLoop::current()->RunAllPending(); |
170 spdy::SpdyFramer::set_enable_compression_default(false); | 170 spdy::SpdyFramer::set_enable_compression_default(false); |
171 } | 171 } |
172 | 172 |
173 virtual void TearDown() { | 173 virtual void TearDown() { |
174 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 174 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
175 MessageLoop::current()->RunAllPending(); | 175 MessageLoop::current()->RunAllPending(); |
176 spdy::SpdyFramer::set_enable_compression_default(true); | 176 spdy::SpdyFramer::set_enable_compression_default(true); |
177 // Empty the current queue. | 177 // Empty the current queue. |
(...skipping 9189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9367 data_writes2, arraysize(data_writes2)); | 9367 data_writes2, arraysize(data_writes2)); |
9368 StaticSocketDataProvider* data[] = { &data1, &data2 }; | 9368 StaticSocketDataProvider* data[] = { &data1, &data2 }; |
9369 | 9369 |
9370 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); | 9370 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); |
9371 | 9371 |
9372 EXPECT_EQ(OK, out.rv); | 9372 EXPECT_EQ(OK, out.rv); |
9373 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); | 9373 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
9374 EXPECT_EQ("hello world", out.response_data); | 9374 EXPECT_EQ("hello world", out.response_data); |
9375 } | 9375 } |
9376 | 9376 |
9377 TEST_F(HttpNetworkTransactionSpdy21Test, CloseOldSpdySessionToOpenNewOne) { | |
9378 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); | |
9379 int old_max_sockets_per_group = | |
9380 ClientSocketPoolManager::max_sockets_per_group(); | |
9381 int old_max_sockets_per_proxy_server = | |
9382 ClientSocketPoolManager::max_sockets_per_proxy_server(); | |
9383 int old_max_sockets_per_pool = | |
9384 ClientSocketPoolManager::max_sockets_per_pool(); | |
9385 ClientSocketPoolManager::set_max_sockets_per_group(1); | |
9386 ClientSocketPoolManager::set_max_sockets_per_proxy_server(1); | |
9387 ClientSocketPoolManager::set_max_sockets_per_pool(1); | |
9388 | |
9389 // Use two different hosts with different IPs so they don't get pooled. | |
9390 SessionDependencies session_deps; | |
9391 session_deps.host_resolver->rules()->AddRule("a.com", "10.0.0.1"); | |
9392 session_deps.host_resolver->rules()->AddRule("b.com", "10.0.0.2"); | |
9393 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
9394 | |
9395 SSLSocketDataProvider ssl1(ASYNC, OK); | |
9396 ssl1.SetNextProto(SSLClientSocket::kProtoSPDY21); | |
9397 SSLSocketDataProvider ssl2(ASYNC, OK); | |
9398 ssl2.SetNextProto(SSLClientSocket::kProtoSPDY21); | |
9399 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl1); | |
9400 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl2); | |
9401 | |
9402 scoped_ptr<spdy::SpdyFrame> host1_req(ConstructSpdyGet( | |
9403 "https://www.a.com", false, 1, LOWEST)); | |
9404 MockWrite spdy1_writes[] = { | |
9405 CreateMockWrite(*host1_req, 1), | |
9406 }; | |
9407 scoped_ptr<spdy::SpdyFrame> host1_resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
9408 scoped_ptr<spdy::SpdyFrame> host1_resp_body(ConstructSpdyBodyFrame(1, true)); | |
9409 MockRead spdy1_reads[] = { | |
9410 CreateMockRead(*host1_resp, 2), | |
9411 CreateMockRead(*host1_resp_body, 3), | |
9412 MockRead(ASYNC, ERR_IO_PENDING, 4), | |
9413 }; | |
9414 | |
9415 scoped_ptr<OrderedSocketData> spdy1_data( | |
9416 new OrderedSocketData( | |
9417 spdy1_reads, arraysize(spdy1_reads), | |
9418 spdy1_writes, arraysize(spdy1_writes))); | |
9419 session_deps.socket_factory.AddSocketDataProvider(spdy1_data.get()); | |
9420 | |
9421 scoped_ptr<spdy::SpdyFrame> host2_req(ConstructSpdyGet( | |
9422 "https://www.b.com", false, 1, LOWEST)); | |
9423 MockWrite spdy2_writes[] = { | |
9424 CreateMockWrite(*host2_req, 1), | |
9425 }; | |
9426 scoped_ptr<spdy::SpdyFrame> host2_resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
9427 scoped_ptr<spdy::SpdyFrame> host2_resp_body(ConstructSpdyBodyFrame(1, true)); | |
9428 MockRead spdy2_reads[] = { | |
9429 CreateMockRead(*host2_resp, 2), | |
9430 CreateMockRead(*host2_resp_body, 3), | |
9431 MockRead(ASYNC, ERR_IO_PENDING, 4), | |
9432 }; | |
9433 | |
9434 scoped_ptr<OrderedSocketData> spdy2_data( | |
9435 new OrderedSocketData( | |
9436 spdy2_reads, arraysize(spdy2_reads), | |
9437 spdy2_writes, arraysize(spdy2_writes))); | |
9438 session_deps.socket_factory.AddSocketDataProvider(spdy2_data.get()); | |
9439 | |
9440 MockWrite http_write[] = { | |
9441 MockWrite("GET / HTTP/1.1\r\n" | |
9442 "Host: www.a.com\r\n" | |
9443 "Connection: keep-alive\r\n\r\n"), | |
9444 }; | |
9445 | |
9446 MockRead http_read[] = { | |
9447 MockRead("HTTP/1.1 200 OK\r\n"), | |
9448 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | |
9449 MockRead("Content-Length: 6\r\n\r\n"), | |
9450 MockRead("hello!"), | |
9451 }; | |
9452 StaticSocketDataProvider http_data(http_read, arraysize(http_read), | |
9453 http_write, arraysize(http_write)); | |
9454 session_deps.socket_factory.AddSocketDataProvider(&http_data); | |
9455 | |
9456 HostPortPair host_port_pair_a("www.a.com", 443); | |
9457 HostPortProxyPair host_port_proxy_pair_a( | |
9458 host_port_pair_a, ProxyServer::Direct()); | |
9459 EXPECT_FALSE( | |
9460 session->spdy_session_pool()->HasSession(host_port_proxy_pair_a)); | |
9461 | |
9462 TestCompletionCallback callback; | |
9463 HttpRequestInfo request1; | |
9464 request1.method = "GET"; | |
9465 request1.url = GURL("https://www.a.com/"); | |
9466 request1.load_flags = 0; | |
9467 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); | |
9468 | |
9469 int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); | |
9470 EXPECT_EQ(ERR_IO_PENDING, rv); | |
9471 EXPECT_EQ(OK, callback.WaitForResult()); | |
9472 | |
9473 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
9474 ASSERT_TRUE(response != NULL); | |
9475 ASSERT_TRUE(response->headers != NULL); | |
9476 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
9477 EXPECT_TRUE(response->was_fetched_via_spdy); | |
9478 EXPECT_TRUE(response->was_npn_negotiated); | |
9479 | |
9480 std::string response_data; | |
9481 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
9482 EXPECT_EQ("hello!", response_data); | |
9483 trans.reset(); | |
9484 EXPECT_TRUE( | |
9485 session->spdy_session_pool()->HasSession(host_port_proxy_pair_a)); | |
9486 | |
9487 HostPortPair host_port_pair_b("www.b.com", 443); | |
9488 HostPortProxyPair host_port_proxy_pair_b( | |
9489 host_port_pair_b, ProxyServer::Direct()); | |
9490 EXPECT_FALSE( | |
9491 session->spdy_session_pool()->HasSession(host_port_proxy_pair_b)); | |
9492 HttpRequestInfo request2; | |
9493 request2.method = "GET"; | |
9494 request2.url = GURL("https://www.b.com/"); | |
9495 request2.load_flags = 0; | |
9496 trans.reset(new HttpNetworkTransaction(session)); | |
9497 | |
9498 rv = trans->Start(&request2, callback.callback(), BoundNetLog()); | |
9499 EXPECT_EQ(ERR_IO_PENDING, rv); | |
9500 EXPECT_EQ(OK, callback.WaitForResult()); | |
9501 | |
9502 response = trans->GetResponseInfo(); | |
9503 ASSERT_TRUE(response != NULL); | |
9504 ASSERT_TRUE(response->headers != NULL); | |
9505 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
9506 EXPECT_TRUE(response->was_fetched_via_spdy); | |
9507 EXPECT_TRUE(response->was_npn_negotiated); | |
9508 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
9509 EXPECT_EQ("hello!", response_data); | |
9510 EXPECT_FALSE( | |
9511 session->spdy_session_pool()->HasSession(host_port_proxy_pair_a)); | |
9512 EXPECT_TRUE( | |
9513 session->spdy_session_pool()->HasSession(host_port_proxy_pair_b)); | |
9514 | |
9515 HostPortPair host_port_pair_a1("www.a.com", 80); | |
9516 HostPortProxyPair host_port_proxy_pair_a1( | |
9517 host_port_pair_a1, ProxyServer::Direct()); | |
9518 EXPECT_FALSE( | |
9519 session->spdy_session_pool()->HasSession(host_port_proxy_pair_a1)); | |
9520 HttpRequestInfo request3; | |
9521 request3.method = "GET"; | |
9522 request3.url = GURL("http://www.a.com/"); | |
9523 request3.load_flags = 0; | |
9524 trans.reset(new HttpNetworkTransaction(session)); | |
9525 | |
9526 rv = trans->Start(&request3, callback.callback(), BoundNetLog()); | |
9527 EXPECT_EQ(ERR_IO_PENDING, rv); | |
9528 EXPECT_EQ(OK, callback.WaitForResult()); | |
9529 | |
9530 response = trans->GetResponseInfo(); | |
9531 ASSERT_TRUE(response != NULL); | |
9532 ASSERT_TRUE(response->headers != NULL); | |
9533 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
9534 EXPECT_FALSE(response->was_fetched_via_spdy); | |
9535 EXPECT_FALSE(response->was_npn_negotiated); | |
9536 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
9537 EXPECT_EQ("hello!", response_data); | |
9538 EXPECT_FALSE( | |
9539 session->spdy_session_pool()->HasSession(host_port_proxy_pair_a)); | |
9540 EXPECT_FALSE( | |
9541 session->spdy_session_pool()->HasSession(host_port_proxy_pair_b)); | |
9542 | |
9543 HttpStreamFactory::SetNextProtos(std::vector<std::string>()); | |
9544 ClientSocketPoolManager::set_max_sockets_per_pool(old_max_sockets_per_pool); | |
9545 ClientSocketPoolManager::set_max_sockets_per_proxy_server( | |
9546 old_max_sockets_per_proxy_server); | |
9547 ClientSocketPoolManager::set_max_sockets_per_group(old_max_sockets_per_group); | |
9548 } | |
9549 | |
9377 } // namespace net | 9550 } // namespace net |
OLD | NEW |