| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "remoting/base/base_mock_objects.h" | 6 #include "remoting/base/base_mock_objects.h" |
| 7 #include "remoting/base/constants.h" |
| 7 #include "remoting/protocol/fake_session.h" | 8 #include "remoting/protocol/fake_session.h" |
| 8 #include "remoting/protocol/connection_to_client.h" | 9 #include "remoting/protocol/connection_to_client.h" |
| 9 #include "remoting/protocol/protocol_mock_objects.h" | 10 #include "remoting/protocol/protocol_mock_objects.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 11 | 12 |
| 12 using ::testing::_; | 13 using ::testing::_; |
| 13 using ::testing::NotNull; | 14 using ::testing::NotNull; |
| 14 using ::testing::StrictMock; | 15 using ::testing::StrictMock; |
| 15 | 16 |
| 16 namespace remoting { | 17 namespace remoting { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 27 session_->set_message_loop(&message_loop_); | 28 session_->set_message_loop(&message_loop_); |
| 28 | 29 |
| 29 // Allocate a ClientConnection object with the mock objects. | 30 // Allocate a ClientConnection object with the mock objects. |
| 30 viewer_ = new ConnectionToClient(&message_loop_, &handler_); | 31 viewer_ = new ConnectionToClient(&message_loop_, &handler_); |
| 31 viewer_->set_host_stub(&host_stub_); | 32 viewer_->set_host_stub(&host_stub_); |
| 32 viewer_->set_input_stub(&input_stub_); | 33 viewer_->set_input_stub(&input_stub_); |
| 33 viewer_->Init(session_); | 34 viewer_->Init(session_); |
| 34 EXPECT_CALL(handler_, OnConnectionOpened(viewer_.get())); | 35 EXPECT_CALL(handler_, OnConnectionOpened(viewer_.get())); |
| 35 session_->state_change_callback()->Run( | 36 session_->state_change_callback()->Run( |
| 36 protocol::Session::CONNECTED); | 37 protocol::Session::CONNECTED); |
| 38 session_->state_change_callback()->Run( |
| 39 protocol::Session::CONNECTED_CHANNELS); |
| 37 message_loop_.RunAllPending(); | 40 message_loop_.RunAllPending(); |
| 38 } | 41 } |
| 39 | 42 |
| 40 MessageLoop message_loop_; | 43 MessageLoop message_loop_; |
| 41 MockConnectionToClientEventHandler handler_; | 44 MockConnectionToClientEventHandler handler_; |
| 42 MockHostStub host_stub_; | 45 MockHostStub host_stub_; |
| 43 MockInputStub input_stub_; | 46 MockInputStub input_stub_; |
| 44 scoped_refptr<ConnectionToClient> viewer_; | 47 scoped_refptr<ConnectionToClient> viewer_; |
| 45 | 48 |
| 46 // Owned by |viewer_|. | 49 // Owned by |viewer_|. |
| 47 protocol::FakeSession* session_; | 50 protocol::FakeSession* session_; |
| 48 | 51 |
| 49 private: | 52 private: |
| 50 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest); | 53 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest); |
| 51 }; | 54 }; |
| 52 | 55 |
| 53 TEST_F(ConnectionToClientTest, SendUpdateStream) { | 56 TEST_F(ConnectionToClientTest, SendUpdateStream) { |
| 54 // Then send the actual data. | 57 // Then send the actual data. |
| 55 VideoPacket* packet = new VideoPacket(); | 58 VideoPacket* packet = new VideoPacket(); |
| 56 viewer_->video_stub()->ProcessVideoPacket( | 59 viewer_->video_stub()->ProcessVideoPacket( |
| 57 packet, new DeleteTask<VideoPacket>(packet)); | 60 packet, new DeleteTask<VideoPacket>(packet)); |
| 58 | 61 |
| 59 message_loop_.RunAllPending(); | 62 message_loop_.RunAllPending(); |
| 60 | 63 |
| 61 // Verify that something has been written. | 64 // Verify that something has been written. |
| 62 // TODO(sergeyu): Verify that the correct data has been written. | 65 // TODO(sergeyu): Verify that the correct data has been written. |
| 63 EXPECT_GT(session_->video_channel()->written_data().size(), 0u); | 66 ASSERT_TRUE(session_->GetStreamChannel(kVideoChannelName)); |
| 67 EXPECT_GT(session_->GetStreamChannel(kVideoChannelName)-> |
| 68 written_data().size(), 0u); |
| 64 | 69 |
| 65 // And then close the connection to ConnectionToClient. | 70 // And then close the connection to ConnectionToClient. |
| 66 viewer_->Disconnect(); | 71 viewer_->Disconnect(); |
| 67 | 72 |
| 68 message_loop_.RunAllPending(); | 73 message_loop_.RunAllPending(); |
| 69 } | 74 } |
| 70 | 75 |
| 71 TEST_F(ConnectionToClientTest, NoWriteAfterDisconnect) { | 76 TEST_F(ConnectionToClientTest, NoWriteAfterDisconnect) { |
| 72 // Then send the actual data. | 77 // Then send the actual data. |
| 73 VideoPacket* packet = new VideoPacket(); | 78 VideoPacket* packet = new VideoPacket(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 96 // Test that we can close client connection more than once. | 101 // Test that we can close client connection more than once. |
| 97 TEST_F(ConnectionToClientTest, Close) { | 102 TEST_F(ConnectionToClientTest, Close) { |
| 98 viewer_->Disconnect(); | 103 viewer_->Disconnect(); |
| 99 message_loop_.RunAllPending(); | 104 message_loop_.RunAllPending(); |
| 100 viewer_->Disconnect(); | 105 viewer_->Disconnect(); |
| 101 message_loop_.RunAllPending(); | 106 message_loop_.RunAllPending(); |
| 102 } | 107 } |
| 103 | 108 |
| 104 } // namespace protocol | 109 } // namespace protocol |
| 105 } // namespace remoting | 110 } // namespace remoting |
| OLD | NEW |