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

Side by Side Diff: net/spdy/spdy_network_transaction_unittest.cc

Issue 2801603003: Add SpdyString alias for std::string in net/spdy. (Closed)
Patch Set: Created 3 years, 8 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/spdy/spdy_log_util_unittest.cc ('k') | net/spdy/spdy_pinnable_buffer_piece_test.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 (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 <cmath> 5 #include <cmath>
6 #include <memory> 6 #include <memory>
7 #include <string>
8 #include <utility> 7 #include <utility>
9 #include <vector> 8 #include <vector>
10 9
11 #include "base/bind.h" 10 #include "base/bind.h"
12 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
13 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
14 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
15 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
16 #include "base/run_loop.h" 15 #include "base/run_loop.h"
17 #include "base/test/test_file_util.h" 16 #include "base/test/test_file_util.h"
(...skipping 14 matching lines...) Expand all
32 #include "net/http/http_transaction_test_util.h" 31 #include "net/http/http_transaction_test_util.h"
33 #include "net/log/net_log_event_type.h" 32 #include "net/log/net_log_event_type.h"
34 #include "net/log/net_log_with_source.h" 33 #include "net/log/net_log_with_source.h"
35 #include "net/log/test_net_log.h" 34 #include "net/log/test_net_log.h"
36 #include "net/log/test_net_log_entry.h" 35 #include "net/log/test_net_log_entry.h"
37 #include "net/log/test_net_log_util.h" 36 #include "net/log/test_net_log_util.h"
38 #include "net/proxy/proxy_server.h" 37 #include "net/proxy/proxy_server.h"
39 #include "net/socket/client_socket_pool_base.h" 38 #include "net/socket/client_socket_pool_base.h"
40 #include "net/socket/next_proto.h" 39 #include "net/socket/next_proto.h"
41 #include "net/spdy/buffered_spdy_framer.h" 40 #include "net/spdy/buffered_spdy_framer.h"
41 #include "net/spdy/platform/api/spdy_string.h"
42 #include "net/spdy/platform/api/spdy_string_piece.h" 42 #include "net/spdy/platform/api/spdy_string_piece.h"
43 #include "net/spdy/spdy_http_stream.h" 43 #include "net/spdy/spdy_http_stream.h"
44 #include "net/spdy/spdy_http_utils.h" 44 #include "net/spdy/spdy_http_utils.h"
45 #include "net/spdy/spdy_protocol.h" 45 #include "net/spdy/spdy_protocol.h"
46 #include "net/spdy/spdy_session.h" 46 #include "net/spdy/spdy_session.h"
47 #include "net/spdy/spdy_session_pool.h" 47 #include "net/spdy/spdy_session_pool.h"
48 #include "net/spdy/spdy_test_util_common.h" 48 #include "net/spdy/spdy_test_util_common.h"
49 #include "net/spdy/spdy_test_utils.h" 49 #include "net/spdy/spdy_test_utils.h"
50 #include "net/ssl/ssl_connection_status_flags.h" 50 #include "net/ssl/ssl_connection_status_flags.h"
51 #include "net/test/cert_test_util.h" 51 #include "net/test/cert_test_util.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 void SetUp() override { 87 void SetUp() override {
88 get_request_initialized_ = false; 88 get_request_initialized_ = false;
89 post_request_initialized_ = false; 89 post_request_initialized_ = false;
90 chunked_post_request_initialized_ = false; 90 chunked_post_request_initialized_ = false;
91 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 91 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
92 } 92 }
93 93
94 struct TransactionHelperResult { 94 struct TransactionHelperResult {
95 int rv; 95 int rv;
96 std::string status_line; 96 SpdyString status_line;
97 std::string response_data; 97 SpdyString response_data;
98 HttpResponseInfo response_info; 98 HttpResponseInfo response_info;
99 }; 99 };
100 100
101 // A helper class that handles all the initial npn/ssl setup. 101 // A helper class that handles all the initial npn/ssl setup.
102 class NormalSpdyTransactionHelper { 102 class NormalSpdyTransactionHelper {
103 public: 103 public:
104 NormalSpdyTransactionHelper( 104 NormalSpdyTransactionHelper(
105 const HttpRequestInfo& request, 105 const HttpRequestInfo& request,
106 RequestPriority priority, 106 RequestPriority priority,
107 const NetLogWithSource& log, 107 const NetLogWithSource& log,
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 upload_chunked_data_stream_.get(); 400 upload_chunked_data_stream_.get();
401 chunked_post_request_initialized_ = true; 401 chunked_post_request_initialized_ = true;
402 } 402 }
403 return chunked_post_request_; 403 return chunked_post_request_;
404 } 404 }
405 405
406 // Read the result of a particular transaction, knowing that we've got 406 // Read the result of a particular transaction, knowing that we've got
407 // multiple transactions in the read pipeline; so as we read, we may have 407 // multiple transactions in the read pipeline; so as we read, we may have
408 // to skip over data destined for other transactions while we consume 408 // to skip over data destined for other transactions while we consume
409 // the data for |trans|. 409 // the data for |trans|.
410 int ReadResult(HttpNetworkTransaction* trans, 410 int ReadResult(HttpNetworkTransaction* trans, SpdyString* result) {
411 std::string* result) {
412 const int kSize = 3000; 411 const int kSize = 3000;
413 412
414 int bytes_read = 0; 413 int bytes_read = 0;
415 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(kSize)); 414 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(kSize));
416 TestCompletionCallback callback; 415 TestCompletionCallback callback;
417 while (true) { 416 while (true) {
418 int rv = trans->Read(buf.get(), kSize, callback.callback()); 417 int rv = trans->Read(buf.get(), kSize, callback.callback());
419 if (rv == ERR_IO_PENDING) { 418 if (rv == ERR_IO_PENDING) {
420 rv = callback.WaitForResult(); 419 rv = callback.WaitForResult();
421 } else if (rv <= 0) { 420 } else if (rv <= 0) {
(...skipping 19 matching lines...) Expand all
441 key, url, 440 key, url,
442 /* enable_ip_based_pooling = */ true, log); 441 /* enable_ip_based_pooling = */ true, log);
443 ASSERT_TRUE(spdy_session); 442 ASSERT_TRUE(spdy_session);
444 EXPECT_EQ(0u, spdy_session->num_active_streams()); 443 EXPECT_EQ(0u, spdy_session->num_active_streams());
445 EXPECT_EQ(0u, spdy_session->num_unclaimed_pushed_streams()); 444 EXPECT_EQ(0u, spdy_session->num_unclaimed_pushed_streams());
446 } 445 }
447 446
448 void RunServerPushTest(SequencedSocketData* data, 447 void RunServerPushTest(SequencedSocketData* data,
449 HttpResponseInfo* response, 448 HttpResponseInfo* response,
450 HttpResponseInfo* push_response, 449 HttpResponseInfo* push_response,
451 const std::string& expected) { 450 const SpdyString& expected) {
452 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 451 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
453 NetLogWithSource(), nullptr); 452 NetLogWithSource(), nullptr);
454 helper.RunPreTestSetup(); 453 helper.RunPreTestSetup();
455 helper.AddData(data); 454 helper.AddData(data);
456 455
457 HttpNetworkTransaction* trans = helper.trans(); 456 HttpNetworkTransaction* trans = helper.trans();
458 457
459 // Start the transaction with basic parameters. 458 // Start the transaction with basic parameters.
460 TestCompletionCallback callback; 459 TestCompletionCallback callback;
461 int rv = trans->Start(&CreateGetRequest(), callback.callback(), 460 int rv = trans->Start(&CreateGetRequest(), callback.callback(),
462 NetLogWithSource()); 461 NetLogWithSource());
463 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 462 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
464 rv = callback.WaitForResult(); 463 rv = callback.WaitForResult();
465 464
466 // Finish async network reads/writes. 465 // Finish async network reads/writes.
467 base::RunLoop().RunUntilIdle(); 466 base::RunLoop().RunUntilIdle();
468 467
469 // Request the pushed path. 468 // Request the pushed path.
470 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); 469 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session());
471 rv = trans2.Start(&CreateGetPushRequest(), callback.callback(), 470 rv = trans2.Start(&CreateGetPushRequest(), callback.callback(),
472 NetLogWithSource()); 471 NetLogWithSource());
473 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 472 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
474 base::RunLoop().RunUntilIdle(); 473 base::RunLoop().RunUntilIdle();
475 474
476 // The data for the pushed path may be coming in more than 1 frame. Compile 475 // The data for the pushed path may be coming in more than 1 frame. Compile
477 // the results into a single string. 476 // the results into a single string.
478 477
479 // Read the server push body. 478 // Read the server push body.
480 std::string result2; 479 SpdyString result2;
481 ReadResult(&trans2, &result2); 480 ReadResult(&trans2, &result2);
482 // Read the response body. 481 // Read the response body.
483 std::string result; 482 SpdyString result;
484 ReadResult(trans, &result); 483 ReadResult(trans, &result);
485 484
486 // Verify that we consumed all test data. 485 // Verify that we consumed all test data.
487 EXPECT_TRUE(data->AllReadDataConsumed()); 486 EXPECT_TRUE(data->AllReadDataConsumed());
488 EXPECT_TRUE(data->AllWriteDataConsumed()); 487 EXPECT_TRUE(data->AllWriteDataConsumed());
489 488
490 LoadTimingInfo load_timing_info; 489 LoadTimingInfo load_timing_info;
491 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); 490 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
492 EXPECT_TRUE(load_timing_info.push_start.is_null()); 491 EXPECT_TRUE(load_timing_info.push_start.is_null());
493 EXPECT_TRUE(load_timing_info.push_end.is_null()); 492 EXPECT_TRUE(load_timing_info.push_end.is_null());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 request.load_flags = 0; 557 request.load_flags = 0;
559 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); 558 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
560 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 559 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
561 callback.WaitForResult(); 560 callback.WaitForResult();
562 } 561 }
563 562
564 ChunkedUploadDataStream* upload_chunked_data_stream() const { 563 ChunkedUploadDataStream* upload_chunked_data_stream() const {
565 return upload_chunked_data_stream_.get(); 564 return upload_chunked_data_stream_.get();
566 } 565 }
567 566
568 std::string GetDefaultUrlWithPath(const char* path) { 567 SpdyString GetDefaultUrlWithPath(const char* path) {
569 return std::string(kDefaultUrl) + path; 568 return SpdyString(kDefaultUrl) + path;
570 } 569 }
571 570
572 const GURL default_url_; 571 const GURL default_url_;
573 const HostPortPair host_port_pair_; 572 const HostPortPair host_port_pair_;
574 SpdyTestUtil spdy_util_; 573 SpdyTestUtil spdy_util_;
575 574
576 private: 575 private:
577 std::unique_ptr<ChunkedUploadDataStream> upload_chunked_data_stream_; 576 std::unique_ptr<ChunkedUploadDataStream> upload_chunked_data_stream_;
578 std::unique_ptr<UploadDataStream> upload_data_stream_; 577 std::unique_ptr<UploadDataStream> upload_data_stream_;
579 bool get_request_initialized_; 578 bool get_request_initialized_;
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 ASSERT_TRUE(helper.StartDefaultTest()); 1664 ASSERT_TRUE(helper.StartDefaultTest());
1666 1665
1667 base::RunLoop().RunUntilIdle(); 1666 base::RunLoop().RunUntilIdle();
1668 upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, false); 1667 upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, false);
1669 base::RunLoop().RunUntilIdle(); 1668 base::RunLoop().RunUntilIdle();
1670 upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, true); 1669 upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, true);
1671 1670
1672 helper.FinishDefaultTest(); 1671 helper.FinishDefaultTest();
1673 helper.VerifyDataConsumed(); 1672 helper.VerifyDataConsumed();
1674 1673
1675 std::string expected_response; 1674 SpdyString expected_response;
1676 expected_response += kUploadData; 1675 expected_response += kUploadData;
1677 expected_response += kUploadData; 1676 expected_response += kUploadData;
1678 expected_response += kUploadData; 1677 expected_response += kUploadData;
1679 1678
1680 TransactionHelperResult out = helper.output(); 1679 TransactionHelperResult out = helper.output();
1681 EXPECT_THAT(out.rv, IsOk()); 1680 EXPECT_THAT(out.rv, IsOk());
1682 EXPECT_EQ("HTTP/1.1 200", out.status_line); 1681 EXPECT_EQ("HTTP/1.1 200", out.status_line);
1683 EXPECT_EQ(expected_response, out.response_data); 1682 EXPECT_EQ(expected_response, out.response_data);
1684 } 1683 }
1685 1684
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1791 // Process the request headers, response headers, and response body. 1790 // Process the request headers, response headers, and response body.
1792 // The request body is still in flight. 1791 // The request body is still in flight.
1793 const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); 1792 const HttpResponseInfo* response = helper.trans()->GetResponseInfo();
1794 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); 1793 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine());
1795 1794
1796 // Finish sending the request body. 1795 // Finish sending the request body.
1797 upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, true); 1796 upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, true);
1798 helper.WaitForCallbackToComplete(); 1797 helper.WaitForCallbackToComplete();
1799 EXPECT_THAT(helper.output().rv, IsOk()); 1798 EXPECT_THAT(helper.output().rv, IsOk());
1800 1799
1801 std::string response_body; 1800 SpdyString response_body;
1802 EXPECT_THAT(ReadTransaction(helper.trans(), &response_body), IsOk()); 1801 EXPECT_THAT(ReadTransaction(helper.trans(), &response_body), IsOk());
1803 EXPECT_EQ(kUploadData, response_body); 1802 EXPECT_EQ(kUploadData, response_body);
1804 1803
1805 // Finish async network reads/writes. 1804 // Finish async network reads/writes.
1806 base::RunLoop().RunUntilIdle(); 1805 base::RunLoop().RunUntilIdle();
1807 helper.VerifyDataConsumed(); 1806 helper.VerifyDataConsumed();
1808 } 1807 }
1809 1808
1810 // The client upon cancellation tries to send a RST_STREAM frame. The mock 1809 // The client upon cancellation tries to send a RST_STREAM frame. The mock
1811 // socket causes the TCP write to return zero. This test checks that the client 1810 // socket causes the TCP write to return zero. This test checks that the client
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1896 int rv = 1895 int rv =
1897 trans->Start(&helper.request(), callback.callback(), NetLogWithSource()); 1896 trans->Start(&helper.request(), callback.callback(), NetLogWithSource());
1898 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 1897 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1899 rv = callback.WaitForResult(); 1898 rv = callback.WaitForResult();
1900 EXPECT_THAT(rv, IsOk()); 1899 EXPECT_THAT(rv, IsOk());
1901 1900
1902 const HttpResponseInfo* response = trans->GetResponseInfo(); 1901 const HttpResponseInfo* response = trans->GetResponseInfo();
1903 ASSERT_TRUE(response); 1902 ASSERT_TRUE(response);
1904 EXPECT_TRUE(response->headers); 1903 EXPECT_TRUE(response->headers);
1905 EXPECT_TRUE(response->was_fetched_via_spdy); 1904 EXPECT_TRUE(response->was_fetched_via_spdy);
1906 std::string response_data; 1905 SpdyString response_data;
1907 rv = ReadTransaction(trans, &response_data); 1906 rv = ReadTransaction(trans, &response_data);
1908 EXPECT_THAT(rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); 1907 EXPECT_THAT(rv, IsError(ERR_SPDY_PROTOCOL_ERROR));
1909 1908
1910 helper.VerifyDataConsumed(); 1909 helper.VerifyDataConsumed();
1911 } 1910 }
1912 1911
1913 TEST_F(SpdyNetworkTransactionTest, ResetReplyWithTransferEncoding) { 1912 TEST_F(SpdyNetworkTransactionTest, ResetReplyWithTransferEncoding) {
1914 // Construct the request. 1913 // Construct the request.
1915 SpdySerializedFrame req( 1914 SpdySerializedFrame req(
1916 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); 1915 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true));
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
2230 spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); 2229 spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true));
2231 MockWrite writes[] = { 2230 MockWrite writes[] = {
2232 CreateMockWrite(req, 0), CreateMockWrite(priority, 2), 2231 CreateMockWrite(req, 0), CreateMockWrite(priority, 2),
2233 }; 2232 };
2234 2233
2235 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); 2234 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1));
2236 SpdySerializedFrame response_body_frame( 2235 SpdySerializedFrame response_body_frame(
2237 spdy_util_.ConstructSpdyDataFrame(1, "should not include", 18, true)); 2236 spdy_util_.ConstructSpdyDataFrame(1, "should not include", 18, true));
2238 2237
2239 SpdyHeaderBlock push_headers; 2238 SpdyHeaderBlock push_headers;
2240 spdy_util_.AddUrlToHeaderBlock(std::string(kDefaultUrl) + "b.dat", 2239 spdy_util_.AddUrlToHeaderBlock(SpdyString(kDefaultUrl) + "b.dat",
2241 &push_headers); 2240 &push_headers);
2242 2241
2243 SpdySerializedFrame push_init_frame( 2242 SpdySerializedFrame push_init_frame(
2244 spdy_util_.ConstructInitialSpdyPushFrame(std::move(push_headers), 2, 1)); 2243 spdy_util_.ConstructInitialSpdyPushFrame(std::move(push_headers), 2, 1));
2245 2244
2246 SpdySerializedFrame push_headers_frame( 2245 SpdySerializedFrame push_headers_frame(
2247 spdy_util_.ConstructSpdyPushHeaders(2, nullptr, 0)); 2246 spdy_util_.ConstructSpdyPushHeaders(2, nullptr, 0));
2248 2247
2249 SpdySerializedFrame push_body_frame(spdy_util_.ConstructSpdyDataFrame( 2248 SpdySerializedFrame push_body_frame(spdy_util_.ConstructSpdyDataFrame(
2250 2, "should not include either", 25, false)); 2249 2, "should not include either", 25, false));
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
2347 r->Start(); 2346 r->Start();
2348 base::RunLoop().Run(); 2347 base::RunLoop().Run();
2349 2348
2350 EXPECT_EQ(1, d.received_redirect_count()); 2349 EXPECT_EQ(1, d.received_redirect_count());
2351 2350
2352 r->FollowDeferredRedirect(); 2351 r->FollowDeferredRedirect();
2353 base::RunLoop().Run(); 2352 base::RunLoop().Run();
2354 EXPECT_EQ(1, d.response_started_count()); 2353 EXPECT_EQ(1, d.response_started_count());
2355 EXPECT_FALSE(d.received_data_before_response()); 2354 EXPECT_FALSE(d.received_data_before_response());
2356 EXPECT_EQ(OK, d.request_status()); 2355 EXPECT_EQ(OK, d.request_status());
2357 std::string contents("hello!"); 2356 SpdyString contents("hello!");
2358 EXPECT_EQ(contents, d.data_received()); 2357 EXPECT_EQ(contents, d.data_received());
2359 } 2358 }
2360 EXPECT_TRUE(data.AllReadDataConsumed()); 2359 EXPECT_TRUE(data.AllReadDataConsumed());
2361 EXPECT_TRUE(data.AllWriteDataConsumed()); 2360 EXPECT_TRUE(data.AllWriteDataConsumed());
2362 EXPECT_TRUE(data2.AllReadDataConsumed()); 2361 EXPECT_TRUE(data2.AllReadDataConsumed());
2363 EXPECT_TRUE(data2.AllWriteDataConsumed()); 2362 EXPECT_TRUE(data2.AllWriteDataConsumed());
2364 } 2363 }
2365 2364
2366 // Send a spdy request to www.example.org. Get a pushed stream that redirects to 2365 // Send a spdy request to www.example.org. Get a pushed stream that redirects to
2367 // www.foo.com. 2366 // www.foo.com.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2415 { 2414 {
2416 std::unique_ptr<URLRequest> r(spdy_url_request_context.CreateRequest( 2415 std::unique_ptr<URLRequest> r(spdy_url_request_context.CreateRequest(
2417 default_url_, DEFAULT_PRIORITY, &d)); 2416 default_url_, DEFAULT_PRIORITY, &d));
2418 spdy_url_request_context.socket_factory(). 2417 spdy_url_request_context.socket_factory().
2419 AddSocketDataProvider(&data); 2418 AddSocketDataProvider(&data);
2420 2419
2421 r->Start(); 2420 r->Start();
2422 base::RunLoop().Run(); 2421 base::RunLoop().Run();
2423 2422
2424 EXPECT_EQ(0, d.received_redirect_count()); 2423 EXPECT_EQ(0, d.received_redirect_count());
2425 std::string contents("hello!"); 2424 SpdyString contents("hello!");
2426 EXPECT_EQ(contents, d.data_received()); 2425 EXPECT_EQ(contents, d.data_received());
2427 2426
2428 std::unique_ptr<URLRequest> r2(spdy_url_request_context.CreateRequest( 2427 std::unique_ptr<URLRequest> r2(spdy_url_request_context.CreateRequest(
2429 GURL(GetDefaultUrlWithPath("/foo.dat")), DEFAULT_PRIORITY, &d2)); 2428 GURL(GetDefaultUrlWithPath("/foo.dat")), DEFAULT_PRIORITY, &d2));
2430 spdy_url_request_context.socket_factory(). 2429 spdy_url_request_context.socket_factory().
2431 AddSocketDataProvider(&data2); 2430 AddSocketDataProvider(&data2);
2432 2431
2433 d2.set_quit_on_redirect(true); 2432 d2.set_quit_on_redirect(true);
2434 r2->Start(); 2433 r2->Start();
2435 base::RunLoop().Run(); 2434 base::RunLoop().Run();
2436 EXPECT_EQ(1, d2.received_redirect_count()); 2435 EXPECT_EQ(1, d2.received_redirect_count());
2437 2436
2438 r2->FollowDeferredRedirect(); 2437 r2->FollowDeferredRedirect();
2439 base::RunLoop().Run(); 2438 base::RunLoop().Run();
2440 EXPECT_EQ(1, d2.response_started_count()); 2439 EXPECT_EQ(1, d2.response_started_count());
2441 EXPECT_FALSE(d2.received_data_before_response()); 2440 EXPECT_FALSE(d2.received_data_before_response());
2442 EXPECT_EQ(OK, d2.request_status()); 2441 EXPECT_EQ(OK, d2.request_status());
2443 std::string contents2("hello!"); 2442 SpdyString contents2("hello!");
2444 EXPECT_EQ(contents2, d2.data_received()); 2443 EXPECT_EQ(contents2, d2.data_received());
2445 } 2444 }
2446 EXPECT_TRUE(data.AllReadDataConsumed()); 2445 EXPECT_TRUE(data.AllReadDataConsumed());
2447 EXPECT_TRUE(data.AllWriteDataConsumed()); 2446 EXPECT_TRUE(data.AllWriteDataConsumed());
2448 EXPECT_TRUE(data2.AllReadDataConsumed()); 2447 EXPECT_TRUE(data2.AllReadDataConsumed());
2449 EXPECT_TRUE(data2.AllWriteDataConsumed()); 2448 EXPECT_TRUE(data2.AllWriteDataConsumed());
2450 } 2449 }
2451 2450
2452 TEST_F(SpdyNetworkTransactionTest, ServerPushSingleDataFrame) { 2451 TEST_F(SpdyNetworkTransactionTest, ServerPushSingleDataFrame) {
2453 SpdySerializedFrame stream1_syn( 2452 SpdySerializedFrame stream1_syn(
(...skipping 13 matching lines...) Expand all
2467 SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( 2466 SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(
2468 2, kPushedData, strlen(kPushedData), true)); 2467 2, kPushedData, strlen(kPushedData), true));
2469 MockRead reads[] = { 2468 MockRead reads[] = {
2470 CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), 2469 CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2),
2471 CreateMockRead(stream1_body, 4), CreateMockRead(stream2_body, 5), 2470 CreateMockRead(stream1_body, 4), CreateMockRead(stream2_body, 5),
2472 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause 2471 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause
2473 }; 2472 };
2474 2473
2475 HttpResponseInfo response; 2474 HttpResponseInfo response;
2476 HttpResponseInfo response2; 2475 HttpResponseInfo response2;
2477 std::string expected_push_result("pushed"); 2476 SpdyString expected_push_result("pushed");
2478 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2477 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
2479 RunServerPushTest(&data, 2478 RunServerPushTest(&data,
2480 &response, 2479 &response,
2481 &response2, 2480 &response2,
2482 expected_push_result); 2481 expected_push_result);
2483 2482
2484 // Verify the response headers. 2483 // Verify the response headers.
2485 EXPECT_TRUE(response.headers); 2484 EXPECT_TRUE(response.headers);
2486 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); 2485 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine());
2487 2486
(...skipping 22 matching lines...) Expand all
2510 MockRead reads[] = { 2509 MockRead reads[] = {
2511 CreateMockRead(stream2_syn, 1), 2510 CreateMockRead(stream2_syn, 1),
2512 CreateMockRead(stream1_reply, 3), 2511 CreateMockRead(stream1_reply, 3),
2513 CreateMockRead(stream1_body, 4, SYNCHRONOUS), 2512 CreateMockRead(stream1_body, 4, SYNCHRONOUS),
2514 CreateMockRead(stream2_body, 5), 2513 CreateMockRead(stream2_body, 5),
2515 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause 2514 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause
2516 }; 2515 };
2517 2516
2518 HttpResponseInfo response; 2517 HttpResponseInfo response;
2519 HttpResponseInfo response2; 2518 HttpResponseInfo response2;
2520 std::string expected_push_result("pushed"); 2519 SpdyString expected_push_result("pushed");
2521 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2520 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
2522 RunServerPushTest(&data, 2521 RunServerPushTest(&data,
2523 &response, 2522 &response,
2524 &response2, 2523 &response2,
2525 expected_push_result); 2524 expected_push_result);
2526 2525
2527 // Verify the response headers. 2526 // Verify the response headers.
2528 EXPECT_TRUE(response.headers); 2527 EXPECT_TRUE(response.headers);
2529 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); 2528 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine());
2530 2529
(...skipping 22 matching lines...) Expand all
2553 MockRead reads[] = { 2552 MockRead reads[] = {
2554 CreateMockRead(stream1_reply, 1), 2553 CreateMockRead(stream1_reply, 1),
2555 CreateMockRead(stream2_syn, 2), 2554 CreateMockRead(stream2_syn, 2),
2556 CreateMockRead(stream2_body, 4), 2555 CreateMockRead(stream2_body, 4),
2557 CreateMockRead(stream1_body, 5, SYNCHRONOUS), 2556 CreateMockRead(stream1_body, 5, SYNCHRONOUS),
2558 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause 2557 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause
2559 }; 2558 };
2560 2559
2561 HttpResponseInfo response; 2560 HttpResponseInfo response;
2562 HttpResponseInfo response2; 2561 HttpResponseInfo response2;
2563 std::string expected_push_result("pushed"); 2562 SpdyString expected_push_result("pushed");
2564 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2563 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
2565 RunServerPushTest(&data, 2564 RunServerPushTest(&data,
2566 &response, 2565 &response,
2567 &response2, 2566 &response2,
2568 expected_push_result); 2567 expected_push_result);
2569 2568
2570 // Verify the response headers. 2569 // Verify the response headers.
2571 EXPECT_TRUE(response.headers); 2570 EXPECT_TRUE(response.headers);
2572 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); 2571 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine());
2573 2572
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2766 CreateMockRead(stream1_reply, 1), 2765 CreateMockRead(stream1_reply, 1),
2767 CreateMockRead(stream2_syn, 2), 2766 CreateMockRead(stream2_syn, 2),
2768 CreateMockRead(stream3_syn, 4), 2767 CreateMockRead(stream3_syn, 4),
2769 CreateMockRead(stream1_body, 6), 2768 CreateMockRead(stream1_body, 6),
2770 CreateMockRead(stream2_body, 7), 2769 CreateMockRead(stream2_body, 7),
2771 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), // Force a pause 2770 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), // Force a pause
2772 }; 2771 };
2773 2772
2774 HttpResponseInfo response; 2773 HttpResponseInfo response;
2775 HttpResponseInfo response2; 2774 HttpResponseInfo response2;
2776 std::string expected_push_result("pushed"); 2775 SpdyString expected_push_result("pushed");
2777 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2776 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
2778 RunServerPushTest(&data, 2777 RunServerPushTest(&data,
2779 &response, 2778 &response,
2780 &response2, 2779 &response2,
2781 expected_push_result); 2780 expected_push_result);
2782 2781
2783 // Verify the response headers. 2782 // Verify the response headers.
2784 EXPECT_TRUE(response.headers); 2783 EXPECT_TRUE(response.headers);
2785 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); 2784 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine());
2786 2785
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2822 CreateMockRead(stream2_body1, 4), 2821 CreateMockRead(stream2_body1, 4),
2823 CreateMockRead(stream2_body2, 5), 2822 CreateMockRead(stream2_body2, 5),
2824 CreateMockRead(stream2_body3, 6), 2823 CreateMockRead(stream2_body3, 6),
2825 CreateMockRead(stream2_body4, 7), 2824 CreateMockRead(stream2_body4, 7),
2826 CreateMockRead(stream1_body, 8, SYNCHRONOUS), 2825 CreateMockRead(stream1_body, 8, SYNCHRONOUS),
2827 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 9), // Force a pause 2826 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 9), // Force a pause
2828 }; 2827 };
2829 2828
2830 HttpResponseInfo response; 2829 HttpResponseInfo response;
2831 HttpResponseInfo response2; 2830 HttpResponseInfo response2;
2832 std::string expected_push_result("pushed my darling hello my baby"); 2831 SpdyString expected_push_result("pushed my darling hello my baby");
2833 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2832 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
2834 RunServerPushTest(&data, &response, &response2, kPushedData); 2833 RunServerPushTest(&data, &response, &response2, kPushedData);
2835 2834
2836 // Verify the response headers. 2835 // Verify the response headers.
2837 EXPECT_TRUE(response.headers); 2836 EXPECT_TRUE(response.headers);
2838 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); 2837 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine());
2839 2838
2840 // Verify the pushed stream. 2839 // Verify the pushed stream.
2841 EXPECT_TRUE(response2.headers); 2840 EXPECT_TRUE(response2.headers);
2842 EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); 2841 EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine());
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
3121 3120
3122 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); 3121 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session());
3123 TestCompletionCallback callback2; 3122 TestCompletionCallback callback2;
3124 rv = trans2.Start(&CreateGetPushRequest(), callback2.callback(), 3123 rv = trans2.Start(&CreateGetPushRequest(), callback2.callback(),
3125 NetLogWithSource()); 3124 NetLogWithSource());
3126 rv = callback2.GetResult(rv); 3125 rv = callback2.GetResult(rv);
3127 EXPECT_THAT(rv, IsOk()); 3126 EXPECT_THAT(rv, IsOk());
3128 response = *trans2.GetResponseInfo(); 3127 response = *trans2.GetResponseInfo();
3129 EXPECT_TRUE(response.headers); 3128 EXPECT_TRUE(response.headers);
3130 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); 3129 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine());
3131 std::string result; 3130 SpdyString result;
3132 ReadResult(&trans2, &result); 3131 ReadResult(&trans2, &result);
3133 EXPECT_EQ(kPushedData, result); 3132 EXPECT_EQ(kPushedData, result);
3134 3133
3135 data.Resume(); 3134 data.Resume();
3136 base::RunLoop().RunUntilIdle(); 3135 base::RunLoop().RunUntilIdle();
3137 3136
3138 EXPECT_TRUE(data.AllReadDataConsumed()); 3137 EXPECT_TRUE(data.AllReadDataConsumed());
3139 EXPECT_TRUE(data.AllWriteDataConsumed()); 3138 EXPECT_TRUE(data.AllWriteDataConsumed());
3140 } 3139 }
3141 3140
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3193 helper.RunToCompletion(&data); 3192 helper.RunToCompletion(&data);
3194 TransactionHelperResult out = helper.output(); 3193 TransactionHelperResult out = helper.output();
3195 3194
3196 EXPECT_THAT(out.rv, IsOk()); 3195 EXPECT_THAT(out.rv, IsOk());
3197 EXPECT_EQ("HTTP/1.1 200", out.status_line); 3196 EXPECT_EQ("HTTP/1.1 200", out.status_line);
3198 EXPECT_EQ("hello!", out.response_data); 3197 EXPECT_EQ("hello!", out.response_data);
3199 3198
3200 scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; 3199 scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers;
3201 EXPECT_TRUE(headers); 3200 EXPECT_TRUE(headers);
3202 size_t iter = 0; 3201 size_t iter = 0;
3203 std::string name, value; 3202 SpdyString name, value;
3204 SpdyHeaderBlock header_block; 3203 SpdyHeaderBlock header_block;
3205 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { 3204 while (headers->EnumerateHeaderLines(&iter, &name, &value)) {
3206 auto value_it = header_block.find(name); 3205 auto value_it = header_block.find(name);
3207 if (value_it == header_block.end() || value_it->second.empty()) { 3206 if (value_it == header_block.end() || value_it->second.empty()) {
3208 header_block[name] = value; 3207 header_block[name] = value;
3209 } else { 3208 } else {
3210 std::string joint_value = value_it->second.as_string(); 3209 SpdyString joint_value = value_it->second.as_string();
3211 joint_value.append(1, '\0'); 3210 joint_value.append(1, '\0');
3212 joint_value.append(value); 3211 joint_value.append(value);
3213 header_block[name] = joint_value; 3212 header_block[name] = joint_value;
3214 } 3213 }
3215 } 3214 }
3216 EXPECT_EQ(test_cases[i].expected_headers, header_block); 3215 EXPECT_EQ(test_cases[i].expected_headers, header_block);
3217 } 3216 }
3218 } 3217 }
3219 3218
3220 // Verify that various response headers parse vary fields correctly through the 3219 // Verify that various response headers parse vary fields correctly through the
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3263 MockWrite writes[] = { 3262 MockWrite writes[] = {
3264 CreateMockWrite(frame_req, 0), 3263 CreateMockWrite(frame_req, 0),
3265 }; 3264 };
3266 3265
3267 // Construct the reply. 3266 // Construct the reply.
3268 SpdyHeaderBlock reply_headers; 3267 SpdyHeaderBlock reply_headers;
3269 AppendToHeaderBlock(test_cases[i].extra_headers[1], 3268 AppendToHeaderBlock(test_cases[i].extra_headers[1],
3270 test_cases[i].num_headers[1], 3269 test_cases[i].num_headers[1],
3271 &reply_headers); 3270 &reply_headers);
3272 // Construct the expected header reply string before moving |reply_headers|. 3271 // Construct the expected header reply string before moving |reply_headers|.
3273 std::string expected_reply = 3272 SpdyString expected_reply =
3274 spdy_test_util.ConstructSpdyReplyString(reply_headers); 3273 spdy_test_util.ConstructSpdyReplyString(reply_headers);
3275 3274
3276 SpdySerializedFrame frame_reply( 3275 SpdySerializedFrame frame_reply(
3277 spdy_test_util.ConstructSpdyReply(1, std::move(reply_headers))); 3276 spdy_test_util.ConstructSpdyReply(1, std::move(reply_headers)));
3278 3277
3279 SpdySerializedFrame body(spdy_test_util.ConstructSpdyDataFrame(1, true)); 3278 SpdySerializedFrame body(spdy_test_util.ConstructSpdyDataFrame(1, true));
3280 MockRead reads[] = { 3279 MockRead reads[] = {
3281 CreateMockRead(frame_reply, 1), CreateMockRead(body, 2), 3280 CreateMockRead(frame_reply, 1), CreateMockRead(body, 2),
3282 MockRead(ASYNC, 0, 3) // EOF 3281 MockRead(ASYNC, 0, 3) // EOF
3283 }; 3282 };
(...skipping 20 matching lines...) Expand all
3304 EXPECT_EQ("hello!", out.response_data) << i; 3303 EXPECT_EQ("hello!", out.response_data) << i;
3305 3304
3306 // Test the response information. 3305 // Test the response information.
3307 EXPECT_EQ(out.response_info.vary_data.is_valid(), 3306 EXPECT_EQ(out.response_info.vary_data.is_valid(),
3308 test_cases[i].vary_matches) << i; 3307 test_cases[i].vary_matches) << i;
3309 3308
3310 // Check the headers. 3309 // Check the headers.
3311 scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; 3310 scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers;
3312 ASSERT_TRUE(headers) << i; 3311 ASSERT_TRUE(headers) << i;
3313 size_t iter = 0; 3312 size_t iter = 0;
3314 std::string name, value, lines; 3313 SpdyString name, value, lines;
3315 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { 3314 while (headers->EnumerateHeaderLines(&iter, &name, &value)) {
3316 lines.append(name); 3315 lines.append(name);
3317 lines.append(": "); 3316 lines.append(": ");
3318 lines.append(value); 3317 lines.append(value);
3319 lines.append("\n"); 3318 lines.append("\n");
3320 } 3319 }
3321 3320
3322 EXPECT_EQ(expected_reply, lines) << i; 3321 EXPECT_EQ(expected_reply, lines) << i;
3323 } 3322 }
3324 } 3323 }
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
3561 3560
3562 // Check that we logged all the headers correctly 3561 // Check that we logged all the headers correctly
3563 pos = ExpectLogContainsSomewhere(entries, 0, 3562 pos = ExpectLogContainsSomewhere(entries, 0,
3564 NetLogEventType::HTTP2_SESSION_SEND_HEADERS, 3563 NetLogEventType::HTTP2_SESSION_SEND_HEADERS,
3565 NetLogEventPhase::NONE); 3564 NetLogEventPhase::NONE);
3566 3565
3567 base::ListValue* header_list; 3566 base::ListValue* header_list;
3568 ASSERT_TRUE(entries[pos].params.get()); 3567 ASSERT_TRUE(entries[pos].params.get());
3569 ASSERT_TRUE(entries[pos].params->GetList("headers", &header_list)); 3568 ASSERT_TRUE(entries[pos].params->GetList("headers", &header_list));
3570 3569
3571 std::vector<std::string> expected; 3570 std::vector<SpdyString> expected;
3572 expected.push_back(std::string(spdy_util_.GetHostKey()) + 3571 expected.push_back(SpdyString(spdy_util_.GetHostKey()) + ": www.example.org");
3573 ": www.example.org"); 3572 expected.push_back(SpdyString(spdy_util_.GetPathKey()) + ": /");
3574 expected.push_back(std::string(spdy_util_.GetPathKey()) + ": /"); 3573 expected.push_back(SpdyString(spdy_util_.GetSchemeKey()) + ": " +
3575 expected.push_back(std::string(spdy_util_.GetSchemeKey()) + ": " +
3576 default_url_.scheme()); 3574 default_url_.scheme());
3577 expected.push_back(std::string(spdy_util_.GetMethodKey()) + ": GET"); 3575 expected.push_back(SpdyString(spdy_util_.GetMethodKey()) + ": GET");
3578 expected.push_back("user-agent: Chrome"); 3576 expected.push_back("user-agent: Chrome");
3579 EXPECT_EQ(expected.size(), header_list->GetSize()); 3577 EXPECT_EQ(expected.size(), header_list->GetSize());
3580 for (std::vector<std::string>::const_iterator it = expected.begin(); 3578 for (std::vector<SpdyString>::const_iterator it = expected.begin();
3581 it != expected.end(); 3579 it != expected.end(); ++it) {
3582 ++it) {
3583 base::Value header(*it); 3580 base::Value header(*it);
3584 EXPECT_NE(header_list->end(), header_list->Find(header)) << 3581 EXPECT_NE(header_list->end(), header_list->Find(header)) <<
3585 "Header not found: " << *it; 3582 "Header not found: " << *it;
3586 } 3583 }
3587 } 3584 }
3588 3585
3589 // Since we buffer the IO from the stream to the renderer, this test verifies 3586 // Since we buffer the IO from the stream to the renderer, this test verifies
3590 // that when we read out the maximum amount of data (e.g. we received 50 bytes 3587 // that when we read out the maximum amount of data (e.g. we received 50 bytes
3591 // on the network, but issued a Read for only 5 of those bytes) that the data 3588 // on the network, but issued a Read for only 5 of those bytes) that the data
3592 // flow still works correctly. 3589 // flow still works correctly.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3639 3636
3640 const HttpResponseInfo* response = trans->GetResponseInfo(); 3637 const HttpResponseInfo* response = trans->GetResponseInfo();
3641 EXPECT_TRUE(response->headers); 3638 EXPECT_TRUE(response->headers);
3642 EXPECT_TRUE(response->was_fetched_via_spdy); 3639 EXPECT_TRUE(response->was_fetched_via_spdy);
3643 out.status_line = response->headers->GetStatusLine(); 3640 out.status_line = response->headers->GetStatusLine();
3644 out.response_info = *response; // Make a copy so we can verify. 3641 out.response_info = *response; // Make a copy so we can verify.
3645 3642
3646 // Read Data 3643 // Read Data
3647 TestCompletionCallback read_callback; 3644 TestCompletionCallback read_callback;
3648 3645
3649 std::string content; 3646 SpdyString content;
3650 do { 3647 do {
3651 // Read small chunks at a time. 3648 // Read small chunks at a time.
3652 const int kSmallReadSize = 3; 3649 const int kSmallReadSize = 3;
3653 scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); 3650 scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize));
3654 rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); 3651 rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback());
3655 if (rv == ERR_IO_PENDING) { 3652 if (rv == ERR_IO_PENDING) {
3656 data.Resume(); 3653 data.Resume();
3657 rv = read_callback.WaitForResult(); 3654 rv = read_callback.WaitForResult();
3658 } 3655 }
3659 if (rv > 0) { 3656 if (rv > 0) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
3724 3721
3725 const HttpResponseInfo* response = trans->GetResponseInfo(); 3722 const HttpResponseInfo* response = trans->GetResponseInfo();
3726 EXPECT_TRUE(response->headers); 3723 EXPECT_TRUE(response->headers);
3727 EXPECT_TRUE(response->was_fetched_via_spdy); 3724 EXPECT_TRUE(response->was_fetched_via_spdy);
3728 out.status_line = response->headers->GetStatusLine(); 3725 out.status_line = response->headers->GetStatusLine();
3729 out.response_info = *response; // Make a copy so we can verify. 3726 out.response_info = *response; // Make a copy so we can verify.
3730 3727
3731 // Read Data 3728 // Read Data
3732 TestCompletionCallback read_callback; 3729 TestCompletionCallback read_callback;
3733 3730
3734 std::string content; 3731 SpdyString content;
3735 int reads_completed = 0; 3732 int reads_completed = 0;
3736 do { 3733 do {
3737 // Read small chunks at a time. 3734 // Read small chunks at a time.
3738 const int kSmallReadSize = 14; 3735 const int kSmallReadSize = 14;
3739 scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); 3736 scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize));
3740 rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); 3737 rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback());
3741 if (rv == ERR_IO_PENDING) { 3738 if (rv == ERR_IO_PENDING) {
3742 data.Resume(); 3739 data.Resume();
3743 rv = read_callback.WaitForResult(); 3740 rv = read_callback.WaitForResult();
3744 } 3741 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
3810 3807
3811 const HttpResponseInfo* response = trans->GetResponseInfo(); 3808 const HttpResponseInfo* response = trans->GetResponseInfo();
3812 EXPECT_TRUE(response->headers); 3809 EXPECT_TRUE(response->headers);
3813 EXPECT_TRUE(response->was_fetched_via_spdy); 3810 EXPECT_TRUE(response->was_fetched_via_spdy);
3814 out.status_line = response->headers->GetStatusLine(); 3811 out.status_line = response->headers->GetStatusLine();
3815 out.response_info = *response; // Make a copy so we can verify. 3812 out.response_info = *response; // Make a copy so we can verify.
3816 3813
3817 // Read Data 3814 // Read Data
3818 TestCompletionCallback read_callback; 3815 TestCompletionCallback read_callback;
3819 3816
3820 std::string content; 3817 SpdyString content;
3821 int reads_completed = 0; 3818 int reads_completed = 0;
3822 do { 3819 do {
3823 // Read small chunks at a time. 3820 // Read small chunks at a time.
3824 const int kSmallReadSize = 14; 3821 const int kSmallReadSize = 14;
3825 scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); 3822 scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize));
3826 rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); 3823 rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback());
3827 if (rv > 0) { 3824 if (rv > 0) {
3828 EXPECT_EQ(kSmallReadSize, rv); 3825 EXPECT_EQ(kSmallReadSize, rv);
3829 content.append(buf->data(), rv); 3826 content.append(buf->data(), rv);
3830 } else if (rv < 0) { 3827 } else if (rv < 0) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
3893 3890
3894 const HttpResponseInfo* response = trans->GetResponseInfo(); 3891 const HttpResponseInfo* response = trans->GetResponseInfo();
3895 EXPECT_TRUE(response->headers); 3892 EXPECT_TRUE(response->headers);
3896 EXPECT_TRUE(response->was_fetched_via_spdy); 3893 EXPECT_TRUE(response->was_fetched_via_spdy);
3897 out.status_line = response->headers->GetStatusLine(); 3894 out.status_line = response->headers->GetStatusLine();
3898 out.response_info = *response; // Make a copy so we can verify. 3895 out.response_info = *response; // Make a copy so we can verify.
3899 3896
3900 // Read Data 3897 // Read Data
3901 TestCompletionCallback read_callback; 3898 TestCompletionCallback read_callback;
3902 3899
3903 std::string content; 3900 SpdyString content;
3904 int reads_completed = 0; 3901 int reads_completed = 0;
3905 do { 3902 do {
3906 // Read small chunks at a time. 3903 // Read small chunks at a time.
3907 const int kSmallReadSize = 14; 3904 const int kSmallReadSize = 14;
3908 scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); 3905 scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize));
3909 rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); 3906 rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback());
3910 if (rv == ERR_IO_PENDING) { 3907 if (rv == ERR_IO_PENDING) {
3911 data.Resume(); 3908 data.Resume();
3912 rv = read_callback.WaitForResult(); 3909 rv = read_callback.WaitForResult();
3913 } 3910 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
4078 // Verify second response. 4075 // Verify second response.
4079 const HttpResponseInfo* response = trans2.GetResponseInfo(); 4076 const HttpResponseInfo* response = trans2.GetResponseInfo();
4080 ASSERT_TRUE(response); 4077 ASSERT_TRUE(response);
4081 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP2, response->connection_info); 4078 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP2, response->connection_info);
4082 ASSERT_TRUE(response->headers); 4079 ASSERT_TRUE(response->headers);
4083 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); 4080 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine());
4084 EXPECT_TRUE(response->was_fetched_via_spdy); 4081 EXPECT_TRUE(response->was_fetched_via_spdy);
4085 EXPECT_TRUE(response->was_alpn_negotiated); 4082 EXPECT_TRUE(response->was_alpn_negotiated);
4086 EXPECT_EQ("127.0.0.1", response->socket_address.host()); 4083 EXPECT_EQ("127.0.0.1", response->socket_address.host());
4087 EXPECT_EQ(443, response->socket_address.port()); 4084 EXPECT_EQ(443, response->socket_address.port());
4088 std::string response_data; 4085 SpdyString response_data;
4089 rv = ReadTransaction(&trans2, &response_data); 4086 rv = ReadTransaction(&trans2, &response_data);
4090 EXPECT_THAT(rv, IsOk()); 4087 EXPECT_THAT(rv, IsOk());
4091 EXPECT_EQ("hello!", response_data); 4088 EXPECT_EQ("hello!", response_data);
4092 4089
4093 // Graceful GOAWAY was received, SpdySession should be unavailable. 4090 // Graceful GOAWAY was received, SpdySession should be unavailable.
4094 spdy_session = spdy_session_pool->FindAvailableSession( 4091 spdy_session = spdy_session_pool->FindAvailableSession(
4095 key, GURL(), 4092 key, GURL(),
4096 /* enable_ip_based_pooling = */ true, log); 4093 /* enable_ip_based_pooling = */ true, log);
4097 EXPECT_FALSE(spdy_session); 4094 EXPECT_FALSE(spdy_session);
4098 4095
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
4194 ASSERT_TRUE(response); 4191 ASSERT_TRUE(response);
4195 ASSERT_TRUE(response->headers); 4192 ASSERT_TRUE(response->headers);
4196 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 4193 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
4197 EXPECT_FALSE(response->was_fetched_via_spdy); 4194 EXPECT_FALSE(response->was_fetched_via_spdy);
4198 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1_1, 4195 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1_1,
4199 response->connection_info); 4196 response->connection_info);
4200 EXPECT_TRUE(response->was_alpn_negotiated); 4197 EXPECT_TRUE(response->was_alpn_negotiated);
4201 EXPECT_TRUE(request.url.SchemeIs("https")); 4198 EXPECT_TRUE(request.url.SchemeIs("https"));
4202 EXPECT_EQ("127.0.0.1", response->socket_address.host()); 4199 EXPECT_EQ("127.0.0.1", response->socket_address.host());
4203 EXPECT_EQ(443, response->socket_address.port()); 4200 EXPECT_EQ(443, response->socket_address.port());
4204 std::string response_data; 4201 SpdyString response_data;
4205 ASSERT_THAT(ReadTransaction(helper.trans(), &response_data), IsOk()); 4202 ASSERT_THAT(ReadTransaction(helper.trans(), &response_data), IsOk());
4206 EXPECT_EQ("hello", response_data); 4203 EXPECT_EQ("hello", response_data);
4207 } 4204 }
4208 4205
4209 // Retry with HTTP/1.1 to the proxy when receiving HTTP_1_1_REQUIRED from the 4206 // Retry with HTTP/1.1 to the proxy when receiving HTTP_1_1_REQUIRED from the
4210 // proxy. Note that no actual protocol negotiation happens, instead this test 4207 // proxy. Note that no actual protocol negotiation happens, instead this test
4211 // forces protocols for both sockets. 4208 // forces protocols for both sockets.
4212 TEST_F(SpdyNetworkTransactionTest, HTTP11RequiredProxyRetry) { 4209 TEST_F(SpdyNetworkTransactionTest, HTTP11RequiredProxyRetry) {
4213 HttpRequestInfo request; 4210 HttpRequestInfo request;
4214 request.method = "GET"; 4211 request.method = "GET";
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
4289 ASSERT_TRUE(response); 4286 ASSERT_TRUE(response);
4290 ASSERT_TRUE(response->headers); 4287 ASSERT_TRUE(response->headers);
4291 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 4288 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
4292 EXPECT_FALSE(response->was_fetched_via_spdy); 4289 EXPECT_FALSE(response->was_fetched_via_spdy);
4293 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1_1, 4290 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1_1,
4294 response->connection_info); 4291 response->connection_info);
4295 EXPECT_FALSE(response->was_alpn_negotiated); 4292 EXPECT_FALSE(response->was_alpn_negotiated);
4296 EXPECT_TRUE(request.url.SchemeIs("https")); 4293 EXPECT_TRUE(request.url.SchemeIs("https"));
4297 EXPECT_EQ("127.0.0.1", response->socket_address.host()); 4294 EXPECT_EQ("127.0.0.1", response->socket_address.host());
4298 EXPECT_EQ(70, response->socket_address.port()); 4295 EXPECT_EQ(70, response->socket_address.port());
4299 std::string response_data; 4296 SpdyString response_data;
4300 ASSERT_THAT(ReadTransaction(helper.trans(), &response_data), IsOk()); 4297 ASSERT_THAT(ReadTransaction(helper.trans(), &response_data), IsOk());
4301 EXPECT_EQ("hello", response_data); 4298 EXPECT_EQ("hello", response_data);
4302 } 4299 }
4303 4300
4304 // Test to make sure we can correctly connect through a proxy. 4301 // Test to make sure we can correctly connect through a proxy.
4305 TEST_F(SpdyNetworkTransactionTest, ProxyConnect) { 4302 TEST_F(SpdyNetworkTransactionTest, ProxyConnect) {
4306 auto session_deps = base::MakeUnique<SpdySessionDependencies>( 4303 auto session_deps = base::MakeUnique<SpdySessionDependencies>(
4307 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); 4304 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
4308 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 4305 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
4309 NetLogWithSource(), 4306 NetLogWithSource(),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4341 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 4338 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
4342 4339
4343 rv = callback.WaitForResult(); 4340 rv = callback.WaitForResult();
4344 EXPECT_EQ(0, rv); 4341 EXPECT_EQ(0, rv);
4345 4342
4346 // Verify the response headers. 4343 // Verify the response headers.
4347 HttpResponseInfo response = *trans->GetResponseInfo(); 4344 HttpResponseInfo response = *trans->GetResponseInfo();
4348 ASSERT_TRUE(response.headers); 4345 ASSERT_TRUE(response.headers);
4349 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); 4346 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine());
4350 4347
4351 std::string response_data; 4348 SpdyString response_data;
4352 ASSERT_THAT(ReadTransaction(trans, &response_data), IsOk()); 4349 ASSERT_THAT(ReadTransaction(trans, &response_data), IsOk());
4353 EXPECT_EQ("hello!", response_data); 4350 EXPECT_EQ("hello!", response_data);
4354 helper.VerifyDataConsumed(); 4351 helper.VerifyDataConsumed();
4355 } 4352 }
4356 4353
4357 // Test to make sure we can correctly connect through a proxy to 4354 // Test to make sure we can correctly connect through a proxy to
4358 // www.example.org, if there already exists a direct spdy connection to 4355 // www.example.org, if there already exists a direct spdy connection to
4359 // www.example.org. See https://crbug.com/49874. 4356 // www.example.org. See https://crbug.com/49874.
4360 TEST_F(SpdyNetworkTransactionTest, DirectConnectProxyReconnect) { 4357 TEST_F(SpdyNetworkTransactionTest, DirectConnectProxyReconnect) {
4361 // Use a proxy service which returns a proxy fallback list from DIRECT to 4358 // Use a proxy service which returns a proxy fallback list from DIRECT to
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
4464 int rv = trans_proxy->Start(&request_proxy, callback_proxy.callback(), 4461 int rv = trans_proxy->Start(&request_proxy, callback_proxy.callback(),
4465 NetLogWithSource()); 4462 NetLogWithSource());
4466 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 4463 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
4467 rv = callback_proxy.WaitForResult(); 4464 rv = callback_proxy.WaitForResult();
4468 EXPECT_EQ(0, rv); 4465 EXPECT_EQ(0, rv);
4469 4466
4470 HttpResponseInfo response_proxy = *trans_proxy->GetResponseInfo(); 4467 HttpResponseInfo response_proxy = *trans_proxy->GetResponseInfo();
4471 ASSERT_TRUE(response_proxy.headers); 4468 ASSERT_TRUE(response_proxy.headers);
4472 EXPECT_EQ("HTTP/1.1 200", response_proxy.headers->GetStatusLine()); 4469 EXPECT_EQ("HTTP/1.1 200", response_proxy.headers->GetStatusLine());
4473 4470
4474 std::string response_data; 4471 SpdyString response_data;
4475 ASSERT_THAT(ReadTransaction(trans_proxy, &response_data), IsOk()); 4472 ASSERT_THAT(ReadTransaction(trans_proxy, &response_data), IsOk());
4476 EXPECT_EQ("hello!", response_data); 4473 EXPECT_EQ("hello!", response_data);
4477 4474
4478 helper_proxy.VerifyDataConsumed(); 4475 helper_proxy.VerifyDataConsumed();
4479 } 4476 }
4480 4477
4481 // When we get a TCP-level RST, we need to retry a HttpNetworkTransaction 4478 // When we get a TCP-level RST, we need to retry a HttpNetworkTransaction
4482 // on a new connection, if the connection was previously known to be good. 4479 // on a new connection, if the connection was previously known to be good.
4483 // This can happen when a server reboots without saying goodbye, or when 4480 // This can happen when a server reboots without saying goodbye, or when
4484 // we're behind a NAT that masked the RST. 4481 // we're behind a NAT that masked the RST.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
4547 // Now schedule the ERR_CONNECTION_RESET. 4544 // Now schedule the ERR_CONNECTION_RESET.
4548 data1.Resume(); 4545 data1.Resume();
4549 } 4546 }
4550 rv = callback.WaitForResult(); 4547 rv = callback.WaitForResult();
4551 EXPECT_THAT(rv, IsOk()); 4548 EXPECT_THAT(rv, IsOk());
4552 4549
4553 const HttpResponseInfo* response = trans.GetResponseInfo(); 4550 const HttpResponseInfo* response = trans.GetResponseInfo();
4554 ASSERT_TRUE(response); 4551 ASSERT_TRUE(response);
4555 EXPECT_TRUE(response->headers); 4552 EXPECT_TRUE(response->headers);
4556 EXPECT_TRUE(response->was_fetched_via_spdy); 4553 EXPECT_TRUE(response->was_fetched_via_spdy);
4557 std::string response_data; 4554 SpdyString response_data;
4558 rv = ReadTransaction(&trans, &response_data); 4555 rv = ReadTransaction(&trans, &response_data);
4559 EXPECT_THAT(rv, IsOk()); 4556 EXPECT_THAT(rv, IsOk());
4560 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); 4557 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine());
4561 EXPECT_EQ("hello!", response_data); 4558 EXPECT_EQ("hello!", response_data);
4562 base::RunLoop().RunUntilIdle(); 4559 base::RunLoop().RunUntilIdle();
4563 } 4560 }
4564 4561
4565 helper.VerifyDataConsumed(); 4562 helper.VerifyDataConsumed();
4566 base::RunLoop().RunUntilIdle(); 4563 base::RunLoop().RunUntilIdle();
4567 } 4564 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
4688 CreateMockRead(stream1_reply, 1), 4685 CreateMockRead(stream1_reply, 1),
4689 CreateMockRead(stream2_syn, 2), 4686 CreateMockRead(stream2_syn, 2),
4690 CreateMockRead(stream2_headers, 4), 4687 CreateMockRead(stream2_headers, 4),
4691 CreateMockRead(stream1_body, 5, SYNCHRONOUS), 4688 CreateMockRead(stream1_body, 5, SYNCHRONOUS),
4692 CreateMockRead(stream2_body, 6), 4689 CreateMockRead(stream2_body, 6),
4693 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 7), // Force a pause 4690 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 7), // Force a pause
4694 }; 4691 };
4695 4692
4696 HttpResponseInfo response; 4693 HttpResponseInfo response;
4697 HttpResponseInfo response2; 4694 HttpResponseInfo response2;
4698 std::string expected_push_result("pushed"); 4695 SpdyString expected_push_result("pushed");
4699 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 4696 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
4700 RunServerPushTest(&data, 4697 RunServerPushTest(&data,
4701 &response, 4698 &response,
4702 &response2, 4699 &response2,
4703 expected_push_result); 4700 expected_push_result);
4704 4701
4705 // Verify the response headers. 4702 // Verify the response headers.
4706 EXPECT_TRUE(response.headers); 4703 EXPECT_TRUE(response.headers);
4707 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); 4704 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine());
4708 4705
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4740 2, kPushedData, strlen(kPushedData), true)); 4737 2, kPushedData, strlen(kPushedData), true));
4741 MockRead reads[] = { 4738 MockRead reads[] = {
4742 CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), 4739 CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2),
4743 CreateMockRead(stream1_body, 4), MockRead(ASYNC, ERR_IO_PENDING, 5), 4740 CreateMockRead(stream1_body, 4), MockRead(ASYNC, ERR_IO_PENDING, 5),
4744 CreateMockRead(stream2_headers, 6), CreateMockRead(stream2_body, 7), 4741 CreateMockRead(stream2_headers, 6), CreateMockRead(stream2_body, 7),
4745 MockRead(ASYNC, ERR_IO_PENDING, 8), MockRead(ASYNC, 0, 9), // EOF 4742 MockRead(ASYNC, ERR_IO_PENDING, 8), MockRead(ASYNC, 0, 9), // EOF
4746 }; 4743 };
4747 4744
4748 HttpResponseInfo response; 4745 HttpResponseInfo response;
4749 HttpResponseInfo response2; 4746 HttpResponseInfo response2;
4750 std::string expected_push_result("pushed"); 4747 SpdyString expected_push_result("pushed");
4751 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 4748 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
4752 4749
4753 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 4750 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
4754 NetLogWithSource(), nullptr); 4751 NetLogWithSource(), nullptr);
4755 helper.AddData(&data); 4752 helper.AddData(&data);
4756 helper.RunPreTestSetup(); 4753 helper.RunPreTestSetup();
4757 4754
4758 HttpNetworkTransaction* trans = helper.trans(); 4755 HttpNetworkTransaction* trans = helper.trans();
4759 4756
4760 // Start the transaction. 4757 // Start the transaction.
(...skipping 11 matching lines...) Expand all
4772 // headers are not yet complete. 4769 // headers are not yet complete.
4773 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); 4770 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session());
4774 rv = trans2.Start(&CreateGetPushRequest(), callback.callback(), 4771 rv = trans2.Start(&CreateGetPushRequest(), callback.callback(),
4775 NetLogWithSource()); 4772 NetLogWithSource());
4776 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 4773 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
4777 data.Resume(); 4774 data.Resume();
4778 data.RunUntilPaused(); 4775 data.RunUntilPaused();
4779 base::RunLoop().RunUntilIdle(); 4776 base::RunLoop().RunUntilIdle();
4780 4777
4781 // Read the server push body. 4778 // Read the server push body.
4782 std::string result2; 4779 SpdyString result2;
4783 ReadResult(&trans2, &result2); 4780 ReadResult(&trans2, &result2);
4784 // Read the response body. 4781 // Read the response body.
4785 std::string result; 4782 SpdyString result;
4786 ReadResult(trans, &result); 4783 ReadResult(trans, &result);
4787 4784
4788 // Verify that the received push data is same as the expected push data. 4785 // Verify that the received push data is same as the expected push data.
4789 EXPECT_EQ(result2.compare(expected_push_result), 0) 4786 EXPECT_EQ(result2.compare(expected_push_result), 0)
4790 << "Received data: " 4787 << "Received data: "
4791 << result2 4788 << result2
4792 << "||||| Expected data: " 4789 << "||||| Expected data: "
4793 << expected_push_result; 4790 << expected_push_result;
4794 4791
4795 // Verify the response headers. 4792 // Verify the response headers.
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
4963 TestCompletionCallback callback; 4960 TestCompletionCallback callback;
4964 4961
4965 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); 4962 int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
4966 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 4963 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
4967 rv = callback.WaitForResult(); 4964 rv = callback.WaitForResult();
4968 4965
4969 // Finish async network reads/writes. 4966 // Finish async network reads/writes.
4970 base::RunLoop().RunUntilIdle(); 4967 base::RunLoop().RunUntilIdle();
4971 4968
4972 // Read the response body. 4969 // Read the response body.
4973 std::string result; 4970 SpdyString result;
4974 ReadResult(trans, &result); 4971 ReadResult(trans, &result);
4975 4972
4976 // Verify that we consumed all test data. 4973 // Verify that we consumed all test data.
4977 EXPECT_TRUE(data.AllReadDataConsumed()); 4974 EXPECT_TRUE(data.AllReadDataConsumed());
4978 EXPECT_TRUE(data.AllWriteDataConsumed()); 4975 EXPECT_TRUE(data.AllWriteDataConsumed());
4979 4976
4980 // Verify the response headers. 4977 // Verify the response headers.
4981 // Copy the response info, because trans goes away. 4978 // Copy the response info, because trans goes away.
4982 response = *trans->GetResponseInfo(); 4979 response = *trans->GetResponseInfo();
4983 4980
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
5060 rv = callback1.GetResult(rv); 5057 rv = callback1.GetResult(rv);
5061 EXPECT_THAT(rv, IsOk()); 5058 EXPECT_THAT(rv, IsOk());
5062 5059
5063 EXPECT_TRUE(spdy_session->unclaimed_pushed_streams_.empty()); 5060 EXPECT_TRUE(spdy_session->unclaimed_pushed_streams_.empty());
5064 EXPECT_EQ(0u, spdy_session->unclaimed_pushed_streams_.size()); 5061 EXPECT_EQ(0u, spdy_session->unclaimed_pushed_streams_.size());
5065 5062
5066 HttpResponseInfo response = *trans0->GetResponseInfo(); 5063 HttpResponseInfo response = *trans0->GetResponseInfo();
5067 EXPECT_TRUE(response.headers); 5064 EXPECT_TRUE(response.headers);
5068 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); 5065 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine());
5069 5066
5070 std::string result0; 5067 SpdyString result0;
5071 ReadResult(trans0, &result0); 5068 ReadResult(trans0, &result0);
5072 EXPECT_EQ("hello!", result0); 5069 EXPECT_EQ("hello!", result0);
5073 5070
5074 HttpResponseInfo push_response = *trans1.GetResponseInfo(); 5071 HttpResponseInfo push_response = *trans1.GetResponseInfo();
5075 EXPECT_TRUE(push_response.headers); 5072 EXPECT_TRUE(push_response.headers);
5076 EXPECT_EQ("HTTP/1.1 200", push_response.headers->GetStatusLine()); 5073 EXPECT_EQ("HTTP/1.1 200", push_response.headers->GetStatusLine());
5077 5074
5078 std::string result1; 5075 SpdyString result1;
5079 ReadResult(&trans1, &result1); 5076 ReadResult(&trans1, &result1);
5080 EXPECT_EQ(kPushedData, result1); 5077 EXPECT_EQ(kPushedData, result1);
5081 5078
5082 base::RunLoop().RunUntilIdle(); 5079 base::RunLoop().RunUntilIdle();
5083 helper.VerifyDataConsumed(); 5080 helper.VerifyDataConsumed();
5084 VerifyStreamsClosed(helper); 5081 VerifyStreamsClosed(helper);
5085 } 5082 }
5086 5083
5087 // Verify that push works cross origin, even if there is already a connection 5084 // Verify that push works cross origin, even if there is already a connection
5088 // open to origin of pushed resource. 5085 // open to origin of pushed resource.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
5224 EXPECT_TRUE(spdy_session0->unclaimed_pushed_streams_.empty()); 5221 EXPECT_TRUE(spdy_session0->unclaimed_pushed_streams_.empty());
5225 EXPECT_EQ(0u, spdy_session0->unclaimed_pushed_streams_.size()); 5222 EXPECT_EQ(0u, spdy_session0->unclaimed_pushed_streams_.size());
5226 5223
5227 EXPECT_TRUE(spdy_session1->unclaimed_pushed_streams_.empty()); 5224 EXPECT_TRUE(spdy_session1->unclaimed_pushed_streams_.empty());
5228 EXPECT_EQ(0u, spdy_session1->unclaimed_pushed_streams_.size()); 5225 EXPECT_EQ(0u, spdy_session1->unclaimed_pushed_streams_.size());
5229 5226
5230 HttpResponseInfo response0 = *trans0->GetResponseInfo(); 5227 HttpResponseInfo response0 = *trans0->GetResponseInfo();
5231 EXPECT_TRUE(response0.headers); 5228 EXPECT_TRUE(response0.headers);
5232 EXPECT_EQ("HTTP/1.1 200", response0.headers->GetStatusLine()); 5229 EXPECT_EQ("HTTP/1.1 200", response0.headers->GetStatusLine());
5233 5230
5234 std::string result0; 5231 SpdyString result0;
5235 ReadResult(trans0, &result0); 5232 ReadResult(trans0, &result0);
5236 EXPECT_EQ(kData0, result0); 5233 EXPECT_EQ(kData0, result0);
5237 5234
5238 HttpResponseInfo response1 = *trans1.GetResponseInfo(); 5235 HttpResponseInfo response1 = *trans1.GetResponseInfo();
5239 EXPECT_TRUE(response1.headers); 5236 EXPECT_TRUE(response1.headers);
5240 EXPECT_EQ("HTTP/1.1 200", response1.headers->GetStatusLine()); 5237 EXPECT_EQ("HTTP/1.1 200", response1.headers->GetStatusLine());
5241 5238
5242 std::string result1; 5239 SpdyString result1;
5243 ReadResult(&trans1, &result1); 5240 ReadResult(&trans1, &result1);
5244 EXPECT_EQ(kData1, result1); 5241 EXPECT_EQ(kData1, result1);
5245 5242
5246 HttpResponseInfo push_response = *trans2.GetResponseInfo(); 5243 HttpResponseInfo push_response = *trans2.GetResponseInfo();
5247 EXPECT_TRUE(push_response.headers); 5244 EXPECT_TRUE(push_response.headers);
5248 EXPECT_EQ("HTTP/1.1 200", push_response.headers->GetStatusLine()); 5245 EXPECT_EQ("HTTP/1.1 200", push_response.headers->GetStatusLine());
5249 5246
5250 std::string result2; 5247 SpdyString result2;
5251 ReadResult(&trans2, &result2); 5248 ReadResult(&trans2, &result2);
5252 EXPECT_EQ(kPushedData, result2); 5249 EXPECT_EQ(kPushedData, result2);
5253 5250
5254 base::RunLoop().RunUntilIdle(); 5251 base::RunLoop().RunUntilIdle();
5255 helper.VerifyDataConsumed(); 5252 helper.VerifyDataConsumed();
5256 VerifyStreamsClosed(helper); 5253 VerifyStreamsClosed(helper);
5257 } 5254 }
5258 5255
5259 TEST_F(SpdyNetworkTransactionTest, ServerPushInvalidCrossOrigin) { 5256 TEST_F(SpdyNetworkTransactionTest, ServerPushInvalidCrossOrigin) {
5260 // "spdy_pooling.pem" is valid for www.example.org, 5257 // "spdy_pooling.pem" is valid for www.example.org,
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
5465 // write, leading to a complete write of request body; after that we send 5462 // write, leading to a complete write of request body; after that we send
5466 // a reply with a body, to cause a graceful shutdown. 5463 // a reply with a body, to cause a graceful shutdown.
5467 5464
5468 // TODO(agayev): develop a socket data provider where both, reads and 5465 // TODO(agayev): develop a socket data provider where both, reads and
5469 // writes are ordered so that writing tests like these are easy and rewrite 5466 // writes are ordered so that writing tests like these are easy and rewrite
5470 // all these tests using it. Right now we are working around the 5467 // all these tests using it. Right now we are working around the
5471 // limitations as described above and it's not deterministic, tests may 5468 // limitations as described above and it's not deterministic, tests may
5472 // fail under specific circumstances. 5469 // fail under specific circumstances.
5473 TEST_F(SpdyNetworkTransactionTest, WindowUpdateReceived) { 5470 TEST_F(SpdyNetworkTransactionTest, WindowUpdateReceived) {
5474 static int kFrameCount = 2; 5471 static int kFrameCount = 2;
5475 std::unique_ptr<std::string> content( 5472 std::unique_ptr<SpdyString> content(
5476 new std::string(kMaxSpdyFrameChunkSize, 'a')); 5473 new SpdyString(kMaxSpdyFrameChunkSize, 'a'));
5477 SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( 5474 SpdySerializedFrame req(spdy_util_.ConstructSpdyPost(
5478 kDefaultUrl, 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, nullptr, 5475 kDefaultUrl, 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, nullptr,
5479 0)); 5476 0));
5480 SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( 5477 SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(
5481 1, content->c_str(), content->size(), false)); 5478 1, content->c_str(), content->size(), false));
5482 SpdySerializedFrame body_end(spdy_util_.ConstructSpdyDataFrame( 5479 SpdySerializedFrame body_end(spdy_util_.ConstructSpdyDataFrame(
5483 1, content->c_str(), content->size(), true)); 5480 1, content->c_str(), content->size(), true));
5484 5481
5485 MockWrite writes[] = { 5482 MockWrite writes[] = {
5486 CreateMockWrite(req, 0), CreateMockWrite(body, 1), 5483 CreateMockWrite(req, 0), CreateMockWrite(body, 1),
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
5609 kHttp2ConnectionHeaderPrefixSize, 0)); 5606 kHttp2ConnectionHeaderPrefixSize, 0));
5610 writes.push_back(CreateMockWrite(initial_settings_frame, writes.size())); 5607 writes.push_back(CreateMockWrite(initial_settings_frame, writes.size()));
5611 writes.push_back(CreateMockWrite(initial_window_update, writes.size())); 5608 writes.push_back(CreateMockWrite(initial_window_update, writes.size()));
5612 writes.push_back(CreateMockWrite(req, writes.size())); 5609 writes.push_back(CreateMockWrite(req, writes.size()));
5613 5610
5614 std::vector<MockRead> reads; 5611 std::vector<MockRead> reads;
5615 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); 5612 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1));
5616 reads.push_back(CreateMockRead(resp, writes.size() + reads.size())); 5613 reads.push_back(CreateMockRead(resp, writes.size() + reads.size()));
5617 5614
5618 std::vector<SpdySerializedFrame> body_frames; 5615 std::vector<SpdySerializedFrame> body_frames;
5619 const std::string body_data(kChunkSize, 'x'); 5616 const SpdyString body_data(kChunkSize, 'x');
5620 for (size_t remaining = kTargetSize; remaining != 0;) { 5617 for (size_t remaining = kTargetSize; remaining != 0;) {
5621 size_t frame_size = std::min(remaining, body_data.size()); 5618 size_t frame_size = std::min(remaining, body_data.size());
5622 body_frames.push_back(spdy_util_.ConstructSpdyDataFrame(1, body_data.data(), 5619 body_frames.push_back(spdy_util_.ConstructSpdyDataFrame(1, body_data.data(),
5623 frame_size, false)); 5620 frame_size, false));
5624 reads.push_back( 5621 reads.push_back(
5625 CreateMockRead(body_frames.back(), writes.size() + reads.size())); 5622 CreateMockRead(body_frames.back(), writes.size() + reads.size()));
5626 remaining -= frame_size; 5623 remaining -= frame_size;
5627 } 5624 }
5628 // Yield. 5625 // Yield.
5629 reads.push_back( 5626 reads.push_back(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
5692 base::RunLoop().RunUntilIdle(); 5689 base::RunLoop().RunUntilIdle();
5693 helper.VerifyDataConsumed(); 5690 helper.VerifyDataConsumed();
5694 } 5691 }
5695 5692
5696 // Test that WINDOW_UPDATE frame causing overflow is handled correctly. 5693 // Test that WINDOW_UPDATE frame causing overflow is handled correctly.
5697 TEST_F(SpdyNetworkTransactionTest, WindowUpdateOverflow) { 5694 TEST_F(SpdyNetworkTransactionTest, WindowUpdateOverflow) {
5698 // Number of full frames we hope to write (but will not, used to 5695 // Number of full frames we hope to write (but will not, used to
5699 // set content-length header correctly) 5696 // set content-length header correctly)
5700 static int kFrameCount = 3; 5697 static int kFrameCount = 3;
5701 5698
5702 std::unique_ptr<std::string> content( 5699 std::unique_ptr<SpdyString> content(
5703 new std::string(kMaxSpdyFrameChunkSize, 'a')); 5700 new SpdyString(kMaxSpdyFrameChunkSize, 'a'));
5704 SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( 5701 SpdySerializedFrame req(spdy_util_.ConstructSpdyPost(
5705 kDefaultUrl, 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, nullptr, 5702 kDefaultUrl, 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, nullptr,
5706 0)); 5703 0));
5707 SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( 5704 SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(
5708 1, content->c_str(), content->size(), false)); 5705 1, content->c_str(), content->size(), false));
5709 SpdySerializedFrame rst( 5706 SpdySerializedFrame rst(
5710 spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_FLOW_CONTROL_ERROR)); 5707 spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_FLOW_CONTROL_ERROR));
5711 5708
5712 // We're not going to write a data frame with FIN, we'll receive a bad 5709 // We're not going to write a data frame with FIN, we'll receive a bad
5713 // WINDOW_UPDATE while sending a request and will send a RST_STREAM frame. 5710 // WINDOW_UPDATE while sending a request and will send a RST_STREAM frame.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
5777 // |initial_window_size|. 5774 // |initial_window_size|.
5778 size_t num_upload_buffers = 5775 size_t num_upload_buffers =
5779 ceil(static_cast<double>(initial_window_size) / kBufferSize); 5776 ceil(static_cast<double>(initial_window_size) / kBufferSize);
5780 // Each upload data buffer consists of |num_frames_in_one_upload_buffer| 5777 // Each upload data buffer consists of |num_frames_in_one_upload_buffer|
5781 // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame, 5778 // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame,
5782 // which has kBufferSize % kMaxSpdyChunkSize bytes. 5779 // which has kBufferSize % kMaxSpdyChunkSize bytes.
5783 size_t num_frames_in_one_upload_buffer = 5780 size_t num_frames_in_one_upload_buffer =
5784 ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize); 5781 ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize);
5785 5782
5786 // Construct content for a data frame of maximum size. 5783 // Construct content for a data frame of maximum size.
5787 std::string content(kMaxSpdyFrameChunkSize, 'a'); 5784 SpdyString content(kMaxSpdyFrameChunkSize, 'a');
5788 5785
5789 SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( 5786 SpdySerializedFrame req(spdy_util_.ConstructSpdyPost(
5790 kDefaultUrl, 1, 5787 kDefaultUrl, 1,
5791 /*content_length=*/kBufferSize * num_upload_buffers + kUploadDataSize, 5788 /*content_length=*/kBufferSize * num_upload_buffers + kUploadDataSize,
5792 LOWEST, nullptr, 0)); 5789 LOWEST, nullptr, 0));
5793 5790
5794 // Full frames. 5791 // Full frames.
5795 SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame( 5792 SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(
5796 1, content.c_str(), content.size(), false)); 5793 1, content.c_str(), content.size(), false));
5797 5794
5798 // Last frame in each upload data buffer. 5795 // Last frame in each upload data buffer.
5799 SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame( 5796 SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(
5800 1, content.c_str(), kBufferSize % kMaxSpdyFrameChunkSize, false)); 5797 1, content.c_str(), kBufferSize % kMaxSpdyFrameChunkSize, false));
5801 5798
5802 // The very last frame before the stalled frames. 5799 // The very last frame before the stalled frames.
5803 SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame( 5800 SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame(
5804 1, content.c_str(), 5801 1, content.c_str(),
5805 initial_window_size % kBufferSize % kMaxSpdyFrameChunkSize, false)); 5802 initial_window_size % kBufferSize % kMaxSpdyFrameChunkSize, false));
5806 5803
5807 // Data frames to be sent once WINDOW_UPDATE frame is received. 5804 // Data frames to be sent once WINDOW_UPDATE frame is received.
5808 5805
5809 // If kBufferSize * num_upload_buffers > initial_window_size, 5806 // If kBufferSize * num_upload_buffers > initial_window_size,
5810 // we need one additional frame to send the rest of 'a'. 5807 // we need one additional frame to send the rest of 'a'.
5811 std::string last_body(kBufferSize * num_upload_buffers - initial_window_size, 5808 SpdyString last_body(kBufferSize * num_upload_buffers - initial_window_size,
5812 'a'); 5809 'a');
5813 SpdySerializedFrame body4(spdy_util_.ConstructSpdyDataFrame( 5810 SpdySerializedFrame body4(spdy_util_.ConstructSpdyDataFrame(
5814 1, last_body.c_str(), last_body.size(), false)); 5811 1, last_body.c_str(), last_body.size(), false));
5815 5812
5816 // Also send a "hello!" after WINDOW_UPDATE. 5813 // Also send a "hello!" after WINDOW_UPDATE.
5817 SpdySerializedFrame body5(spdy_util_.ConstructSpdyDataFrame(1, true)); 5814 SpdySerializedFrame body5(spdy_util_.ConstructSpdyDataFrame(1, true));
5818 5815
5819 // Fill in mock writes. 5816 // Fill in mock writes.
5820 size_t i = 0; 5817 size_t i = 0;
5821 std::vector<MockWrite> writes; 5818 std::vector<MockWrite> writes;
5822 writes.push_back(CreateMockWrite(req, i++)); 5819 writes.push_back(CreateMockWrite(req, i++));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
5859 SpdySerializedFrame reply(spdy_util_.ConstructSpdyPostReply(nullptr, 0)); 5856 SpdySerializedFrame reply(spdy_util_.ConstructSpdyPostReply(nullptr, 0));
5860 reads.push_back(CreateMockRead(reply, i++)); 5857 reads.push_back(CreateMockRead(reply, i++));
5861 reads.push_back(CreateMockRead(body2, i++)); 5858 reads.push_back(CreateMockRead(body2, i++));
5862 reads.push_back(CreateMockRead(body5, i++)); 5859 reads.push_back(CreateMockRead(body5, i++));
5863 reads.push_back(MockRead(ASYNC, 0, i++)); // EOF 5860 reads.push_back(MockRead(ASYNC, 0, i++)); // EOF
5864 5861
5865 SequencedSocketData data(reads.data(), reads.size(), writes.data(), 5862 SequencedSocketData data(reads.data(), reads.size(), writes.data(),
5866 writes.size()); 5863 writes.size());
5867 5864
5868 std::vector<std::unique_ptr<UploadElementReader>> element_readers; 5865 std::vector<std::unique_ptr<UploadElementReader>> element_readers;
5869 std::string upload_data_string(kBufferSize * num_upload_buffers, 'a'); 5866 SpdyString upload_data_string(kBufferSize * num_upload_buffers, 'a');
5870 upload_data_string.append(kUploadData, kUploadDataSize); 5867 upload_data_string.append(kUploadData, kUploadDataSize);
5871 element_readers.push_back(base::WrapUnique(new UploadBytesElementReader( 5868 element_readers.push_back(base::WrapUnique(new UploadBytesElementReader(
5872 upload_data_string.c_str(), upload_data_string.size()))); 5869 upload_data_string.c_str(), upload_data_string.size())));
5873 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); 5870 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0);
5874 5871
5875 HttpRequestInfo request; 5872 HttpRequestInfo request;
5876 request.method = "POST"; 5873 request.method = "POST";
5877 request.url = default_url_; 5874 request.url = default_url_;
5878 request.upload_data_stream = &upload_data_stream; 5875 request.upload_data_stream = &upload_data_stream;
5879 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, 5876 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
5927 // |initial_window_size|. 5924 // |initial_window_size|.
5928 size_t num_upload_buffers = 5925 size_t num_upload_buffers =
5929 ceil(static_cast<double>(initial_window_size) / kBufferSize); 5926 ceil(static_cast<double>(initial_window_size) / kBufferSize);
5930 // Each upload data buffer consists of |num_frames_in_one_upload_buffer| 5927 // Each upload data buffer consists of |num_frames_in_one_upload_buffer|
5931 // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame, 5928 // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame,
5932 // which has kBufferSize % kMaxSpdyChunkSize bytes. 5929 // which has kBufferSize % kMaxSpdyChunkSize bytes.
5933 size_t num_frames_in_one_upload_buffer = 5930 size_t num_frames_in_one_upload_buffer =
5934 ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize); 5931 ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize);
5935 5932
5936 // Construct content for a data frame of maximum size. 5933 // Construct content for a data frame of maximum size.
5937 std::string content(kMaxSpdyFrameChunkSize, 'a'); 5934 SpdyString content(kMaxSpdyFrameChunkSize, 'a');
5938 5935
5939 SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( 5936 SpdySerializedFrame req(spdy_util_.ConstructSpdyPost(
5940 kDefaultUrl, 1, 5937 kDefaultUrl, 1,
5941 /*content_length=*/kBufferSize * num_upload_buffers + kUploadDataSize, 5938 /*content_length=*/kBufferSize * num_upload_buffers + kUploadDataSize,
5942 LOWEST, nullptr, 0)); 5939 LOWEST, nullptr, 0));
5943 5940
5944 // Full frames. 5941 // Full frames.
5945 SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame( 5942 SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(
5946 1, content.c_str(), content.size(), false)); 5943 1, content.c_str(), content.size(), false));
5947 5944
5948 // Last frame in each upload data buffer. 5945 // Last frame in each upload data buffer.
5949 SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame( 5946 SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(
5950 1, content.c_str(), kBufferSize % kMaxSpdyFrameChunkSize, false)); 5947 1, content.c_str(), kBufferSize % kMaxSpdyFrameChunkSize, false));
5951 5948
5952 // The very last frame before the stalled frames. 5949 // The very last frame before the stalled frames.
5953 SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame( 5950 SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame(
5954 1, content.c_str(), 5951 1, content.c_str(),
5955 initial_window_size % kBufferSize % kMaxSpdyFrameChunkSize, false)); 5952 initial_window_size % kBufferSize % kMaxSpdyFrameChunkSize, false));
5956 5953
5957 // Data frames to be sent once WINDOW_UPDATE frame is received. 5954 // Data frames to be sent once WINDOW_UPDATE frame is received.
5958 5955
5959 // If kBufferSize * num_upload_buffers > initial_window_size, 5956 // If kBufferSize * num_upload_buffers > initial_window_size,
5960 // we need one additional frame to send the rest of 'a'. 5957 // we need one additional frame to send the rest of 'a'.
5961 std::string last_body(kBufferSize * num_upload_buffers - initial_window_size, 5958 SpdyString last_body(kBufferSize * num_upload_buffers - initial_window_size,
5962 'a'); 5959 'a');
5963 SpdySerializedFrame body4(spdy_util_.ConstructSpdyDataFrame( 5960 SpdySerializedFrame body4(spdy_util_.ConstructSpdyDataFrame(
5964 1, last_body.c_str(), last_body.size(), false)); 5961 1, last_body.c_str(), last_body.size(), false));
5965 5962
5966 // Also send a "hello!" after WINDOW_UPDATE. 5963 // Also send a "hello!" after WINDOW_UPDATE.
5967 SpdySerializedFrame body5(spdy_util_.ConstructSpdyDataFrame(1, true)); 5964 SpdySerializedFrame body5(spdy_util_.ConstructSpdyDataFrame(1, true));
5968 5965
5969 // Fill in mock writes. 5966 // Fill in mock writes.
5970 size_t i = 0; 5967 size_t i = 0;
5971 std::vector<MockWrite> writes; 5968 std::vector<MockWrite> writes;
5972 writes.push_back(CreateMockWrite(req, i++)); 5969 writes.push_back(CreateMockWrite(req, i++));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
6018 reads.push_back(CreateMockRead(body2, i++)); 6015 reads.push_back(CreateMockRead(body2, i++));
6019 reads.push_back(CreateMockRead(body5, i++)); 6016 reads.push_back(CreateMockRead(body5, i++));
6020 reads.push_back(MockRead(ASYNC, 0, i++)); // EOF 6017 reads.push_back(MockRead(ASYNC, 0, i++)); // EOF
6021 6018
6022 // Force all writes to happen before any read, last write will not 6019 // Force all writes to happen before any read, last write will not
6023 // actually queue a frame, due to window size being 0. 6020 // actually queue a frame, due to window size being 0.
6024 SequencedSocketData data(reads.data(), reads.size(), writes.data(), 6021 SequencedSocketData data(reads.data(), reads.size(), writes.data(),
6025 writes.size()); 6022 writes.size());
6026 6023
6027 std::vector<std::unique_ptr<UploadElementReader>> element_readers; 6024 std::vector<std::unique_ptr<UploadElementReader>> element_readers;
6028 std::string upload_data_string(kBufferSize * num_upload_buffers, 'a'); 6025 SpdyString upload_data_string(kBufferSize * num_upload_buffers, 'a');
6029 upload_data_string.append(kUploadData, kUploadDataSize); 6026 upload_data_string.append(kUploadData, kUploadDataSize);
6030 element_readers.push_back(base::WrapUnique(new UploadBytesElementReader( 6027 element_readers.push_back(base::WrapUnique(new UploadBytesElementReader(
6031 upload_data_string.c_str(), upload_data_string.size()))); 6028 upload_data_string.c_str(), upload_data_string.size())));
6032 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); 6029 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0);
6033 6030
6034 HttpRequestInfo request; 6031 HttpRequestInfo request;
6035 request.method = "POST"; 6032 request.method = "POST";
6036 request.url = default_url_; 6033 request.url = default_url_;
6037 request.upload_data_stream = &upload_data_stream; 6034 request.upload_data_stream = &upload_data_stream;
6038 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, 6035 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
6089 // |initial_window_size|. 6086 // |initial_window_size|.
6090 size_t num_upload_buffers = 6087 size_t num_upload_buffers =
6091 ceil(static_cast<double>(initial_window_size) / kBufferSize); 6088 ceil(static_cast<double>(initial_window_size) / kBufferSize);
6092 // Each upload data buffer consists of |num_frames_in_one_upload_buffer| 6089 // Each upload data buffer consists of |num_frames_in_one_upload_buffer|
6093 // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame, 6090 // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame,
6094 // which has kBufferSize % kMaxSpdyChunkSize bytes. 6091 // which has kBufferSize % kMaxSpdyChunkSize bytes.
6095 size_t num_frames_in_one_upload_buffer = 6092 size_t num_frames_in_one_upload_buffer =
6096 ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize); 6093 ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize);
6097 6094
6098 // Construct content for a data frame of maximum size. 6095 // Construct content for a data frame of maximum size.
6099 std::string content(kMaxSpdyFrameChunkSize, 'a'); 6096 SpdyString content(kMaxSpdyFrameChunkSize, 'a');
6100 6097
6101 SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( 6098 SpdySerializedFrame req(spdy_util_.ConstructSpdyPost(
6102 kDefaultUrl, 1, 6099 kDefaultUrl, 1,
6103 /*content_length=*/kBufferSize * num_upload_buffers + kUploadDataSize, 6100 /*content_length=*/kBufferSize * num_upload_buffers + kUploadDataSize,
6104 LOWEST, nullptr, 0)); 6101 LOWEST, nullptr, 0));
6105 6102
6106 // Full frames. 6103 // Full frames.
6107 SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame( 6104 SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(
6108 1, content.c_str(), content.size(), false)); 6105 1, content.c_str(), content.size(), false));
6109 6106
6110 // Last frame in each upload data buffer. 6107 // Last frame in each upload data buffer.
6111 SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame( 6108 SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(
6112 1, content.c_str(), kBufferSize % kMaxSpdyFrameChunkSize, false)); 6109 1, content.c_str(), kBufferSize % kMaxSpdyFrameChunkSize, false));
6113 6110
6114 // The very last frame before the stalled frames. 6111 // The very last frame before the stalled frames.
6115 SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame( 6112 SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame(
6116 1, content.c_str(), 6113 1, content.c_str(),
6117 initial_window_size % kBufferSize % kMaxSpdyFrameChunkSize, false)); 6114 initial_window_size % kBufferSize % kMaxSpdyFrameChunkSize, false));
6118 6115
6119 // Data frames to be sent once WINDOW_UPDATE frame is received. 6116 // Data frames to be sent once WINDOW_UPDATE frame is received.
6120 6117
6121 // If kBufferSize * num_upload_buffers > initial_window_size, 6118 // If kBufferSize * num_upload_buffers > initial_window_size,
6122 // we need one additional frame to send the rest of 'a'. 6119 // we need one additional frame to send the rest of 'a'.
6123 std::string last_body(kBufferSize * num_upload_buffers - initial_window_size, 6120 SpdyString last_body(kBufferSize * num_upload_buffers - initial_window_size,
6124 'a'); 6121 'a');
6125 SpdySerializedFrame body4(spdy_util_.ConstructSpdyDataFrame( 6122 SpdySerializedFrame body4(spdy_util_.ConstructSpdyDataFrame(
6126 1, last_body.c_str(), last_body.size(), false)); 6123 1, last_body.c_str(), last_body.size(), false));
6127 6124
6128 // Also send a "hello!" after WINDOW_UPDATE. 6125 // Also send a "hello!" after WINDOW_UPDATE.
6129 SpdySerializedFrame body5(spdy_util_.ConstructSpdyDataFrame(1, true)); 6126 SpdySerializedFrame body5(spdy_util_.ConstructSpdyDataFrame(1, true));
6130 6127
6131 // Fill in mock writes. 6128 // Fill in mock writes.
6132 size_t i = 0; 6129 size_t i = 0;
6133 std::vector<MockWrite> writes; 6130 std::vector<MockWrite> writes;
6134 writes.push_back(CreateMockWrite(req, i++)); 6131 writes.push_back(CreateMockWrite(req, i++));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
6182 reads.push_back(CreateMockRead(body2, i++)); 6179 reads.push_back(CreateMockRead(body2, i++));
6183 reads.push_back(CreateMockRead(body5, i++)); 6180 reads.push_back(CreateMockRead(body5, i++));
6184 reads.push_back(MockRead(ASYNC, 0, i++)); // EOF 6181 reads.push_back(MockRead(ASYNC, 0, i++)); // EOF
6185 6182
6186 // Force all writes to happen before any read, last write will not 6183 // Force all writes to happen before any read, last write will not
6187 // actually queue a frame, due to window size being 0. 6184 // actually queue a frame, due to window size being 0.
6188 SequencedSocketData data(reads.data(), reads.size(), writes.data(), 6185 SequencedSocketData data(reads.data(), reads.size(), writes.data(),
6189 writes.size()); 6186 writes.size());
6190 6187
6191 std::vector<std::unique_ptr<UploadElementReader>> element_readers; 6188 std::vector<std::unique_ptr<UploadElementReader>> element_readers;
6192 std::string upload_data_string(kBufferSize * num_upload_buffers, 'a'); 6189 SpdyString upload_data_string(kBufferSize * num_upload_buffers, 'a');
6193 upload_data_string.append(kUploadData, kUploadDataSize); 6190 upload_data_string.append(kUploadData, kUploadDataSize);
6194 element_readers.push_back(base::WrapUnique(new UploadBytesElementReader( 6191 element_readers.push_back(base::WrapUnique(new UploadBytesElementReader(
6195 upload_data_string.c_str(), upload_data_string.size()))); 6192 upload_data_string.c_str(), upload_data_string.size())));
6196 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); 6193 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0);
6197 6194
6198 HttpRequestInfo request; 6195 HttpRequestInfo request;
6199 request.method = "POST"; 6196 request.method = "POST";
6200 request.url = default_url_; 6197 request.url = default_url_;
6201 request.upload_data_stream = &upload_data_stream; 6198 request.upload_data_stream = &upload_data_stream;
6202 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, 6199 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
6290 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 6287 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
6291 NetLogWithSource(), nullptr); 6288 NetLogWithSource(), nullptr);
6292 helper.RunToCompletion(&data); 6289 helper.RunToCompletion(&data);
6293 TransactionHelperResult out = helper.output(); 6290 TransactionHelperResult out = helper.output();
6294 EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); 6291 EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR));
6295 } 6292 }
6296 6293
6297 // Regression test for https://crbug.com/493348: request header exceeds 16 kB 6294 // Regression test for https://crbug.com/493348: request header exceeds 16 kB
6298 // and thus sent in multiple frames when using HTTP/2. 6295 // and thus sent in multiple frames when using HTTP/2.
6299 TEST_F(SpdyNetworkTransactionTest, LargeRequest) { 6296 TEST_F(SpdyNetworkTransactionTest, LargeRequest) {
6300 const std::string kKey("foo"); 6297 const SpdyString kKey("foo");
6301 const std::string kValue(1 << 15, 'z'); 6298 const SpdyString kValue(1 << 15, 'z');
6302 6299
6303 HttpRequestInfo request; 6300 HttpRequestInfo request;
6304 request.method = "GET"; 6301 request.method = "GET";
6305 request.url = default_url_; 6302 request.url = default_url_;
6306 request.extra_headers.SetHeader(kKey, kValue); 6303 request.extra_headers.SetHeader(kKey, kValue);
6307 6304
6308 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); 6305 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl));
6309 headers[kKey] = kValue; 6306 headers[kKey] = kValue;
6310 SpdySerializedFrame req( 6307 SpdySerializedFrame req(
6311 spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); 6308 spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true));
(...skipping 23 matching lines...) Expand all
6335 TEST_F(SpdyNetworkTransactionTest, LargeResponseHeader) { 6332 TEST_F(SpdyNetworkTransactionTest, LargeResponseHeader) {
6336 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); 6333 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl));
6337 SpdySerializedFrame req( 6334 SpdySerializedFrame req(
6338 spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); 6335 spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true));
6339 MockWrite writes[] = { 6336 MockWrite writes[] = {
6340 CreateMockWrite(req, 0), 6337 CreateMockWrite(req, 0),
6341 }; 6338 };
6342 6339
6343 // HPACK decoder implementation limits string literal length to 16 kB. 6340 // HPACK decoder implementation limits string literal length to 16 kB.
6344 const char* response_headers[2]; 6341 const char* response_headers[2];
6345 const std::string kKey(16 * 1024, 'a'); 6342 const SpdyString kKey(16 * 1024, 'a');
6346 response_headers[0] = kKey.data(); 6343 response_headers[0] = kKey.data();
6347 const std::string kValue(16 * 1024, 'b'); 6344 const SpdyString kValue(16 * 1024, 'b');
6348 response_headers[1] = kValue.data(); 6345 response_headers[1] = kValue.data();
6349 6346
6350 SpdySerializedFrame resp( 6347 SpdySerializedFrame resp(
6351 spdy_util_.ConstructSpdyGetReply(response_headers, 1, 1)); 6348 spdy_util_.ConstructSpdyGetReply(response_headers, 1, 1));
6352 SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); 6349 SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true));
6353 MockRead reads[] = { 6350 MockRead reads[] = {
6354 CreateMockRead(resp, 1), CreateMockRead(body, 2), 6351 CreateMockRead(resp, 1), CreateMockRead(body, 2),
6355 MockRead(ASYNC, 0, 3) // EOF 6352 MockRead(ASYNC, 0, 3) // EOF
6356 }; 6353 };
6357 6354
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
6597 TEST_F(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { 6594 TEST_F(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) {
6598 std::unique_ptr<SSLSocketDataProvider> ssl_provider( 6595 std::unique_ptr<SSLSocketDataProvider> ssl_provider(
6599 new SSLSocketDataProvider(ASYNC, OK)); 6596 new SSLSocketDataProvider(ASYNC, OK));
6600 // Set to TLS_RSA_WITH_NULL_MD5 6597 // Set to TLS_RSA_WITH_NULL_MD5
6601 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); 6598 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status);
6602 6599
6603 RunTLSUsageCheckTest(std::move(ssl_provider)); 6600 RunTLSUsageCheckTest(std::move(ssl_provider));
6604 } 6601 }
6605 6602
6606 } // namespace net 6603 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_log_util_unittest.cc ('k') | net/spdy/spdy_pinnable_buffer_piece_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698