| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 output_.rv = trans_->Start(&request_, callback_.callback(), log_); | 219 output_.rv = trans_->Start(&request_, callback_.callback(), log_); |
| 220 | 220 |
| 221 // We expect an IO Pending or some sort of error. | 221 // We expect an IO Pending or some sort of error. |
| 222 EXPECT_LT(output_.rv, 0); | 222 EXPECT_LT(output_.rv, 0); |
| 223 return output_.rv == ERR_IO_PENDING; | 223 return output_.rv == ERR_IO_PENDING; |
| 224 } | 224 } |
| 225 | 225 |
| 226 void FinishDefaultTest() { | 226 void FinishDefaultTest() { |
| 227 output_.rv = callback_.WaitForResult(); | 227 output_.rv = callback_.WaitForResult(); |
| 228 if (output_.rv != OK) { | 228 if (output_.rv != OK) { |
| 229 session_->spdy_session_pool()->CloseCurrentSessions(net::ERR_ABORTED); | 229 session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); |
| 230 return; | 230 return; |
| 231 } | 231 } |
| 232 | 232 |
| 233 // Verify responses. | 233 // Verify responses. |
| 234 const HttpResponseInfo* response = trans_->GetResponseInfo(); | 234 const HttpResponseInfo* response = trans_->GetResponseInfo(); |
| 235 ASSERT_TRUE(response != NULL); | 235 ASSERT_TRUE(response != NULL); |
| 236 ASSERT_TRUE(response->headers.get() != NULL); | 236 ASSERT_TRUE(response->headers.get() != NULL); |
| 237 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 237 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 238 EXPECT_EQ(spdy_enabled_, response->was_fetched_via_spdy); | 238 EXPECT_EQ(spdy_enabled_, response->was_fetched_via_spdy); |
| 239 if (HttpStreamFactory::spdy_enabled()) { | 239 if (HttpStreamFactory::spdy_enabled()) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 259 EXPECT_EQ("127.0.0.1", response->socket_address.host()); | 259 EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 260 EXPECT_EQ(port_, response->socket_address.port()); | 260 EXPECT_EQ(port_, response->socket_address.port()); |
| 261 output_.status_line = response->headers->GetStatusLine(); | 261 output_.status_line = response->headers->GetStatusLine(); |
| 262 output_.response_info = *response; // Make a copy so we can verify. | 262 output_.response_info = *response; // Make a copy so we can verify. |
| 263 output_.rv = ReadTransaction(trans_.get(), &output_.response_data); | 263 output_.rv = ReadTransaction(trans_.get(), &output_.response_data); |
| 264 } | 264 } |
| 265 | 265 |
| 266 void FinishDefaultTestWithoutVerification() { | 266 void FinishDefaultTestWithoutVerification() { |
| 267 output_.rv = callback_.WaitForResult(); | 267 output_.rv = callback_.WaitForResult(); |
| 268 if (output_.rv != OK) | 268 if (output_.rv != OK) |
| 269 session_->spdy_session_pool()->CloseCurrentSessions(net::ERR_ABORTED); | 269 session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); |
| 270 } | 270 } |
| 271 | 271 |
| 272 // Most tests will want to call this function. In particular, the MockReads | 272 // Most tests will want to call this function. In particular, the MockReads |
| 273 // should end with an empty read, and that read needs to be processed to | 273 // should end with an empty read, and that read needs to be processed to |
| 274 // ensure proper deletion of the spdy_session_pool. | 274 // ensure proper deletion of the spdy_session_pool. |
| 275 void VerifyDataConsumed() { | 275 void VerifyDataConsumed() { |
| 276 for (DataVector::iterator it = data_vector_.begin(); | 276 for (DataVector::iterator it = data_vector_.begin(); |
| 277 it != data_vector_.end(); ++it) { | 277 it != data_vector_.end(); ++it) { |
| 278 EXPECT_TRUE((*it)->at_read_eof()) << "Read count: " | 278 EXPECT_TRUE((*it)->at_read_eof()) << "Read count: " |
| 279 << (*it)->read_count() | 279 << (*it)->read_count() |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 // Read the result of a particular transaction, knowing that we've got | 574 // Read the result of a particular transaction, knowing that we've got |
| 575 // multiple transactions in the read pipeline; so as we read, we may have | 575 // multiple transactions in the read pipeline; so as we read, we may have |
| 576 // to skip over data destined for other transactions while we consume | 576 // to skip over data destined for other transactions while we consume |
| 577 // the data for |trans|. | 577 // the data for |trans|. |
| 578 int ReadResult(HttpNetworkTransaction* trans, | 578 int ReadResult(HttpNetworkTransaction* trans, |
| 579 StaticSocketDataProvider* data, | 579 StaticSocketDataProvider* data, |
| 580 std::string* result) { | 580 std::string* result) { |
| 581 const int kSize = 3000; | 581 const int kSize = 3000; |
| 582 | 582 |
| 583 int bytes_read = 0; | 583 int bytes_read = 0; |
| 584 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(kSize)); | 584 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(kSize)); |
| 585 TestCompletionCallback callback; | 585 TestCompletionCallback callback; |
| 586 while (true) { | 586 while (true) { |
| 587 int rv = trans->Read(buf.get(), kSize, callback.callback()); | 587 int rv = trans->Read(buf.get(), kSize, callback.callback()); |
| 588 if (rv == ERR_IO_PENDING) { | 588 if (rv == ERR_IO_PENDING) { |
| 589 // Multiple transactions may be in the data set. Keep pulling off | 589 // Multiple transactions may be in the data set. Keep pulling off |
| 590 // reads until we complete our callback. | 590 // reads until we complete our callback. |
| 591 while (!callback.have_result()) { | 591 while (!callback.have_result()) { |
| 592 data->CompleteRead(); | 592 data->CompleteRead(); |
| 593 base::RunLoop().RunUntilIdle(); | 593 base::RunLoop().RunUntilIdle(); |
| 594 } | 594 } |
| (...skipping 1773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2368 helper.AddData(&data2); | 2368 helper.AddData(&data2); |
| 2369 HttpNetworkTransaction* trans = helper.trans(); | 2369 HttpNetworkTransaction* trans = helper.trans(); |
| 2370 | 2370 |
| 2371 // Start the transaction with basic parameters. | 2371 // Start the transaction with basic parameters. |
| 2372 TestCompletionCallback callback; | 2372 TestCompletionCallback callback; |
| 2373 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); | 2373 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 2374 EXPECT_EQ(ERR_IO_PENDING, rv); | 2374 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2375 rv = callback.WaitForResult(); | 2375 rv = callback.WaitForResult(); |
| 2376 | 2376 |
| 2377 const int kSize = 3000; | 2377 const int kSize = 3000; |
| 2378 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); | 2378 scoped_refptr<IOBuffer> buf(new IOBuffer(kSize)); |
| 2379 rv = trans->Read( | 2379 rv = trans->Read( |
| 2380 buf.get(), | 2380 buf.get(), |
| 2381 kSize, | 2381 kSize, |
| 2382 base::Bind(&SpdyNetworkTransactionTest::StartTransactionCallback, | 2382 base::Bind(&SpdyNetworkTransactionTest::StartTransactionCallback, |
| 2383 helper.session())); | 2383 helper.session())); |
| 2384 // This forces an err_IO_pending, which sets the callback. | 2384 // This forces an err_IO_pending, which sets the callback. |
| 2385 data.CompleteRead(); | 2385 data.CompleteRead(); |
| 2386 // This finishes the read. | 2386 // This finishes the read. |
| 2387 data.CompleteRead(); | 2387 data.CompleteRead(); |
| 2388 helper.VerifyDataConsumed(); | 2388 helper.VerifyDataConsumed(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2416 | 2416 |
| 2417 // Start the transaction with basic parameters. | 2417 // Start the transaction with basic parameters. |
| 2418 TestCompletionCallback callback; | 2418 TestCompletionCallback callback; |
| 2419 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); | 2419 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 2420 EXPECT_EQ(ERR_IO_PENDING, rv); | 2420 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2421 rv = callback.WaitForResult(); | 2421 rv = callback.WaitForResult(); |
| 2422 | 2422 |
| 2423 // Setup a user callback which will delete the session, and clear out the | 2423 // Setup a user callback which will delete the session, and clear out the |
| 2424 // memory holding the stream object. Note that the callback deletes trans. | 2424 // memory holding the stream object. Note that the callback deletes trans. |
| 2425 const int kSize = 3000; | 2425 const int kSize = 3000; |
| 2426 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); | 2426 scoped_refptr<IOBuffer> buf(new IOBuffer(kSize)); |
| 2427 rv = trans->Read( | 2427 rv = trans->Read( |
| 2428 buf.get(), | 2428 buf.get(), |
| 2429 kSize, | 2429 kSize, |
| 2430 base::Bind(&SpdyNetworkTransactionTest::DeleteSessionCallback, | 2430 base::Bind(&SpdyNetworkTransactionTest::DeleteSessionCallback, |
| 2431 base::Unretained(&helper))); | 2431 base::Unretained(&helper))); |
| 2432 ASSERT_EQ(ERR_IO_PENDING, rv); | 2432 ASSERT_EQ(ERR_IO_PENDING, rv); |
| 2433 data.CompleteRead(); | 2433 data.CompleteRead(); |
| 2434 | 2434 |
| 2435 // Finish running rest of tasks. | 2435 // Finish running rest of tasks. |
| 2436 base::RunLoop().RunUntilIdle(); | 2436 base::RunLoop().RunUntilIdle(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2498 d.set_quit_on_redirect(true); | 2498 d.set_quit_on_redirect(true); |
| 2499 r->Start(); | 2499 r->Start(); |
| 2500 base::RunLoop().Run(); | 2500 base::RunLoop().Run(); |
| 2501 | 2501 |
| 2502 EXPECT_EQ(1, d.received_redirect_count()); | 2502 EXPECT_EQ(1, d.received_redirect_count()); |
| 2503 | 2503 |
| 2504 r->FollowDeferredRedirect(); | 2504 r->FollowDeferredRedirect(); |
| 2505 base::RunLoop().Run(); | 2505 base::RunLoop().Run(); |
| 2506 EXPECT_EQ(1, d.response_started_count()); | 2506 EXPECT_EQ(1, d.response_started_count()); |
| 2507 EXPECT_FALSE(d.received_data_before_response()); | 2507 EXPECT_FALSE(d.received_data_before_response()); |
| 2508 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r->status().status()); | 2508 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 2509 std::string contents("hello!"); | 2509 std::string contents("hello!"); |
| 2510 EXPECT_EQ(contents, d.data_received()); | 2510 EXPECT_EQ(contents, d.data_received()); |
| 2511 } | 2511 } |
| 2512 EXPECT_TRUE(data.at_read_eof()); | 2512 EXPECT_TRUE(data.at_read_eof()); |
| 2513 EXPECT_TRUE(data.at_write_eof()); | 2513 EXPECT_TRUE(data.at_write_eof()); |
| 2514 EXPECT_TRUE(data2.at_read_eof()); | 2514 EXPECT_TRUE(data2.at_read_eof()); |
| 2515 EXPECT_TRUE(data2.at_write_eof()); | 2515 EXPECT_TRUE(data2.at_write_eof()); |
| 2516 } | 2516 } |
| 2517 | 2517 |
| 2518 // Send a spdy request to www.google.com. Get a pushed stream that redirects to | 2518 // Send a spdy request to www.google.com. Get a pushed stream that redirects to |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2606 | 2606 |
| 2607 d2.set_quit_on_redirect(true); | 2607 d2.set_quit_on_redirect(true); |
| 2608 r2->Start(); | 2608 r2->Start(); |
| 2609 base::RunLoop().Run(); | 2609 base::RunLoop().Run(); |
| 2610 EXPECT_EQ(1, d2.received_redirect_count()); | 2610 EXPECT_EQ(1, d2.received_redirect_count()); |
| 2611 | 2611 |
| 2612 r2->FollowDeferredRedirect(); | 2612 r2->FollowDeferredRedirect(); |
| 2613 base::RunLoop().Run(); | 2613 base::RunLoop().Run(); |
| 2614 EXPECT_EQ(1, d2.response_started_count()); | 2614 EXPECT_EQ(1, d2.response_started_count()); |
| 2615 EXPECT_FALSE(d2.received_data_before_response()); | 2615 EXPECT_FALSE(d2.received_data_before_response()); |
| 2616 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r2->status().status()); | 2616 EXPECT_EQ(URLRequestStatus::SUCCESS, r2->status().status()); |
| 2617 std::string contents2("hello!"); | 2617 std::string contents2("hello!"); |
| 2618 EXPECT_EQ(contents2, d2.data_received()); | 2618 EXPECT_EQ(contents2, d2.data_received()); |
| 2619 } | 2619 } |
| 2620 data.CompleteRead(); | 2620 data.CompleteRead(); |
| 2621 data2.CompleteRead(); | 2621 data2.CompleteRead(); |
| 2622 EXPECT_TRUE(data.at_read_eof()); | 2622 EXPECT_TRUE(data.at_read_eof()); |
| 2623 EXPECT_TRUE(data.at_write_eof()); | 2623 EXPECT_TRUE(data.at_write_eof()); |
| 2624 EXPECT_TRUE(data2.at_read_eof()); | 2624 EXPECT_TRUE(data2.at_read_eof()); |
| 2625 EXPECT_TRUE(data2.at_write_eof()); | 2625 EXPECT_TRUE(data2.at_write_eof()); |
| 2626 } | 2626 } |
| (...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3747 helper.RunToCompletion(&data); | 3747 helper.RunToCompletion(&data); |
| 3748 TransactionHelperResult out = helper.output(); | 3748 TransactionHelperResult out = helper.output(); |
| 3749 EXPECT_EQ(OK, out.rv); | 3749 EXPECT_EQ(OK, out.rv); |
| 3750 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 3750 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 3751 EXPECT_EQ("hello!", out.response_data); | 3751 EXPECT_EQ("hello!", out.response_data); |
| 3752 | 3752 |
| 3753 // Check that the NetLog was filled reasonably. | 3753 // Check that the NetLog was filled reasonably. |
| 3754 // This test is intentionally non-specific about the exact ordering of the | 3754 // This test is intentionally non-specific about the exact ordering of the |
| 3755 // log; instead we just check to make sure that certain events exist, and that | 3755 // log; instead we just check to make sure that certain events exist, and that |
| 3756 // they are in the right order. | 3756 // they are in the right order. |
| 3757 net::CapturingNetLog::CapturedEntryList entries; | 3757 CapturingNetLog::CapturedEntryList entries; |
| 3758 log.GetEntries(&entries); | 3758 log.GetEntries(&entries); |
| 3759 | 3759 |
| 3760 EXPECT_LT(0u, entries.size()); | 3760 EXPECT_LT(0u, entries.size()); |
| 3761 int pos = 0; | 3761 int pos = 0; |
| 3762 pos = net::ExpectLogContainsSomewhere(entries, 0, | 3762 pos = ExpectLogContainsSomewhere(entries, 0, |
| 3763 net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, | 3763 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, |
| 3764 net::NetLog::PHASE_BEGIN); | 3764 NetLog::PHASE_BEGIN); |
| 3765 pos = net::ExpectLogContainsSomewhere(entries, pos + 1, | 3765 pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3766 net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, | 3766 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, |
| 3767 net::NetLog::PHASE_END); | 3767 NetLog::PHASE_END); |
| 3768 pos = net::ExpectLogContainsSomewhere(entries, pos + 1, | 3768 pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3769 net::NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, | 3769 NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, |
| 3770 net::NetLog::PHASE_BEGIN); | 3770 NetLog::PHASE_BEGIN); |
| 3771 pos = net::ExpectLogContainsSomewhere(entries, pos + 1, | 3771 pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3772 net::NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, | 3772 NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, |
| 3773 net::NetLog::PHASE_END); | 3773 NetLog::PHASE_END); |
| 3774 pos = net::ExpectLogContainsSomewhere(entries, pos + 1, | 3774 pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3775 net::NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, | 3775 NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, |
| 3776 net::NetLog::PHASE_BEGIN); | 3776 NetLog::PHASE_BEGIN); |
| 3777 pos = net::ExpectLogContainsSomewhere(entries, pos + 1, | 3777 pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3778 net::NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, | 3778 NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, |
| 3779 net::NetLog::PHASE_END); | 3779 NetLog::PHASE_END); |
| 3780 | 3780 |
| 3781 // Check that we logged all the headers correctly | 3781 // Check that we logged all the headers correctly |
| 3782 const NetLog::EventType type = | 3782 const NetLog::EventType type = (GetParam().protocol <= kProtoSPDY31) |
| 3783 (GetParam().protocol <= kProtoSPDY31) | 3783 ? NetLog::TYPE_HTTP2_SESSION_SYN_STREAM |
| 3784 ? net::NetLog::TYPE_HTTP2_SESSION_SYN_STREAM | 3784 : NetLog::TYPE_HTTP2_SESSION_SEND_HEADERS; |
| 3785 : net::NetLog::TYPE_HTTP2_SESSION_SEND_HEADERS; | 3785 pos = ExpectLogContainsSomewhere(entries, 0, type, NetLog::PHASE_NONE); |
| 3786 pos = net::ExpectLogContainsSomewhere(entries, 0, type, | |
| 3787 net::NetLog::PHASE_NONE); | |
| 3788 | 3786 |
| 3789 base::ListValue* header_list; | 3787 base::ListValue* header_list; |
| 3790 ASSERT_TRUE(entries[pos].params.get()); | 3788 ASSERT_TRUE(entries[pos].params.get()); |
| 3791 ASSERT_TRUE(entries[pos].params->GetList("headers", &header_list)); | 3789 ASSERT_TRUE(entries[pos].params->GetList("headers", &header_list)); |
| 3792 | 3790 |
| 3793 std::vector<std::string> expected; | 3791 std::vector<std::string> expected; |
| 3794 expected.push_back(std::string(spdy_util_.GetHostKey()) + ": www.google.com"); | 3792 expected.push_back(std::string(spdy_util_.GetHostKey()) + ": www.google.com"); |
| 3795 expected.push_back(std::string(spdy_util_.GetPathKey()) + ": /"); | 3793 expected.push_back(std::string(spdy_util_.GetPathKey()) + ": /"); |
| 3796 expected.push_back(std::string(spdy_util_.GetSchemeKey()) + ": http"); | 3794 expected.push_back(std::string(spdy_util_.GetSchemeKey()) + ": http"); |
| 3797 expected.push_back(std::string(spdy_util_.GetMethodKey()) + ": GET"); | 3795 expected.push_back(std::string(spdy_util_.GetMethodKey()) + ": GET"); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3871 out.status_line = response->headers->GetStatusLine(); | 3869 out.status_line = response->headers->GetStatusLine(); |
| 3872 out.response_info = *response; // Make a copy so we can verify. | 3870 out.response_info = *response; // Make a copy so we can verify. |
| 3873 | 3871 |
| 3874 // Read Data | 3872 // Read Data |
| 3875 TestCompletionCallback read_callback; | 3873 TestCompletionCallback read_callback; |
| 3876 | 3874 |
| 3877 std::string content; | 3875 std::string content; |
| 3878 do { | 3876 do { |
| 3879 // Read small chunks at a time. | 3877 // Read small chunks at a time. |
| 3880 const int kSmallReadSize = 3; | 3878 const int kSmallReadSize = 3; |
| 3881 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSmallReadSize)); | 3879 scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
| 3882 rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); | 3880 rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
| 3883 if (rv == net::ERR_IO_PENDING) { | 3881 if (rv == ERR_IO_PENDING) { |
| 3884 data.CompleteRead(); | 3882 data.CompleteRead(); |
| 3885 rv = read_callback.WaitForResult(); | 3883 rv = read_callback.WaitForResult(); |
| 3886 } | 3884 } |
| 3887 if (rv > 0) { | 3885 if (rv > 0) { |
| 3888 content.append(buf->data(), rv); | 3886 content.append(buf->data(), rv); |
| 3889 } else if (rv < 0) { | 3887 } else if (rv < 0) { |
| 3890 NOTREACHED(); | 3888 NOTREACHED(); |
| 3891 } | 3889 } |
| 3892 } while (rv > 0); | 3890 } while (rv > 0); |
| 3893 | 3891 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3964 out.response_info = *response; // Make a copy so we can verify. | 3962 out.response_info = *response; // Make a copy so we can verify. |
| 3965 | 3963 |
| 3966 // Read Data | 3964 // Read Data |
| 3967 TestCompletionCallback read_callback; | 3965 TestCompletionCallback read_callback; |
| 3968 | 3966 |
| 3969 std::string content; | 3967 std::string content; |
| 3970 int reads_completed = 0; | 3968 int reads_completed = 0; |
| 3971 do { | 3969 do { |
| 3972 // Read small chunks at a time. | 3970 // Read small chunks at a time. |
| 3973 const int kSmallReadSize = 14; | 3971 const int kSmallReadSize = 14; |
| 3974 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSmallReadSize)); | 3972 scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
| 3975 rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); | 3973 rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
| 3976 if (rv == net::ERR_IO_PENDING) { | 3974 if (rv == ERR_IO_PENDING) { |
| 3977 data.CompleteRead(); | 3975 data.CompleteRead(); |
| 3978 rv = read_callback.WaitForResult(); | 3976 rv = read_callback.WaitForResult(); |
| 3979 } | 3977 } |
| 3980 if (rv > 0) { | 3978 if (rv > 0) { |
| 3981 EXPECT_EQ(kSmallReadSize, rv); | 3979 EXPECT_EQ(kSmallReadSize, rv); |
| 3982 content.append(buf->data(), rv); | 3980 content.append(buf->data(), rv); |
| 3983 } else if (rv < 0) { | 3981 } else if (rv < 0) { |
| 3984 FAIL() << "Unexpected read error: " << rv; | 3982 FAIL() << "Unexpected read error: " << rv; |
| 3985 } | 3983 } |
| 3986 reads_completed++; | 3984 reads_completed++; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4053 out.response_info = *response; // Make a copy so we can verify. | 4051 out.response_info = *response; // Make a copy so we can verify. |
| 4054 | 4052 |
| 4055 // Read Data | 4053 // Read Data |
| 4056 TestCompletionCallback read_callback; | 4054 TestCompletionCallback read_callback; |
| 4057 | 4055 |
| 4058 std::string content; | 4056 std::string content; |
| 4059 int reads_completed = 0; | 4057 int reads_completed = 0; |
| 4060 do { | 4058 do { |
| 4061 // Read small chunks at a time. | 4059 // Read small chunks at a time. |
| 4062 const int kSmallReadSize = 14; | 4060 const int kSmallReadSize = 14; |
| 4063 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSmallReadSize)); | 4061 scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
| 4064 rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); | 4062 rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
| 4065 if (rv > 0) { | 4063 if (rv > 0) { |
| 4066 EXPECT_EQ(kSmallReadSize, rv); | 4064 EXPECT_EQ(kSmallReadSize, rv); |
| 4067 content.append(buf->data(), rv); | 4065 content.append(buf->data(), rv); |
| 4068 } else if (rv < 0) { | 4066 } else if (rv < 0) { |
| 4069 FAIL() << "Unexpected read error: " << rv; | 4067 FAIL() << "Unexpected read error: " << rv; |
| 4070 } | 4068 } |
| 4071 reads_completed++; | 4069 reads_completed++; |
| 4072 } while (rv > 0); | 4070 } while (rv > 0); |
| 4073 | 4071 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4143 out.response_info = *response; // Make a copy so we can verify. | 4141 out.response_info = *response; // Make a copy so we can verify. |
| 4144 | 4142 |
| 4145 // Read Data | 4143 // Read Data |
| 4146 TestCompletionCallback read_callback; | 4144 TestCompletionCallback read_callback; |
| 4147 | 4145 |
| 4148 std::string content; | 4146 std::string content; |
| 4149 int reads_completed = 0; | 4147 int reads_completed = 0; |
| 4150 do { | 4148 do { |
| 4151 // Read small chunks at a time. | 4149 // Read small chunks at a time. |
| 4152 const int kSmallReadSize = 14; | 4150 const int kSmallReadSize = 14; |
| 4153 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSmallReadSize)); | 4151 scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
| 4154 rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); | 4152 rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
| 4155 if (rv == net::ERR_IO_PENDING) { | 4153 if (rv == ERR_IO_PENDING) { |
| 4156 data.CompleteRead(); | 4154 data.CompleteRead(); |
| 4157 rv = read_callback.WaitForResult(); | 4155 rv = read_callback.WaitForResult(); |
| 4158 } | 4156 } |
| 4159 if (rv > 0) { | 4157 if (rv > 0) { |
| 4160 content.append(buf->data(), rv); | 4158 content.append(buf->data(), rv); |
| 4161 } else if (rv < 0) { | 4159 } else if (rv < 0) { |
| 4162 // This test intentionally closes the connection, and will get an error. | 4160 // This test intentionally closes the connection, and will get an error. |
| 4163 EXPECT_EQ(ERR_CONNECTION_CLOSED, rv); | 4161 EXPECT_EQ(ERR_CONNECTION_CLOSED, rv); |
| 4164 break; | 4162 break; |
| 4165 } | 4163 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4221 const HttpResponseInfo* response = trans->GetResponseInfo(); | 4219 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4222 EXPECT_TRUE(response->headers.get() != NULL); | 4220 EXPECT_TRUE(response->headers.get() != NULL); |
| 4223 EXPECT_TRUE(response->was_fetched_via_spdy); | 4221 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4224 out.status_line = response->headers->GetStatusLine(); | 4222 out.status_line = response->headers->GetStatusLine(); |
| 4225 out.response_info = *response; // Make a copy so we can verify. | 4223 out.response_info = *response; // Make a copy so we can verify. |
| 4226 | 4224 |
| 4227 // Read Data | 4225 // Read Data |
| 4228 TestCompletionCallback read_callback; | 4226 TestCompletionCallback read_callback; |
| 4229 | 4227 |
| 4230 const int kReadSize = 256; | 4228 const int kReadSize = 256; |
| 4231 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kReadSize)); | 4229 scoped_refptr<IOBuffer> buf(new IOBuffer(kReadSize)); |
| 4232 rv = trans->Read(buf.get(), kReadSize, read_callback.callback()); | 4230 rv = trans->Read(buf.get(), kReadSize, read_callback.callback()); |
| 4233 ASSERT_EQ(net::ERR_IO_PENDING, rv) << "Unexpected read: " << rv; | 4231 ASSERT_EQ(ERR_IO_PENDING, rv) << "Unexpected read: " << rv; |
| 4234 | 4232 |
| 4235 // Complete the read now, which causes buffering to start. | 4233 // Complete the read now, which causes buffering to start. |
| 4236 data.CompleteRead(); | 4234 data.CompleteRead(); |
| 4237 // Destroy the transaction, causing the stream to get cancelled | 4235 // Destroy the transaction, causing the stream to get cancelled |
| 4238 // and orphaning the buffered IO task. | 4236 // and orphaning the buffered IO task. |
| 4239 helper.ResetTrans(); | 4237 helper.ResetTrans(); |
| 4240 | 4238 |
| 4241 // Flush the MessageLoop; this will cause the buffered IO task | 4239 // Flush the MessageLoop; this will cause the buffered IO task |
| 4242 // to run for the final time. | 4240 // to run for the final time. |
| 4243 base::RunLoop().RunUntilIdle(); | 4241 base::RunLoop().RunUntilIdle(); |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5027 request_proxy.url = GURL("http://www.google.com/foo.dat"); | 5025 request_proxy.url = GURL("http://www.google.com/foo.dat"); |
| 5028 request_proxy.load_flags = 0; | 5026 request_proxy.load_flags = 0; |
| 5029 scoped_ptr<SpdySessionDependencies> ssd_proxy( | 5027 scoped_ptr<SpdySessionDependencies> ssd_proxy( |
| 5030 CreateSpdySessionDependencies(GetParam())); | 5028 CreateSpdySessionDependencies(GetParam())); |
| 5031 // Ensure that this transaction uses the same SpdySessionPool. | 5029 // Ensure that this transaction uses the same SpdySessionPool. |
| 5032 scoped_refptr<HttpNetworkSession> session_proxy( | 5030 scoped_refptr<HttpNetworkSession> session_proxy( |
| 5033 SpdySessionDependencies::SpdyCreateSession(ssd_proxy.get())); | 5031 SpdySessionDependencies::SpdyCreateSession(ssd_proxy.get())); |
| 5034 NormalSpdyTransactionHelper helper_proxy(request_proxy, DEFAULT_PRIORITY, | 5032 NormalSpdyTransactionHelper helper_proxy(request_proxy, DEFAULT_PRIORITY, |
| 5035 BoundNetLog(), GetParam(), NULL); | 5033 BoundNetLog(), GetParam(), NULL); |
| 5036 HttpNetworkSessionPeer session_peer(session_proxy); | 5034 HttpNetworkSessionPeer session_peer(session_proxy); |
| 5037 scoped_ptr<net::ProxyService> proxy_service( | 5035 scoped_ptr<ProxyService> proxy_service( |
| 5038 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); | 5036 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 5039 session_peer.SetProxyService(proxy_service.get()); | 5037 session_peer.SetProxyService(proxy_service.get()); |
| 5040 helper_proxy.session_deps().swap(ssd_proxy); | 5038 helper_proxy.session_deps().swap(ssd_proxy); |
| 5041 helper_proxy.SetSession(session_proxy); | 5039 helper_proxy.SetSession(session_proxy); |
| 5042 helper_proxy.RunPreTestSetup(); | 5040 helper_proxy.RunPreTestSetup(); |
| 5043 helper_proxy.AddData(data_proxy.get()); | 5041 helper_proxy.AddData(data_proxy.get()); |
| 5044 | 5042 |
| 5045 HttpNetworkTransaction* trans_proxy = helper_proxy.trans(); | 5043 HttpNetworkTransaction* trans_proxy = helper_proxy.trans(); |
| 5046 TestCompletionCallback callback_proxy; | 5044 TestCompletionCallback callback_proxy; |
| 5047 int rv = trans_proxy->Start( | 5045 int rv = trans_proxy->Start( |
| 5048 &request_proxy, callback_proxy.callback(), BoundNetLog()); | 5046 &request_proxy, callback_proxy.callback(), BoundNetLog()); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5161 DelayedSocketData data(1, spdy_reads, arraysize(spdy_reads), | 5159 DelayedSocketData data(1, spdy_reads, arraysize(spdy_reads), |
| 5162 spdy_writes, arraysize(spdy_writes)); | 5160 spdy_writes, arraysize(spdy_writes)); |
| 5163 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 5161 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 5164 BoundNetLog(), GetParam(), NULL); | 5162 BoundNetLog(), GetParam(), NULL); |
| 5165 helper.RunToCompletion(&data); | 5163 helper.RunToCompletion(&data); |
| 5166 TransactionHelperResult out = helper.output(); | 5164 TransactionHelperResult out = helper.output(); |
| 5167 EXPECT_EQ(OK, out.rv); | 5165 EXPECT_EQ(OK, out.rv); |
| 5168 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 5166 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 5169 EXPECT_EQ("hello!", out.response_data); | 5167 EXPECT_EQ("hello!", out.response_data); |
| 5170 | 5168 |
| 5171 net::HttpStreamFactory::set_spdy_enabled(false); | 5169 HttpStreamFactory::set_spdy_enabled(false); |
| 5172 MockRead http_reads[] = { | 5170 MockRead http_reads[] = { |
| 5173 MockRead("HTTP/1.1 200 OK\r\n\r\n"), | 5171 MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 5174 MockRead("hello from http"), | 5172 MockRead("hello from http"), |
| 5175 MockRead(SYNCHRONOUS, OK), | 5173 MockRead(SYNCHRONOUS, OK), |
| 5176 }; | 5174 }; |
| 5177 DelayedSocketData data2(1, http_reads, arraysize(http_reads), NULL, 0); | 5175 DelayedSocketData data2(1, http_reads, arraysize(http_reads), NULL, 0); |
| 5178 NormalSpdyTransactionHelper helper2(CreateGetRequest(), DEFAULT_PRIORITY, | 5176 NormalSpdyTransactionHelper helper2(CreateGetRequest(), DEFAULT_PRIORITY, |
| 5179 BoundNetLog(), GetParam(), NULL); | 5177 BoundNetLog(), GetParam(), NULL); |
| 5180 helper2.SetSpdyDisabled(); | 5178 helper2.SetSpdyDisabled(); |
| 5181 helper2.RunToCompletion(&data2); | 5179 helper2.RunToCompletion(&data2); |
| 5182 TransactionHelperResult out2 = helper2.output(); | 5180 TransactionHelperResult out2 = helper2.output(); |
| 5183 EXPECT_EQ(OK, out2.rv); | 5181 EXPECT_EQ(OK, out2.rv); |
| 5184 EXPECT_EQ("HTTP/1.1 200 OK", out2.status_line); | 5182 EXPECT_EQ("HTTP/1.1 200 OK", out2.status_line); |
| 5185 EXPECT_EQ("hello from http", out2.response_data); | 5183 EXPECT_EQ("hello from http", out2.response_data); |
| 5186 | 5184 |
| 5187 net::HttpStreamFactory::set_spdy_enabled(true); | 5185 HttpStreamFactory::set_spdy_enabled(true); |
| 5188 } | 5186 } |
| 5189 | 5187 |
| 5190 // Tests that Basic authentication works over SPDY | 5188 // Tests that Basic authentication works over SPDY |
| 5191 TEST_P(SpdyNetworkTransactionTest, SpdyBasicAuth) { | 5189 TEST_P(SpdyNetworkTransactionTest, SpdyBasicAuth) { |
| 5192 net::HttpStreamFactory::set_spdy_enabled(true); | 5190 HttpStreamFactory::set_spdy_enabled(true); |
| 5193 | 5191 |
| 5194 // The first request will be a bare GET, the second request will be a | 5192 // The first request will be a bare GET, the second request will be a |
| 5195 // GET with an Authorization header. | 5193 // GET with an Authorization header. |
| 5196 scoped_ptr<SpdyFrame> req_get( | 5194 scoped_ptr<SpdyFrame> req_get( |
| 5197 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 5195 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5198 const char* const kExtraAuthorizationHeaders[] = { | 5196 const char* const kExtraAuthorizationHeaders[] = { |
| 5199 "authorization", "Basic Zm9vOmJhcg==" | 5197 "authorization", "Basic Zm9vOmJhcg==" |
| 5200 }; | 5198 }; |
| 5201 scoped_ptr<SpdyFrame> req_get_authorization( | 5199 scoped_ptr<SpdyFrame> req_get_authorization( |
| 5202 spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, | 5200 spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| (...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6217 stream->stream()->recv_window_size()); | 6215 stream->stream()->recv_window_size()); |
| 6218 | 6216 |
| 6219 const HttpResponseInfo* response = trans->GetResponseInfo(); | 6217 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6220 ASSERT_TRUE(response != NULL); | 6218 ASSERT_TRUE(response != NULL); |
| 6221 ASSERT_TRUE(response->headers.get() != NULL); | 6219 ASSERT_TRUE(response->headers.get() != NULL); |
| 6222 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 6220 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6223 EXPECT_TRUE(response->was_fetched_via_spdy); | 6221 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 6224 | 6222 |
| 6225 // Issue a read which will cause a WINDOW_UPDATE to be sent and window | 6223 // Issue a read which will cause a WINDOW_UPDATE to be sent and window |
| 6226 // size increased to default. | 6224 // size increased to default. |
| 6227 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kTargetSize)); | 6225 scoped_refptr<IOBuffer> buf(new IOBuffer(kTargetSize)); |
| 6228 EXPECT_EQ(static_cast<int>(kTargetSize), | 6226 EXPECT_EQ(static_cast<int>(kTargetSize), |
| 6229 trans->Read(buf.get(), kTargetSize, CompletionCallback())); | 6227 trans->Read(buf.get(), kTargetSize, CompletionCallback())); |
| 6230 EXPECT_EQ(static_cast<int>(initial_window_size), | 6228 EXPECT_EQ(static_cast<int>(initial_window_size), |
| 6231 stream->stream()->recv_window_size()); | 6229 stream->stream()->recv_window_size()); |
| 6232 EXPECT_THAT(base::StringPiece(buf->data(), kTargetSize), Each(Eq('x'))); | 6230 EXPECT_THAT(base::StringPiece(buf->data(), kTargetSize), Each(Eq('x'))); |
| 6233 | 6231 |
| 6234 // Allow scheduled WINDOW_UPDATE frames to write. | 6232 // Allow scheduled WINDOW_UPDATE frames to write. |
| 6235 base::RunLoop().RunUntilIdle(); | 6233 base::RunLoop().RunUntilIdle(); |
| 6236 helper.VerifyDataConsumed(); | 6234 helper.VerifyDataConsumed(); |
| 6237 } | 6235 } |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6822 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { | 6820 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { |
| 6823 scoped_ptr<SSLSocketDataProvider> ssl_provider( | 6821 scoped_ptr<SSLSocketDataProvider> ssl_provider( |
| 6824 new SSLSocketDataProvider(ASYNC, OK)); | 6822 new SSLSocketDataProvider(ASYNC, OK)); |
| 6825 // Set to TLS_RSA_WITH_NULL_MD5 | 6823 // Set to TLS_RSA_WITH_NULL_MD5 |
| 6826 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); | 6824 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
| 6827 | 6825 |
| 6828 RunTLSUsageCheckTest(ssl_provider.Pass()); | 6826 RunTLSUsageCheckTest(ssl_provider.Pass()); |
| 6829 } | 6827 } |
| 6830 | 6828 |
| 6831 } // namespace net | 6829 } // namespace net |
| OLD | NEW |