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 "crypto/ec_private_key.h" | 7 #include "crypto/ec_private_key.h" |
8 #include "crypto/ec_signature_creator.h" | 8 #include "crypto/ec_signature_creator.h" |
9 #include "crypto/signature_creator.h" | 9 #include "crypto/signature_creator.h" |
10 #include "net/base/asn1_util.h" | 10 #include "net/base/asn1_util.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 EXPECT_TRUE(data()->at_write_eof()); | 117 EXPECT_TRUE(data()->at_write_eof()); |
118 } | 118 } |
119 | 119 |
120 TEST_F(SpdyHttpStreamSpdy2Test, SendChunkedPost) { | 120 TEST_F(SpdyHttpStreamSpdy2Test, SendChunkedPost) { |
121 UploadDataStream::set_merge_chunks(false); | 121 UploadDataStream::set_merge_chunks(false); |
122 | 122 |
123 scoped_ptr<SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0)); | 123 scoped_ptr<SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0)); |
124 scoped_ptr<SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false)); | 124 scoped_ptr<SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false)); |
125 scoped_ptr<SpdyFrame> chunk2(ConstructSpdyBodyFrame(1, true)); | 125 scoped_ptr<SpdyFrame> chunk2(ConstructSpdyBodyFrame(1, true)); |
126 MockWrite writes[] = { | 126 MockWrite writes[] = { |
127 CreateMockWrite(*req.get(), 1), | 127 CreateMockWrite(*req.get(), 0), |
128 CreateMockWrite(*chunk1, 2), // POST upload frames | 128 CreateMockWrite(*chunk1, 1), // POST upload frames |
129 CreateMockWrite(*chunk2, 3), | 129 CreateMockWrite(*chunk2, 2), |
130 }; | 130 }; |
131 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); | 131 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); |
132 MockRead reads[] = { | 132 MockRead reads[] = { |
133 CreateMockRead(*resp, 4), | 133 CreateMockRead(*resp, 3), |
134 CreateMockRead(*chunk1, 5), | 134 CreateMockRead(*chunk1, 4), |
135 CreateMockRead(*chunk2, 5), | 135 CreateMockRead(*chunk2, 5), |
136 MockRead(SYNCHRONOUS, 0, 6) // EOF | 136 MockRead(SYNCHRONOUS, 0, 6) // EOF |
137 }; | 137 }; |
138 | 138 |
139 HostPortPair host_port_pair("www.google.com", 80); | 139 HostPortPair host_port_pair("www.google.com", 80); |
140 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); | 140 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); |
141 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), | 141 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), |
142 host_port_pair)); | 142 host_port_pair)); |
143 | 143 |
144 HttpRequestInfo request; | 144 HttpRequestInfo request; |
(...skipping 26 matching lines...) Expand all Loading... | |
171 data()->CompleteRead(); | 171 data()->CompleteRead(); |
172 MessageLoop::current()->RunAllPending(); | 172 MessageLoop::current()->RunAllPending(); |
173 | 173 |
174 // Because we abandoned the stream, we don't expect to find a session in the | 174 // Because we abandoned the stream, we don't expect to find a session in the |
175 // pool anymore. | 175 // pool anymore. |
176 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); | 176 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); |
177 EXPECT_TRUE(data()->at_read_eof()); | 177 EXPECT_TRUE(data()->at_read_eof()); |
178 EXPECT_TRUE(data()->at_write_eof()); | 178 EXPECT_TRUE(data()->at_write_eof()); |
179 } | 179 } |
180 | 180 |
181 TEST_F(SpdyHttpStreamSpdy2Test, DelayedSendChunkedPost) { | |
Ryan Hamilton
2012/07/02 22:34:32
Does this test fail when run w/o your changes to t
ramant (doing other things)
2012/07/04 21:04:33
It doesn't fail. IMO, it is just new test.
| |
182 UploadDataStream::set_merge_chunks(false); | |
183 | |
184 scoped_ptr<SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0)); | |
185 scoped_ptr<SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false)); | |
186 scoped_ptr<SpdyFrame> chunk2(ConstructSpdyBodyFrame(1, true)); | |
187 MockWrite writes[] = { | |
188 CreateMockWrite(*req.get(), 0), | |
189 CreateMockWrite(*chunk1, 1), // POST upload frames | |
190 CreateMockWrite(*chunk2, 2), | |
191 }; | |
192 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); | |
193 MockRead reads[] = { | |
194 CreateMockRead(*resp, 3), | |
195 CreateMockRead(*chunk1, 4), | |
196 CreateMockRead(*chunk2, 5), | |
197 MockRead(ASYNC, 0, 6) // EOF | |
198 }; | |
199 | |
200 HostPortPair host_port_pair("www.google.com", 80); | |
201 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); | |
202 | |
203 scoped_refptr<DeterministicSocketData> data( | |
204 new DeterministicSocketData(reads, arraysize(reads), | |
205 writes, arraysize(writes))); | |
206 | |
207 DeterministicMockClientSocketFactory* socket_factory = | |
208 session_deps_.deterministic_socket_factory.get(); | |
209 socket_factory->AddSocketDataProvider(data.get()); | |
210 | |
211 http_session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic( | |
212 &session_deps_); | |
213 session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog()); | |
214 transport_params_ = new TransportSocketParams(host_port_pair, | |
215 MEDIUM, false, false, | |
216 OnHostResolutionCallback()); | |
217 | |
218 TestCompletionCallback callback0; | |
219 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | |
220 | |
221 EXPECT_EQ(ERR_IO_PENDING, | |
222 connection->Init(host_port_pair.ToString(), | |
223 transport_params_, | |
224 MEDIUM, | |
225 callback0.callback(), | |
226 http_session_->GetTransportSocketPool( | |
227 HttpNetworkSession::NORMAL_SOCKET_POOL), | |
228 BoundNetLog())); | |
229 | |
230 callback0.WaitForResult(); | |
231 EXPECT_EQ(OK, | |
232 session_->InitializeWithSocket(connection.release(), false, OK)); | |
233 | |
234 HttpRequestInfo request; | |
235 request.method = "POST"; | |
236 request.url = GURL("http://www.google.com/"); | |
237 request.upload_data = new UploadData(); | |
238 request.upload_data->set_is_chunked(true); | |
239 | |
240 BoundNetLog net_log; | |
241 scoped_ptr<SpdyHttpStream> http_stream( | |
242 new SpdyHttpStream(session_.get(), true)); | |
243 ASSERT_EQ( | |
244 OK, | |
245 http_stream->InitializeStream(&request, net_log, CompletionCallback())); | |
246 | |
247 scoped_ptr<UploadDataStream> upload_stream( | |
248 new UploadDataStream(request.upload_data)); | |
249 ASSERT_EQ(OK, upload_stream->Init()); | |
250 | |
251 request.upload_data->AppendChunk(kUploadData, kUploadDataSize, false); | |
252 | |
253 TestCompletionCallback callback; | |
254 HttpRequestHeaders headers; | |
255 HttpResponseInfo response; | |
256 // This will attempt to Write() the initial request and headers, which will | |
257 // complete asynchronously. | |
258 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest( | |
259 headers, upload_stream.Pass(), &response, callback.callback())); | |
260 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); | |
261 | |
262 // Complete the initial request write. Additionally, this should enqueue the | |
263 // first chunk. | |
264 data->RunFor(1); | |
265 | |
266 // Now append final chunk. This will enqueue another write. | |
267 request.upload_data->AppendChunk(kUploadData, kUploadDataSize, true); | |
268 | |
269 // Finalize writing the last chunk, which will enqueue the trailer. | |
270 data->RunFor(3); | |
271 int rv = callback.WaitForResult(); | |
272 EXPECT_GT(rv, 0); | |
273 | |
274 data->RunFor(2); | |
275 EXPECT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); | |
276 | |
277 data->RunFor(1); | |
278 ASSERT_TRUE(response.headers.get() != NULL); | |
279 ASSERT_EQ(200, response.headers->response_code()); | |
280 EXPECT_TRUE(data->at_read_eof()); | |
281 EXPECT_TRUE(data->at_write_eof()); | |
282 } | |
283 | |
181 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 | 284 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 |
182 TEST_F(SpdyHttpStreamSpdy2Test, SpdyURLTest) { | 285 TEST_F(SpdyHttpStreamSpdy2Test, SpdyURLTest) { |
183 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; | 286 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; |
184 const char * const base_url = "http://www.google.com/foo?query=what"; | 287 const char * const base_url = "http://www.google.com/foo?query=what"; |
185 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(base_url, false, 1, LOWEST)); | 288 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(base_url, false, 1, LOWEST)); |
186 MockWrite writes[] = { | 289 MockWrite writes[] = { |
187 CreateMockWrite(*req.get(), 1), | 290 CreateMockWrite(*req.get(), 1), |
188 }; | 291 }; |
189 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 292 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
190 MockRead reads[] = { | 293 MockRead reads[] = { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 // pool anymore. | 334 // pool anymore. |
232 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); | 335 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); |
233 EXPECT_TRUE(data()->at_read_eof()); | 336 EXPECT_TRUE(data()->at_read_eof()); |
234 EXPECT_TRUE(data()->at_write_eof()); | 337 EXPECT_TRUE(data()->at_write_eof()); |
235 } | 338 } |
236 | 339 |
237 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 340 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
238 // methods. | 341 // methods. |
239 | 342 |
240 } // namespace net | 343 } // namespace net |
OLD | NEW |