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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
8 #include "remoting/jingle_glue/mock_objects.h" | 8 #include "remoting/jingle_glue/mock_objects.h" |
9 #include "remoting/host/audio_capturer.h" | 9 #include "remoting/host/audio_capturer.h" |
10 #include "remoting/host/chromoting_host_context.h" | 10 #include "remoting/host/chromoting_host_context.h" |
11 #include "remoting/host/chromoting_host.h" | 11 #include "remoting/host/chromoting_host.h" |
12 #include "remoting/host/desktop_environment.h" | |
13 #include "remoting/host/desktop_environment_factory.h" | |
14 #include "remoting/host/event_executor_fake.h" | |
15 #include "remoting/host/host_mock_objects.h" | 12 #include "remoting/host/host_mock_objects.h" |
16 #include "remoting/host/it2me_host_user_interface.h" | 13 #include "remoting/host/it2me_host_user_interface.h" |
17 #include "remoting/host/video_frame_capturer_fake.h" | 14 #include "remoting/host/video_frame_capturer_fake.h" |
18 #include "remoting/proto/video.pb.h" | 15 #include "remoting/proto/video.pb.h" |
19 #include "remoting/protocol/errors.h" | 16 #include "remoting/protocol/errors.h" |
20 #include "remoting/protocol/protocol_mock_objects.h" | 17 #include "remoting/protocol/protocol_mock_objects.h" |
21 #include "remoting/protocol/session_config.h" | 18 #include "remoting/protocol/session_config.h" |
22 #include "testing/gmock_mutant.h" | 19 #include "testing/gmock_mutant.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // done callbacks. | 55 // done callbacks. |
59 ACTION(RunDoneTask) { | 56 ACTION(RunDoneTask) { |
60 arg1.Run(); | 57 arg1.Run(); |
61 } | 58 } |
62 | 59 |
63 void DoNothing() { | 60 void DoNothing() { |
64 } | 61 } |
65 | 62 |
66 } // namespace | 63 } // namespace |
67 | 64 |
68 class MockDesktopEnvironmentFactory : public DesktopEnvironmentFactory { | |
69 public: | |
70 MockDesktopEnvironmentFactory(); | |
71 virtual ~MockDesktopEnvironmentFactory(); | |
72 | |
73 virtual scoped_ptr<DesktopEnvironment> Create( | |
74 ChromotingHostContext* context) OVERRIDE; | |
75 | |
76 private: | |
77 DISALLOW_COPY_AND_ASSIGN(MockDesktopEnvironmentFactory); | |
78 }; | |
79 | |
80 MockDesktopEnvironmentFactory::MockDesktopEnvironmentFactory() { | |
81 } | |
82 | |
83 MockDesktopEnvironmentFactory::~MockDesktopEnvironmentFactory() { | |
84 } | |
85 | |
86 scoped_ptr<DesktopEnvironment> MockDesktopEnvironmentFactory::Create( | |
87 ChromotingHostContext* context) { | |
88 scoped_ptr<EventExecutor> event_executor(new EventExecutorFake()); | |
89 scoped_ptr<VideoFrameCapturer> video_capturer(new VideoFrameCapturerFake()); | |
90 return scoped_ptr<DesktopEnvironment>(new DesktopEnvironment( | |
91 scoped_ptr<AudioCapturer>(NULL), | |
92 event_executor.Pass(), | |
93 video_capturer.Pass())); | |
94 } | |
95 | |
96 class ChromotingHostTest : public testing::Test { | 65 class ChromotingHostTest : public testing::Test { |
97 public: | 66 public: |
98 ChromotingHostTest() { | 67 ChromotingHostTest() { |
99 } | 68 } |
100 | 69 |
101 virtual void SetUp() OVERRIDE { | 70 virtual void SetUp() OVERRIDE { |
102 message_loop_proxy_ = base::MessageLoopProxy::current(); | 71 message_loop_proxy_ = base::MessageLoopProxy::current(); |
103 | 72 |
104 EXPECT_CALL(context_, ui_task_runner()) | 73 EXPECT_CALL(context_, ui_task_runner()) |
105 .Times(AnyNumber()) | 74 .Times(AnyNumber()) |
106 .WillRepeatedly(Return(message_loop_proxy_.get())); | 75 .WillRepeatedly(Return(message_loop_proxy_.get())); |
107 EXPECT_CALL(context_, capture_task_runner()) | 76 EXPECT_CALL(context_, capture_task_runner()) |
108 .Times(AnyNumber()) | 77 .Times(AnyNumber()) |
109 .WillRepeatedly(Return(message_loop_proxy_.get())); | 78 .WillRepeatedly(Return(message_loop_proxy_.get())); |
110 EXPECT_CALL(context_, encode_task_runner()) | 79 EXPECT_CALL(context_, encode_task_runner()) |
111 .Times(AnyNumber()) | 80 .Times(AnyNumber()) |
112 .WillRepeatedly(Return(message_loop_proxy_.get())); | 81 .WillRepeatedly(Return(message_loop_proxy_.get())); |
113 EXPECT_CALL(context_, network_task_runner()) | 82 EXPECT_CALL(context_, network_task_runner()) |
114 .Times(AnyNumber()) | 83 .Times(AnyNumber()) |
115 .WillRepeatedly(Return(message_loop_proxy_.get())); | 84 .WillRepeatedly(Return(message_loop_proxy_.get())); |
116 | 85 |
117 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); | 86 scoped_ptr<VideoFrameCapturer> capturer(new VideoFrameCapturerFake()); |
| 87 scoped_ptr<AudioCapturer> audio_capturer(NULL); |
| 88 event_executor_ = new MockEventExecutor(); |
| 89 desktop_environment_ = DesktopEnvironment::CreateFake( |
| 90 &context_, |
| 91 capturer.Pass(), |
| 92 scoped_ptr<EventExecutor>(event_executor_), |
| 93 audio_capturer.Pass()); |
118 session_manager_ = new protocol::MockSessionManager(); | 94 session_manager_ = new protocol::MockSessionManager(); |
119 | 95 |
120 host_ = new ChromotingHost( | 96 host_ = new ChromotingHost( |
121 &context_, &signal_strategy_, desktop_environment_factory_.get(), | 97 &context_, &signal_strategy_, desktop_environment_.get(), |
122 scoped_ptr<protocol::SessionManager>(session_manager_)); | 98 scoped_ptr<protocol::SessionManager>(session_manager_)); |
123 host_->AddStatusObserver(&host_status_observer_); | 99 host_->AddStatusObserver(&host_status_observer_); |
124 | 100 |
125 disconnect_window_ = new MockDisconnectWindow(); | 101 disconnect_window_ = new MockDisconnectWindow(); |
126 continue_window_ = new MockContinueWindow(); | 102 continue_window_ = new MockContinueWindow(); |
127 local_input_monitor_ = new MockLocalInputMonitor(); | 103 local_input_monitor_ = new MockLocalInputMonitor(); |
128 it2me_host_user_interface_.reset(new It2MeHostUserInterface(&context_)); | 104 it2me_host_user_interface_.reset(new It2MeHostUserInterface(&context_)); |
129 it2me_host_user_interface_->StartForTest( | 105 it2me_host_user_interface_->StartForTest( |
130 host_, | 106 host_, |
131 base::Bind(&ChromotingHost::Shutdown, host_, base::Closure()), | 107 base::Bind(&ChromotingHost::Shutdown, host_, base::Closure()), |
(...skipping 30 matching lines...) Expand all Loading... |
162 EXPECT_CALL(*session_unowned1_, SetEventHandler(_)) | 138 EXPECT_CALL(*session_unowned1_, SetEventHandler(_)) |
163 .Times(AnyNumber()) | 139 .Times(AnyNumber()) |
164 .WillRepeatedly(Invoke(this, &ChromotingHostTest::SetEventHandler)); | 140 .WillRepeatedly(Invoke(this, &ChromotingHostTest::SetEventHandler)); |
165 EXPECT_CALL(*session_unowned2_, SetEventHandler(_)) | 141 EXPECT_CALL(*session_unowned2_, SetEventHandler(_)) |
166 .Times(AnyNumber()); | 142 .Times(AnyNumber()); |
167 EXPECT_CALL(*session1_, config()) | 143 EXPECT_CALL(*session1_, config()) |
168 .WillRepeatedly(ReturnRef(session_config1_)); | 144 .WillRepeatedly(ReturnRef(session_config1_)); |
169 EXPECT_CALL(*session2_, config()) | 145 EXPECT_CALL(*session2_, config()) |
170 .WillRepeatedly(ReturnRef(session_config2_)); | 146 .WillRepeatedly(ReturnRef(session_config2_)); |
171 | 147 |
172 owned_connection1_.reset(new MockConnectionToClient(session1_, | 148 owned_connection1_.reset(new MockConnectionToClient( |
173 &host_stub1_)); | 149 session1_, &host_stub1_, desktop_environment_->event_executor())); |
174 connection1_ = owned_connection1_.get(); | 150 connection1_ = owned_connection1_.get(); |
175 owned_connection2_.reset(new MockConnectionToClient(session2_, | 151 owned_connection2_.reset(new MockConnectionToClient( |
176 &host_stub2_)); | 152 session2_, &host_stub2_, desktop_environment_->event_executor())); |
177 connection2_ = owned_connection2_.get(); | 153 connection2_ = owned_connection2_.get(); |
178 | 154 |
179 ON_CALL(video_stub1_, ProcessVideoPacketPtr(_, _)) | 155 ON_CALL(video_stub1_, ProcessVideoPacketPtr(_, _)) |
180 .WillByDefault(DeleteArg<0>()); | 156 .WillByDefault(DeleteArg<0>()); |
181 ON_CALL(video_stub2_, ProcessVideoPacketPtr(_, _)) | 157 ON_CALL(video_stub2_, ProcessVideoPacketPtr(_, _)) |
182 .WillByDefault(DeleteArg<0>()); | 158 .WillByDefault(DeleteArg<0>()); |
183 ON_CALL(*connection1_, video_stub()) | 159 ON_CALL(*connection1_, video_stub()) |
184 .WillByDefault(Return(&video_stub1_)); | 160 .WillByDefault(Return(&video_stub1_)); |
185 ON_CALL(*connection1_, client_stub()) | 161 ON_CALL(*connection1_, client_stub()) |
186 .WillByDefault(Return(&client_stub1_)); | 162 .WillByDefault(Return(&client_stub1_)); |
(...skipping 24 matching lines...) Expand all Loading... |
211 protocol::CandidateSessionConfig::CreateDefault(); | 187 protocol::CandidateSessionConfig::CreateDefault(); |
212 } | 188 } |
213 | 189 |
214 // Helper method to pretend a client is connected to ChromotingHost. | 190 // Helper method to pretend a client is connected to ChromotingHost. |
215 void SimulateClientConnection(int connection_index, bool authenticate, | 191 void SimulateClientConnection(int connection_index, bool authenticate, |
216 bool reject) { | 192 bool reject) { |
217 scoped_ptr<protocol::ConnectionToClient> connection = | 193 scoped_ptr<protocol::ConnectionToClient> connection = |
218 ((connection_index == 0) ? owned_connection1_ : owned_connection2_). | 194 ((connection_index == 0) ? owned_connection1_ : owned_connection2_). |
219 PassAs<protocol::ConnectionToClient>(); | 195 PassAs<protocol::ConnectionToClient>(); |
220 protocol::ConnectionToClient* connection_ptr = connection.get(); | 196 protocol::ConnectionToClient* connection_ptr = connection.get(); |
221 scoped_ptr<DesktopEnvironment> desktop_environment = | |
222 host_->desktop_environment_factory_->Create(&context_); | |
223 connection_ptr->set_input_stub(desktop_environment->event_executor()); | |
224 | |
225 ClientSession* client = new ClientSession( | 197 ClientSession* client = new ClientSession( |
226 host_.get(), | 198 host_.get(), |
227 context_.capture_task_runner(), | |
228 context_.encode_task_runner(), | |
229 context_.network_task_runner(), | |
230 connection.Pass(), | 199 connection.Pass(), |
231 host_->desktop_environment_factory_->Create(&context_), | 200 desktop_environment_->event_executor(), |
| 201 desktop_environment_->event_executor(), |
| 202 desktop_environment_->capturer(), |
232 base::TimeDelta()); | 203 base::TimeDelta()); |
233 connection_ptr->set_host_stub(client); | 204 connection_ptr->set_host_stub(client); |
234 | 205 |
235 context_.network_task_runner()->PostTask( | 206 context_.network_task_runner()->PostTask( |
236 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost, | 207 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost, |
237 host_, client)); | 208 host_, client)); |
238 | 209 |
239 if (authenticate) { | 210 if (authenticate) { |
240 context_.network_task_runner()->PostTask( | 211 context_.network_task_runner()->PostTask( |
241 FROM_HERE, base::Bind(&ClientSession::OnConnectionAuthenticated, | 212 FROM_HERE, base::Bind(&ClientSession::OnConnectionAuthenticated, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 // Do |action| when that happens. | 297 // Do |action| when that happens. |
327 template <class A> | 298 template <class A> |
328 Expectation ExpectClientConnected(int connection_index, A action) { | 299 Expectation ExpectClientConnected(int connection_index, A action) { |
329 const std::string& session_jid = get_session_jid(connection_index); | 300 const std::string& session_jid = get_session_jid(connection_index); |
330 MockVideoStub& video_stub = get_video_stub(connection_index); | 301 MockVideoStub& video_stub = get_video_stub(connection_index); |
331 | 302 |
332 Expectation client_authenticated = | 303 Expectation client_authenticated = |
333 EXPECT_CALL(host_status_observer_, OnClientAuthenticated(session_jid)); | 304 EXPECT_CALL(host_status_observer_, OnClientAuthenticated(session_jid)); |
334 EXPECT_CALL(host_status_observer_, OnClientConnected(session_jid)) | 305 EXPECT_CALL(host_status_observer_, OnClientConnected(session_jid)) |
335 .After(client_authenticated); | 306 .After(client_authenticated); |
| 307 Expectation session_started = |
| 308 EXPECT_CALL(*event_executor_, OnSessionStartedPtr(_)) |
| 309 .After(client_authenticated); |
336 Expectation video_packet_sent = | 310 Expectation video_packet_sent = |
337 EXPECT_CALL(video_stub, ProcessVideoPacketPtr(_, _)) | 311 EXPECT_CALL(video_stub, ProcessVideoPacketPtr(_, _)) |
338 .After(client_authenticated) | 312 .After(session_started) |
339 .WillOnce(DoAll( | 313 .WillOnce(DoAll( |
340 action, | 314 action, |
341 RunDoneTask())) | 315 RunDoneTask())) |
342 .RetiresOnSaturation(); | 316 .RetiresOnSaturation(); |
343 EXPECT_CALL(video_stub, ProcessVideoPacketPtr(_, _)) | 317 EXPECT_CALL(video_stub, ProcessVideoPacketPtr(_, _)) |
344 .Times(AnyNumber()) | 318 .Times(AnyNumber()) |
345 .After(video_packet_sent) | 319 .After(video_packet_sent) |
346 .WillRepeatedly(RunDoneTask()); | 320 .WillRepeatedly(RunDoneTask()); |
347 return video_packet_sent; | 321 return video_packet_sent; |
348 } | 322 } |
(...skipping 25 matching lines...) Expand all Loading... |
374 // Expect the side-effects of a client disconnection, after a given | 348 // Expect the side-effects of a client disconnection, after a given |
375 // expectation. The given action will be done after the event executor is | 349 // expectation. The given action will be done after the event executor is |
376 // notifed that the session has finished. | 350 // notifed that the session has finished. |
377 template <class A> | 351 template <class A> |
378 void ExpectClientDisconnectEffects(int connection_index, | 352 void ExpectClientDisconnectEffects(int connection_index, |
379 bool expect_host_status_change, | 353 bool expect_host_status_change, |
380 Expectation after, | 354 Expectation after, |
381 A action) { | 355 A action) { |
382 const std::string& session_jid = get_session_jid(connection_index); | 356 const std::string& session_jid = get_session_jid(connection_index); |
383 | 357 |
| 358 EXPECT_CALL(*event_executor_, OnSessionFinished()) |
| 359 .After(after) |
| 360 .WillOnce(action); |
384 if (expect_host_status_change) { | 361 if (expect_host_status_change) { |
385 EXPECT_CALL(host_status_observer_, OnClientDisconnected(session_jid)) | 362 EXPECT_CALL(host_status_observer_, OnClientDisconnected(session_jid)) |
386 .After(after) | 363 .After(after) |
387 .WillOnce(action) | |
388 .RetiresOnSaturation(); | 364 .RetiresOnSaturation(); |
389 } | 365 } |
390 } | 366 } |
391 | 367 |
392 protected: | 368 protected: |
393 MessageLoop message_loop_; | 369 MessageLoop message_loop_; |
394 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 370 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
395 MockChromotingHostContext context_; | 371 MockChromotingHostContext context_; |
396 MockConnectionToClientEventHandler handler_; | 372 MockConnectionToClientEventHandler handler_; |
397 MockSignalStrategy signal_strategy_; | 373 MockSignalStrategy signal_strategy_; |
398 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; | 374 MockEventExecutor* event_executor_; |
| 375 scoped_ptr<DesktopEnvironment> desktop_environment_; |
399 scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface_; | 376 scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface_; |
400 scoped_refptr<ChromotingHost> host_; | 377 scoped_refptr<ChromotingHost> host_; |
401 MockHostStatusObserver host_status_observer_; | 378 MockHostStatusObserver host_status_observer_; |
402 protocol::MockSessionManager* session_manager_; | 379 protocol::MockSessionManager* session_manager_; |
403 std::string xmpp_login_; | 380 std::string xmpp_login_; |
404 MockConnectionToClient* connection1_; | 381 MockConnectionToClient* connection1_; |
405 scoped_ptr<MockConnectionToClient> owned_connection1_; | 382 scoped_ptr<MockConnectionToClient> owned_connection1_; |
406 ClientSession* client1_; | 383 ClientSession* client1_; |
407 std::string session_jid1_; | 384 std::string session_jid1_; |
408 MockSession* session1_; // Owned by |connection_|. | 385 MockSession* session1_; // Owned by |connection_|. |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 ExpectClientDisconnected(0, true, video_packet_sent, | 632 ExpectClientDisconnected(0, true, video_packet_sent, |
656 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); | 633 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); |
657 EXPECT_CALL(host_status_observer_, OnShutdown()); | 634 EXPECT_CALL(host_status_observer_, OnShutdown()); |
658 | 635 |
659 host_->Start(xmpp_login_); | 636 host_->Start(xmpp_login_); |
660 SimulateClientConnection(0, true, false); | 637 SimulateClientConnection(0, true, false); |
661 message_loop_.Run(); | 638 message_loop_.Run(); |
662 } | 639 } |
663 | 640 |
664 } // namespace remoting | 641 } // namespace remoting |
OLD | NEW |