OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_websocket_stream.h" | 5 #include "net/spdy/spdy_websocket_stream.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 kMessageFrame, | 228 kMessageFrame, |
229 kMessageFrameLength, | 229 kMessageFrameLength, |
230 stream_id_, | 230 stream_id_, |
231 false)); | 231 false)); |
232 | 232 |
233 closing_frame_.reset(spdy_util_.ConstructSpdyWebSocketDataFrame( | 233 closing_frame_.reset(spdy_util_.ConstructSpdyWebSocketDataFrame( |
234 kClosingFrame, | 234 kClosingFrame, |
235 kClosingFrameLength, | 235 kClosingFrameLength, |
236 stream_id_, | 236 stream_id_, |
237 false)); | 237 false)); |
| 238 |
| 239 closing_frame_fin_.reset(spdy_util_.ConstructSpdyWebSocketDataFrame( |
| 240 kClosingFrame, |
| 241 kClosingFrameLength, |
| 242 stream_id_, |
| 243 true)); |
238 } | 244 } |
239 | 245 |
240 void InitSession(MockRead* reads, size_t reads_count, | 246 void InitSession(MockRead* reads, size_t reads_count, |
241 MockWrite* writes, size_t writes_count) { | 247 MockWrite* writes, size_t writes_count) { |
242 data_.reset(new OrderedSocketData(reads, reads_count, | 248 data_.reset(new OrderedSocketData(reads, reads_count, |
243 writes, writes_count)); | 249 writes, writes_count)); |
244 session_deps_.socket_factory->AddSocketDataProvider(data_.get()); | 250 session_deps_.socket_factory->AddSocketDataProvider(data_.get()); |
245 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 251 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
246 session_ = CreateInsecureSpdySession( | 252 session_ = CreateInsecureSpdySession( |
247 http_session_, spdy_session_key_, BoundNetLog()); | 253 http_session_, spdy_session_key_, BoundNetLog()); |
(...skipping 18 matching lines...) Expand all Loading... |
266 scoped_ptr<OrderedSocketData> data_; | 272 scoped_ptr<OrderedSocketData> data_; |
267 scoped_refptr<HttpNetworkSession> http_session_; | 273 scoped_refptr<HttpNetworkSession> http_session_; |
268 base::WeakPtr<SpdySession> session_; | 274 base::WeakPtr<SpdySession> session_; |
269 scoped_ptr<SpdyWebSocketStream> websocket_stream_; | 275 scoped_ptr<SpdyWebSocketStream> websocket_stream_; |
270 SpdyStreamId stream_id_; | 276 SpdyStreamId stream_id_; |
271 SpdyStreamId created_stream_id_; | 277 SpdyStreamId created_stream_id_; |
272 scoped_ptr<SpdyFrame> request_frame_; | 278 scoped_ptr<SpdyFrame> request_frame_; |
273 scoped_ptr<SpdyFrame> response_frame_; | 279 scoped_ptr<SpdyFrame> response_frame_; |
274 scoped_ptr<SpdyFrame> message_frame_; | 280 scoped_ptr<SpdyFrame> message_frame_; |
275 scoped_ptr<SpdyFrame> closing_frame_; | 281 scoped_ptr<SpdyFrame> closing_frame_; |
| 282 scoped_ptr<SpdyFrame> closing_frame_fin_; |
276 HostPortPair host_port_pair_; | 283 HostPortPair host_port_pair_; |
277 SpdySessionKey spdy_session_key_; | 284 SpdySessionKey spdy_session_key_; |
278 TestCompletionCallback completion_callback_; | 285 TestCompletionCallback completion_callback_; |
279 TestCompletionCallback sync_callback_; | 286 TestCompletionCallback sync_callback_; |
280 | 287 |
281 static const char kMessageFrame[]; | 288 static const char kMessageFrame[]; |
282 static const char kClosingFrame[]; | 289 static const char kClosingFrame[]; |
283 static const size_t kMessageFrameLength; | 290 static const size_t kMessageFrameLength; |
284 static const size_t kClosingFrameLength; | 291 static const size_t kClosingFrameLength; |
285 }; | 292 }; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 events[6].event_type); | 375 events[6].event_type); |
369 EXPECT_EQ(OK, events[6].result); | 376 EXPECT_EQ(OK, events[6].result); |
370 | 377 |
371 // EOF close SPDY session. | 378 // EOF close SPDY session. |
372 EXPECT_FALSE( | 379 EXPECT_FALSE( |
373 HasSpdySession(http_session_->spdy_session_pool(), spdy_session_key_)); | 380 HasSpdySession(http_session_->spdy_session_pool(), spdy_session_key_)); |
374 EXPECT_TRUE(data()->at_read_eof()); | 381 EXPECT_TRUE(data()->at_read_eof()); |
375 EXPECT_TRUE(data()->at_write_eof()); | 382 EXPECT_TRUE(data()->at_write_eof()); |
376 } | 383 } |
377 | 384 |
| 385 // A SPDY websocket may still send it's close frame after |
| 386 // recieving a close with SPDY stream FIN. |
| 387 TEST_P(SpdyWebSocketStreamTest, RemoteCloseWithFin) { |
| 388 Prepare(1); |
| 389 MockWrite writes[] = { |
| 390 CreateMockWrite(*request_frame_.get(), 1), |
| 391 CreateMockWrite(*closing_frame_.get(), 4), |
| 392 }; |
| 393 MockRead reads[] = { |
| 394 CreateMockRead(*response_frame_.get(), 2), |
| 395 CreateMockRead(*closing_frame_fin_.get(), 3), |
| 396 MockRead(SYNCHRONOUS, 0, 5) // EOF cause OnCloseSpdyStream event. |
| 397 }; |
| 398 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 399 |
| 400 SpdyWebSocketStreamEventRecorder delegate(completion_callback_.callback()); |
| 401 delegate.SetOnReceivedData( |
| 402 base::Bind(&SpdyWebSocketStreamTest::DoSendClosingFrame, |
| 403 base::Unretained(this))); |
| 404 |
| 405 websocket_stream_.reset(new SpdyWebSocketStream(session_, &delegate)); |
| 406 BoundNetLog net_log; |
| 407 GURL url("ws://example.com/echo"); |
| 408 ASSERT_EQ(OK, websocket_stream_->InitializeStream(url, HIGHEST, net_log)); |
| 409 |
| 410 SendRequest(); |
| 411 completion_callback_.WaitForResult(); |
| 412 websocket_stream_.reset(); |
| 413 |
| 414 const std::vector<SpdyWebSocketStreamEvent>& events = |
| 415 delegate.GetSeenEvents(); |
| 416 EXPECT_EQ(5U, events.size()); |
| 417 |
| 418 EXPECT_EQ(SpdyWebSocketStreamEvent::EVENT_SENT_HEADERS, |
| 419 events[0].event_type); |
| 420 EXPECT_EQ(OK, events[0].result); |
| 421 EXPECT_EQ(SpdyWebSocketStreamEvent::EVENT_RECEIVED_HEADER, |
| 422 events[1].event_type); |
| 423 EXPECT_EQ(OK, events[1].result); |
| 424 EXPECT_EQ(SpdyWebSocketStreamEvent::EVENT_RECEIVED_DATA, |
| 425 events[2].event_type); |
| 426 EXPECT_EQ(static_cast<int>(kClosingFrameLength), events[2].result); |
| 427 EXPECT_EQ(SpdyWebSocketStreamEvent::EVENT_SENT_DATA, |
| 428 events[3].event_type); |
| 429 EXPECT_EQ(static_cast<int>(kClosingFrameLength), events[3].result); |
| 430 EXPECT_EQ(SpdyWebSocketStreamEvent::EVENT_CLOSE, |
| 431 events[4].event_type); |
| 432 EXPECT_EQ(OK, events[4].result); |
| 433 |
| 434 // EOF closes SPDY session. |
| 435 EXPECT_FALSE( |
| 436 HasSpdySession(http_session_->spdy_session_pool(), spdy_session_key_)); |
| 437 EXPECT_TRUE(data()->at_read_eof()); |
| 438 EXPECT_TRUE(data()->at_write_eof()); |
| 439 } |
| 440 |
378 TEST_P(SpdyWebSocketStreamTest, DestructionBeforeClose) { | 441 TEST_P(SpdyWebSocketStreamTest, DestructionBeforeClose) { |
379 Prepare(1); | 442 Prepare(1); |
380 MockWrite writes[] = { | 443 MockWrite writes[] = { |
381 CreateMockWrite(*request_frame_.get(), 1), | 444 CreateMockWrite(*request_frame_.get(), 1), |
382 CreateMockWrite(*message_frame_.get(), 3) | 445 CreateMockWrite(*message_frame_.get(), 3) |
383 }; | 446 }; |
384 | 447 |
385 MockRead reads[] = { | 448 MockRead reads[] = { |
386 CreateMockRead(*response_frame_.get(), 2), | 449 CreateMockRead(*response_frame_.get(), 2), |
387 CreateMockRead(*message_frame_.get(), 4), | 450 CreateMockRead(*message_frame_.get(), 4), |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 EXPECT_EQ(OK, events[7].result); | 661 EXPECT_EQ(OK, events[7].result); |
599 | 662 |
600 // EOF close SPDY session. | 663 // EOF close SPDY session. |
601 EXPECT_FALSE( | 664 EXPECT_FALSE( |
602 HasSpdySession(http_session_->spdy_session_pool(), spdy_session_key_)); | 665 HasSpdySession(http_session_->spdy_session_pool(), spdy_session_key_)); |
603 EXPECT_TRUE(data.at_read_eof()); | 666 EXPECT_TRUE(data.at_read_eof()); |
604 EXPECT_TRUE(data.at_write_eof()); | 667 EXPECT_TRUE(data.at_write_eof()); |
605 } | 668 } |
606 | 669 |
607 } // namespace net | 670 } // namespace net |
OLD | NEW |