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

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

Issue 10810069: SPDY: Add WriteHeaders interface to SpdySession and SpdyStream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for commit Created 8 years, 4 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_stream_spdy2_unittest.cc ('k') | net/spdy/spdy_stream_test_util.h » ('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 "base/memory/ref_counted.h" 5 #include "base/memory/ref_counted.h"
6 #include "net/base/completion_callback.h" 6 #include "net/base/completion_callback.h"
7 #include "net/base/net_log_unittest.h" 7 #include "net/base/net_log_unittest.h"
8 #include "net/spdy/buffered_spdy_framer.h" 8 #include "net/spdy/buffered_spdy_framer.h"
9 #include "net/spdy/spdy_stream.h" 9 #include "net/spdy/spdy_stream.h"
10 #include "net/spdy/spdy_http_utils.h" 10 #include "net/spdy/spdy_http_utils.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 scoped_refptr<SpdyStream> stream; 139 scoped_refptr<SpdyStream> stream;
140 ASSERT_EQ( 140 ASSERT_EQ(
141 OK, 141 OK,
142 session->CreateStream(url, LOWEST, &stream, BoundNetLog(), 142 session->CreateStream(url, LOWEST, &stream, BoundNetLog(),
143 CompletionCallback())); 143 CompletionCallback()));
144 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(8)); 144 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(8));
145 memcpy(buf->data(), "\0hello!\xff", 8); 145 memcpy(buf->data(), "\0hello!\xff", 8);
146 TestCompletionCallback callback; 146 TestCompletionCallback callback;
147 147
148 scoped_ptr<TestSpdyStreamDelegate> delegate( 148 scoped_ptr<TestSpdyStreamDelegate> delegate(
149 new TestSpdyStreamDelegate(stream.get(), buf.get(), callback.callback())); 149 new TestSpdyStreamDelegate(
150 stream.get(), NULL, buf.get(), callback.callback()));
150 stream->SetDelegate(delegate.get()); 151 stream->SetDelegate(delegate.get());
151 152
152 EXPECT_FALSE(stream->HasUrl()); 153 EXPECT_FALSE(stream->HasUrl());
153 154
154 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); 155 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
155 (*headers)[":method"] = "GET"; 156 (*headers)[":method"] = "GET";
156 (*headers)[":scheme"] = url.scheme(); 157 (*headers)[":scheme"] = url.scheme();
157 (*headers)[":host"] = url.host(); 158 (*headers)[":host"] = url.host();
158 (*headers)[":path"] = url.path(); 159 (*headers)[":path"] = url.path();
159 (*headers)[":version"] = "HTTP/1.1"; 160 (*headers)[":version"] = "HTTP/1.1";
160 stream->set_spdy_headers(headers.Pass()); 161 stream->set_spdy_headers(headers.Pass());
161 EXPECT_TRUE(stream->HasUrl()); 162 EXPECT_TRUE(stream->HasUrl());
162 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); 163 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec());
163 164
164 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); 165 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true));
165 166
166 EXPECT_EQ(OK, callback.WaitForResult()); 167 EXPECT_EQ(OK, callback.WaitForResult());
167 168
168 EXPECT_TRUE(delegate->send_headers_completed()); 169 EXPECT_TRUE(delegate->send_headers_completed());
169 EXPECT_EQ("200", (*delegate->response())[":status"]); 170 EXPECT_EQ("200", (*delegate->response())[":status"]);
170 EXPECT_EQ("HTTP/1.1", (*delegate->response())[":version"]); 171 EXPECT_EQ("HTTP/1.1", (*delegate->response())[":version"]);
171 EXPECT_EQ(std::string("\0hello!\xff", 8), delegate->received_data()); 172 EXPECT_EQ(std::string("\0hello!\xff", 8), delegate->received_data());
172 EXPECT_EQ(8, delegate->data_sent()); 173 EXPECT_EQ(8, delegate->data_sent());
173 EXPECT_TRUE(delegate->closed()); 174 EXPECT_TRUE(delegate->closed());
174 } 175 }
175 176
177 TEST_F(SpdyStreamSpdy3Test, SendHeaderAndDataAfterOpen) {
178 SpdySessionDependencies session_deps;
179
180 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps);
181 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool());
182
183 scoped_ptr<SpdyFrame> expected_request(ConstructSpdyWebSocket(
184 1,
185 "/chat",
186 "server.example.com",
187 "http://example.com"));
188 scoped_ptr<SpdyFrame> expected_headers(ConstructSpdyWebSocketHeadersFrame(
189 1, "6", true));
190 scoped_ptr<SpdyFrame> expected_message(ConstructSpdyBodyFrame("hello!", 6));
191 MockWrite writes[] = {
192 CreateMockWrite(*expected_request),
193 CreateMockWrite(*expected_headers),
194 CreateMockWrite(*expected_message)
195 };
196 writes[0].sequence_number = 0;
197 writes[1].sequence_number = 2;
198 writes[1].sequence_number = 3;
199
200 scoped_ptr<SpdyFrame> response(
201 ConstructSpdyWebSocketSynReply(1));
202 MockRead reads[] = {
203 CreateMockRead(*response),
204 MockRead(ASYNC, 0, 0), // EOF
205 };
206 reads[0].sequence_number = 1;
207 reads[1].sequence_number = 4;
208
209 OrderedSocketData data(reads, arraysize(reads),
210 writes, arraysize(writes));
211 MockConnect connect_data(SYNCHRONOUS, OK);
212 data.set_connect_data(connect_data);
213
214 session_deps.socket_factory->AddSocketDataProvider(&data);
215
216 scoped_refptr<SpdySession> session(CreateSpdySession());
217 const char* kStreamUrl = "ws://server.example.com/chat";
218 GURL url(kStreamUrl);
219
220 HostPortPair host_port_pair("server.example.com", 80);
221 scoped_refptr<TransportSocketParams> transport_params(
222 new TransportSocketParams(host_port_pair, LOWEST, false, false,
223 OnHostResolutionCallback()));
224
225 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
226 EXPECT_EQ(OK, connection->Init(host_port_pair.ToString(), transport_params,
227 LOWEST, CompletionCallback(),
228 session_->GetTransportSocketPool(
229 HttpNetworkSession::NORMAL_SOCKET_POOL),
230 BoundNetLog()));
231 session->InitializeWithSocket(connection.release(), false, OK);
232
233 scoped_refptr<SpdyStream> stream;
234 ASSERT_EQ(
235 OK,
236 session->CreateStream(url, LOWEST, &stream, BoundNetLog(),
237 CompletionCallback()));
238 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(6));
239 memcpy(buf->data(), "hello!", 6);
240 TestCompletionCallback callback;
241 scoped_ptr<SpdyHeaderBlock> message_headers(new SpdyHeaderBlock);
242 (*message_headers)[":opcode"] = "1";
243 (*message_headers)[":length"] = "6";
244 (*message_headers)[":fin"] = "1";
245
246 scoped_ptr<TestSpdyStreamDelegate> delegate(
247 new TestSpdyStreamDelegate(stream.get(),
248 message_headers.release(),
249 buf.get(),
250 callback.callback()));
251 stream->SetDelegate(delegate.get());
252
253 EXPECT_FALSE(stream->HasUrl());
254
255 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
256 (*headers)[":path"] = url.path();
257 (*headers)[":host"] = url.host();
258 (*headers)[":version"] = "WebSocket/13";
259 (*headers)[":scheme"] = url.scheme();
260 (*headers)[":origin"] = "http://example.com";
261 stream->set_spdy_headers(headers.Pass());
262 EXPECT_TRUE(stream->HasUrl());
263
264 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true));
265
266 EXPECT_EQ(OK, callback.WaitForResult());
267
268 EXPECT_TRUE(delegate->send_headers_completed());
269 EXPECT_EQ("101", (*delegate->response())[":status"]);
270 EXPECT_EQ(std::string(), delegate->received_data());
271 // TODO(toyoshim): OnDataSent should be invoked when each data frame is sent.
272 // But current implementation invokes also when each HEADERS frame is sent.
273 //EXPECT_EQ(6, delegate->data_sent());
274 }
275
176 TEST_F(SpdyStreamSpdy3Test, PushedStream) { 276 TEST_F(SpdyStreamSpdy3Test, PushedStream) {
177 const char kStreamUrl[] = "http://www.google.com/"; 277 const char kStreamUrl[] = "http://www.google.com/";
178 278
179 SpdySessionDependencies session_deps; 279 SpdySessionDependencies session_deps;
180 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps); 280 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps);
181 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool()); 281 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool());
182 scoped_refptr<SpdySession> spdy_session(CreateSpdySession()); 282 scoped_refptr<SpdySession> spdy_session(CreateSpdySession());
183 283
184 MockRead reads[] = { 284 MockRead reads[] = {
185 MockRead(ASYNC, 0, 0), // EOF 285 MockRead(ASYNC, 0, 0), // EOF
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 scoped_refptr<SpdyStream> stream; 417 scoped_refptr<SpdyStream> stream;
318 ASSERT_EQ( 418 ASSERT_EQ(
319 OK, 419 OK,
320 session->CreateStream(url, LOWEST, &stream, log.bound(), 420 session->CreateStream(url, LOWEST, &stream, log.bound(),
321 CompletionCallback())); 421 CompletionCallback()));
322 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(8)); 422 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(8));
323 memcpy(buf->data(), "\0hello!\xff", 8); 423 memcpy(buf->data(), "\0hello!\xff", 8);
324 TestCompletionCallback callback; 424 TestCompletionCallback callback;
325 425
326 scoped_ptr<TestSpdyStreamDelegate> delegate( 426 scoped_ptr<TestSpdyStreamDelegate> delegate(
327 new TestSpdyStreamDelegate(stream.get(), buf.get(), callback.callback())); 427 new TestSpdyStreamDelegate(
428 stream.get(), NULL, buf.get(), callback.callback()));
328 stream->SetDelegate(delegate.get()); 429 stream->SetDelegate(delegate.get());
329 430
330 EXPECT_FALSE(stream->HasUrl()); 431 EXPECT_FALSE(stream->HasUrl());
331 432
332 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); 433 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
333 (*headers)[":method"] = "GET"; 434 (*headers)[":method"] = "GET";
334 (*headers)[":scheme"] = url.scheme(); 435 (*headers)[":scheme"] = url.scheme();
335 (*headers)[":host"] = url.host(); 436 (*headers)[":host"] = url.host();
336 (*headers)[":path"] = url.path(); 437 (*headers)[":path"] = url.path();
337 (*headers)[":version"] = "HTTP/1.1"; 438 (*headers)[":version"] = "HTTP/1.1";
(...skipping 26 matching lines...) Expand all
364 net::NetLog::PHASE_NONE); 465 net::NetLog::PHASE_NONE);
365 466
366 int stream_id2; 467 int stream_id2;
367 ASSERT_TRUE(entries[pos].GetIntegerValue("stream_id", &stream_id2)); 468 ASSERT_TRUE(entries[pos].GetIntegerValue("stream_id", &stream_id2));
368 EXPECT_EQ(static_cast<int>(stream_id), stream_id2); 469 EXPECT_EQ(static_cast<int>(stream_id), stream_id2);
369 } 470 }
370 471
371 } // namespace test 472 } // namespace test
372 473
373 } // namespace net 474 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_stream_spdy2_unittest.cc ('k') | net/spdy/spdy_stream_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698