| 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 4002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4327 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); | 4307 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 4328 EXPECT_EQ("hello!", response_data); | 4308 EXPECT_EQ("hello!", response_data); |
| 4329 base::RunLoop().RunUntilIdle(); | 4309 base::RunLoop().RunUntilIdle(); |
| 4330 } | 4310 } |
| 4331 | 4311 |
| 4332 helper.VerifyDataConsumed(); | 4312 helper.VerifyDataConsumed(); |
| 4333 base::RunLoop().RunUntilIdle(); | 4313 base::RunLoop().RunUntilIdle(); |
| 4334 } | 4314 } |
| 4335 } | 4315 } |
| 4336 | 4316 |
| 4337 // Test that turning SPDY on and off works properly. | |
| 4338 TEST_P(SpdyNetworkTransactionTest, DISABLED_SpdyOnOffToggle) { | |
| 4339 HttpStreamFactory::set_spdy_enabled(true); | |
| 4340 SpdySerializedFrame req( | |
| 4341 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | |
| 4342 MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; | |
| 4343 | |
| 4344 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | |
| 4345 SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); | |
| 4346 MockRead spdy_reads[] = { | |
| 4347 CreateMockRead(resp, 1), CreateMockRead(body, 2), | |
| 4348 MockRead(ASYNC, 0, 3) // EOF | |
| 4349 }; | |
| 4350 | |
| 4351 SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, | |
| 4352 arraysize(spdy_writes)); | |
| 4353 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | |
| 4354 BoundNetLog(), GetParam(), NULL); | |
| 4355 helper.RunToCompletion(&data); | |
| 4356 TransactionHelperResult out = helper.output(); | |
| 4357 EXPECT_THAT(out.rv, IsOk()); | |
| 4358 EXPECT_EQ("HTTP/1.1 200", out.status_line); | |
| 4359 EXPECT_EQ("hello!", out.response_data); | |
| 4360 | |
| 4361 HttpStreamFactory::set_spdy_enabled(false); | |
| 4362 MockWrite http_writes[] = { | |
| 4363 MockWrite(SYNCHRONOUS, 0, | |
| 4364 "GET / HTTP/1.1\r\n" | |
| 4365 "Host: www.example.org\r\n" | |
| 4366 "Connection: keep-alive\r\n\r\n"), | |
| 4367 }; | |
| 4368 | |
| 4369 MockRead http_reads[] = { | |
| 4370 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n\r\n"), | |
| 4371 MockRead(SYNCHRONOUS, 2, "hello from http"), | |
| 4372 MockRead(SYNCHRONOUS, OK, 3), | |
| 4373 }; | |
| 4374 SequencedSocketData data2(http_reads, arraysize(http_reads), http_writes, | |
| 4375 arraysize(http_writes)); | |
| 4376 NormalSpdyTransactionHelper helper2(CreateGetRequest(), DEFAULT_PRIORITY, | |
| 4377 BoundNetLog(), GetParam(), NULL); | |
| 4378 helper2.SetSpdyDisabled(); | |
| 4379 helper2.RunToCompletion(&data2); | |
| 4380 TransactionHelperResult out2 = helper2.output(); | |
| 4381 EXPECT_THAT(out2.rv, IsOk()); | |
| 4382 EXPECT_EQ("HTTP/1.1 200 OK", out2.status_line); | |
| 4383 EXPECT_EQ("hello from http", out2.response_data); | |
| 4384 | |
| 4385 HttpStreamFactory::set_spdy_enabled(true); | |
| 4386 } | |
| 4387 | |
| 4388 // Tests that Basic authentication works over SPDY | 4317 // Tests that Basic authentication works over SPDY |
| 4389 TEST_P(SpdyNetworkTransactionTest, SpdyBasicAuth) { | 4318 TEST_P(SpdyNetworkTransactionTest, SpdyBasicAuth) { |
| 4390 HttpStreamFactory::set_spdy_enabled(true); | |
| 4391 | |
| 4392 // The first request will be a bare GET, the second request will be a | 4319 // The first request will be a bare GET, the second request will be a |
| 4393 // GET with an Authorization header. | 4320 // GET with an Authorization header. |
| 4394 SpdySerializedFrame req_get( | 4321 SpdySerializedFrame req_get( |
| 4395 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 4322 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 4396 // Will be refused for lack of auth. | 4323 // Will be refused for lack of auth. |
| 4397 spdy_util_.UpdateWithStreamDestruction(1); | 4324 spdy_util_.UpdateWithStreamDestruction(1); |
| 4398 const char* const kExtraAuthorizationHeaders[] = { | 4325 const char* const kExtraAuthorizationHeaders[] = { |
| 4399 "authorization", "Basic Zm9vOmJhcg==" | 4326 "authorization", "Basic Zm9vOmJhcg==" |
| 4400 }; | 4327 }; |
| 4401 SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( | 4328 SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| (...skipping 2004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6406 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { | 6333 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { |
| 6407 std::unique_ptr<SSLSocketDataProvider> ssl_provider( | 6334 std::unique_ptr<SSLSocketDataProvider> ssl_provider( |
| 6408 new SSLSocketDataProvider(ASYNC, OK)); | 6335 new SSLSocketDataProvider(ASYNC, OK)); |
| 6409 // Set to TLS_RSA_WITH_NULL_MD5 | 6336 // Set to TLS_RSA_WITH_NULL_MD5 |
| 6410 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); | 6337 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
| 6411 | 6338 |
| 6412 RunTLSUsageCheckTest(std::move(ssl_provider)); | 6339 RunTLSUsageCheckTest(std::move(ssl_provider)); |
| 6413 } | 6340 } |
| 6414 | 6341 |
| 6415 } // namespace net | 6342 } // namespace net |
| OLD | NEW |