| 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/task.h" | 5 #include "base/task.h" |
| 6 #include "remoting/host/capturer_fake.h" | 6 #include "remoting/host/capturer_fake.h" |
| 7 #include "remoting/host/chromoting_host.h" | 7 #include "remoting/host/chromoting_host.h" |
| 8 #include "remoting/host/chromoting_host_context.h" | 8 #include "remoting/host/chromoting_host_context.h" |
| 9 #include "remoting/host/desktop_environment_fake.h" | 9 #include "remoting/host/desktop_environment_fake.h" |
| 10 #include "remoting/host/host_mock_objects.h" | 10 #include "remoting/host/host_mock_objects.h" |
| 11 #include "remoting/host/in_memory_host_config.h" | 11 #include "remoting/host/in_memory_host_config.h" |
| 12 #include "remoting/proto/video.pb.h" | 12 #include "remoting/proto/video.pb.h" |
| 13 #include "remoting/protocol/protocol_mock_objects.h" | 13 #include "remoting/protocol/protocol_mock_objects.h" |
| 14 #include "remoting/protocol/session_config.h" | 14 #include "remoting/protocol/session_config.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 using ::remoting::protocol::LocalLoginCredentials; |
| 19 using ::remoting::protocol::MockClientStub; |
| 20 using ::remoting::protocol::MockConnectionToClient; |
| 21 using ::remoting::protocol::MockConnectionToClientEventHandler; |
| 22 using ::remoting::protocol::MockHostStub; |
| 23 using ::remoting::protocol::MockInputStub; |
| 24 using ::remoting::protocol::MockSession; |
| 25 using ::remoting::protocol::MockVideoStub; |
| 26 using ::remoting::protocol::SessionConfig; |
| 27 |
| 18 using testing::_; | 28 using testing::_; |
| 19 using testing::AnyNumber; | 29 using testing::AnyNumber; |
| 20 using testing::DeleteArg; | 30 using testing::DeleteArg; |
| 21 using testing::DoAll; | 31 using testing::DoAll; |
| 22 using testing::InSequence; | 32 using testing::InSequence; |
| 23 using testing::InvokeWithoutArgs; | 33 using testing::InvokeWithoutArgs; |
| 24 using testing::Return; | 34 using testing::Return; |
| 25 | 35 |
| 26 namespace remoting { | 36 namespace remoting { |
| 27 | 37 |
| 28 namespace { | 38 namespace { |
| 29 | 39 |
| 30 void PostQuitTask(MessageLoop* message_loop) { | 40 void PostQuitTask(MessageLoop* message_loop) { |
| 31 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 41 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 32 } | 42 } |
| 33 | 43 |
| 34 void BeginSessionRequest(protocol::HostStub* host_stub) { | 44 void BeginSessionRequest(protocol::HostStub* host_stub) { |
| 35 protocol::LocalLoginCredentials* credentials = | 45 LocalLoginCredentials* credentials = |
| 36 new protocol::LocalLoginCredentials(); | 46 new LocalLoginCredentials(); |
| 37 credentials->set_type(protocol::PASSWORD); | 47 credentials->set_type(protocol::PASSWORD); |
| 38 credentials->set_username("hello"); | 48 credentials->set_username("hello"); |
| 39 | 49 |
| 40 const std::string password = "world!"; | 50 const std::string password = "world!"; |
| 41 credentials->set_credential(password.data(), password.length()); | 51 credentials->set_credential(password.data(), password.length()); |
| 42 | 52 |
| 43 host_stub->BeginSessionRequest( | 53 host_stub->BeginSessionRequest( |
| 44 credentials, | 54 credentials, |
| 45 new DeleteTask<protocol::LocalLoginCredentials>(credentials)); | 55 new DeleteTask<LocalLoginCredentials>(credentials)); |
| 46 } | 56 } |
| 47 | 57 |
| 48 // Run the task and delete it afterwards. This action is used to deal with | 58 // Run the task and delete it afterwards. This action is used to deal with |
| 49 // done callbacks. | 59 // done callbacks. |
| 50 ACTION(RunDoneTask) { | 60 ACTION(RunDoneTask) { |
| 51 arg1->Run(); | 61 arg1->Run(); |
| 52 delete arg1; | 62 delete arg1; |
| 53 } | 63 } |
| 54 | 64 |
| 55 ACTION_P(QuitMainMessageLoop, message_loop) { | 65 ACTION_P(QuitMainMessageLoop, message_loop) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 72 ON_CALL(context_, network_message_loop()) | 82 ON_CALL(context_, network_message_loop()) |
| 73 .WillByDefault(Return(&message_loop_)); | 83 .WillByDefault(Return(&message_loop_)); |
| 74 EXPECT_CALL(context_, main_message_loop()) | 84 EXPECT_CALL(context_, main_message_loop()) |
| 75 .Times(AnyNumber()); | 85 .Times(AnyNumber()); |
| 76 EXPECT_CALL(context_, encode_message_loop()) | 86 EXPECT_CALL(context_, encode_message_loop()) |
| 77 .Times(AnyNumber()); | 87 .Times(AnyNumber()); |
| 78 EXPECT_CALL(context_, network_message_loop()) | 88 EXPECT_CALL(context_, network_message_loop()) |
| 79 .Times(AnyNumber()); | 89 .Times(AnyNumber()); |
| 80 | 90 |
| 81 Capturer* capturer = new CapturerFake(context_.main_message_loop()); | 91 Capturer* capturer = new CapturerFake(context_.main_message_loop()); |
| 82 input_stub_ = new protocol::MockInputStub(); | 92 host_stub_ = new MockHostStub(); |
| 93 input_stub_ = new MockInputStub(); |
| 83 DesktopEnvironment* desktop = | 94 DesktopEnvironment* desktop = |
| 84 new DesktopEnvironmentFake(capturer, input_stub_); | 95 new DesktopEnvironmentFake(capturer, input_stub_); |
| 85 host_ = ChromotingHost::Create(&context_, config_, desktop); | 96 host_ = ChromotingHost::Create(&context_, config_, desktop); |
| 86 connection_ = new protocol::MockConnectionToClient(); | 97 connection_ = new MockConnectionToClient( |
| 87 session_ = new protocol::MockSession(); | 98 &message_loop_, &handler_, host_stub_, input_stub_); |
| 88 session_config_.reset(protocol::SessionConfig::CreateDefault()); | 99 session_ = new MockSession(); |
| 100 session_config_.reset(SessionConfig::CreateDefault()); |
| 89 | 101 |
| 90 ON_CALL(video_stub_, ProcessVideoPacket(_, _)) | 102 ON_CALL(video_stub_, ProcessVideoPacket(_, _)) |
| 91 .WillByDefault( | 103 .WillByDefault( |
| 92 DoAll(DeleteArg<0>(), DeleteArg<1>())); | 104 DoAll(DeleteArg<0>(), DeleteArg<1>())); |
| 93 ON_CALL(*connection_.get(), video_stub()) | 105 ON_CALL(*connection_.get(), video_stub()) |
| 94 .WillByDefault(Return(&video_stub_)); | 106 .WillByDefault(Return(&video_stub_)); |
| 95 ON_CALL(*connection_.get(), client_stub()) | 107 ON_CALL(*connection_.get(), client_stub()) |
| 96 .WillByDefault(Return(&client_stub_)); | 108 .WillByDefault(Return(&client_stub_)); |
| 97 ON_CALL(*connection_.get(), session()) | 109 ON_CALL(*connection_.get(), session()) |
| 98 .WillByDefault(Return(session_)); | 110 .WillByDefault(Return(session_)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 void RemoveClientConnection() { | 144 void RemoveClientConnection() { |
| 133 context_.network_message_loop()->PostTask( | 145 context_.network_message_loop()->PostTask( |
| 134 FROM_HERE, | 146 FROM_HERE, |
| 135 NewRunnableMethod(host_.get(), | 147 NewRunnableMethod(host_.get(), |
| 136 &ChromotingHost::OnClientDisconnected, | 148 &ChromotingHost::OnClientDisconnected, |
| 137 connection_)); | 149 connection_)); |
| 138 } | 150 } |
| 139 | 151 |
| 140 protected: | 152 protected: |
| 141 MessageLoop message_loop_; | 153 MessageLoop message_loop_; |
| 154 MockConnectionToClientEventHandler handler_; |
| 142 scoped_refptr<ChromotingHost> host_; | 155 scoped_refptr<ChromotingHost> host_; |
| 143 scoped_refptr<InMemoryHostConfig> config_; | 156 scoped_refptr<InMemoryHostConfig> config_; |
| 144 MockChromotingHostContext context_; | 157 MockChromotingHostContext context_; |
| 145 scoped_refptr<protocol::MockConnectionToClient> connection_; | 158 scoped_refptr<MockConnectionToClient> connection_; |
| 146 scoped_refptr<protocol::MockSession> session_; | 159 scoped_refptr<MockSession> session_; |
| 147 scoped_ptr<protocol::SessionConfig> session_config_; | 160 scoped_ptr<SessionConfig> session_config_; |
| 148 protocol::MockVideoStub video_stub_; | 161 MockVideoStub video_stub_; |
| 149 protocol::MockClientStub client_stub_; | 162 MockClientStub client_stub_; |
| 150 protocol::MockInputStub* input_stub_; | 163 MockHostStub* host_stub_; |
| 164 MockInputStub* input_stub_; |
| 151 }; | 165 }; |
| 152 | 166 |
| 153 TEST_F(ChromotingHostTest, StartAndShutdown) { | 167 TEST_F(ChromotingHostTest, StartAndShutdown) { |
| 154 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_)); | 168 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_)); |
| 155 | 169 |
| 156 message_loop_.PostTask(FROM_HERE, | 170 message_loop_.PostTask(FROM_HERE, |
| 157 NewRunnableMethod(host_.get(), | 171 NewRunnableMethod(host_.get(), |
| 158 &ChromotingHost::Shutdown)); | 172 &ChromotingHost::Shutdown)); |
| 159 message_loop_.Run(); | 173 message_loop_.Run(); |
| 160 } | 174 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 .Times(AnyNumber()); | 237 .Times(AnyNumber()); |
| 224 } | 238 } |
| 225 EXPECT_CALL(*connection_.get(), Disconnect()) | 239 EXPECT_CALL(*connection_.get(), Disconnect()) |
| 226 .RetiresOnSaturation(); | 240 .RetiresOnSaturation(); |
| 227 | 241 |
| 228 SimulateClientConnection(); | 242 SimulateClientConnection(); |
| 229 message_loop_.Run(); | 243 message_loop_.Run(); |
| 230 } | 244 } |
| 231 | 245 |
| 232 } // namespace remoting | 246 } // namespace remoting |
| OLD | NEW |