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 <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/test/test_simple_task_runner.h" | 13 #include "base/test/test_simple_task_runner.h" |
14 #include "remoting/base/auto_thread_task_runner.h" | 14 #include "remoting/base/auto_thread_task_runner.h" |
15 #include "remoting/base/constants.h" | 15 #include "remoting/base/constants.h" |
16 #include "remoting/host/audio_capturer.h" | 16 #include "remoting/host/audio_capturer.h" |
17 #include "remoting/host/client_session.h" | 17 #include "remoting/host/client_session.h" |
18 #include "remoting/host/desktop_environment.h" | 18 #include "remoting/host/desktop_environment.h" |
19 #include "remoting/host/fake_host_extension.h" | 19 #include "remoting/host/fake_host_extension.h" |
20 #include "remoting/host/fake_mouse_cursor_monitor.h" | 20 #include "remoting/host/fake_mouse_cursor_monitor.h" |
21 #include "remoting/host/host_extension.h" | 21 #include "remoting/host/host_extension.h" |
22 #include "remoting/host/host_extension_session.h" | 22 #include "remoting/host/host_extension_session.h" |
23 #include "remoting/host/host_mock_objects.h" | 23 #include "remoting/host/host_mock_objects.h" |
| 24 #include "remoting/protocol/fake_connection_to_client.h" |
24 #include "remoting/protocol/fake_desktop_capturer.h" | 25 #include "remoting/protocol/fake_desktop_capturer.h" |
25 #include "remoting/protocol/protocol_mock_objects.h" | 26 #include "remoting/protocol/protocol_mock_objects.h" |
26 #include "remoting/protocol/test_event_matchers.h" | 27 #include "remoting/protocol/test_event_matchers.h" |
27 #include "testing/gmock/include/gmock/gmock-matchers.h" | 28 #include "testing/gmock/include/gmock/gmock-matchers.h" |
28 #include "testing/gmock_mutant.h" | 29 #include "testing/gmock_mutant.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
30 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 31 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
31 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" | 32 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" |
32 #include "third_party/webrtc/modules/desktop_capture/screen_capturer_mock_object
s.h" | 33 #include "third_party/webrtc/modules/desktop_capture/screen_capturer_mock_object
s.h" |
33 | 34 |
34 namespace remoting { | 35 namespace remoting { |
35 | 36 |
36 using protocol::MockClientStub; | 37 using protocol::MockClientStub; |
37 using protocol::MockConnectionToClient; | |
38 using protocol::MockHostStub; | 38 using protocol::MockHostStub; |
39 using protocol::MockInputStub; | 39 using protocol::MockInputStub; |
40 using protocol::MockSession; | 40 using protocol::MockSession; |
41 using protocol::MockVideoStub; | 41 using protocol::MockVideoStub; |
42 using protocol::SessionConfig; | 42 using protocol::SessionConfig; |
43 using protocol::test::EqualsClipboardEvent; | 43 using protocol::test::EqualsClipboardEvent; |
44 using protocol::test::EqualsMouseButtonEvent; | 44 using protocol::test::EqualsMouseButtonEvent; |
45 using protocol::test::EqualsMouseMoveEvent; | 45 using protocol::test::EqualsMouseMoveEvent; |
46 using protocol::test::EqualsKeyEvent; | 46 using protocol::test::EqualsKeyEvent; |
47 | 47 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 186 |
187 // Stubs returned to |client_session_| components by |connection_|. | 187 // Stubs returned to |client_session_| components by |connection_|. |
188 MockClientStub client_stub_; | 188 MockClientStub client_stub_; |
189 MockVideoStub video_stub_; | 189 MockVideoStub video_stub_; |
190 | 190 |
191 // DesktopEnvironment owns |input_injector_|, but input injection tests need | 191 // DesktopEnvironment owns |input_injector_|, but input injection tests need |
192 // to express expectations on it. | 192 // to express expectations on it. |
193 scoped_ptr<MockInputInjector> input_injector_; | 193 scoped_ptr<MockInputInjector> input_injector_; |
194 | 194 |
195 // ClientSession owns |connection_| but tests need it to inject fake events. | 195 // ClientSession owns |connection_| but tests need it to inject fake events. |
196 MockConnectionToClient* connection_; | 196 protocol::FakeConnectionToClient* connection_; |
197 | 197 |
198 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; | 198 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; |
199 }; | 199 }; |
200 | 200 |
201 void ClientSessionTest::SetUp() { | 201 void ClientSessionTest::SetUp() { |
202 // Arrange to run |message_loop_| until no components depend on it. | 202 // Arrange to run |message_loop_| until no components depend on it. |
203 task_runner_ = new AutoThreadTaskRunner( | 203 task_runner_ = new AutoThreadTaskRunner( |
204 message_loop_.task_runner(), run_loop_.QuitClosure()); | 204 message_loop_.task_runner(), run_loop_.QuitClosure()); |
205 | 205 |
206 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); | 206 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); |
(...skipping 18 matching lines...) Expand all Loading... |
225 } | 225 } |
226 | 226 |
227 void ClientSessionTest::CreateClientSession() { | 227 void ClientSessionTest::CreateClientSession() { |
228 // Mock protocol::Session APIs called directly by ClientSession. | 228 // Mock protocol::Session APIs called directly by ClientSession. |
229 scoped_ptr<protocol::MockSession> session(new MockSession()); | 229 scoped_ptr<protocol::MockSession> session(new MockSession()); |
230 EXPECT_CALL(*session, config()).WillRepeatedly(ReturnRef(*session_config_)); | 230 EXPECT_CALL(*session, config()).WillRepeatedly(ReturnRef(*session_config_)); |
231 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); | 231 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); |
232 | 232 |
233 // Mock protocol::ConnectionToClient APIs called directly by ClientSession. | 233 // Mock protocol::ConnectionToClient APIs called directly by ClientSession. |
234 // HostStub is not touched by ClientSession, so we can safely pass nullptr. | 234 // HostStub is not touched by ClientSession, so we can safely pass nullptr. |
235 scoped_ptr<MockConnectionToClient> connection( | 235 scoped_ptr<protocol::FakeConnectionToClient> connection( |
236 new MockConnectionToClient(session.Pass(), nullptr)); | 236 new protocol::FakeConnectionToClient(session.Pass())); |
237 EXPECT_CALL(*connection, client_stub()) | 237 connection->set_client_stub(&client_stub_); |
238 .WillRepeatedly(Return(&client_stub_)); | 238 connection->set_video_stub(&video_stub_); |
239 EXPECT_CALL(*connection, video_stub()).WillRepeatedly(Return(&video_stub_)); | |
240 EXPECT_CALL(*connection, Disconnect(_)); | |
241 connection_ = connection.get(); | 239 connection_ = connection.get(); |
242 | 240 |
243 client_session_.reset(new ClientSession( | 241 client_session_.reset(new ClientSession( |
244 &session_event_handler_, | 242 &session_event_handler_, |
245 task_runner_, // Audio thread. | 243 task_runner_, // Audio thread. |
246 task_runner_, // Input thread. | 244 task_runner_, // Input thread. |
247 task_runner_, // Capture thread. | 245 task_runner_, // Capture thread. |
248 task_runner_, // Encode thread. | 246 task_runner_, // Encode thread. |
249 task_runner_, // Network thread. | 247 task_runner_, // Network thread. |
250 task_runner_, // UI thread. | 248 task_runner_, // UI thread. |
251 connection.Pass(), | 249 connection.Pass(), |
252 desktop_environment_factory_.get(), | 250 desktop_environment_factory_.get(), |
253 base::TimeDelta(), | 251 base::TimeDelta(), |
254 nullptr, | 252 nullptr, |
255 extensions_)); | 253 extensions_)); |
256 } | 254 } |
257 | 255 |
258 void ClientSessionTest::DisconnectClientSession() { | 256 void ClientSessionTest::DisconnectClientSession() { |
259 client_session_->DisconnectSession(protocol::OK); | 257 client_session_->DisconnectSession(protocol::OK); |
260 // MockSession won't trigger OnConnectionClosed, so fake it. | |
261 client_session_->OnConnectionClosed(client_session_->connection(), | |
262 protocol::OK); | |
263 } | 258 } |
264 | 259 |
265 void ClientSessionTest::StopClientSession() { | 260 void ClientSessionTest::StopClientSession() { |
266 client_session_.reset(); | 261 client_session_.reset(); |
267 | 262 |
268 desktop_environment_factory_.reset(); | 263 desktop_environment_factory_.reset(); |
269 } | 264 } |
270 | 265 |
271 DesktopEnvironment* ClientSessionTest::CreateDesktopEnvironment() { | 266 DesktopEnvironment* ClientSessionTest::CreateDesktopEnvironment() { |
272 MockDesktopEnvironment* desktop_environment = new MockDesktopEnvironment(); | 267 MockDesktopEnvironment* desktop_environment = new MockDesktopEnvironment(); |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 | 753 |
759 DisconnectClientSession(); | 754 DisconnectClientSession(); |
760 StopClientSession(); | 755 StopClientSession(); |
761 | 756 |
762 // ext1 was instantiated and wrapped the video capturer. | 757 // ext1 was instantiated and wrapped the video capturer. |
763 EXPECT_TRUE(extension.was_instantiated()); | 758 EXPECT_TRUE(extension.was_instantiated()); |
764 EXPECT_TRUE(extension.has_wrapped_video_capturer()); | 759 EXPECT_TRUE(extension.has_wrapped_video_capturer()); |
765 } | 760 } |
766 | 761 |
767 } // namespace remoting | 762 } // namespace remoting |
OLD | NEW |