Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 9390027: SPDY - trun off spdy/2.1 by default. It could be enabled (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( 370 CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool(
371 HostResolver* host_resolver, 371 HostResolver* host_resolver,
372 CertVerifier* cert_verifier) 372 CertVerifier* cert_verifier)
373 : SSLClientSocketPool(0, 0, NULL, host_resolver, cert_verifier, NULL, 373 : SSLClientSocketPool(0, 0, NULL, host_resolver, cert_verifier, NULL,
374 NULL, NULL, "", NULL, NULL, NULL, NULL, NULL, NULL) {} 374 NULL, NULL, "", NULL, NULL, NULL, NULL, NULL, NULL) {}
375 375
376 //----------------------------------------------------------------------------- 376 //-----------------------------------------------------------------------------
377 377
378 // This is the expected return from a current server advertising SPDY. 378 // This is the expected return from a current server advertising SPDY.
379 static const char kAlternateProtocolHttpHeader[] = 379 static const char kAlternateProtocolHttpHeader[] =
380 "Alternate-Protocol: 443:npn-spdy/2.1\r\n\r\n"; 380 "Alternate-Protocol: 443:npn-spdy/2\r\n\r\n";
381 381
382 // Helper functions for validating that AuthChallengeInfo's are correctly 382 // Helper functions for validating that AuthChallengeInfo's are correctly
383 // configured for common cases. 383 // configured for common cases.
384 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { 384 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) {
385 if (!auth_challenge) 385 if (!auth_challenge)
386 return false; 386 return false;
387 EXPECT_FALSE(auth_challenge->is_proxy); 387 EXPECT_FALSE(auth_challenge->is_proxy);
388 EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString()); 388 EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString());
389 EXPECT_EQ("MyRealm1", auth_challenge->realm); 389 EXPECT_EQ("MyRealm1", auth_challenge->realm);
390 EXPECT_EQ("basic", auth_challenge->scheme); 390 EXPECT_EQ("basic", auth_challenge->scheme);
(...skipping 5082 matching lines...) Expand 10 before | Expand all | Expand 10 after
5473 }; 5473 };
5474 5474
5475 scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( 5475 scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests(
5476 SessionDependencies* session_deps) { 5476 SessionDependencies* session_deps) {
5477 scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps)); 5477 scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps));
5478 5478
5479 HttpServerProperties* http_server_properties = 5479 HttpServerProperties* http_server_properties =
5480 session->http_server_properties(); 5480 session->http_server_properties();
5481 http_server_properties->SetAlternateProtocol( 5481 http_server_properties->SetAlternateProtocol(
5482 HostPortPair("host.with.alternate", 80), 443, 5482 HostPortPair("host.with.alternate", 80), 443,
5483 NPN_SPDY_21); 5483 NPN_SPDY_2);
5484 5484
5485 return session; 5485 return session;
5486 } 5486 }
5487 5487
5488 int GroupNameTransactionHelper( 5488 int GroupNameTransactionHelper(
5489 const std::string& url, 5489 const std::string& url,
5490 const scoped_refptr<HttpNetworkSession>& session) { 5490 const scoped_refptr<HttpNetworkSession>& session) {
5491 HttpRequestInfo request; 5491 HttpRequestInfo request;
5492 request.method = "GET"; 5492 request.method = "GET";
5493 request.url = GURL(url); 5493 request.url = GURL(url);
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
6413 6413
6414 std::string response_data; 6414 std::string response_data;
6415 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 6415 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
6416 EXPECT_EQ("hello world", response_data); 6416 EXPECT_EQ("hello world", response_data);
6417 6417
6418 ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair)); 6418 ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair));
6419 const PortAlternateProtocolPair alternate = 6419 const PortAlternateProtocolPair alternate =
6420 http_server_properties.GetAlternateProtocol(http_host_port_pair); 6420 http_server_properties.GetAlternateProtocol(http_host_port_pair);
6421 PortAlternateProtocolPair expected_alternate; 6421 PortAlternateProtocolPair expected_alternate;
6422 expected_alternate.port = 443; 6422 expected_alternate.port = 443;
6423 expected_alternate.protocol = NPN_SPDY_21; 6423 expected_alternate.protocol = NPN_SPDY_2;
6424 EXPECT_TRUE(expected_alternate.Equals(alternate)); 6424 EXPECT_TRUE(expected_alternate.Equals(alternate));
6425 6425
6426 HttpStreamFactory::set_use_alternate_protocols(false); 6426 HttpStreamFactory::set_use_alternate_protocols(false);
6427 HttpStreamFactory::set_next_protos(std::vector<std::string>()); 6427 HttpStreamFactory::set_next_protos(std::vector<std::string>());
6428 } 6428 }
6429 6429
6430 TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { 6430 TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) {
6431 HttpStreamFactory::set_use_alternate_protocols(true); 6431 HttpStreamFactory::set_use_alternate_protocols(true);
6432 SessionDependencies session_deps; 6432 SessionDependencies session_deps;
6433 6433
(...skipping 18 matching lines...) Expand all
6452 6452
6453 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 6453 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
6454 6454
6455 HttpServerProperties* http_server_properties = 6455 HttpServerProperties* http_server_properties =
6456 session->http_server_properties(); 6456 session->http_server_properties();
6457 // Port must be < 1024, or the header will be ignored (since initial port was 6457 // Port must be < 1024, or the header will be ignored (since initial port was
6458 // port 80 (another restricted port). 6458 // port 80 (another restricted port).
6459 http_server_properties->SetAlternateProtocol( 6459 http_server_properties->SetAlternateProtocol(
6460 HostPortPair::FromURL(request.url), 6460 HostPortPair::FromURL(request.url),
6461 666 /* port is ignored by MockConnect anyway */, 6461 666 /* port is ignored by MockConnect anyway */,
6462 NPN_SPDY_21); 6462 NPN_SPDY_2);
6463 6463
6464 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 6464 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
6465 TestCompletionCallback callback; 6465 TestCompletionCallback callback;
6466 6466
6467 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 6467 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
6468 EXPECT_EQ(ERR_IO_PENDING, rv); 6468 EXPECT_EQ(ERR_IO_PENDING, rv);
6469 EXPECT_EQ(OK, callback.WaitForResult()); 6469 EXPECT_EQ(OK, callback.WaitForResult());
6470 6470
6471 const HttpResponseInfo* response = trans->GetResponseInfo(); 6471 const HttpResponseInfo* response = trans->GetResponseInfo();
6472 ASSERT_TRUE(response != NULL); 6472 ASSERT_TRUE(response != NULL);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
6514 session_deps.socket_factory.AddSocketDataProvider(&second_data); 6514 session_deps.socket_factory.AddSocketDataProvider(&second_data);
6515 6515
6516 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 6516 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
6517 6517
6518 HttpServerProperties* http_server_properties = 6518 HttpServerProperties* http_server_properties =
6519 session->http_server_properties(); 6519 session->http_server_properties();
6520 const int kUnrestrictedAlternatePort = 1024; 6520 const int kUnrestrictedAlternatePort = 1024;
6521 http_server_properties->SetAlternateProtocol( 6521 http_server_properties->SetAlternateProtocol(
6522 HostPortPair::FromURL(restricted_port_request.url), 6522 HostPortPair::FromURL(restricted_port_request.url),
6523 kUnrestrictedAlternatePort, 6523 kUnrestrictedAlternatePort,
6524 NPN_SPDY_21); 6524 NPN_SPDY_2);
6525 6525
6526 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 6526 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
6527 TestCompletionCallback callback; 6527 TestCompletionCallback callback;
6528 6528
6529 int rv = trans->Start( 6529 int rv = trans->Start(
6530 &restricted_port_request, callback.callback(), BoundNetLog()); 6530 &restricted_port_request, callback.callback(), BoundNetLog());
6531 EXPECT_EQ(ERR_IO_PENDING, rv); 6531 EXPECT_EQ(ERR_IO_PENDING, rv);
6532 // Invalid change to unrestricted port should fail. 6532 // Invalid change to unrestricted port should fail.
6533 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); 6533 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult());
6534 6534
(...skipping 28 matching lines...) Expand all
6563 session_deps.socket_factory.AddSocketDataProvider(&second_data); 6563 session_deps.socket_factory.AddSocketDataProvider(&second_data);
6564 6564
6565 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 6565 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
6566 6566
6567 HttpServerProperties* http_server_properties = 6567 HttpServerProperties* http_server_properties =
6568 session->http_server_properties(); 6568 session->http_server_properties();
6569 const int kRestrictedAlternatePort = 80; 6569 const int kRestrictedAlternatePort = 80;
6570 http_server_properties->SetAlternateProtocol( 6570 http_server_properties->SetAlternateProtocol(
6571 HostPortPair::FromURL(restricted_port_request.url), 6571 HostPortPair::FromURL(restricted_port_request.url),
6572 kRestrictedAlternatePort, 6572 kRestrictedAlternatePort,
6573 NPN_SPDY_21); 6573 NPN_SPDY_2);
6574 6574
6575 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 6575 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
6576 TestCompletionCallback callback; 6576 TestCompletionCallback callback;
6577 6577
6578 int rv = trans->Start( 6578 int rv = trans->Start(
6579 &restricted_port_request, callback.callback(), BoundNetLog()); 6579 &restricted_port_request, callback.callback(), BoundNetLog());
6580 EXPECT_EQ(ERR_IO_PENDING, rv); 6580 EXPECT_EQ(ERR_IO_PENDING, rv);
6581 // Valid change to restricted port should pass. 6581 // Valid change to restricted port should pass.
6582 EXPECT_EQ(OK, callback.WaitForResult()); 6582 EXPECT_EQ(OK, callback.WaitForResult());
6583 6583
(...skipping 28 matching lines...) Expand all
6612 session_deps.socket_factory.AddSocketDataProvider(&second_data); 6612 session_deps.socket_factory.AddSocketDataProvider(&second_data);
6613 6613
6614 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 6614 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
6615 6615
6616 HttpServerProperties* http_server_properties = 6616 HttpServerProperties* http_server_properties =
6617 session->http_server_properties(); 6617 session->http_server_properties();
6618 const int kRestrictedAlternatePort = 80; 6618 const int kRestrictedAlternatePort = 80;
6619 http_server_properties->SetAlternateProtocol( 6619 http_server_properties->SetAlternateProtocol(
6620 HostPortPair::FromURL(unrestricted_port_request.url), 6620 HostPortPair::FromURL(unrestricted_port_request.url),
6621 kRestrictedAlternatePort, 6621 kRestrictedAlternatePort,
6622 NPN_SPDY_21); 6622 NPN_SPDY_2);
6623 6623
6624 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 6624 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
6625 TestCompletionCallback callback; 6625 TestCompletionCallback callback;
6626 6626
6627 int rv = trans->Start( 6627 int rv = trans->Start(
6628 &unrestricted_port_request, callback.callback(), BoundNetLog()); 6628 &unrestricted_port_request, callback.callback(), BoundNetLog());
6629 EXPECT_EQ(ERR_IO_PENDING, rv); 6629 EXPECT_EQ(ERR_IO_PENDING, rv);
6630 // Valid change to restricted port should pass. 6630 // Valid change to restricted port should pass.
6631 EXPECT_EQ(OK, callback.WaitForResult()); 6631 EXPECT_EQ(OK, callback.WaitForResult());
6632 6632
(...skipping 28 matching lines...) Expand all
6661 session_deps.socket_factory.AddSocketDataProvider(&second_data); 6661 session_deps.socket_factory.AddSocketDataProvider(&second_data);
6662 6662
6663 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 6663 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
6664 6664
6665 HttpServerProperties* http_server_properties = 6665 HttpServerProperties* http_server_properties =
6666 session->http_server_properties(); 6666 session->http_server_properties();
6667 const int kUnrestrictedAlternatePort = 1024; 6667 const int kUnrestrictedAlternatePort = 1024;
6668 http_server_properties->SetAlternateProtocol( 6668 http_server_properties->SetAlternateProtocol(
6669 HostPortPair::FromURL(unrestricted_port_request.url), 6669 HostPortPair::FromURL(unrestricted_port_request.url),
6670 kUnrestrictedAlternatePort, 6670 kUnrestrictedAlternatePort,
6671 NPN_SPDY_21); 6671 NPN_SPDY_2);
6672 6672
6673 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 6673 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
6674 TestCompletionCallback callback; 6674 TestCompletionCallback callback;
6675 6675
6676 int rv = trans->Start( 6676 int rv = trans->Start(
6677 &unrestricted_port_request, callback.callback(), BoundNetLog()); 6677 &unrestricted_port_request, callback.callback(), BoundNetLog());
6678 EXPECT_EQ(ERR_IO_PENDING, rv); 6678 EXPECT_EQ(ERR_IO_PENDING, rv);
6679 // Valid change to an unrestricted port should pass. 6679 // Valid change to an unrestricted port should pass.
6680 EXPECT_EQ(OK, callback.WaitForResult()); 6680 EXPECT_EQ(OK, callback.WaitForResult());
6681 6681
(...skipping 1473 matching lines...) Expand 10 before | Expand all | Expand 10 after
8155 // First round goes unauthenticated through the proxy. 8155 // First round goes unauthenticated through the proxy.
8156 MockWrite data_writes_1[] = { 8156 MockWrite data_writes_1[] = {
8157 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" 8157 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
8158 "Host: www.google.com\r\n" 8158 "Host: www.google.com\r\n"
8159 "Proxy-Connection: keep-alive\r\n" 8159 "Proxy-Connection: keep-alive\r\n"
8160 "\r\n"), 8160 "\r\n"),
8161 }; 8161 };
8162 MockRead data_reads_1[] = { 8162 MockRead data_reads_1[] = {
8163 MockRead(false, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), 8163 MockRead(false, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
8164 MockRead("HTTP/1.1 200 OK\r\n" 8164 MockRead("HTTP/1.1 200 OK\r\n"
8165 "Alternate-Protocol: 443:npn-spdy/2.1\r\n" 8165 "Alternate-Protocol: 443:npn-spdy/2\r\n"
8166 "Proxy-Connection: close\r\n" 8166 "Proxy-Connection: close\r\n"
8167 "\r\n"), 8167 "\r\n"),
8168 }; 8168 };
8169 StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), 8169 StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1),
8170 data_writes_1, arraysize(data_writes_1)); 8170 data_writes_1, arraysize(data_writes_1));
8171 8171
8172 // Second round tries to tunnel to www.google.com due to the 8172 // Second round tries to tunnel to www.google.com due to the
8173 // Alternate-Protocol announcement in the first round. It fails due 8173 // Alternate-Protocol announcement in the first round. It fails due
8174 // to a proxy authentication challenge. 8174 // to a proxy authentication challenge.
8175 // After the failure, a tunnel is established to www.google.com using 8175 // After the failure, a tunnel is established to www.google.com using
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after
9238 StaticSocketDataProvider* data[] = { &data1, &data2 }; 9238 StaticSocketDataProvider* data[] = { &data1, &data2 };
9239 9239
9240 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); 9240 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data));
9241 9241
9242 EXPECT_EQ(OK, out.rv); 9242 EXPECT_EQ(OK, out.rv);
9243 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); 9243 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line);
9244 EXPECT_EQ("hello world", out.response_data); 9244 EXPECT_EQ("hello world", out.response_data);
9245 } 9245 }
9246 9246
9247 } // namespace net 9247 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698