| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ice_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/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "remoting/base/constants.h" | 10 #include "remoting/base/constants.h" |
| 11 #include "remoting/protocol/fake_session.h" | 11 #include "remoting/protocol/fake_session.h" |
| 12 #include "remoting/protocol/protocol_mock_objects.h" | 12 #include "remoting/protocol/protocol_mock_objects.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 | 14 |
| 15 using ::testing::_; | 15 using ::testing::_; |
| 16 using ::testing::InvokeWithoutArgs; | 16 using ::testing::InvokeWithoutArgs; |
| 17 using ::testing::NotNull; | 17 using ::testing::NotNull; |
| 18 using ::testing::StrictMock; | 18 using ::testing::StrictMock; |
| 19 | 19 |
| 20 namespace remoting { | 20 namespace remoting { |
| 21 namespace protocol { | 21 namespace protocol { |
| 22 | 22 |
| 23 class ConnectionToClientTest : public testing::Test { | 23 class IpcConnectionToClientTest : public testing::Test { |
| 24 public: | 24 public: |
| 25 ConnectionToClientTest() { | 25 IpcConnectionToClientTest() {} |
| 26 } | |
| 27 | 26 |
| 28 protected: | 27 protected: |
| 29 void SetUp() override { | 28 void SetUp() override { |
| 30 session_ = new FakeSession(); | 29 session_ = new FakeSession(); |
| 31 | 30 |
| 32 // Allocate a ClientConnection object with the mock objects. | 31 // Allocate a ClientConnection object with the mock objects. |
| 33 viewer_.reset(new ConnectionToClient(session_)); | 32 viewer_.reset(new IceConnectionToClient(make_scoped_ptr(session_))); |
| 34 viewer_->SetEventHandler(&handler_); | 33 viewer_->SetEventHandler(&handler_); |
| 35 EXPECT_CALL(handler_, OnConnectionAuthenticated(viewer_.get())) | 34 EXPECT_CALL(handler_, OnConnectionAuthenticated(viewer_.get())) |
| 36 .WillOnce( | 35 .WillOnce( |
| 37 InvokeWithoutArgs(this, &ConnectionToClientTest::ConnectStubs)); | 36 InvokeWithoutArgs(this, &IpcConnectionToClientTest::ConnectStubs)); |
| 38 EXPECT_CALL(handler_, OnConnectionChannelsConnected(viewer_.get())); | 37 EXPECT_CALL(handler_, OnConnectionChannelsConnected(viewer_.get())); |
| 39 session_->event_handler()->OnSessionStateChange(Session::CONNECTED); | 38 session_->event_handler()->OnSessionStateChange(Session::CONNECTED); |
| 40 session_->event_handler()->OnSessionStateChange(Session::AUTHENTICATED); | 39 session_->event_handler()->OnSessionStateChange(Session::AUTHENTICATED); |
| 41 base::RunLoop().RunUntilIdle(); | 40 base::RunLoop().RunUntilIdle(); |
| 42 } | 41 } |
| 43 | 42 |
| 44 void TearDown() override { | 43 void TearDown() override { |
| 45 viewer_.reset(); | 44 viewer_.reset(); |
| 46 base::RunLoop().RunUntilIdle(); | 45 base::RunLoop().RunUntilIdle(); |
| 47 } | 46 } |
| 48 | 47 |
| 49 void ConnectStubs() { | 48 void ConnectStubs() { |
| 50 viewer_->set_clipboard_stub(&clipboard_stub_); | 49 viewer_->set_clipboard_stub(&clipboard_stub_); |
| 51 viewer_->set_host_stub(&host_stub_); | 50 viewer_->set_host_stub(&host_stub_); |
| 52 viewer_->set_input_stub(&input_stub_); | 51 viewer_->set_input_stub(&input_stub_); |
| 53 } | 52 } |
| 54 | 53 |
| 55 base::MessageLoop message_loop_; | 54 base::MessageLoop message_loop_; |
| 56 MockConnectionToClientEventHandler handler_; | 55 MockConnectionToClientEventHandler handler_; |
| 57 MockClipboardStub clipboard_stub_; | 56 MockClipboardStub clipboard_stub_; |
| 58 MockHostStub host_stub_; | 57 MockHostStub host_stub_; |
| 59 MockInputStub input_stub_; | 58 MockInputStub input_stub_; |
| 60 scoped_ptr<ConnectionToClient> viewer_; | 59 scoped_ptr<ConnectionToClient> viewer_; |
| 61 | 60 |
| 62 // Owned by |viewer_|. | |
| 63 FakeSession* session_; | 61 FakeSession* session_; |
| 64 | 62 |
| 65 private: | 63 private: |
| 66 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest); | 64 DISALLOW_COPY_AND_ASSIGN(IpcConnectionToClientTest); |
| 67 }; | 65 }; |
| 68 | 66 |
| 69 TEST_F(ConnectionToClientTest, SendUpdateStream) { | 67 TEST_F(IpcConnectionToClientTest, SendUpdateStream) { |
| 70 scoped_ptr<VideoPacket> packet(new VideoPacket()); | 68 scoped_ptr<VideoPacket> packet(new VideoPacket()); |
| 71 viewer_->video_stub()->ProcessVideoPacket(packet.Pass(), base::Closure()); | 69 viewer_->video_stub()->ProcessVideoPacket(packet.Pass(), base::Closure()); |
| 72 | 70 |
| 73 base::RunLoop().RunUntilIdle(); | 71 base::RunLoop().RunUntilIdle(); |
| 74 | 72 |
| 75 // Verify that something has been written. | 73 // Verify that something has been written. |
| 76 // TODO(sergeyu): Verify that the correct data has been written. | 74 // TODO(sergeyu): Verify that the correct data has been written. |
| 77 FakeStreamSocket* channel = | 75 FakeStreamSocket* channel = |
| 78 session_->GetTransport()->GetStreamChannelFactory()->GetFakeChannel( | 76 session_->GetTransport()->GetStreamChannelFactory()->GetFakeChannel( |
| 79 kVideoChannelName); | 77 kVideoChannelName); |
| 80 ASSERT_TRUE(channel); | 78 ASSERT_TRUE(channel); |
| 81 EXPECT_FALSE(channel->written_data().empty()); | 79 EXPECT_FALSE(channel->written_data().empty()); |
| 82 | 80 |
| 83 // And then close the connection to ConnectionToClient. | 81 // And then close the connection to ConnectionToClient. |
| 84 viewer_->Disconnect(protocol::OK); | 82 viewer_->Disconnect(protocol::OK); |
| 85 | 83 |
| 86 base::RunLoop().RunUntilIdle(); | 84 base::RunLoop().RunUntilIdle(); |
| 87 } | 85 } |
| 88 | 86 |
| 89 TEST_F(ConnectionToClientTest, NoWriteAfterDisconnect) { | 87 TEST_F(IpcConnectionToClientTest, NoWriteAfterDisconnect) { |
| 90 scoped_ptr<VideoPacket> packet(new VideoPacket()); | 88 scoped_ptr<VideoPacket> packet(new VideoPacket()); |
| 91 viewer_->video_stub()->ProcessVideoPacket(packet.Pass(), base::Closure()); | 89 viewer_->video_stub()->ProcessVideoPacket(packet.Pass(), base::Closure()); |
| 92 | 90 |
| 93 // And then close the connection to ConnectionToClient. | 91 // And then close the connection to ConnectionToClient. |
| 94 viewer_->Disconnect(protocol::OK); | 92 viewer_->Disconnect(protocol::OK); |
| 95 | 93 |
| 96 // The test will crash if data writer tries to write data to the | 94 // The test will crash if data writer tries to write data to the |
| 97 // channel socket. | 95 // channel socket. |
| 98 // TODO(sergeyu): Use MockSession to verify that no data is written? | 96 // TODO(sergeyu): Use MockSession to verify that no data is written? |
| 99 base::RunLoop().RunUntilIdle(); | 97 base::RunLoop().RunUntilIdle(); |
| 100 } | 98 } |
| 101 | 99 |
| 102 TEST_F(ConnectionToClientTest, StateChange) { | 100 TEST_F(IpcConnectionToClientTest, StateChange) { |
| 103 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), OK)); | 101 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), OK)); |
| 104 session_->event_handler()->OnSessionStateChange(Session::CLOSED); | 102 session_->event_handler()->OnSessionStateChange(Session::CLOSED); |
| 105 base::RunLoop().RunUntilIdle(); | 103 base::RunLoop().RunUntilIdle(); |
| 106 | 104 |
| 107 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), SESSION_REJECTED)); | 105 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), SESSION_REJECTED)); |
| 108 session_->set_error(SESSION_REJECTED); | 106 session_->set_error(SESSION_REJECTED); |
| 109 session_->event_handler()->OnSessionStateChange(Session::FAILED); | 107 session_->event_handler()->OnSessionStateChange(Session::FAILED); |
| 110 base::RunLoop().RunUntilIdle(); | 108 base::RunLoop().RunUntilIdle(); |
| 111 } | 109 } |
| 112 | 110 |
| 113 } // namespace protocol | 111 } // namespace protocol |
| 114 } // namespace remoting | 112 } // namespace remoting |
| OLD | NEW |