| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 std::unique_ptr<SpdySessionDependencies> session_deps) | 123 std::unique_ptr<SpdySessionDependencies> session_deps) |
| 124 : request_(request), | 124 : request_(request), |
| 125 priority_(priority), | 125 priority_(priority), |
| 126 session_deps_( | 126 session_deps_( |
| 127 session_deps.get() == NULL | 127 session_deps.get() == NULL |
| 128 ? CreateSpdySessionDependencies(priority_to_dependency) | 128 ? CreateSpdySessionDependencies(priority_to_dependency) |
| 129 : std::move(session_deps)), | 129 : std::move(session_deps)), |
| 130 session_( | 130 session_( |
| 131 SpdySessionDependencies::SpdyCreateSession(session_deps_.get())), | 131 SpdySessionDependencies::SpdyCreateSession(session_deps_.get())), |
| 132 log_(log), | 132 log_(log), |
| 133 priority_to_dependency_(priority_to_dependency), | 133 priority_to_dependency_(priority_to_dependency) {} |
| 134 spdy_enabled_(true) {} | |
| 135 | 134 |
| 136 ~NormalSpdyTransactionHelper() { | 135 ~NormalSpdyTransactionHelper() { |
| 137 // Any test which doesn't close the socket by sending it an EOF will | 136 // Any test which doesn't close the socket by sending it an EOF will |
| 138 // have a valid session left open, which leaks the entire session pool. | 137 // have a valid session left open, which leaks the entire session pool. |
| 139 // This is just fine - in fact, some of our tests intentionally do this | 138 // This is just fine - in fact, some of our tests intentionally do this |
| 140 // so that we can check consistency of the SpdySessionPool as the test | 139 // so that we can check consistency of the SpdySessionPool as the test |
| 141 // finishes. If we had put an EOF on the socket, the SpdySession would | 140 // finishes. If we had put an EOF on the socket, the SpdySession would |
| 142 // have closed and we wouldn't be able to check the consistency. | 141 // have closed and we wouldn't be able to check the consistency. |
| 143 | 142 |
| 144 // Forcefully close existing sessions here. | 143 // Forcefully close existing sessions here. |
| 145 session()->spdy_session_pool()->CloseAllSessions(); | 144 session()->spdy_session_pool()->CloseAllSessions(); |
| 146 } | 145 } |
| 147 | 146 |
| 148 void SetSpdyDisabled() { | |
| 149 spdy_enabled_ = false; | |
| 150 } | |
| 151 | |
| 152 void RunPreTestSetup() { | 147 void RunPreTestSetup() { |
| 153 if (!session_deps_.get()) | 148 if (!session_deps_.get()) |
| 154 session_deps_ = CreateSpdySessionDependencies(priority_to_dependency_); | 149 session_deps_ = CreateSpdySessionDependencies(priority_to_dependency_); |
| 155 if (!session_.get()) { | 150 if (!session_.get()) { |
| 156 session_ = SpdySessionDependencies::SpdyCreateSession( | 151 session_ = SpdySessionDependencies::SpdyCreateSession( |
| 157 session_deps_.get()); | 152 session_deps_.get()); |
| 158 } | 153 } |
| 159 | 154 |
| 160 // We're now ready to use SSL-npn SPDY. | 155 // We're now ready to use SSL-npn SPDY. |
| 161 trans_.reset(new HttpNetworkTransaction(priority_, session_.get())); | 156 trans_.reset(new HttpNetworkTransaction(priority_, session_.get())); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 180 output_.rv = callback_.WaitForResult(); | 175 output_.rv = callback_.WaitForResult(); |
| 181 if (output_.rv != OK) { | 176 if (output_.rv != OK) { |
| 182 session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); | 177 session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); |
| 183 return; | 178 return; |
| 184 } | 179 } |
| 185 | 180 |
| 186 // Verify responses. | 181 // Verify responses. |
| 187 const HttpResponseInfo* response = trans_->GetResponseInfo(); | 182 const HttpResponseInfo* response = trans_->GetResponseInfo(); |
| 188 ASSERT_TRUE(response); | 183 ASSERT_TRUE(response); |
| 189 ASSERT_TRUE(response->headers); | 184 ASSERT_TRUE(response->headers); |
| 190 if (HttpStreamFactory::spdy_enabled()) { | 185 EXPECT_EQ(HttpResponseInfo::ConnectionInfoFromNextProto(kProtoHTTP2), |
| 191 EXPECT_EQ(HttpResponseInfo::ConnectionInfoFromNextProto(kProtoHTTP2), | 186 response->connection_info); |
| 192 response->connection_info); | 187 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 193 } else { | 188 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 194 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1_1, | 189 EXPECT_TRUE(response->was_npn_negotiated); |
| 195 response->connection_info); | |
| 196 } | |
| 197 if (spdy_enabled_) { | |
| 198 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); | |
| 199 EXPECT_TRUE(response->was_fetched_via_spdy); | |
| 200 EXPECT_TRUE(response->was_npn_negotiated); | |
| 201 } else { | |
| 202 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
| 203 EXPECT_FALSE(response->was_fetched_via_spdy); | |
| 204 // If SPDY is disabled, an HTTP request should not be diverted | |
| 205 // over an SSL session. | |
| 206 EXPECT_EQ(request_.url.SchemeIs("https"), | |
| 207 response->was_npn_negotiated); | |
| 208 } | |
| 209 EXPECT_EQ("127.0.0.1", response->socket_address.host()); | 190 EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 210 EXPECT_EQ(443, response->socket_address.port()); | 191 EXPECT_EQ(443, response->socket_address.port()); |
| 211 output_.status_line = response->headers->GetStatusLine(); | 192 output_.status_line = response->headers->GetStatusLine(); |
| 212 output_.response_info = *response; // Make a copy so we can verify. | 193 output_.response_info = *response; // Make a copy so we can verify. |
| 213 output_.rv = ReadTransaction(trans_.get(), &output_.response_data); | 194 output_.rv = ReadTransaction(trans_.get(), &output_.response_data); |
| 214 } | 195 } |
| 215 | 196 |
| 216 void FinishDefaultTestWithoutVerification() { | 197 void FinishDefaultTestWithoutVerification() { |
| 217 output_.rv = callback_.WaitForResult(); | 198 output_.rv = callback_.WaitForResult(); |
| 218 if (output_.rv != OK) | 199 if (output_.rv != OK) |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 TransactionHelperResult output_; | 285 TransactionHelperResult output_; |
| 305 std::unique_ptr<SocketDataProvider> first_transaction_; | 286 std::unique_ptr<SocketDataProvider> first_transaction_; |
| 306 SSLVector ssl_vector_; | 287 SSLVector ssl_vector_; |
| 307 TestCompletionCallback callback_; | 288 TestCompletionCallback callback_; |
| 308 std::unique_ptr<HttpNetworkTransaction> trans_; | 289 std::unique_ptr<HttpNetworkTransaction> trans_; |
| 309 std::unique_ptr<HttpNetworkTransaction> trans_http_; | 290 std::unique_ptr<HttpNetworkTransaction> trans_http_; |
| 310 DataVector data_vector_; | 291 DataVector data_vector_; |
| 311 AlternateVector alternate_vector_; | 292 AlternateVector alternate_vector_; |
| 312 const BoundNetLog log_; | 293 const BoundNetLog log_; |
| 313 bool priority_to_dependency_; | 294 bool priority_to_dependency_; |
| 314 bool spdy_enabled_; | |
| 315 }; | 295 }; |
| 316 | 296 |
| 317 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, | 297 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 318 int expected_status); | 298 int expected_status); |
| 319 | 299 |
| 320 void ConnectStatusHelper(const MockRead& status); | 300 void ConnectStatusHelper(const MockRead& status); |
| 321 | 301 |
| 322 const HttpRequestInfo& CreateGetPushRequest() { | 302 const HttpRequestInfo& CreateGetPushRequest() { |
| 323 get_push_request_.method = "GET"; | 303 get_push_request_.method = "GET"; |
| 324 get_push_request_.url = GURL(GetDefaultUrlWithPath("/foo.dat")); | 304 get_push_request_.url = GURL(GetDefaultUrlWithPath("/foo.dat")); |
| (...skipping 4227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4552 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); | 4532 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 4553 EXPECT_EQ("hello!", response_data); | 4533 EXPECT_EQ("hello!", response_data); |
| 4554 base::RunLoop().RunUntilIdle(); | 4534 base::RunLoop().RunUntilIdle(); |
| 4555 } | 4535 } |
| 4556 | 4536 |
| 4557 helper.VerifyDataConsumed(); | 4537 helper.VerifyDataConsumed(); |
| 4558 base::RunLoop().RunUntilIdle(); | 4538 base::RunLoop().RunUntilIdle(); |
| 4559 } | 4539 } |
| 4560 } | 4540 } |
| 4561 | 4541 |
| 4562 // Test that turning SPDY on and off works properly. | |
| 4563 TEST_P(SpdyNetworkTransactionTest, SpdyOnOffToggle) { | |
| 4564 HttpStreamFactory::set_spdy_enabled(true); | |
| 4565 std::unique_ptr<SpdySerializedFrame> req( | |
| 4566 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | |
| 4567 MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; | |
| 4568 | |
| 4569 std::unique_ptr<SpdySerializedFrame> resp( | |
| 4570 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | |
| 4571 std::unique_ptr<SpdySerializedFrame> body( | |
| 4572 spdy_util_.ConstructSpdyBodyFrame(1, true)); | |
| 4573 MockRead spdy_reads[] = { | |
| 4574 CreateMockRead(*resp, 1), | |
| 4575 CreateMockRead(*body, 2), | |
| 4576 MockRead(ASYNC, 0, 3) // EOF | |
| 4577 }; | |
| 4578 | |
| 4579 SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, | |
| 4580 arraysize(spdy_writes)); | |
| 4581 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | |
| 4582 BoundNetLog(), GetParam(), NULL); | |
| 4583 helper.RunToCompletion(&data); | |
| 4584 TransactionHelperResult out = helper.output(); | |
| 4585 EXPECT_THAT(out.rv, IsOk()); | |
| 4586 EXPECT_EQ("HTTP/1.1 200", out.status_line); | |
| 4587 EXPECT_EQ("hello!", out.response_data); | |
| 4588 | |
| 4589 HttpStreamFactory::set_spdy_enabled(false); | |
| 4590 MockWrite http_writes[] = { | |
| 4591 MockWrite(SYNCHRONOUS, 0, | |
| 4592 "GET / HTTP/1.1\r\n" | |
| 4593 "Host: www.example.org\r\n" | |
| 4594 "Connection: keep-alive\r\n\r\n"), | |
| 4595 }; | |
| 4596 | |
| 4597 MockRead http_reads[] = { | |
| 4598 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n\r\n"), | |
| 4599 MockRead(SYNCHRONOUS, 2, "hello from http"), | |
| 4600 MockRead(SYNCHRONOUS, OK, 3), | |
| 4601 }; | |
| 4602 SequencedSocketData data2(http_reads, arraysize(http_reads), http_writes, | |
| 4603 arraysize(http_writes)); | |
| 4604 NormalSpdyTransactionHelper helper2(CreateGetRequest(), DEFAULT_PRIORITY, | |
| 4605 BoundNetLog(), GetParam(), NULL); | |
| 4606 helper2.SetSpdyDisabled(); | |
| 4607 helper2.RunToCompletion(&data2); | |
| 4608 TransactionHelperResult out2 = helper2.output(); | |
| 4609 EXPECT_THAT(out2.rv, IsOk()); | |
| 4610 EXPECT_EQ("HTTP/1.1 200 OK", out2.status_line); | |
| 4611 EXPECT_EQ("hello from http", out2.response_data); | |
| 4612 | |
| 4613 HttpStreamFactory::set_spdy_enabled(true); | |
| 4614 } | |
| 4615 | |
| 4616 // Tests that Basic authentication works over SPDY | 4542 // Tests that Basic authentication works over SPDY |
| 4617 TEST_P(SpdyNetworkTransactionTest, SpdyBasicAuth) { | 4543 TEST_P(SpdyNetworkTransactionTest, SpdyBasicAuth) { |
| 4618 HttpStreamFactory::set_spdy_enabled(true); | |
| 4619 | |
| 4620 // The first request will be a bare GET, the second request will be a | 4544 // The first request will be a bare GET, the second request will be a |
| 4621 // GET with an Authorization header. | 4545 // GET with an Authorization header. |
| 4622 std::unique_ptr<SpdySerializedFrame> req_get( | 4546 std::unique_ptr<SpdySerializedFrame> req_get( |
| 4623 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 4547 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 4624 // Will be refused for lack of auth. | 4548 // Will be refused for lack of auth. |
| 4625 spdy_util_.UpdateWithStreamDestruction(1); | 4549 spdy_util_.UpdateWithStreamDestruction(1); |
| 4626 const char* const kExtraAuthorizationHeaders[] = { | 4550 const char* const kExtraAuthorizationHeaders[] = { |
| 4627 "authorization", "Basic Zm9vOmJhcg==" | 4551 "authorization", "Basic Zm9vOmJhcg==" |
| 4628 }; | 4552 }; |
| 4629 std::unique_ptr<SpdySerializedFrame> req_get_authorization( | 4553 std::unique_ptr<SpdySerializedFrame> req_get_authorization( |
| (...skipping 2076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6706 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { | 6630 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { |
| 6707 std::unique_ptr<SSLSocketDataProvider> ssl_provider( | 6631 std::unique_ptr<SSLSocketDataProvider> ssl_provider( |
| 6708 new SSLSocketDataProvider(ASYNC, OK)); | 6632 new SSLSocketDataProvider(ASYNC, OK)); |
| 6709 // Set to TLS_RSA_WITH_NULL_MD5 | 6633 // Set to TLS_RSA_WITH_NULL_MD5 |
| 6710 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); | 6634 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
| 6711 | 6635 |
| 6712 RunTLSUsageCheckTest(std::move(ssl_provider)); | 6636 RunTLSUsageCheckTest(std::move(ssl_provider)); |
| 6713 } | 6637 } |
| 6714 | 6638 |
| 6715 } // namespace net | 6639 } // namespace net |
| OLD | NEW |