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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 RequestPriority priority, | 102 RequestPriority priority, |
103 const BoundNetLog& log, | 103 const BoundNetLog& log, |
104 std::unique_ptr<SpdySessionDependencies> session_deps) | 104 std::unique_ptr<SpdySessionDependencies> session_deps) |
105 : request_(request), | 105 : request_(request), |
106 priority_(priority), | 106 priority_(priority), |
107 session_deps_(session_deps.get() == NULL | 107 session_deps_(session_deps.get() == NULL |
108 ? base::MakeUnique<SpdySessionDependencies>() | 108 ? base::MakeUnique<SpdySessionDependencies>() |
109 : std::move(session_deps)), | 109 : std::move(session_deps)), |
110 session_( | 110 session_( |
111 SpdySessionDependencies::SpdyCreateSession(session_deps_.get())), | 111 SpdySessionDependencies::SpdyCreateSession(session_deps_.get())), |
112 log_(log), | 112 log_(log) {} |
113 spdy_enabled_(true) {} | |
114 | 113 |
115 ~NormalSpdyTransactionHelper() { | 114 ~NormalSpdyTransactionHelper() { |
116 // Any test which doesn't close the socket by sending it an EOF will | 115 // Any test which doesn't close the socket by sending it an EOF will |
117 // have a valid session left open, which leaks the entire session pool. | 116 // have a valid session left open, which leaks the entire session pool. |
118 // This is just fine - in fact, some of our tests intentionally do this | 117 // This is just fine - in fact, some of our tests intentionally do this |
119 // so that we can check consistency of the SpdySessionPool as the test | 118 // so that we can check consistency of the SpdySessionPool as the test |
120 // finishes. If we had put an EOF on the socket, the SpdySession would | 119 // finishes. If we had put an EOF on the socket, the SpdySession would |
121 // have closed and we wouldn't be able to check the consistency. | 120 // have closed and we wouldn't be able to check the consistency. |
122 | 121 |
123 // Forcefully close existing sessions here. | 122 // Forcefully close existing sessions here. |
124 session()->spdy_session_pool()->CloseAllSessions(); | 123 session()->spdy_session_pool()->CloseAllSessions(); |
125 } | 124 } |
126 | 125 |
127 void SetSpdyDisabled() { | |
128 spdy_enabled_ = false; | |
129 } | |
130 | |
131 void RunPreTestSetup() { | 126 void RunPreTestSetup() { |
132 // We're now ready to use SSL-npn SPDY. | 127 // We're now ready to use SSL-npn SPDY. |
133 trans_.reset(new HttpNetworkTransaction(priority_, session_.get())); | 128 trans_.reset(new HttpNetworkTransaction(priority_, session_.get())); |
134 } | 129 } |
135 | 130 |
136 // Start the transaction, read some data, finish. | 131 // Start the transaction, read some data, finish. |
137 void RunDefaultTest() { | 132 void RunDefaultTest() { |
138 if (!StartDefaultTest()) | 133 if (!StartDefaultTest()) |
139 return; | 134 return; |
140 FinishDefaultTest(); | 135 FinishDefaultTest(); |
(...skipping 11 matching lines...) Expand all Loading... |
152 output_.rv = callback_.WaitForResult(); | 147 output_.rv = callback_.WaitForResult(); |
153 if (output_.rv != OK) { | 148 if (output_.rv != OK) { |
154 session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); | 149 session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); |
155 return; | 150 return; |
156 } | 151 } |
157 | 152 |
158 // Verify responses. | 153 // Verify responses. |
159 const HttpResponseInfo* response = trans_->GetResponseInfo(); | 154 const HttpResponseInfo* response = trans_->GetResponseInfo(); |
160 ASSERT_TRUE(response); | 155 ASSERT_TRUE(response); |
161 ASSERT_TRUE(response->headers); | 156 ASSERT_TRUE(response->headers); |
162 if (HttpStreamFactory::spdy_enabled()) { | 157 EXPECT_EQ(HttpResponseInfo::ConnectionInfoFromNextProto(kProtoHTTP2), |
163 EXPECT_EQ(HttpResponseInfo::ConnectionInfoFromNextProto(kProtoHTTP2), | 158 response->connection_info); |
164 response->connection_info); | 159 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
165 } else { | 160 EXPECT_TRUE(response->was_fetched_via_spdy); |
166 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1_1, | 161 EXPECT_TRUE(response->was_npn_negotiated); |
167 response->connection_info); | |
168 } | |
169 if (spdy_enabled_) { | |
170 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); | |
171 EXPECT_TRUE(response->was_fetched_via_spdy); | |
172 EXPECT_TRUE(response->was_npn_negotiated); | |
173 } else { | |
174 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
175 EXPECT_FALSE(response->was_fetched_via_spdy); | |
176 // If SPDY is disabled, an HTTP request should not be diverted | |
177 // over an SSL session. | |
178 EXPECT_EQ(request_.url.SchemeIs("https"), | |
179 response->was_npn_negotiated); | |
180 } | |
181 EXPECT_EQ("127.0.0.1", response->socket_address.host()); | 162 EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
182 EXPECT_EQ(443, response->socket_address.port()); | 163 EXPECT_EQ(443, response->socket_address.port()); |
183 output_.status_line = response->headers->GetStatusLine(); | 164 output_.status_line = response->headers->GetStatusLine(); |
184 output_.response_info = *response; // Make a copy so we can verify. | 165 output_.response_info = *response; // Make a copy so we can verify. |
185 output_.rv = ReadTransaction(trans_.get(), &output_.response_data); | 166 output_.rv = ReadTransaction(trans_.get(), &output_.response_data); |
186 } | 167 } |
187 | 168 |
188 void FinishDefaultTestWithoutVerification() { | 169 void FinishDefaultTestWithoutVerification() { |
189 output_.rv = callback_.WaitForResult(); | 170 output_.rv = callback_.WaitForResult(); |
190 if (output_.rv != OK) | 171 if (output_.rv != OK) |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 std::unique_ptr<HttpNetworkSession> session_; | 251 std::unique_ptr<HttpNetworkSession> session_; |
271 TransactionHelperResult output_; | 252 TransactionHelperResult output_; |
272 std::unique_ptr<SocketDataProvider> first_transaction_; | 253 std::unique_ptr<SocketDataProvider> first_transaction_; |
273 SSLVector ssl_vector_; | 254 SSLVector ssl_vector_; |
274 TestCompletionCallback callback_; | 255 TestCompletionCallback callback_; |
275 std::unique_ptr<HttpNetworkTransaction> trans_; | 256 std::unique_ptr<HttpNetworkTransaction> trans_; |
276 std::unique_ptr<HttpNetworkTransaction> trans_http_; | 257 std::unique_ptr<HttpNetworkTransaction> trans_http_; |
277 DataVector data_vector_; | 258 DataVector data_vector_; |
278 AlternateVector alternate_vector_; | 259 AlternateVector alternate_vector_; |
279 const BoundNetLog log_; | 260 const BoundNetLog log_; |
280 bool spdy_enabled_; | |
281 }; | 261 }; |
282 | 262 |
283 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, | 263 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
284 int expected_status); | 264 int expected_status); |
285 | 265 |
286 void ConnectStatusHelper(const MockRead& status); | 266 void ConnectStatusHelper(const MockRead& status); |
287 | 267 |
288 const HttpRequestInfo& CreateGetPushRequest() { | 268 const HttpRequestInfo& CreateGetPushRequest() { |
289 get_push_request_.method = "GET"; | 269 get_push_request_.method = "GET"; |
290 get_push_request_.url = GURL(GetDefaultUrlWithPath("/foo.dat")); | 270 get_push_request_.url = GURL(GetDefaultUrlWithPath("/foo.dat")); |
(...skipping 3956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4247 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); | 4227 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
4248 EXPECT_EQ("hello!", response_data); | 4228 EXPECT_EQ("hello!", response_data); |
4249 base::RunLoop().RunUntilIdle(); | 4229 base::RunLoop().RunUntilIdle(); |
4250 } | 4230 } |
4251 | 4231 |
4252 helper.VerifyDataConsumed(); | 4232 helper.VerifyDataConsumed(); |
4253 base::RunLoop().RunUntilIdle(); | 4233 base::RunLoop().RunUntilIdle(); |
4254 } | 4234 } |
4255 } | 4235 } |
4256 | 4236 |
4257 // Test that turning SPDY on and off works properly. | |
4258 TEST_F(SpdyNetworkTransactionTest, DISABLED_SpdyOnOffToggle) { | |
4259 HttpStreamFactory::set_spdy_enabled(true); | |
4260 SpdySerializedFrame req( | |
4261 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | |
4262 MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; | |
4263 | |
4264 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | |
4265 SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); | |
4266 MockRead spdy_reads[] = { | |
4267 CreateMockRead(resp, 1), CreateMockRead(body, 2), | |
4268 MockRead(ASYNC, 0, 3) // EOF | |
4269 }; | |
4270 | |
4271 SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, | |
4272 arraysize(spdy_writes)); | |
4273 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | |
4274 BoundNetLog(), NULL); | |
4275 helper.RunToCompletion(&data); | |
4276 TransactionHelperResult out = helper.output(); | |
4277 EXPECT_THAT(out.rv, IsOk()); | |
4278 EXPECT_EQ("HTTP/1.1 200", out.status_line); | |
4279 EXPECT_EQ("hello!", out.response_data); | |
4280 | |
4281 HttpStreamFactory::set_spdy_enabled(false); | |
4282 MockWrite http_writes[] = { | |
4283 MockWrite(SYNCHRONOUS, 0, | |
4284 "GET / HTTP/1.1\r\n" | |
4285 "Host: www.example.org\r\n" | |
4286 "Connection: keep-alive\r\n\r\n"), | |
4287 }; | |
4288 | |
4289 MockRead http_reads[] = { | |
4290 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n\r\n"), | |
4291 MockRead(SYNCHRONOUS, 2, "hello from http"), | |
4292 MockRead(SYNCHRONOUS, OK, 3), | |
4293 }; | |
4294 SequencedSocketData data2(http_reads, arraysize(http_reads), http_writes, | |
4295 arraysize(http_writes)); | |
4296 NormalSpdyTransactionHelper helper2(CreateGetRequest(), DEFAULT_PRIORITY, | |
4297 BoundNetLog(), NULL); | |
4298 helper2.SetSpdyDisabled(); | |
4299 helper2.RunToCompletion(&data2); | |
4300 TransactionHelperResult out2 = helper2.output(); | |
4301 EXPECT_THAT(out2.rv, IsOk()); | |
4302 EXPECT_EQ("HTTP/1.1 200 OK", out2.status_line); | |
4303 EXPECT_EQ("hello from http", out2.response_data); | |
4304 | |
4305 HttpStreamFactory::set_spdy_enabled(true); | |
4306 } | |
4307 | |
4308 // Tests that Basic authentication works over SPDY | 4237 // Tests that Basic authentication works over SPDY |
4309 TEST_F(SpdyNetworkTransactionTest, SpdyBasicAuth) { | 4238 TEST_F(SpdyNetworkTransactionTest, SpdyBasicAuth) { |
4310 HttpStreamFactory::set_spdy_enabled(true); | |
4311 | |
4312 // The first request will be a bare GET, the second request will be a | 4239 // The first request will be a bare GET, the second request will be a |
4313 // GET with an Authorization header. | 4240 // GET with an Authorization header. |
4314 SpdySerializedFrame req_get( | 4241 SpdySerializedFrame req_get( |
4315 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 4242 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
4316 // Will be refused for lack of auth. | 4243 // Will be refused for lack of auth. |
4317 spdy_util_.UpdateWithStreamDestruction(1); | 4244 spdy_util_.UpdateWithStreamDestruction(1); |
4318 const char* const kExtraAuthorizationHeaders[] = { | 4245 const char* const kExtraAuthorizationHeaders[] = { |
4319 "authorization", "Basic Zm9vOmJhcg==" | 4246 "authorization", "Basic Zm9vOmJhcg==" |
4320 }; | 4247 }; |
4321 SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( | 4248 SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
(...skipping 1996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6318 TEST_F(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { | 6245 TEST_F(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { |
6319 std::unique_ptr<SSLSocketDataProvider> ssl_provider( | 6246 std::unique_ptr<SSLSocketDataProvider> ssl_provider( |
6320 new SSLSocketDataProvider(ASYNC, OK)); | 6247 new SSLSocketDataProvider(ASYNC, OK)); |
6321 // Set to TLS_RSA_WITH_NULL_MD5 | 6248 // Set to TLS_RSA_WITH_NULL_MD5 |
6322 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); | 6249 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
6323 | 6250 |
6324 RunTLSUsageCheckTest(std::move(ssl_provider)); | 6251 RunTLSUsageCheckTest(std::move(ssl_provider)); |
6325 } | 6252 } |
6326 | 6253 |
6327 } // namespace net | 6254 } // namespace net |
OLD | NEW |