| 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 <cmath> | 5 #include <cmath> |
| 6 #include <memory> | 6 #include <memory> |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 227 |
| 228 session_deps_->socket_factory->AddSSLSocketDataProvider( | 228 session_deps_->socket_factory->AddSSLSocketDataProvider( |
| 229 ssl_provider.get()); | 229 ssl_provider.get()); |
| 230 ssl_vector_.push_back(std::move(ssl_provider)); | 230 ssl_vector_.push_back(std::move(ssl_provider)); |
| 231 | 231 |
| 232 session_deps_->socket_factory->AddSocketDataProvider(data); | 232 session_deps_->socket_factory->AddSocketDataProvider(data); |
| 233 } | 233 } |
| 234 | 234 |
| 235 HttpNetworkTransaction* trans() { return trans_.get(); } | 235 HttpNetworkTransaction* trans() { return trans_.get(); } |
| 236 void ResetTrans() { trans_.reset(); } | 236 void ResetTrans() { trans_.reset(); } |
| 237 TransactionHelperResult& output() { return output_; } | 237 const TransactionHelperResult& output() { return output_; } |
| 238 const HttpRequestInfo& request() const { return request_; } | 238 const HttpRequestInfo& request() const { return request_; } |
| 239 HttpNetworkSession* session() const { return session_.get(); } | 239 HttpNetworkSession* session() const { return session_.get(); } |
| 240 SpdySessionDependencies* session_deps() { return session_deps_.get(); } | 240 SpdySessionDependencies* session_deps() { return session_deps_.get(); } |
| 241 | 241 |
| 242 private: | 242 private: |
| 243 typedef std::vector<SocketDataProvider*> DataVector; | 243 typedef std::vector<SocketDataProvider*> DataVector; |
| 244 typedef std::vector<std::unique_ptr<SSLSocketDataProvider>> SSLVector; | 244 typedef std::vector<std::unique_ptr<SSLSocketDataProvider>> SSLVector; |
| 245 typedef std::vector<std::unique_ptr<SocketDataProvider>> AlternateVector; | 245 typedef std::vector<std::unique_ptr<SocketDataProvider>> AlternateVector; |
| 246 HttpRequestInfo request_; | 246 HttpRequestInfo request_; |
| 247 RequestPriority priority_; | 247 RequestPriority priority_; |
| 248 std::unique_ptr<SpdySessionDependencies> session_deps_; | 248 std::unique_ptr<SpdySessionDependencies> session_deps_; |
| 249 std::unique_ptr<HttpNetworkSession> session_; | 249 std::unique_ptr<HttpNetworkSession> session_; |
| 250 TransactionHelperResult output_; | 250 TransactionHelperResult output_; |
| 251 std::unique_ptr<SocketDataProvider> first_transaction_; | |
| 252 SSLVector ssl_vector_; | 251 SSLVector ssl_vector_; |
| 253 TestCompletionCallback callback_; | 252 TestCompletionCallback callback_; |
| 254 std::unique_ptr<HttpNetworkTransaction> trans_; | 253 std::unique_ptr<HttpNetworkTransaction> trans_; |
| 255 std::unique_ptr<HttpNetworkTransaction> trans_http_; | |
| 256 DataVector data_vector_; | 254 DataVector data_vector_; |
| 257 AlternateVector alternate_vector_; | |
| 258 const BoundNetLog log_; | 255 const BoundNetLog log_; |
| 259 }; | 256 }; |
| 260 | 257 |
| 261 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, | 258 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 262 int expected_status); | 259 int expected_status); |
| 263 | 260 |
| 264 void ConnectStatusHelper(const MockRead& status); | 261 void ConnectStatusHelper(const MockRead& status); |
| 265 | 262 |
| 266 const HttpRequestInfo& CreateGetPushRequest() { | 263 const HttpRequestInfo& CreateGetPushRequest() { |
| 267 get_push_request_.method = "GET"; | 264 get_push_request_.method = "GET"; |
| (...skipping 1501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1769 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); | 1766 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 1770 MockRead reads[] = { | 1767 MockRead reads[] = { |
| 1771 CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 0, 4) // EOF | 1768 CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 0, 4) // EOF |
| 1772 }; | 1769 }; |
| 1773 | 1770 |
| 1774 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | 1771 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 1775 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 1772 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 1776 BoundNetLog(), NULL); | 1773 BoundNetLog(), NULL); |
| 1777 helper.RunPreTestSetup(); | 1774 helper.RunPreTestSetup(); |
| 1778 helper.AddData(&data); | 1775 helper.AddData(&data); |
| 1779 HttpNetworkTransaction* trans = helper.trans(); | 1776 helper.StartDefaultTest(); |
| 1777 EXPECT_THAT(helper.output().rv, IsError(ERR_IO_PENDING)); |
| 1780 | 1778 |
| 1781 TestCompletionCallback callback; | 1779 helper.WaitForCallbackToComplete(); |
| 1782 int rv = trans->Start( | 1780 EXPECT_THAT(helper.output().rv, IsOk()); |
| 1783 &CreateGetRequest(), callback.callback(), BoundNetLog()); | |
| 1784 EXPECT_THAT(callback.GetResult(rv), IsOk()); | |
| 1785 | 1781 |
| 1786 helper.ResetTrans(); | 1782 helper.ResetTrans(); |
| 1787 base::RunLoop().RunUntilIdle(); | 1783 base::RunLoop().RunUntilIdle(); |
| 1788 | 1784 |
| 1789 helper.VerifyDataConsumed(); | 1785 helper.VerifyDataConsumed(); |
| 1790 } | 1786 } |
| 1791 | 1787 |
| 1792 // Test that the transaction doesn't crash when we don't have a reply. | 1788 // Test that the transaction doesn't crash when we don't have a reply. |
| 1793 TEST_F(SpdyNetworkTransactionTest, ResponseWithoutHeaders) { | 1789 TEST_F(SpdyNetworkTransactionTest, ResponseWithoutHeaders) { |
| 1794 SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); | 1790 SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| (...skipping 1950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3745 SpdySerializedFrame req( | 3741 SpdySerializedFrame req( |
| 3746 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 3742 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 3747 MockWrite writes[] = {CreateMockWrite(req, 0)}; | 3743 MockWrite writes[] = {CreateMockWrite(req, 0)}; |
| 3748 | 3744 |
| 3749 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); | 3745 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 3750 MockRead reads[] = { | 3746 MockRead reads[] = { |
| 3751 CreateMockRead(resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF | 3747 CreateMockRead(resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF |
| 3752 }; | 3748 }; |
| 3753 | 3749 |
| 3754 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | 3750 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 3755 BoundNetLog log; | 3751 |
| 3756 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, log, | 3752 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 3757 NULL); | 3753 BoundNetLog(), NULL); |
| 3758 helper.RunPreTestSetup(); | 3754 helper.RunPreTestSetup(); |
| 3759 helper.AddData(&data); | 3755 helper.AddData(&data); |
| 3760 HttpNetworkTransaction* trans = helper.trans(); | 3756 helper.StartDefaultTest(); |
| 3757 EXPECT_THAT(helper.output().rv, IsError(ERR_IO_PENDING)); |
| 3761 | 3758 |
| 3762 TestCompletionCallback callback; | 3759 helper.WaitForCallbackToComplete(); |
| 3763 TransactionHelperResult out; | 3760 EXPECT_THAT(helper.output().rv, IsError(ERR_CONNECTION_CLOSED)); |
| 3764 out.rv = trans->Start(&CreateGetRequest(), callback.callback(), log); | |
| 3765 | 3761 |
| 3766 EXPECT_EQ(out.rv, ERR_IO_PENDING); | 3762 const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
| 3767 out.rv = callback.WaitForResult(); | |
| 3768 EXPECT_EQ(out.rv, ERR_CONNECTION_CLOSED); | |
| 3769 | |
| 3770 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
| 3771 EXPECT_TRUE(response->headers); | 3763 EXPECT_TRUE(response->headers); |
| 3772 EXPECT_TRUE(response->was_fetched_via_spdy); | 3764 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3773 out.rv = ReadTransaction(trans, &out.response_data); | |
| 3774 EXPECT_THAT(out.rv, IsError(ERR_CONNECTION_CLOSED)); | |
| 3775 | 3765 |
| 3776 // Verify that we consumed all test data. | 3766 // Verify that we consumed all test data. |
| 3777 helper.VerifyDataConsumed(); | 3767 helper.VerifyDataConsumed(); |
| 3778 } | 3768 } |
| 3779 | 3769 |
| 3780 // Retry with HTTP/1.1 when receiving HTTP_1_1_REQUIRED. Note that no actual | 3770 // Retry with HTTP/1.1 when receiving HTTP_1_1_REQUIRED. Note that no actual |
| 3781 // protocol negotiation happens, instead this test forces protocols for both | 3771 // protocol negotiation happens, instead this test forces protocols for both |
| 3782 // sockets. | 3772 // sockets. |
| 3783 TEST_F(SpdyNetworkTransactionTest, HTTP11RequiredRetry) { | 3773 TEST_F(SpdyNetworkTransactionTest, HTTP11RequiredRetry) { |
| 3784 HttpRequestInfo request; | 3774 HttpRequestInfo request; |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4249 CreateMockRead(resp_authentication, 1), | 4239 CreateMockRead(resp_authentication, 1), |
| 4250 CreateMockRead(body_authentication, 2), | 4240 CreateMockRead(body_authentication, 2), |
| 4251 CreateMockRead(resp_data, 4), | 4241 CreateMockRead(resp_data, 4), |
| 4252 CreateMockRead(body_data, 5), | 4242 CreateMockRead(body_data, 5), |
| 4253 MockRead(ASYNC, 0, 6), | 4243 MockRead(ASYNC, 0, 6), |
| 4254 }; | 4244 }; |
| 4255 | 4245 |
| 4256 SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, | 4246 SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4257 arraysize(spdy_writes)); | 4247 arraysize(spdy_writes)); |
| 4258 HttpRequestInfo request(CreateGetRequest()); | 4248 HttpRequestInfo request(CreateGetRequest()); |
| 4259 BoundNetLog net_log; | 4249 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 4260 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, net_log, NULL); | 4250 NULL); |
| 4261 | 4251 |
| 4262 helper.RunPreTestSetup(); | 4252 helper.RunPreTestSetup(); |
| 4263 helper.AddData(&data); | 4253 helper.AddData(&data); |
| 4264 HttpNetworkTransaction* trans = helper.trans(); | 4254 helper.StartDefaultTest(); |
| 4265 TestCompletionCallback callback; | 4255 EXPECT_THAT(helper.output().rv, IsError(ERR_IO_PENDING)); |
| 4266 const int rv_start = trans->Start(&request, callback.callback(), net_log); | 4256 |
| 4267 EXPECT_THAT(rv_start, IsError(ERR_IO_PENDING)); | 4257 helper.WaitForCallbackToComplete(); |
| 4268 const int rv_start_complete = callback.WaitForResult(); | 4258 EXPECT_THAT(helper.output().rv, IsOk()); |
| 4269 EXPECT_THAT(rv_start_complete, IsOk()); | |
| 4270 | 4259 |
| 4271 // Make sure the response has an auth challenge. | 4260 // Make sure the response has an auth challenge. |
| 4261 HttpNetworkTransaction* trans = helper.trans(); |
| 4272 const HttpResponseInfo* const response_start = trans->GetResponseInfo(); | 4262 const HttpResponseInfo* const response_start = trans->GetResponseInfo(); |
| 4273 ASSERT_TRUE(response_start); | 4263 ASSERT_TRUE(response_start); |
| 4274 ASSERT_TRUE(response_start->headers); | 4264 ASSERT_TRUE(response_start->headers); |
| 4275 EXPECT_EQ(401, response_start->headers->response_code()); | 4265 EXPECT_EQ(401, response_start->headers->response_code()); |
| 4276 EXPECT_TRUE(response_start->was_fetched_via_spdy); | 4266 EXPECT_TRUE(response_start->was_fetched_via_spdy); |
| 4277 AuthChallengeInfo* auth_challenge = response_start->auth_challenge.get(); | 4267 AuthChallengeInfo* auth_challenge = response_start->auth_challenge.get(); |
| 4278 ASSERT_TRUE(auth_challenge); | 4268 ASSERT_TRUE(auth_challenge); |
| 4279 EXPECT_FALSE(auth_challenge->is_proxy); | 4269 EXPECT_FALSE(auth_challenge->is_proxy); |
| 4280 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); | 4270 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 4281 EXPECT_EQ("MyRealm", auth_challenge->realm); | 4271 EXPECT_EQ("MyRealm", auth_challenge->realm); |
| (...skipping 1952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6234 TEST_F(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { | 6224 TEST_F(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { |
| 6235 std::unique_ptr<SSLSocketDataProvider> ssl_provider( | 6225 std::unique_ptr<SSLSocketDataProvider> ssl_provider( |
| 6236 new SSLSocketDataProvider(ASYNC, OK)); | 6226 new SSLSocketDataProvider(ASYNC, OK)); |
| 6237 // Set to TLS_RSA_WITH_NULL_MD5 | 6227 // Set to TLS_RSA_WITH_NULL_MD5 |
| 6238 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); | 6228 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
| 6239 | 6229 |
| 6240 RunTLSUsageCheckTest(std::move(ssl_provider)); | 6230 RunTLSUsageCheckTest(std::move(ssl_provider)); |
| 6241 } | 6231 } |
| 6242 | 6232 |
| 6243 } // namespace net | 6233 } // namespace net |
| OLD | NEW |