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_stub.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 |
| 24 namespace { |
| 25 |
| 26 void IgnoreProgress(VideoStub::PacketProgress progress) { |
| 27 } |
| 28 |
| 29 } |
| 30 |
23 class ConnectionToClientTest : public testing::Test { | 31 class ConnectionToClientTest : public testing::Test { |
24 public: | 32 public: |
25 ConnectionToClientTest() { | 33 ConnectionToClientTest() { |
26 } | 34 } |
27 | 35 |
28 protected: | 36 protected: |
29 void SetUp() override { | 37 void SetUp() override { |
30 session_ = new FakeSession(); | 38 session_ = new FakeSession(); |
31 | 39 |
32 // Allocate a ClientConnection object with the mock objects. | 40 // Allocate a ClientConnection object with the mock objects. |
(...skipping 23 matching lines...) Expand all Loading... |
56 | 64 |
57 // Owned by |viewer_|. | 65 // Owned by |viewer_|. |
58 FakeSession* session_; | 66 FakeSession* session_; |
59 | 67 |
60 private: | 68 private: |
61 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest); | 69 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest); |
62 }; | 70 }; |
63 | 71 |
64 TEST_F(ConnectionToClientTest, SendUpdateStream) { | 72 TEST_F(ConnectionToClientTest, SendUpdateStream) { |
65 scoped_ptr<VideoPacket> packet(new VideoPacket()); | 73 scoped_ptr<VideoPacket> packet(new VideoPacket()); |
66 viewer_->video_stub()->ProcessVideoPacket(packet.Pass(), base::Closure()); | 74 viewer_->video_stub()->ProcessVideoPacket(packet.Pass(), |
| 75 base::Bind(&IgnoreProgress)); |
67 | 76 |
68 base::RunLoop().RunUntilIdle(); | 77 base::RunLoop().RunUntilIdle(); |
69 | 78 |
70 // Verify that something has been written. | 79 // Verify that something has been written. |
71 // TODO(sergeyu): Verify that the correct data has been written. | 80 // TODO(sergeyu): Verify that the correct data has been written. |
72 ASSERT_TRUE( | 81 ASSERT_TRUE( |
73 session_->fake_channel_factory().GetFakeChannel(kVideoChannelName)); | 82 session_->fake_channel_factory().GetFakeChannel(kVideoChannelName)); |
74 EXPECT_FALSE(session_->fake_channel_factory() | 83 EXPECT_FALSE(session_->fake_channel_factory() |
75 .GetFakeChannel(kVideoChannelName)->written_data().empty()); | 84 .GetFakeChannel(kVideoChannelName)->written_data().empty()); |
76 | 85 |
77 // And then close the connection to ConnectionToClient. | 86 // And then close the connection to ConnectionToClient. |
78 viewer_->Disconnect(); | 87 viewer_->Disconnect(); |
79 | 88 |
80 base::RunLoop().RunUntilIdle(); | 89 base::RunLoop().RunUntilIdle(); |
81 } | 90 } |
82 | 91 |
83 TEST_F(ConnectionToClientTest, NoWriteAfterDisconnect) { | 92 TEST_F(ConnectionToClientTest, NoWriteAfterDisconnect) { |
84 scoped_ptr<VideoPacket> packet(new VideoPacket()); | 93 scoped_ptr<VideoPacket> packet(new VideoPacket()); |
85 viewer_->video_stub()->ProcessVideoPacket(packet.Pass(), base::Closure()); | 94 viewer_->video_stub()->ProcessVideoPacket(packet.Pass(), |
| 95 base::Bind(&IgnoreProgress)); |
86 | 96 |
87 // And then close the connection to ConnectionToClient. | 97 // And then close the connection to ConnectionToClient. |
88 viewer_->Disconnect(); | 98 viewer_->Disconnect(); |
89 | 99 |
90 // The test will crash if data writer tries to write data to the | 100 // The test will crash if data writer tries to write data to the |
91 // channel socket. | 101 // channel socket. |
92 // TODO(sergeyu): Use MockSession to verify that no data is written? | 102 // TODO(sergeyu): Use MockSession to verify that no data is written? |
93 base::RunLoop().RunUntilIdle(); | 103 base::RunLoop().RunUntilIdle(); |
94 } | 104 } |
95 | 105 |
96 TEST_F(ConnectionToClientTest, StateChange) { | 106 TEST_F(ConnectionToClientTest, StateChange) { |
97 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), OK)); | 107 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), OK)); |
98 session_->event_handler()->OnSessionStateChange(Session::CLOSED); | 108 session_->event_handler()->OnSessionStateChange(Session::CLOSED); |
99 base::RunLoop().RunUntilIdle(); | 109 base::RunLoop().RunUntilIdle(); |
100 | 110 |
101 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), SESSION_REJECTED)); | 111 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), SESSION_REJECTED)); |
102 session_->set_error(SESSION_REJECTED); | 112 session_->set_error(SESSION_REJECTED); |
103 session_->event_handler()->OnSessionStateChange(Session::FAILED); | 113 session_->event_handler()->OnSessionStateChange(Session::FAILED); |
104 base::RunLoop().RunUntilIdle(); | 114 base::RunLoop().RunUntilIdle(); |
105 } | 115 } |
106 | 116 |
107 } // namespace protocol | 117 } // namespace protocol |
108 } // namespace remoting | 118 } // namespace remoting |
OLD | NEW |