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 "net/socket_stream/socket_stream.h" | 5 #include "net/socket_stream/socket_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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 GetMockClientSocketFactory(); | 349 GetMockClientSocketFactory(); |
350 mock_socket_factory->AddSocketDataProvider(&data_provider); | 350 mock_socket_factory->AddSocketDataProvider(&data_provider); |
351 | 351 |
352 socket_stream->SetClientSocketFactory(mock_socket_factory); | 352 socket_stream->SetClientSocketFactory(mock_socket_factory); |
353 | 353 |
354 socket_stream->Connect(); | 354 socket_stream->Connect(); |
355 | 355 |
356 test_callback.WaitForResult(); | 356 test_callback.WaitForResult(); |
357 | 357 |
358 const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents(); | 358 const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents(); |
359 ASSERT_EQ(8U, events.size()); | 359 ASSERT_EQ(7U, events.size()); |
360 | 360 |
361 EXPECT_EQ(SocketStreamEvent::EVENT_START_OPEN_CONNECTION, | 361 EXPECT_EQ(SocketStreamEvent::EVENT_START_OPEN_CONNECTION, |
362 events[0].event_type); | 362 events[0].event_type); |
363 EXPECT_EQ(SocketStreamEvent::EVENT_CONNECTED, events[1].event_type); | 363 EXPECT_EQ(SocketStreamEvent::EVENT_CONNECTED, events[1].event_type); |
364 EXPECT_EQ(SocketStreamEvent::EVENT_SENT_DATA, events[2].event_type); | 364 EXPECT_EQ(SocketStreamEvent::EVENT_SENT_DATA, events[2].event_type); |
365 EXPECT_EQ(SocketStreamEvent::EVENT_RECEIVED_DATA, events[3].event_type); | 365 EXPECT_EQ(SocketStreamEvent::EVENT_RECEIVED_DATA, events[3].event_type); |
366 EXPECT_EQ(SocketStreamEvent::EVENT_SENT_DATA, events[4].event_type); | 366 EXPECT_EQ(SocketStreamEvent::EVENT_SENT_DATA, events[4].event_type); |
367 EXPECT_EQ(SocketStreamEvent::EVENT_SENT_DATA, events[5].event_type); | 367 EXPECT_EQ(SocketStreamEvent::EVENT_SENT_DATA, events[5].event_type); |
368 EXPECT_EQ(SocketStreamEvent::EVENT_ERROR, events[6].event_type); | 368 EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[6].event_type); |
369 EXPECT_EQ(ERR_CONNECTION_CLOSED, events[6].error_code); | |
370 EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[7].event_type); | |
371 } | 369 } |
372 | 370 |
373 TEST_F(SocketStreamTest, ExceedMaxPendingSendAllowed) { | 371 TEST_F(SocketStreamTest, ExceedMaxPendingSendAllowed) { |
374 TestCompletionCallback test_callback; | 372 TestCompletionCallback test_callback; |
375 | 373 |
376 scoped_ptr<SocketStreamEventRecorder> delegate( | 374 scoped_ptr<SocketStreamEventRecorder> delegate( |
377 new SocketStreamEventRecorder(test_callback.callback())); | 375 new SocketStreamEventRecorder(test_callback.callback())); |
378 delegate->SetOnConnected(base::Bind( | 376 delegate->SetOnConnected(base::Bind( |
379 &SocketStreamTest::DoFailByTooBigDataAndClose, base::Unretained(this))); | 377 &SocketStreamTest::DoFailByTooBigDataAndClose, base::Unretained(this))); |
380 | 378 |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 | 636 |
639 socket_stream->Connect(); | 637 socket_stream->Connect(); |
640 io_test_callback_.WaitForResult(); | 638 io_test_callback_.WaitForResult(); |
641 EXPECT_EQ(SocketStream::STATE_RESOLVE_PROTOCOL_COMPLETE, | 639 EXPECT_EQ(SocketStream::STATE_RESOLVE_PROTOCOL_COMPLETE, |
642 socket_stream->next_state_); | 640 socket_stream->next_state_); |
643 delegate->CompleteConnection(OK); | 641 delegate->CompleteConnection(OK); |
644 | 642 |
645 EXPECT_EQ(OK, test_callback.WaitForResult()); | 643 EXPECT_EQ(OK, test_callback.WaitForResult()); |
646 | 644 |
647 const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents(); | 645 const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents(); |
648 ASSERT_EQ(8U, events.size()); | 646 ASSERT_EQ(7U, events.size()); |
649 | 647 |
650 EXPECT_EQ(SocketStreamEvent::EVENT_START_OPEN_CONNECTION, | 648 EXPECT_EQ(SocketStreamEvent::EVENT_START_OPEN_CONNECTION, |
651 events[0].event_type); | 649 events[0].event_type); |
652 EXPECT_EQ(SocketStreamEvent::EVENT_CONNECTED, events[1].event_type); | 650 EXPECT_EQ(SocketStreamEvent::EVENT_CONNECTED, events[1].event_type); |
653 EXPECT_EQ(SocketStreamEvent::EVENT_SENT_DATA, events[2].event_type); | 651 EXPECT_EQ(SocketStreamEvent::EVENT_SENT_DATA, events[2].event_type); |
654 EXPECT_EQ(SocketStreamEvent::EVENT_RECEIVED_DATA, events[3].event_type); | 652 EXPECT_EQ(SocketStreamEvent::EVENT_RECEIVED_DATA, events[3].event_type); |
655 EXPECT_EQ(SocketStreamEvent::EVENT_SENT_DATA, events[4].event_type); | 653 EXPECT_EQ(SocketStreamEvent::EVENT_SENT_DATA, events[4].event_type); |
656 EXPECT_EQ(SocketStreamEvent::EVENT_SENT_DATA, events[5].event_type); | 654 EXPECT_EQ(SocketStreamEvent::EVENT_SENT_DATA, events[5].event_type); |
657 EXPECT_EQ(SocketStreamEvent::EVENT_ERROR, events[6].event_type); | 655 EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[6].event_type); |
658 EXPECT_EQ(ERR_CONNECTION_CLOSED, events[6].error_code); | |
659 EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[7].event_type); | |
660 } | 656 } |
661 | 657 |
662 TEST_F(SocketStreamTest, SwitchToSpdy) { | 658 TEST_F(SocketStreamTest, SwitchToSpdy) { |
663 TestCompletionCallback test_callback; | 659 TestCompletionCallback test_callback; |
664 | 660 |
665 scoped_ptr<SocketStreamEventRecorder> delegate( | 661 scoped_ptr<SocketStreamEventRecorder> delegate( |
666 new SocketStreamEventRecorder(test_callback.callback())); | 662 new SocketStreamEventRecorder(test_callback.callback())); |
667 delegate->SetOnStartOpenConnection(base::Bind( | 663 delegate->SetOnStartOpenConnection(base::Bind( |
668 &SocketStreamTest::DoSwitchToSpdyTest, base::Unretained(this))); | 664 &SocketStreamTest::DoSwitchToSpdyTest, base::Unretained(this))); |
669 | 665 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 | 840 |
845 const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents(); | 841 const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents(); |
846 ASSERT_EQ(2U, events.size()); | 842 ASSERT_EQ(2U, events.size()); |
847 | 843 |
848 EXPECT_EQ(SocketStreamEvent::EVENT_ERROR, events[0].event_type); | 844 EXPECT_EQ(SocketStreamEvent::EVENT_ERROR, events[0].event_type); |
849 EXPECT_EQ(ERR_ACCESS_DENIED, events[0].error_code); | 845 EXPECT_EQ(ERR_ACCESS_DENIED, events[0].error_code); |
850 EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[1].event_type); | 846 EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[1].event_type); |
851 } | 847 } |
852 | 848 |
853 } // namespace net | 849 } // namespace net |
OLD | NEW |