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 "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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 scoped_refptr<SpdyStream> stream; | 138 scoped_refptr<SpdyStream> stream; |
139 ASSERT_EQ( | 139 ASSERT_EQ( |
140 OK, | 140 OK, |
141 session->CreateStream(url, LOWEST, &stream, BoundNetLog(), | 141 session->CreateStream(url, LOWEST, &stream, BoundNetLog(), |
142 CompletionCallback())); | 142 CompletionCallback())); |
143 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(8)); | 143 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(8)); |
144 memcpy(buf->data(), "\0hello!\xff", 8); | 144 memcpy(buf->data(), "\0hello!\xff", 8); |
145 TestCompletionCallback callback; | 145 TestCompletionCallback callback; |
146 | 146 |
147 scoped_ptr<TestSpdyStreamDelegate> delegate( | 147 scoped_ptr<TestSpdyStreamDelegate> delegate( |
148 new TestSpdyStreamDelegate(stream.get(), buf.get(), callback.callback())); | 148 new TestSpdyStreamDelegate( |
149 stream.get(), NULL, buf.get(), callback.callback())); | |
149 stream->SetDelegate(delegate.get()); | 150 stream->SetDelegate(delegate.get()); |
150 | 151 |
151 EXPECT_FALSE(stream->HasUrl()); | 152 EXPECT_FALSE(stream->HasUrl()); |
152 | 153 |
153 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); | 154 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); |
154 (*headers)["method"] = "GET"; | 155 (*headers)["method"] = "GET"; |
155 (*headers)["scheme"] = url.scheme(); | 156 (*headers)["scheme"] = url.scheme(); |
156 (*headers)["host"] = url.host(); | 157 (*headers)["host"] = url.host(); |
157 (*headers)["url"] = url.path(); | 158 (*headers)["url"] = url.path(); |
158 (*headers)["version"] = "HTTP/1.1"; | 159 (*headers)["version"] = "HTTP/1.1"; |
159 stream->set_spdy_headers(headers.Pass()); | 160 stream->set_spdy_headers(headers.Pass()); |
160 EXPECT_TRUE(stream->HasUrl()); | 161 EXPECT_TRUE(stream->HasUrl()); |
161 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); | 162 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
162 | 163 |
163 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); | 164 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
164 | 165 |
165 EXPECT_EQ(OK, callback.WaitForResult()); | 166 EXPECT_EQ(OK, callback.WaitForResult()); |
166 | 167 |
167 EXPECT_TRUE(delegate->send_headers_completed()); | 168 EXPECT_TRUE(delegate->send_headers_completed()); |
168 EXPECT_EQ("200", (*delegate->response())["status"]); | 169 EXPECT_EQ("200", (*delegate->response())["status"]); |
169 EXPECT_EQ("HTTP/1.1", (*delegate->response())["version"]); | 170 EXPECT_EQ("HTTP/1.1", (*delegate->response())["version"]); |
170 EXPECT_EQ(std::string("\0hello!\xff", 8), delegate->received_data()); | 171 EXPECT_EQ(std::string("\0hello!\xff", 8), delegate->received_data()); |
171 EXPECT_EQ(8, delegate->data_sent()); | 172 EXPECT_EQ(8, delegate->data_sent()); |
172 EXPECT_TRUE(delegate->closed()); | 173 EXPECT_TRUE(delegate->closed()); |
173 } | 174 } |
174 | 175 |
176 TEST_F(SpdyStreamSpdy2Test, SendHeaderAndDataAfterOpen) { | |
177 SpdySessionDependencies session_deps; | |
178 | |
179 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps); | |
180 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool()); | |
181 | |
182 scoped_ptr<SpdyFrame> expected_request(ConstructSpdyWebSocket( | |
183 1, | |
184 "/chat", | |
185 "server.example.com", | |
186 "http://example.com")); | |
187 scoped_ptr<SpdyFrame> expected_headers(ConstructSpdyWebSocketHeadersFrame( | |
188 1, "6", true)); | |
189 scoped_ptr<SpdyFrame> expected_message(ConstructSpdyBodyFrame("hello!", 6)); | |
190 MockWrite writes[] = { | |
191 CreateMockWrite(*expected_request), | |
192 CreateMockWrite(*expected_headers), | |
193 CreateMockWrite(*expected_message) | |
194 }; | |
195 writes[0].sequence_number = 0; | |
196 writes[1].sequence_number = 2; | |
197 writes[1].sequence_number = 3; | |
198 | |
199 scoped_ptr<SpdyFrame> response( | |
200 ConstructSpdyWebSocketSynReply(1)); | |
201 MockRead reads[] = { | |
202 CreateMockRead(*response), | |
203 MockRead(ASYNC, 0, 0), // EOF | |
204 }; | |
205 reads[0].sequence_number = 1; | |
206 reads[1].sequence_number = 4; | |
207 | |
208 OrderedSocketData data(reads, arraysize(reads), | |
209 writes, arraysize(writes)); | |
210 MockConnect connect_data(SYNCHRONOUS, OK); | |
211 data.set_connect_data(connect_data); | |
212 | |
213 session_deps.socket_factory->AddSocketDataProvider(&data); | |
214 | |
215 scoped_refptr<SpdySession> session(CreateSpdySession()); | |
216 const char* kStreamUrl = "ws://server.example.com/chat"; | |
217 GURL url(kStreamUrl); | |
218 | |
219 HostPortPair host_port_pair("server.example.com", 80); | |
220 scoped_refptr<TransportSocketParams> transport_params( | |
221 new TransportSocketParams(host_port_pair, LOWEST, false, false, | |
222 OnHostResolutionCallback())); | |
223 | |
224 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | |
225 EXPECT_EQ(OK, connection->Init(host_port_pair.ToString(), transport_params, | |
226 LOWEST, CompletionCallback(), | |
227 session_->GetTransportSocketPool( | |
228 HttpNetworkSession::NORMAL_SOCKET_POOL), | |
229 BoundNetLog())); | |
230 session->InitializeWithSocket(connection.release(), false, OK); | |
231 | |
232 scoped_refptr<SpdyStream> stream; | |
233 ASSERT_EQ( | |
234 OK, | |
235 session->CreateStream(url, LOWEST, &stream, BoundNetLog(), | |
236 CompletionCallback())); | |
237 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(6)); | |
238 memcpy(buf->data(), "hello!", 6); | |
239 TestCompletionCallback callback; | |
240 scoped_ptr<SpdyHeaderBlock> message_headers(new SpdyHeaderBlock); | |
241 (*message_headers)["opcode"] = "1"; | |
242 (*message_headers)["length"] = "6"; | |
243 (*message_headers)["fin"] = "1"; | |
244 | |
245 scoped_ptr<TestSpdyStreamDelegate> delegate( | |
246 new TestSpdyStreamDelegate(stream.get(), | |
247 message_headers.release(), | |
248 buf.get(), | |
249 callback.callback())); | |
250 stream->SetDelegate(delegate.get()); | |
251 | |
252 EXPECT_FALSE(stream->HasUrl()); | |
253 | |
254 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); | |
255 (*headers)["path"] = url.path(); | |
256 (*headers)["host"] = url.host(); | |
257 (*headers)["version"] = "WebSocket/13"; | |
258 (*headers)["scheme"] = url.scheme(); | |
259 (*headers)["origin"] = "http://example.com"; | |
260 stream->set_spdy_headers(headers.Pass()); | |
261 EXPECT_TRUE(stream->HasUrl()); | |
262 | |
263 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); | |
264 | |
265 EXPECT_EQ(OK, callback.WaitForResult()); | |
266 | |
267 EXPECT_TRUE(delegate->send_headers_completed()); | |
268 EXPECT_EQ("101", (*delegate->response())["status"]); | |
269 EXPECT_EQ(std::string(), delegate->received_data()); | |
270 // TODO(toyoshim): OnDataSent should be invoked when each data frame is sent. | |
271 // But current implementation invokes also when each HEADERS frame is sent. | |
Ryan Hamilton
2012/08/02 16:32:23
Hm... I'm not sure about this comment. I think t
Takashi Toyoshima
2012/08/03 05:11:12
OK, I'll add OnHeadersSent.
WriteData returns user
| |
272 //EXPECT_EQ(6, delegate->data_sent()); | |
273 } | |
274 | |
175 TEST_F(SpdyStreamSpdy2Test, PushedStream) { | 275 TEST_F(SpdyStreamSpdy2Test, PushedStream) { |
176 const char kStreamUrl[] = "http://www.google.com/"; | 276 const char kStreamUrl[] = "http://www.google.com/"; |
177 | 277 |
178 SpdySessionDependencies session_deps; | 278 SpdySessionDependencies session_deps; |
179 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps); | 279 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps); |
180 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool()); | 280 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool()); |
181 scoped_refptr<SpdySession> spdy_session(CreateSpdySession()); | 281 scoped_refptr<SpdySession> spdy_session(CreateSpdySession()); |
182 | 282 |
183 MockRead reads[] = { | 283 MockRead reads[] = { |
184 MockRead(ASYNC, 0, 0), // EOF | 284 MockRead(ASYNC, 0, 0), // EOF |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 scoped_refptr<SpdyStream> stream; | 412 scoped_refptr<SpdyStream> stream; |
313 ASSERT_EQ( | 413 ASSERT_EQ( |
314 OK, | 414 OK, |
315 session->CreateStream(url, LOWEST, &stream, log.bound(), | 415 session->CreateStream(url, LOWEST, &stream, log.bound(), |
316 CompletionCallback())); | 416 CompletionCallback())); |
317 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(8)); | 417 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(8)); |
318 memcpy(buf->data(), "\0hello!\xff", 8); | 418 memcpy(buf->data(), "\0hello!\xff", 8); |
319 TestCompletionCallback callback; | 419 TestCompletionCallback callback; |
320 | 420 |
321 scoped_ptr<TestSpdyStreamDelegate> delegate( | 421 scoped_ptr<TestSpdyStreamDelegate> delegate( |
322 new TestSpdyStreamDelegate(stream.get(), buf.get(), callback.callback())); | 422 new TestSpdyStreamDelegate( |
423 stream.get(), NULL, buf.get(), callback.callback())); | |
323 stream->SetDelegate(delegate.get()); | 424 stream->SetDelegate(delegate.get()); |
324 | 425 |
325 EXPECT_FALSE(stream->HasUrl()); | 426 EXPECT_FALSE(stream->HasUrl()); |
326 | 427 |
327 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); | 428 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); |
328 (*headers)["method"] = "GET"; | 429 (*headers)["method"] = "GET"; |
329 (*headers)["scheme"] = url.scheme(); | 430 (*headers)["scheme"] = url.scheme(); |
330 (*headers)["host"] = url.host(); | 431 (*headers)["host"] = url.host(); |
331 (*headers)["url"] = url.path(); | 432 (*headers)["url"] = url.path(); |
332 (*headers)["version"] = "HTTP/1.1"; | 433 (*headers)["version"] = "HTTP/1.1"; |
(...skipping 26 matching lines...) Expand all Loading... | |
359 net::NetLog::PHASE_NONE); | 460 net::NetLog::PHASE_NONE); |
360 | 461 |
361 int stream_id2; | 462 int stream_id2; |
362 ASSERT_TRUE(entries[pos].GetIntegerValue("stream_id", &stream_id2)); | 463 ASSERT_TRUE(entries[pos].GetIntegerValue("stream_id", &stream_id2)); |
363 EXPECT_EQ(static_cast<int>(stream_id), stream_id2); | 464 EXPECT_EQ(static_cast<int>(stream_id), stream_id2); |
364 } | 465 } |
365 | 466 |
366 } //namespace test | 467 } //namespace test |
367 | 468 |
368 } // namespace net | 469 } // namespace net |
OLD | NEW |