| 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/bind.h" |
| 5 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 6 #include "base/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
| 7 #include "remoting/base/base_mock_objects.h" | 8 #include "remoting/base/base_mock_objects.h" |
| 8 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
| 9 #include "remoting/protocol/fake_session.h" | 10 #include "remoting/protocol/fake_session.h" |
| 10 #include "remoting/protocol/connection_to_client.h" | 11 #include "remoting/protocol/connection_to_client.h" |
| 11 #include "remoting/protocol/protocol_mock_objects.h" | 12 #include "remoting/protocol/protocol_mock_objects.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 13 | 14 |
| 14 using ::testing::_; | 15 using ::testing::_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 28 session_ = new protocol::FakeSession(); | 29 session_ = new protocol::FakeSession(); |
| 29 session_->set_message_loop(&message_loop_); | 30 session_->set_message_loop(&message_loop_); |
| 30 | 31 |
| 31 // Allocate a ClientConnection object with the mock objects. | 32 // Allocate a ClientConnection object with the mock objects. |
| 32 viewer_ = new ConnectionToClient( | 33 viewer_ = new ConnectionToClient( |
| 33 base::MessageLoopProxy::current(), &handler_); | 34 base::MessageLoopProxy::current(), &handler_); |
| 34 viewer_->set_host_stub(&host_stub_); | 35 viewer_->set_host_stub(&host_stub_); |
| 35 viewer_->set_input_stub(&input_stub_); | 36 viewer_->set_input_stub(&input_stub_); |
| 36 viewer_->Init(session_); | 37 viewer_->Init(session_); |
| 37 EXPECT_CALL(handler_, OnConnectionOpened(viewer_.get())); | 38 EXPECT_CALL(handler_, OnConnectionOpened(viewer_.get())); |
| 38 session_->state_change_callback()->Run( | 39 session_->state_change_callback().Run( |
| 39 protocol::Session::CONNECTED); | 40 protocol::Session::CONNECTED); |
| 40 session_->state_change_callback()->Run( | 41 session_->state_change_callback().Run( |
| 41 protocol::Session::CONNECTED_CHANNELS); | 42 protocol::Session::CONNECTED_CHANNELS); |
| 42 message_loop_.RunAllPending(); | 43 message_loop_.RunAllPending(); |
| 43 } | 44 } |
| 44 | 45 |
| 45 MessageLoop message_loop_; | 46 MessageLoop message_loop_; |
| 46 MockConnectionToClientEventHandler handler_; | 47 MockConnectionToClientEventHandler handler_; |
| 47 MockHostStub host_stub_; | 48 MockHostStub host_stub_; |
| 48 MockInputStub input_stub_; | 49 MockInputStub input_stub_; |
| 49 scoped_refptr<ConnectionToClient> viewer_; | 50 scoped_refptr<ConnectionToClient> viewer_; |
| 50 | 51 |
| 51 // Owned by |viewer_|. | 52 // Owned by |viewer_|. |
| 52 protocol::FakeSession* session_; | 53 protocol::FakeSession* session_; |
| 53 | 54 |
| 54 private: | 55 private: |
| 55 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest); | 56 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest); |
| 56 }; | 57 }; |
| 57 | 58 |
| 58 TEST_F(ConnectionToClientTest, SendUpdateStream) { | 59 TEST_F(ConnectionToClientTest, SendUpdateStream) { |
| 59 // Then send the actual data. | 60 // Then send the actual data. |
| 60 VideoPacket* packet = new VideoPacket(); | 61 VideoPacket* packet = new VideoPacket(); |
| 61 viewer_->video_stub()->ProcessVideoPacket( | 62 viewer_->video_stub()->ProcessVideoPacket( |
| 62 packet, new DeleteTask<VideoPacket>(packet)); | 63 packet, base::Bind(&DeletePointer<VideoPacket>, packet)); |
| 63 | 64 |
| 64 message_loop_.RunAllPending(); | 65 message_loop_.RunAllPending(); |
| 65 | 66 |
| 66 // Verify that something has been written. | 67 // Verify that something has been written. |
| 67 // TODO(sergeyu): Verify that the correct data has been written. | 68 // TODO(sergeyu): Verify that the correct data has been written. |
| 68 ASSERT_TRUE(session_->GetStreamChannel(kVideoChannelName)); | 69 ASSERT_TRUE(session_->GetStreamChannel(kVideoChannelName)); |
| 69 EXPECT_GT(session_->GetStreamChannel(kVideoChannelName)-> | 70 EXPECT_GT(session_->GetStreamChannel(kVideoChannelName)-> |
| 70 written_data().size(), 0u); | 71 written_data().size(), 0u); |
| 71 | 72 |
| 72 // And then close the connection to ConnectionToClient. | 73 // And then close the connection to ConnectionToClient. |
| 73 viewer_->Disconnect(); | 74 viewer_->Disconnect(); |
| 74 | 75 |
| 75 message_loop_.RunAllPending(); | 76 message_loop_.RunAllPending(); |
| 76 } | 77 } |
| 77 | 78 |
| 78 TEST_F(ConnectionToClientTest, NoWriteAfterDisconnect) { | 79 TEST_F(ConnectionToClientTest, NoWriteAfterDisconnect) { |
| 79 // Then send the actual data. | 80 // Then send the actual data. |
| 80 VideoPacket* packet = new VideoPacket(); | 81 VideoPacket* packet = new VideoPacket(); |
| 81 viewer_->video_stub()->ProcessVideoPacket( | 82 viewer_->video_stub()->ProcessVideoPacket( |
| 82 packet, new DeleteTask<VideoPacket>(packet)); | 83 packet, base::Bind(&DeletePointer<VideoPacket>, packet)); |
| 83 | 84 |
| 84 // And then close the connection to ConnectionToClient. | 85 // And then close the connection to ConnectionToClient. |
| 85 viewer_->Disconnect(); | 86 viewer_->Disconnect(); |
| 86 | 87 |
| 87 // The test will crash if data writer tries to write data to the | 88 // The test will crash if data writer tries to write data to the |
| 88 // channel socket. | 89 // channel socket. |
| 89 // TODO(sergeyu): Use MockSession to verify that no data is written? | 90 // TODO(sergeyu): Use MockSession to verify that no data is written? |
| 90 message_loop_.RunAllPending(); | 91 message_loop_.RunAllPending(); |
| 91 } | 92 } |
| 92 | 93 |
| 93 TEST_F(ConnectionToClientTest, StateChange) { | 94 TEST_F(ConnectionToClientTest, StateChange) { |
| 94 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get())); | 95 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get())); |
| 95 session_->state_change_callback()->Run(protocol::Session::CLOSED); | 96 session_->state_change_callback().Run(protocol::Session::CLOSED); |
| 96 message_loop_.RunAllPending(); | 97 message_loop_.RunAllPending(); |
| 97 | 98 |
| 98 EXPECT_CALL(handler_, OnConnectionFailed(viewer_.get())); | 99 EXPECT_CALL(handler_, OnConnectionFailed(viewer_.get())); |
| 99 session_->state_change_callback()->Run(protocol::Session::FAILED); | 100 session_->state_change_callback().Run(protocol::Session::FAILED); |
| 100 message_loop_.RunAllPending(); | 101 message_loop_.RunAllPending(); |
| 101 } | 102 } |
| 102 | 103 |
| 103 // Test that we can close client connection more than once. | 104 // Test that we can close client connection more than once. |
| 104 TEST_F(ConnectionToClientTest, Close) { | 105 TEST_F(ConnectionToClientTest, Close) { |
| 105 viewer_->Disconnect(); | 106 viewer_->Disconnect(); |
| 106 message_loop_.RunAllPending(); | 107 message_loop_.RunAllPending(); |
| 107 viewer_->Disconnect(); | 108 viewer_->Disconnect(); |
| 108 message_loop_.RunAllPending(); | 109 message_loop_.RunAllPending(); |
| 109 } | 110 } |
| 110 | 111 |
| 111 } // namespace protocol | 112 } // namespace protocol |
| 112 } // namespace remoting | 113 } // namespace remoting |
| OLD | NEW |