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

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

Issue 885443002: Roll Chrome into Mojo. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebase to ToT mojo Created 5 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
« no previous file with comments | « net/http/http_network_session.cc ('k') | net/http/http_response_headers.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 470
471 private: 471 private:
472 bool observed_before_proxy_headers_sent_; 472 bool observed_before_proxy_headers_sent_;
473 std::string observed_proxy_server_uri_; 473 std::string observed_proxy_server_uri_;
474 474
475 DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); 475 DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler);
476 }; 476 };
477 477
478 // Fill |str| with a long header list that consumes >= |size| bytes. 478 // Fill |str| with a long header list that consumes >= |size| bytes.
479 void FillLargeHeadersString(std::string* str, int size) { 479 void FillLargeHeadersString(std::string* str, int size) {
480 const char* row = 480 const char row[] =
481 "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; 481 "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n";
482 const int sizeof_row = strlen(row); 482 const int sizeof_row = strlen(row);
483 const int num_rows = static_cast<int>( 483 const int num_rows = static_cast<int>(
484 ceil(static_cast<float>(size) / sizeof_row)); 484 ceil(static_cast<float>(size) / sizeof_row));
485 const int sizeof_data = num_rows * sizeof_row; 485 const int sizeof_data = num_rows * sizeof_row;
486 DCHECK(sizeof_data >= size); 486 DCHECK(sizeof_data >= size);
487 str->reserve(sizeof_data); 487 str->reserve(sizeof_data);
488 488
489 for (int i = 0; i < num_rows; ++i) 489 for (int i = 0; i < num_rows; ++i)
490 str->append(row, sizeof_row); 490 str->append(row, sizeof_row);
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 session_deps_.socket_factory->AddSocketDataProvider(&data1); 1306 session_deps_.socket_factory->AddSocketDataProvider(&data1);
1307 1307
1308 MockRead data2_reads[] = { 1308 MockRead data2_reads[] = {
1309 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), 1309 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
1310 MockRead("world"), 1310 MockRead("world"),
1311 MockRead(ASYNC, OK), 1311 MockRead(ASYNC, OK),
1312 }; 1312 };
1313 StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); 1313 StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0);
1314 session_deps_.socket_factory->AddSocketDataProvider(&data2); 1314 session_deps_.socket_factory->AddSocketDataProvider(&data2);
1315 1315
1316 const char* kExpectedResponseData[] = { 1316 const char* const kExpectedResponseData[] = {
1317 "hello", "world" 1317 "hello", "world"
1318 }; 1318 };
1319 1319
1320 uint32 first_socket_log_id = NetLog::Source::kInvalidId; 1320 uint32 first_socket_log_id = NetLog::Source::kInvalidId;
1321 for (int i = 0; i < 2; ++i) { 1321 for (int i = 0; i < 2; ++i) {
1322 TestCompletionCallback callback; 1322 TestCompletionCallback callback;
1323 1323
1324 scoped_ptr<HttpTransaction> trans( 1324 scoped_ptr<HttpTransaction> trans(
1325 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 1325 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
1326 1326
(...skipping 2091 matching lines...) Expand 10 before | Expand all | Expand 10 after
3418 session_deps_.net_log = log.bound().net_log(); 3418 session_deps_.net_log = log.bound().net_log();
3419 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 3419 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
3420 3420
3421 scoped_ptr<HttpTransaction> trans( 3421 scoped_ptr<HttpTransaction> trans(
3422 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 3422 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
3423 3423
3424 // CONNECT to www.google.com:443 via SPDY 3424 // CONNECT to www.google.com:443 via SPDY
3425 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( 3425 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(
3426 NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); 3426 NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443)));
3427 // fetch https://www.google.com/ via SPDY 3427 // fetch https://www.google.com/ via SPDY
3428 const char* const kMyUrl = "https://www.google.com/"; 3428 const char kMyUrl[] = "https://www.google.com/";
3429 scoped_ptr<SpdyFrame> get( 3429 scoped_ptr<SpdyFrame> get(
3430 spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); 3430 spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST));
3431 scoped_ptr<SpdyFrame> wrapped_get( 3431 scoped_ptr<SpdyFrame> wrapped_get(
3432 spdy_util_.ConstructWrappedSpdyFrame(get, 1)); 3432 spdy_util_.ConstructWrappedSpdyFrame(get, 1));
3433 scoped_ptr<SpdyFrame> conn_resp( 3433 scoped_ptr<SpdyFrame> conn_resp(
3434 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 3434 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
3435 scoped_ptr<SpdyFrame> get_resp( 3435 scoped_ptr<SpdyFrame> get_resp(
3436 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 3436 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
3437 scoped_ptr<SpdyFrame> wrapped_get_resp( 3437 scoped_ptr<SpdyFrame> wrapped_get_resp(
3438 spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); 3438 spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1));
(...skipping 1704 matching lines...) Expand 10 before | Expand all | Expand 10 after
5143 MockWrite data_writes2[] = { 5143 MockWrite data_writes2[] = {
5144 MockWrite(SYNCHRONOUS, 93), // POST 5144 MockWrite(SYNCHRONOUS, 93), // POST
5145 MockWrite(SYNCHRONOUS, 3), // POST data 5145 MockWrite(SYNCHRONOUS, 3), // POST data
5146 }; 5146 };
5147 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), 5147 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
5148 data_writes2, arraysize(data_writes2)); 5148 data_writes2, arraysize(data_writes2));
5149 5149
5150 session_deps_.socket_factory->AddSocketDataProvider(&data1); 5150 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5151 session_deps_.socket_factory->AddSocketDataProvider(&data2); 5151 session_deps_.socket_factory->AddSocketDataProvider(&data2);
5152 5152
5153 const char* kExpectedResponseData[] = { 5153 const char* const kExpectedResponseData[] = {
5154 "hello world", "welcome" 5154 "hello world", "welcome"
5155 }; 5155 };
5156 5156
5157 for (int i = 0; i < 2; ++i) { 5157 for (int i = 0; i < 2; ++i) {
5158 scoped_ptr<HttpTransaction> trans( 5158 scoped_ptr<HttpTransaction> trans(
5159 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 5159 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
5160 5160
5161 TestCompletionCallback callback; 5161 TestCompletionCallback callback;
5162 5162
5163 int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); 5163 int rv = trans->Start(&request[i], callback.callback(), BoundNetLog());
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after
6491 6491
6492 MockWrite spdy_writes[] = { 6492 MockWrite spdy_writes[] = {
6493 CreateMockWrite(*req, 1, ASYNC), 6493 CreateMockWrite(*req, 1, ASYNC),
6494 CreateMockWrite(*rst, 4, ASYNC), 6494 CreateMockWrite(*rst, 4, ASYNC),
6495 CreateMockWrite(*connect2, 5), 6495 CreateMockWrite(*connect2, 5),
6496 CreateMockWrite(*wrapped_get, 8), 6496 CreateMockWrite(*wrapped_get, 8),
6497 }; 6497 };
6498 6498
6499 // The proxy responds to the connect with a 407, using a persistent 6499 // The proxy responds to the connect with a 407, using a persistent
6500 // connection. 6500 // connection.
6501 const char* const kAuthStatus = "407"; 6501 const char kAuthStatus[] = "407";
6502 const char* const kAuthChallenge[] = { 6502 const char* const kAuthChallenge[] = {
6503 "proxy-authenticate", "Basic realm=\"MyRealm1\"", 6503 "proxy-authenticate", "Basic realm=\"MyRealm1\"",
6504 }; 6504 };
6505 scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( 6505 scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError(
6506 kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); 6506 kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1));
6507 6507
6508 scoped_ptr<SpdyFrame> conn_resp( 6508 scoped_ptr<SpdyFrame> conn_resp(
6509 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); 6509 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
6510 const char resp[] = "HTTP/1.1 200 OK\r\n" 6510 const char resp[] = "HTTP/1.1 200 OK\r\n"
6511 "Content-Length: 5\r\n\r\n"; 6511 "Content-Length: 5\r\n\r\n";
(...skipping 3030 matching lines...) Expand 10 before | Expand all | Expand 10 after
9542 MockWrite write; 9542 MockWrite write;
9543 MockRead read; 9543 MockRead read;
9544 int expected_rv; 9544 int expected_rv;
9545 const MockWrite* extra_write; 9545 const MockWrite* extra_write;
9546 const MockRead* extra_read; 9546 const MockRead* extra_read;
9547 }; 9547 };
9548 9548
9549 static const int kNoSSL = 500; 9549 static const int kNoSSL = 500;
9550 9550
9551 struct TestConfig { 9551 struct TestConfig {
9552 const char* proxy_url; 9552 const char* const proxy_url;
9553 AuthTiming proxy_auth_timing; 9553 AuthTiming proxy_auth_timing;
9554 int proxy_auth_rv; 9554 int proxy_auth_rv;
9555 const char* server_url; 9555 const char* const server_url;
9556 AuthTiming server_auth_timing; 9556 AuthTiming server_auth_timing;
9557 int server_auth_rv; 9557 int server_auth_rv;
9558 int num_auth_rounds; 9558 int num_auth_rounds;
9559 int first_ssl_round; 9559 int first_ssl_round;
9560 TestRound rounds[3]; 9560 TestRound rounds[3];
9561 } test_configs[] = { 9561 } test_configs[] = {
9562 // Non-authenticating HTTP server with a direct connection. 9562 // Non-authenticating HTTP server with a direct connection.
9563 { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, 9563 { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL,
9564 { TestRound(kGet, kSuccess, OK)}}, 9564 { TestRound(kGet, kSuccess, OK)}},
9565 // Authenticating HTTP server with a direct connection. 9565 // Authenticating HTTP server with a direct connection.
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
9927 kServerChallenge, 9927 kServerChallenge,
9928 // Fourth round 9928 // Fourth round
9929 kSuccess, 9929 kSuccess,
9930 // Competing response 9930 // Competing response
9931 kSuccess, 9931 kSuccess,
9932 }; 9932 };
9933 StaticSocketDataProvider data_provider(reads, arraysize(reads), 9933 StaticSocketDataProvider data_provider(reads, arraysize(reads),
9934 writes, arraysize(writes)); 9934 writes, arraysize(writes));
9935 session_deps_.socket_factory->AddSocketDataProvider(&data_provider); 9935 session_deps_.socket_factory->AddSocketDataProvider(&data_provider);
9936 9936
9937 const char* const kSocketGroup = "www.example.com:80"; 9937 const char kSocketGroup[] = "www.example.com:80";
9938 9938
9939 // First round of authentication. 9939 // First round of authentication.
9940 auth_handler->SetGenerateExpectation(false, OK); 9940 auth_handler->SetGenerateExpectation(false, OK);
9941 rv = trans->Start(&request, callback.callback(), BoundNetLog()); 9941 rv = trans->Start(&request, callback.callback(), BoundNetLog());
9942 if (rv == ERR_IO_PENDING) 9942 if (rv == ERR_IO_PENDING)
9943 rv = callback.WaitForResult(); 9943 rv = callback.WaitForResult();
9944 EXPECT_EQ(OK, rv); 9944 EXPECT_EQ(OK, rv);
9945 response = trans->GetResponseInfo(); 9945 response = trans->GetResponseInfo();
9946 ASSERT_TRUE(response != NULL); 9946 ASSERT_TRUE(response != NULL);
9947 EXPECT_FALSE(response->auth_challenge.get() == NULL); 9947 EXPECT_FALSE(response->auth_challenge.get() == NULL);
(...skipping 3608 matching lines...) Expand 10 before | Expand all | Expand 10 after
13556 ASSERT_TRUE(response); 13556 ASSERT_TRUE(response);
13557 ASSERT_TRUE(response->headers.get()); 13557 ASSERT_TRUE(response->headers.get());
13558 13558
13559 EXPECT_EQ(101, response->headers->response_code()); 13559 EXPECT_EQ(101, response->headers->response_code());
13560 13560
13561 trans.reset(); 13561 trans.reset();
13562 session->CloseAllConnections(); 13562 session->CloseAllConnections();
13563 } 13563 }
13564 13564
13565 } // namespace net 13565 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_session.cc ('k') | net/http/http_response_headers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698