Chromium Code Reviews| 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 "net/spdy/spdy_http_stream.h" | 5 #include "net/spdy/spdy_http_stream.h" |
| 6 | 6 |
| 7 #include "base/threading/sequenced_worker_pool.h" | 7 #include "base/threading/sequenced_worker_pool.h" |
| 8 #include "crypto/ec_private_key.h" | 8 #include "crypto/ec_private_key.h" |
| 9 #include "crypto/ec_signature_creator.h" | 9 #include "crypto/ec_signature_creator.h" |
| 10 #include "crypto/signature_creator.h" | 10 #include "crypto/signature_creator.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 EXPECT_TRUE(data()->at_write_eof()); | 124 EXPECT_TRUE(data()->at_write_eof()); |
| 125 } | 125 } |
| 126 | 126 |
| 127 TEST_F(SpdyHttpStreamSpdy3Test, SendChunkedPost) { | 127 TEST_F(SpdyHttpStreamSpdy3Test, SendChunkedPost) { |
| 128 UploadDataStream::set_merge_chunks(false); | 128 UploadDataStream::set_merge_chunks(false); |
| 129 | 129 |
| 130 scoped_ptr<SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0)); | 130 scoped_ptr<SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0)); |
| 131 scoped_ptr<SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false)); | 131 scoped_ptr<SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false)); |
| 132 scoped_ptr<SpdyFrame> chunk2(ConstructSpdyBodyFrame(1, true)); | 132 scoped_ptr<SpdyFrame> chunk2(ConstructSpdyBodyFrame(1, true)); |
| 133 MockWrite writes[] = { | 133 MockWrite writes[] = { |
| 134 CreateMockWrite(*req.get(), 1), | 134 CreateMockWrite(*req.get(), 0), |
| 135 CreateMockWrite(*chunk1, 2), // POST upload frames | 135 CreateMockWrite(*chunk1, 1), // POST upload frames |
| 136 CreateMockWrite(*chunk2, 3), | 136 CreateMockWrite(*chunk2, 2), |
| 137 }; | 137 }; |
| 138 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); | 138 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); |
| 139 MockRead reads[] = { | 139 MockRead reads[] = { |
| 140 CreateMockRead(*resp, 4), | 140 CreateMockRead(*resp, 3), |
| 141 CreateMockRead(*chunk1, 5), | 141 CreateMockRead(*chunk1, 4), |
| 142 CreateMockRead(*chunk2, 5), | 142 CreateMockRead(*chunk2, 5), |
| 143 MockRead(SYNCHRONOUS, 0, 6) // EOF | 143 MockRead(SYNCHRONOUS, 0, 6) // EOF |
| 144 }; | 144 }; |
| 145 | 145 |
| 146 HostPortPair host_port_pair("www.google.com", 80); | 146 HostPortPair host_port_pair("www.google.com", 80); |
| 147 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); | 147 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); |
| 148 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), | 148 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), |
| 149 host_port_pair)); | 149 host_port_pair)); |
| 150 | 150 |
| 151 HttpRequestInfo request; | 151 HttpRequestInfo request; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 178 data()->CompleteRead(); | 178 data()->CompleteRead(); |
| 179 MessageLoop::current()->RunAllPending(); | 179 MessageLoop::current()->RunAllPending(); |
| 180 | 180 |
| 181 // Because we abandoned the stream, we don't expect to find a session in the | 181 // Because we abandoned the stream, we don't expect to find a session in the |
| 182 // pool anymore. | 182 // pool anymore. |
| 183 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); | 183 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); |
| 184 EXPECT_TRUE(data()->at_read_eof()); | 184 EXPECT_TRUE(data()->at_read_eof()); |
| 185 EXPECT_TRUE(data()->at_write_eof()); | 185 EXPECT_TRUE(data()->at_write_eof()); |
| 186 } | 186 } |
| 187 | 187 |
| 188 TEST_F(SpdyHttpStreamSpdy3Test, DelayedSendChunkedPost) { | |
| 189 UploadDataStream::set_merge_chunks(false); | |
| 190 | |
| 191 scoped_ptr<SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0)); | |
| 192 scoped_ptr<SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false)); | |
| 193 scoped_ptr<SpdyFrame> chunk2(ConstructSpdyBodyFrame(1, true)); | |
| 194 MockWrite writes[] = { | |
| 195 CreateMockWrite(*req.get(), 0), | |
| 196 CreateMockWrite(*chunk1, 1), // POST upload frames | |
| 197 CreateMockWrite(*chunk2, 2), | |
| 198 }; | |
| 199 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); | |
| 200 MockRead reads[] = { | |
| 201 CreateMockRead(*resp, 3), | |
| 202 CreateMockRead(*chunk1, 4), | |
| 203 CreateMockRead(*chunk2, 5), | |
| 204 MockRead(ASYNC, 0, 6) // EOF | |
| 205 }; | |
| 206 | |
| 207 HostPortPair host_port_pair("www.google.com", 80); | |
| 208 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); | |
| 209 | |
| 210 scoped_refptr<DeterministicSocketData> data( | |
| 211 new DeterministicSocketData(reads, arraysize(reads), | |
| 212 writes, arraysize(writes))); | |
| 213 | |
| 214 DeterministicMockClientSocketFactory* socket_factory = | |
| 215 session_deps_.deterministic_socket_factory.get(); | |
| 216 socket_factory->AddSocketDataProvider(data.get()); | |
| 217 | |
| 218 http_session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic( | |
| 219 &session_deps_); | |
| 220 session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog()); | |
| 221 transport_params_ = new TransportSocketParams(host_port_pair, | |
| 222 MEDIUM, false, false, | |
| 223 OnHostResolutionCallback()); | |
| 224 | |
| 225 TestCompletionCallback callback0; | |
|
Ryan Sleevi
2012/07/02 21:52:47
nit: You can re-use existing TestCompletionCallbac
ramant (doing other things)
2012/07/04 21:04:33
Done.
| |
| 226 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | |
| 227 | |
| 228 EXPECT_EQ(ERR_IO_PENDING, | |
| 229 connection->Init(host_port_pair.ToString(), | |
| 230 transport_params_, | |
| 231 MEDIUM, | |
| 232 callback0.callback(), | |
| 233 http_session_->GetTransportSocketPool( | |
| 234 HttpNetworkSession::NORMAL_SOCKET_POOL), | |
| 235 BoundNetLog())); | |
| 236 | |
| 237 callback0.WaitForResult(); | |
| 238 EXPECT_EQ(OK, | |
| 239 session_->InitializeWithSocket(connection.release(), false, OK)); | |
| 240 | |
| 241 HttpRequestInfo request; | |
| 242 request.method = "POST"; | |
| 243 request.url = GURL("http://www.google.com/"); | |
| 244 request.upload_data = new UploadData(); | |
| 245 request.upload_data->set_is_chunked(true); | |
| 246 | |
| 247 BoundNetLog net_log; | |
| 248 scoped_ptr<SpdyHttpStream> http_stream( | |
| 249 new SpdyHttpStream(session_.get(), true)); | |
| 250 ASSERT_EQ( | |
| 251 OK, | |
| 252 http_stream->InitializeStream(&request, net_log, CompletionCallback())); | |
|
Ryan Sleevi
2012/07/02 21:52:47
nit: Would this be more readable as
ASSERT_EQ(OK,
ramant (doing other things)
2012/07/04 21:04:33
Done.
| |
| 253 | |
| 254 scoped_ptr<UploadDataStream> upload_stream( | |
| 255 new UploadDataStream(request.upload_data)); | |
| 256 ASSERT_EQ(OK, upload_stream->Init()); | |
| 257 | |
| 258 request.upload_data->AppendChunk(kUploadData, kUploadDataSize, false); | |
| 259 | |
| 260 TestCompletionCallback callback; | |
| 261 HttpRequestHeaders headers; | |
| 262 HttpResponseInfo response; | |
| 263 // This will attempt to Write() the initial request and headers, which will | |
| 264 // complete asynchronously. | |
| 265 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest( | |
|
Ryan Sleevi
2012/07/02 21:52:47
whitespace nit:
EXPECT_EQ(ERR_IO_PENDING,
ramant (doing other things)
2012/07/04 21:04:33
Done.
| |
| 266 headers, upload_stream.Pass(), &response, callback.callback())); | |
| 267 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); | |
| 268 | |
| 269 // Complete the initial request write. Additionally, this should enqueue the | |
| 270 // first chunk. | |
| 271 data->RunFor(1); | |
| 272 | |
| 273 // Now append final chunk. This will enqueue another write. | |
| 274 request.upload_data->AppendChunk(kUploadData, kUploadDataSize, true); | |
| 275 | |
| 276 // Finalize writing the last chunk, which will enqueue the trailer. | |
|
Ryan Sleevi
2012/07/02 21:52:47
Does |trailer| make sense here? In the case of HTT
ramant (doing other things)
2012/07/04 21:04:33
You are right. "trailer" doesn't make sense.
Done.
| |
| 277 data->RunFor(3); | |
| 278 int rv = callback.WaitForResult(); | |
| 279 EXPECT_GT(rv, 0); | |
| 280 | |
| 281 data->RunFor(2); | |
|
Ryan Sleevi
2012/07/02 21:52:47
nit: Add a comment explaining what the two events
ramant (doing other things)
2012/07/04 21:04:33
Done.
| |
| 282 EXPECT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); | |
| 283 | |
| 284 data->RunFor(1); | |
| 285 ASSERT_TRUE(response.headers.get() != NULL); | |
|
Ryan Sleevi
2012/07/02 21:52:47
I thought the preference was instead
ASSERT_TRUE(
ramant (doing other things)
2012/07/04 21:04:33
Done.
| |
| 286 ASSERT_EQ(200, response.headers->response_code()); | |
| 287 EXPECT_TRUE(data->at_read_eof()); | |
| 288 EXPECT_TRUE(data->at_write_eof()); | |
| 289 } | |
| 290 | |
| 188 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 | 291 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 |
| 189 TEST_F(SpdyHttpStreamSpdy3Test, SpdyURLTest) { | 292 TEST_F(SpdyHttpStreamSpdy3Test, SpdyURLTest) { |
| 190 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; | 293 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; |
| 191 const char * const base_url = "http://www.google.com/foo?query=what"; | 294 const char * const base_url = "http://www.google.com/foo?query=what"; |
| 192 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(base_url, false, 1, LOWEST)); | 295 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(base_url, false, 1, LOWEST)); |
| 193 MockWrite writes[] = { | 296 MockWrite writes[] = { |
| 194 CreateMockWrite(*req.get(), 1), | 297 CreateMockWrite(*req.get(), 1), |
| 195 }; | 298 }; |
| 196 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 299 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 197 MockRead reads[] = { | 300 MockRead reads[] = { |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 | 629 |
| 527 sequenced_worker_pool->Shutdown(); | 630 sequenced_worker_pool->Shutdown(); |
| 528 } | 631 } |
| 529 | 632 |
| 530 #endif // !defined(USE_OPENSSL) | 633 #endif // !defined(USE_OPENSSL) |
| 531 | 634 |
| 532 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 635 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
| 533 // methods. | 636 // methods. |
| 534 | 637 |
| 535 } // namespace net | 638 } // namespace net |
| OLD | NEW |