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