| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "base/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
| 8 #include "remoting/base/base_mock_objects.h" | 8 #include "remoting/base/base_mock_objects.h" |
| 9 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
| 10 #include "remoting/protocol/fake_session.h" | 10 #include "remoting/protocol/fake_session.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 scoped_ptr<ConnectionToClient> viewer_; | 57 scoped_ptr<ConnectionToClient> viewer_; |
| 58 | 58 |
| 59 // Owned by |viewer_|. | 59 // Owned by |viewer_|. |
| 60 protocol::FakeSession* session_; | 60 protocol::FakeSession* session_; |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest); | 63 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest); |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 TEST_F(ConnectionToClientTest, SendUpdateStream) { | 66 TEST_F(ConnectionToClientTest, SendUpdateStream) { |
| 67 // Then send the actual data. | 67 scoped_ptr<VideoPacket> packet(new VideoPacket()); |
| 68 VideoPacket* packet = new VideoPacket(); | 68 viewer_->video_stub()->ProcessVideoPacket(packet.Pass(), base::Closure()); |
| 69 viewer_->video_stub()->ProcessVideoPacket( | |
| 70 packet, base::Bind(&base::DeletePointer<VideoPacket>, packet)); | |
| 71 | 69 |
| 72 message_loop_.RunAllPending(); | 70 message_loop_.RunAllPending(); |
| 73 | 71 |
| 74 // Verify that something has been written. | 72 // Verify that something has been written. |
| 75 // TODO(sergeyu): Verify that the correct data has been written. | 73 // TODO(sergeyu): Verify that the correct data has been written. |
| 76 ASSERT_TRUE(session_->GetStreamChannel(kVideoChannelName)); | 74 ASSERT_TRUE(session_->GetStreamChannel(kVideoChannelName)); |
| 77 EXPECT_GT(session_->GetStreamChannel(kVideoChannelName)-> | 75 EXPECT_GT(session_->GetStreamChannel(kVideoChannelName)-> |
| 78 written_data().size(), 0u); | 76 written_data().size(), 0u); |
| 79 | 77 |
| 80 // And then close the connection to ConnectionToClient. | 78 // And then close the connection to ConnectionToClient. |
| 81 viewer_->Disconnect(); | 79 viewer_->Disconnect(); |
| 82 | 80 |
| 83 message_loop_.RunAllPending(); | 81 message_loop_.RunAllPending(); |
| 84 } | 82 } |
| 85 | 83 |
| 86 TEST_F(ConnectionToClientTest, NoWriteAfterDisconnect) { | 84 TEST_F(ConnectionToClientTest, NoWriteAfterDisconnect) { |
| 87 // Then send the actual data. | 85 scoped_ptr<VideoPacket> packet(new VideoPacket()); |
| 88 VideoPacket* packet = new VideoPacket(); | 86 viewer_->video_stub()->ProcessVideoPacket(packet.Pass(), base::Closure()); |
| 89 viewer_->video_stub()->ProcessVideoPacket( | |
| 90 packet, base::Bind(&base::DeletePointer<VideoPacket>, packet)); | |
| 91 | 87 |
| 92 // And then close the connection to ConnectionToClient. | 88 // And then close the connection to ConnectionToClient. |
| 93 viewer_->Disconnect(); | 89 viewer_->Disconnect(); |
| 94 | 90 |
| 95 // The test will crash if data writer tries to write data to the | 91 // The test will crash if data writer tries to write data to the |
| 96 // channel socket. | 92 // channel socket. |
| 97 // TODO(sergeyu): Use MockSession to verify that no data is written? | 93 // TODO(sergeyu): Use MockSession to verify that no data is written? |
| 98 message_loop_.RunAllPending(); | 94 message_loop_.RunAllPending(); |
| 99 } | 95 } |
| 100 | 96 |
| 101 TEST_F(ConnectionToClientTest, StateChange) { | 97 TEST_F(ConnectionToClientTest, StateChange) { |
| 102 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), OK)); | 98 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), OK)); |
| 103 session_->state_change_callback().Run(protocol::Session::CLOSED); | 99 session_->state_change_callback().Run(protocol::Session::CLOSED); |
| 104 message_loop_.RunAllPending(); | 100 message_loop_.RunAllPending(); |
| 105 | 101 |
| 106 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), SESSION_REJECTED)); | 102 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), SESSION_REJECTED)); |
| 107 session_->set_error(SESSION_REJECTED); | 103 session_->set_error(SESSION_REJECTED); |
| 108 session_->state_change_callback().Run(protocol::Session::FAILED); | 104 session_->state_change_callback().Run(protocol::Session::FAILED); |
| 109 message_loop_.RunAllPending(); | 105 message_loop_.RunAllPending(); |
| 110 } | 106 } |
| 111 | 107 |
| 112 } // namespace protocol | 108 } // namespace protocol |
| 113 } // namespace remoting | 109 } // namespace remoting |
| OLD | NEW |