| 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/protocol/fake_session.h" | 7 #include "remoting/protocol/fake_session.h" |
| 8 #include "remoting/protocol/connection_to_client.h" | 8 #include "remoting/protocol/connection_to_client.h" |
| 9 #include "remoting/protocol/protocol_mock_objects.h" | 9 #include "remoting/protocol/protocol_mock_objects.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 private: | 48 private: |
| 49 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest); | 49 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest); |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 TEST_F(ConnectionToClientTest, SendUpdateStream) { | 52 TEST_F(ConnectionToClientTest, SendUpdateStream) { |
| 53 // Then send the actual data. | 53 // Then send the actual data. |
| 54 VideoPacket* packet = new VideoPacket(); | 54 VideoPacket* packet = new VideoPacket(); |
| 55 viewer_->video_stub()->ProcessVideoPacket( | 55 viewer_->video_stub()->ProcessVideoPacket( |
| 56 packet, new DeleteTask<VideoPacket>(packet)); | 56 packet, new DeleteTask<VideoPacket>(packet)); |
| 57 | 57 |
| 58 message_loop_.RunAllPending(); |
| 59 |
| 58 // And then close the connection to ConnectionToClient. | 60 // And then close the connection to ConnectionToClient. |
| 59 viewer_->Disconnect(); | 61 viewer_->Disconnect(); |
| 60 | 62 |
| 61 message_loop_.RunAllPending(); | 63 message_loop_.RunAllPending(); |
| 62 | 64 |
| 63 // Verify that something has been written. | 65 // Verify that something has been written. |
| 64 // TODO(sergeyu): Verify that the correct data has been written. | 66 // TODO(sergeyu): Verify that the correct data has been written. |
| 65 EXPECT_GT(session_->video_channel()->written_data().size(), 0u); | 67 EXPECT_GT(session_->video_channel()->written_data().size(), 0u); |
| 66 } | 68 } |
| 67 | 69 |
| 70 TEST_F(ConnectionToClientTest, NoWriteAfterDisconnect) { |
| 71 // Then send the actual data. |
| 72 VideoPacket* packet = new VideoPacket(); |
| 73 viewer_->video_stub()->ProcessVideoPacket( |
| 74 packet, new DeleteTask<VideoPacket>(packet)); |
| 75 |
| 76 // And then close the connection to ConnectionToClient. |
| 77 viewer_->Disconnect(); |
| 78 |
| 79 message_loop_.RunAllPending(); |
| 80 |
| 81 // Nothing should be written because connection has been closed. |
| 82 EXPECT_EQ(session_->video_channel()->written_data().size(), 0u); |
| 83 } |
| 84 |
| 68 TEST_F(ConnectionToClientTest, StateChange) { | 85 TEST_F(ConnectionToClientTest, StateChange) { |
| 69 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get())); | 86 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get())); |
| 70 session_->state_change_callback()->Run(protocol::Session::CLOSED); | 87 session_->state_change_callback()->Run(protocol::Session::CLOSED); |
| 71 message_loop_.RunAllPending(); | 88 message_loop_.RunAllPending(); |
| 72 | 89 |
| 73 EXPECT_CALL(handler_, OnConnectionFailed(viewer_.get())); | 90 EXPECT_CALL(handler_, OnConnectionFailed(viewer_.get())); |
| 74 session_->state_change_callback()->Run(protocol::Session::FAILED); | 91 session_->state_change_callback()->Run(protocol::Session::FAILED); |
| 75 message_loop_.RunAllPending(); | 92 message_loop_.RunAllPending(); |
| 76 } | 93 } |
| 77 | 94 |
| 78 // Test that we can close client connection more than once. | 95 // Test that we can close client connection more than once. |
| 79 TEST_F(ConnectionToClientTest, Close) { | 96 TEST_F(ConnectionToClientTest, Close) { |
| 80 viewer_->Disconnect(); | 97 viewer_->Disconnect(); |
| 81 message_loop_.RunAllPending(); | 98 message_loop_.RunAllPending(); |
| 82 EXPECT_TRUE(session_->is_closed()); | 99 EXPECT_TRUE(session_->is_closed()); |
| 83 | 100 |
| 84 viewer_->Disconnect(); | 101 viewer_->Disconnect(); |
| 85 message_loop_.RunAllPending(); | 102 message_loop_.RunAllPending(); |
| 86 } | 103 } |
| 87 | 104 |
| 88 } // namespace protocol | 105 } // namespace protocol |
| 89 } // namespace remoting | 106 } // namespace remoting |
| OLD | NEW |