Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: net/spdy/spdy_http_stream_spdy2_unittest.cc

Issue 10689034: SPDY - chunked upload - speech recognition doesn't work with SPDY/3 (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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) {
182 UploadDataStream::set_merge_chunks(false);
Ryan Sleevi 2012/07/05 06:52:06 You appear to append chunks sequentially, at least
ramant (doing other things) 2012/07/06 22:55:42 Good point. Fixed SendChunkedPost and this test to
183
184 const char kUploadData1[] = "12345678";
185 const int kUploadData1Size = arraysize(kUploadData1)-1;
186 scoped_ptr<SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0));
187 scoped_ptr<SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false));
188 scoped_ptr<SpdyFrame> chunk2(
189 ConstructSpdyBodyFrame(1, kUploadData1, kUploadData1Size, false));
190 scoped_ptr<SpdyFrame> chunk3(ConstructSpdyBodyFrame(1, true));
191 MockWrite writes[] = {
192 CreateMockWrite(*req.get(), 0),
193 CreateMockWrite(*chunk1, 1), // POST upload frames
194 CreateMockWrite(*chunk2, 2),
195 CreateMockWrite(*chunk3, 3),
196 };
197 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0));
198 MockRead reads[] = {
199 CreateMockRead(*resp, 4),
200 CreateMockRead(*chunk1, 5),
201 CreateMockRead(*chunk2, 6),
202 CreateMockRead(*chunk3, 7),
203 MockRead(ASYNC, 0, 8) // EOF
204 };
205
206 HostPortPair host_port_pair("www.google.com", 80);
207 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct());
208
209 scoped_refptr<DeterministicSocketData> data(
210 new DeterministicSocketData(reads, arraysize(reads),
211 writes, arraysize(writes)));
212
213 DeterministicMockClientSocketFactory* socket_factory =
214 session_deps_.deterministic_socket_factory.get();
215 socket_factory->AddSocketDataProvider(data.get());
216
217 http_session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic(
218 &session_deps_);
219 session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog());
220 transport_params_ = new TransportSocketParams(host_port_pair,
221 MEDIUM, false, false,
222 OnHostResolutionCallback());
223
224 TestCompletionCallback callback;
225 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
226
227 EXPECT_EQ(ERR_IO_PENDING,
228 connection->Init(host_port_pair.ToString(),
229 transport_params_,
230 MEDIUM,
231 callback.callback(),
232 http_session_->GetTransportSocketPool(
233 HttpNetworkSession::NORMAL_SOCKET_POOL),
234 BoundNetLog()));
235
236 callback.WaitForResult();
237 EXPECT_EQ(OK,
238 session_->InitializeWithSocket(connection.release(), false, OK));
239
240 HttpRequestInfo request;
241 request.method = "POST";
242 request.url = GURL("http://www.google.com/");
243 request.upload_data = new UploadData();
244 request.upload_data->set_is_chunked(true);
245
246 BoundNetLog net_log;
247 scoped_ptr<SpdyHttpStream> http_stream(
248 new SpdyHttpStream(session_.get(), true));
249 ASSERT_EQ(OK,
250 http_stream->InitializeStream(&request,
251 net_log,
252 CompletionCallback()));
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 HttpRequestHeaders headers;
261 HttpResponseInfo response;
262 // This will attempt to Write() the initial request and headers, which will
263 // complete asynchronously.
264 EXPECT_EQ(ERR_IO_PENDING,
265 http_stream->SendRequest(headers,
266 upload_stream.Pass(),
267 &response,
268 callback.callback()));
269 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair));
270
271 // Complete the initial request write and the first chunk.
272 data->RunFor(1);
273
274 // Now append the second chunk. This will enqueue another write.
275 request.upload_data->AppendChunk(kUploadData1, kUploadData1Size, false);
276
277 // Complete the second chunk.
278 data->RunFor(1);
279
280 // Now append final chunk. This will enqueue another write.
281 request.upload_data->AppendChunk(kUploadData, kUploadDataSize, true);
282
283 // Finalize writing the last chunk, which will enqueue the trailer.
284 data->RunFor(3);
Ryan Sleevi 2012/07/05 06:52:06 As mentioned in-person, I think it would be good t
ramant (doing other things) 2012/07/06 22:55:42 Done.
285 int rv = callback.WaitForResult();
286 EXPECT_GT(rv, 0);
287 EXPECT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback()));
288
289 // Finish reading |chunk1|, |chunk2| and |chunk3|.
290 data->RunFor(1);
291 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize));
292 http_stream->ReadResponseBody(buf1, kUploadDataSize, callback.callback());
293 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize));
Ryan Sleevi 2012/07/05 06:52:06 BUG?: It seems like these tests should be checking
ramant (doing other things) 2012/07/06 22:55:42 Added check for the callback is called.
294
295 data->RunFor(1);
Ryan Sleevi 2012/07/06 21:04:45 I just realized there's another bug here in the co
296 scoped_refptr<IOBuffer> buf2(new IOBuffer(kUploadData1Size));
297 http_stream->ReadResponseBody(buf2, kUploadData1Size, callback.callback());
298 EXPECT_EQ(kUploadData1, std::string(buf2->data(), kUploadData1Size));
299
300 data->RunFor(1);
301 scoped_refptr<IOBuffer> buf3(new IOBuffer(kUploadDataSize));
302 http_stream->ReadResponseBody(buf3, kUploadDataSize, callback.callback());
303 EXPECT_EQ(kUploadData, std::string(buf3->data(), kUploadDataSize));
304
305 // Finish reading the |EOF|.
306 data->RunFor(1);
307 ASSERT_TRUE(response.headers.get());
308 ASSERT_EQ(200, response.headers->response_code());
309 EXPECT_TRUE(data->at_read_eof());
310 EXPECT_TRUE(data->at_write_eof());
311 }
312
181 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 313 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058
182 TEST_F(SpdyHttpStreamSpdy2Test, SpdyURLTest) { 314 TEST_F(SpdyHttpStreamSpdy2Test, SpdyURLTest) {
183 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; 315 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"; 316 const char * const base_url = "http://www.google.com/foo?query=what";
185 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(base_url, false, 1, LOWEST)); 317 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(base_url, false, 1, LOWEST));
186 MockWrite writes[] = { 318 MockWrite writes[] = {
187 CreateMockWrite(*req.get(), 1), 319 CreateMockWrite(*req.get(), 1),
188 }; 320 };
189 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); 321 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
190 MockRead reads[] = { 322 MockRead reads[] = {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // pool anymore. 363 // pool anymore.
232 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); 364 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair));
233 EXPECT_TRUE(data()->at_read_eof()); 365 EXPECT_TRUE(data()->at_read_eof());
234 EXPECT_TRUE(data()->at_write_eof()); 366 EXPECT_TRUE(data()->at_write_eof());
235 } 367 }
236 368
237 // TODO(willchan): Write a longer test for SpdyStream that exercises all 369 // TODO(willchan): Write a longer test for SpdyStream that exercises all
238 // methods. 370 // methods.
239 371
240 } // namespace net 372 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698