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

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
« no previous file with comments | « net/spdy/spdy_http_stream.cc ('k') | net/spdy/spdy_http_stream_spdy3_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 13 matching lines...) Expand all
24 OrderedSocketData* data() { return data_.get(); } 24 OrderedSocketData* data() { return data_.get(); }
25 protected: 25 protected:
26 SpdyHttpStreamSpdy2Test() {} 26 SpdyHttpStreamSpdy2Test() {}
27 27
28 virtual void SetUp() { 28 virtual void SetUp() {
29 SpdySession::set_default_protocol(kProtoSPDY2); 29 SpdySession::set_default_protocol(kProtoSPDY2);
30 } 30 }
31 31
32 virtual void TearDown() { 32 virtual void TearDown() {
33 crypto::ECSignatureCreator::SetFactoryForTesting(NULL); 33 crypto::ECSignatureCreator::SetFactoryForTesting(NULL);
34 UploadDataStream::ResetMergeChunks();
34 MessageLoop::current()->RunAllPending(); 35 MessageLoop::current()->RunAllPending();
35 } 36 }
36 37
38 void set_merge_chunks(bool merge) {
39 UploadDataStream::set_merge_chunks(merge);
40 }
41
37 int InitSession(MockRead* reads, size_t reads_count, 42 int InitSession(MockRead* reads, size_t reads_count,
38 MockWrite* writes, size_t writes_count, 43 MockWrite* writes, size_t writes_count,
39 HostPortPair& host_port_pair) { 44 HostPortPair& host_port_pair) {
40 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); 45 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct());
41 data_.reset(new OrderedSocketData(reads, reads_count, 46 data_.reset(new OrderedSocketData(reads, reads_count,
42 writes, writes_count)); 47 writes, writes_count));
43 session_deps_.socket_factory->AddSocketDataProvider(data_.get()); 48 session_deps_.socket_factory->AddSocketDataProvider(data_.get());
44 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); 49 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_);
45 session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog()); 50 session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog());
46 transport_params_ = new TransportSocketParams(host_port_pair, 51 transport_params_ = new TransportSocketParams(host_port_pair,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 data()->CompleteRead(); 116 data()->CompleteRead();
112 117
113 // Because we abandoned the stream, we don't expect to find a session in the 118 // Because we abandoned the stream, we don't expect to find a session in the
114 // pool anymore. 119 // pool anymore.
115 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); 120 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair));
116 EXPECT_TRUE(data()->at_read_eof()); 121 EXPECT_TRUE(data()->at_read_eof());
117 EXPECT_TRUE(data()->at_write_eof()); 122 EXPECT_TRUE(data()->at_write_eof());
118 } 123 }
119 124
120 TEST_F(SpdyHttpStreamSpdy2Test, SendChunkedPost) { 125 TEST_F(SpdyHttpStreamSpdy2Test, SendChunkedPost) {
121 UploadDataStream::set_merge_chunks(false); 126 set_merge_chunks(false);
122 127
123 scoped_ptr<SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0)); 128 scoped_ptr<SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0));
124 scoped_ptr<SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false)); 129 scoped_ptr<SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false));
125 scoped_ptr<SpdyFrame> chunk2(ConstructSpdyBodyFrame(1, true)); 130 scoped_ptr<SpdyFrame> chunk2(ConstructSpdyBodyFrame(1, true));
126 MockWrite writes[] = { 131 MockWrite writes[] = {
127 CreateMockWrite(*req.get(), 1), 132 CreateMockWrite(*req.get(), 0),
128 CreateMockWrite(*chunk1, 2), // POST upload frames 133 CreateMockWrite(*chunk1, 1), // POST upload frames
129 CreateMockWrite(*chunk2, 3), 134 CreateMockWrite(*chunk2, 2),
130 }; 135 };
131 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); 136 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0));
132 MockRead reads[] = { 137 MockRead reads[] = {
133 CreateMockRead(*resp, 4), 138 CreateMockRead(*resp, 3),
134 CreateMockRead(*chunk1, 5), 139 CreateMockRead(*chunk1, 4),
135 CreateMockRead(*chunk2, 5), 140 CreateMockRead(*chunk2, 5),
136 MockRead(SYNCHRONOUS, 0, 6) // EOF 141 MockRead(SYNCHRONOUS, 0, 6) // EOF
137 }; 142 };
138 143
139 HostPortPair host_port_pair("www.google.com", 80); 144 HostPortPair host_port_pair("www.google.com", 80);
140 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); 145 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct());
141 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), 146 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes),
142 host_port_pair)); 147 host_port_pair));
143 148
144 HttpRequestInfo request; 149 HttpRequestInfo request;
(...skipping 26 matching lines...) Expand all
171 data()->CompleteRead(); 176 data()->CompleteRead();
172 MessageLoop::current()->RunAllPending(); 177 MessageLoop::current()->RunAllPending();
173 178
174 // Because we abandoned the stream, we don't expect to find a session in the 179 // Because we abandoned the stream, we don't expect to find a session in the
175 // pool anymore. 180 // pool anymore.
176 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); 181 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair));
177 EXPECT_TRUE(data()->at_read_eof()); 182 EXPECT_TRUE(data()->at_read_eof());
178 EXPECT_TRUE(data()->at_write_eof()); 183 EXPECT_TRUE(data()->at_write_eof());
179 } 184 }
180 185
186 // Test to ensure the SpdyStream state machine does not get confused when a
187 // chunk becomes available while a write is pending.
188 TEST_F(SpdyHttpStreamSpdy2Test, DelayedSendChunkedPost) {
189 set_merge_chunks(false);
190
191 const char kUploadData1[] = "12345678";
192 const int kUploadData1Size = arraysize(kUploadData1)-1;
193 scoped_ptr<SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0));
194 scoped_ptr<SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false));
195 scoped_ptr<SpdyFrame> chunk2(
196 ConstructSpdyBodyFrame(1, kUploadData1, kUploadData1Size, false));
197 scoped_ptr<SpdyFrame> chunk3(ConstructSpdyBodyFrame(1, true));
198 MockWrite writes[] = {
199 CreateMockWrite(*req.get(), 0),
200 CreateMockWrite(*chunk1, 1), // POST upload frames
201 CreateMockWrite(*chunk2, 2),
202 CreateMockWrite(*chunk3, 3),
203 };
204 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0));
205 MockRead reads[] = {
206 CreateMockRead(*resp, 4),
207 CreateMockRead(*chunk1, 5),
208 CreateMockRead(*chunk2, 6),
209 CreateMockRead(*chunk3, 7),
210 MockRead(ASYNC, 0, 8) // EOF
211 };
212
213 HostPortPair host_port_pair("www.google.com", 80);
214 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct());
215
216 scoped_ptr<DeterministicSocketData> data(
217 new DeterministicSocketData(reads, arraysize(reads),
218 writes, arraysize(writes)));
219
220 DeterministicMockClientSocketFactory* socket_factory =
221 session_deps_.deterministic_socket_factory.get();
222 socket_factory->AddSocketDataProvider(data.get());
223
224 http_session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic(
225 &session_deps_);
226 session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog());
227 transport_params_ = new TransportSocketParams(host_port_pair,
228 MEDIUM, false, false,
229 OnHostResolutionCallback());
230
231 TestCompletionCallback callback;
232 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
233
234 EXPECT_EQ(ERR_IO_PENDING,
235 connection->Init(host_port_pair.ToString(),
236 transport_params_,
237 MEDIUM,
238 callback.callback(),
239 http_session_->GetTransportSocketPool(
240 HttpNetworkSession::NORMAL_SOCKET_POOL),
241 BoundNetLog()));
242
243 callback.WaitForResult();
244 EXPECT_EQ(OK,
245 session_->InitializeWithSocket(connection.release(), false, OK));
246
247 HttpRequestInfo request;
248 request.method = "POST";
249 request.url = GURL("http://www.google.com/");
250 request.upload_data = new UploadData();
251 request.upload_data->set_is_chunked(true);
252
253 BoundNetLog net_log;
254 scoped_ptr<SpdyHttpStream> http_stream(
255 new SpdyHttpStream(session_.get(), true));
256 ASSERT_EQ(OK,
257 http_stream->InitializeStream(&request,
258 net_log,
259 CompletionCallback()));
260
261 scoped_ptr<UploadDataStream> upload_stream(
262 new UploadDataStream(request.upload_data));
263 ASSERT_EQ(OK, upload_stream->Init());
264
265 request.upload_data->AppendChunk(kUploadData, kUploadDataSize, false);
266
267 HttpRequestHeaders headers;
268 HttpResponseInfo response;
269 // This will attempt to Write() the initial request and headers, which will
270 // complete asynchronously.
271 EXPECT_EQ(ERR_IO_PENDING,
272 http_stream->SendRequest(headers,
273 upload_stream.Pass(),
274 &response,
275 callback.callback()));
276 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair));
277
278 // Complete the initial request write and the first chunk.
279 data->RunFor(2);
280 ASSERT_TRUE(callback.have_result());
281 EXPECT_GT(callback.WaitForResult(), 0);
282
283 // Now append the final two chunks which will enqueue two more writes.
284 request.upload_data->AppendChunk(kUploadData1, kUploadData1Size, false);
285 request.upload_data->AppendChunk(kUploadData, kUploadDataSize, true);
286
287 // Finish writing all the chunks.
288 data->RunFor(2);
289
290 // Read response headers.
291 data->RunFor(1);
292 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback()));
293
294 // Read and check |chunk1| response.
295 data->RunFor(1);
296 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize));
297 ASSERT_EQ(kUploadDataSize,
298 http_stream->ReadResponseBody(buf1,
299 kUploadDataSize,
300 callback.callback()));
301 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize));
302
303 // Read and check |chunk2| response.
304 data->RunFor(1);
305 scoped_refptr<IOBuffer> buf2(new IOBuffer(kUploadData1Size));
306 ASSERT_EQ(kUploadData1Size,
307 http_stream->ReadResponseBody(buf2,
308 kUploadData1Size,
309 callback.callback()));
310 EXPECT_EQ(kUploadData1, std::string(buf2->data(), kUploadData1Size));
311
312 // Read and check |chunk3| response.
313 data->RunFor(1);
314 scoped_refptr<IOBuffer> buf3(new IOBuffer(kUploadDataSize));
315 ASSERT_EQ(kUploadDataSize,
316 http_stream->ReadResponseBody(buf3,
317 kUploadDataSize,
318 callback.callback()));
319 EXPECT_EQ(kUploadData, std::string(buf3->data(), kUploadDataSize));
320
321 // Finish reading the |EOF|.
322 data->RunFor(1);
323 ASSERT_TRUE(response.headers.get());
324 ASSERT_EQ(200, response.headers->response_code());
325 EXPECT_TRUE(data->at_read_eof());
326 EXPECT_TRUE(data->at_write_eof());
327 }
328
181 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 329 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058
182 TEST_F(SpdyHttpStreamSpdy2Test, SpdyURLTest) { 330 TEST_F(SpdyHttpStreamSpdy2Test, SpdyURLTest) {
183 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; 331 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"; 332 const char * const base_url = "http://www.google.com/foo?query=what";
185 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(base_url, false, 1, LOWEST)); 333 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(base_url, false, 1, LOWEST));
186 MockWrite writes[] = { 334 MockWrite writes[] = {
187 CreateMockWrite(*req.get(), 1), 335 CreateMockWrite(*req.get(), 1),
188 }; 336 };
189 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); 337 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
190 MockRead reads[] = { 338 MockRead reads[] = {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // pool anymore. 379 // pool anymore.
232 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); 380 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair));
233 EXPECT_TRUE(data()->at_read_eof()); 381 EXPECT_TRUE(data()->at_read_eof());
234 EXPECT_TRUE(data()->at_write_eof()); 382 EXPECT_TRUE(data()->at_write_eof());
235 } 383 }
236 384
237 // TODO(willchan): Write a longer test for SpdyStream that exercises all 385 // TODO(willchan): Write a longer test for SpdyStream that exercises all
238 // methods. 386 // methods.
239 387
240 } // namespace net 388 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_http_stream.cc ('k') | net/spdy/spdy_http_stream_spdy3_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698