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 "remoting/protocol/connection_to_client.h" | 5 #include "remoting/protocol/connection_to_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "remoting/base/constants.h" | 11 #include "remoting/base/constants.h" |
12 #include "remoting/protocol/fake_session.h" | 12 #include "remoting/protocol/fake_session.h" |
13 #include "remoting/protocol/protocol_mock_objects.h" | 13 #include "remoting/protocol/protocol_mock_objects.h" |
| 14 #include "remoting/protocol/video_sender.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
15 | 16 |
16 using ::testing::_; | 17 using ::testing::_; |
17 using ::testing::NotNull; | 18 using ::testing::NotNull; |
18 using ::testing::StrictMock; | 19 using ::testing::StrictMock; |
19 | 20 |
20 namespace remoting { | 21 namespace remoting { |
21 namespace protocol { | 22 namespace protocol { |
22 | 23 |
23 class ConnectionToClientTest : public testing::Test { | 24 class ConnectionToClientTest : public testing::Test { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 57 |
57 // Owned by |viewer_|. | 58 // Owned by |viewer_|. |
58 FakeSession* session_; | 59 FakeSession* session_; |
59 | 60 |
60 private: | 61 private: |
61 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest); | 62 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest); |
62 }; | 63 }; |
63 | 64 |
64 TEST_F(ConnectionToClientTest, SendUpdateStream) { | 65 TEST_F(ConnectionToClientTest, SendUpdateStream) { |
65 scoped_ptr<VideoPacket> packet(new VideoPacket()); | 66 scoped_ptr<VideoPacket> packet(new VideoPacket()); |
66 viewer_->video_stub()->ProcessVideoPacket(packet.Pass(), base::Closure()); | 67 viewer_->video_sender()->ProcessVideoPacket(packet.Pass(), base::Closure()); |
67 | 68 |
68 base::RunLoop().RunUntilIdle(); | 69 base::RunLoop().RunUntilIdle(); |
69 | 70 |
70 // Verify that something has been written. | 71 // Verify that something has been written. |
71 // TODO(sergeyu): Verify that the correct data has been written. | 72 // TODO(sergeyu): Verify that the correct data has been written. |
72 ASSERT_TRUE( | 73 ASSERT_TRUE( |
73 session_->fake_channel_factory().GetFakeChannel(kVideoChannelName)); | 74 session_->fake_channel_factory().GetFakeChannel(kVideoChannelName)); |
74 EXPECT_FALSE(session_->fake_channel_factory() | 75 EXPECT_FALSE(session_->fake_channel_factory() |
75 .GetFakeChannel(kVideoChannelName)->written_data().empty()); | 76 .GetFakeChannel(kVideoChannelName)->written_data().empty()); |
76 | 77 |
77 // And then close the connection to ConnectionToClient. | 78 // And then close the connection to ConnectionToClient. |
78 viewer_->Disconnect(); | 79 viewer_->Disconnect(); |
79 | 80 |
80 base::RunLoop().RunUntilIdle(); | 81 base::RunLoop().RunUntilIdle(); |
81 } | 82 } |
82 | 83 |
83 TEST_F(ConnectionToClientTest, NoWriteAfterDisconnect) { | 84 TEST_F(ConnectionToClientTest, NoWriteAfterDisconnect) { |
84 scoped_ptr<VideoPacket> packet(new VideoPacket()); | 85 scoped_ptr<VideoPacket> packet(new VideoPacket()); |
85 viewer_->video_stub()->ProcessVideoPacket(packet.Pass(), base::Closure()); | 86 viewer_->video_sender()->ProcessVideoPacket(packet.Pass(), base::Closure()); |
86 | 87 |
87 // And then close the connection to ConnectionToClient. | 88 // And then close the connection to ConnectionToClient. |
88 viewer_->Disconnect(); | 89 viewer_->Disconnect(); |
89 | 90 |
90 // 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 |
91 // channel socket. | 92 // channel socket. |
92 // TODO(sergeyu): Use MockSession to verify that no data is written? | 93 // TODO(sergeyu): Use MockSession to verify that no data is written? |
93 base::RunLoop().RunUntilIdle(); | 94 base::RunLoop().RunUntilIdle(); |
94 } | 95 } |
95 | 96 |
96 TEST_F(ConnectionToClientTest, StateChange) { | 97 TEST_F(ConnectionToClientTest, StateChange) { |
97 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), OK)); | 98 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), OK)); |
98 session_->event_handler()->OnSessionStateChange(Session::CLOSED); | 99 session_->event_handler()->OnSessionStateChange(Session::CLOSED); |
99 base::RunLoop().RunUntilIdle(); | 100 base::RunLoop().RunUntilIdle(); |
100 | 101 |
101 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), SESSION_REJECTED)); | 102 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), SESSION_REJECTED)); |
102 session_->set_error(SESSION_REJECTED); | 103 session_->set_error(SESSION_REJECTED); |
103 session_->event_handler()->OnSessionStateChange(Session::FAILED); | 104 session_->event_handler()->OnSessionStateChange(Session::FAILED); |
104 base::RunLoop().RunUntilIdle(); | 105 base::RunLoop().RunUntilIdle(); |
105 } | 106 } |
106 | 107 |
107 } // namespace protocol | 108 } // namespace protocol |
108 } // namespace remoting | 109 } // namespace remoting |
OLD | NEW |