OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 118 |
119 void ConnectTerminal(int terminal_id, | 119 void ConnectTerminal(int terminal_id, |
120 const ScreenResolution& resolution, | 120 const ScreenResolution& resolution, |
121 bool virtual_terminal); | 121 bool virtual_terminal); |
122 void DisconnectTerminal(int terminal_id); | 122 void DisconnectTerminal(int terminal_id); |
123 | 123 |
124 // Creates a DesktopEnvironment with a fake media::ScreenCapturer, to mock | 124 // Creates a DesktopEnvironment with a fake media::ScreenCapturer, to mock |
125 // DesktopEnvironmentFactory::Create(). | 125 // DesktopEnvironmentFactory::Create(). |
126 DesktopEnvironment* CreateDesktopEnvironment(); | 126 DesktopEnvironment* CreateDesktopEnvironment(); |
127 | 127 |
128 // Creates a dummy EventExecutor, to mock | 128 // Creates a dummy InputInjector, to mock |
129 // DesktopEnvironment::CreateEventExecutor(). | 129 // DesktopEnvironment::CreateInputInjector(). |
130 EventExecutor* CreateEventExecutor(); | 130 InputInjector* CreateInputInjector(); |
131 | 131 |
132 // Creates a dummy SessionController, to mock | 132 // Creates a dummy SessionController, to mock |
133 // DesktopEnvironment::CreateSessionController(). | 133 // DesktopEnvironment::CreateSessionController(). |
134 SessionController* CreateSessionController(); | 134 SessionController* CreateSessionController(); |
135 | 135 |
136 // Creates a fake media::ScreenCapturer, to mock | 136 // Creates a fake media::ScreenCapturer, to mock |
137 // DesktopEnvironment::CreateVideoCapturer(). | 137 // DesktopEnvironment::CreateVideoCapturer(). |
138 media::ScreenCapturer* CreateVideoCapturer(); | 138 media::ScreenCapturer* CreateVideoCapturer(); |
139 | 139 |
140 void DeleteDesktopEnvironment(); | 140 void DeleteDesktopEnvironment(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 std::string desktop_channel_name_; | 177 std::string desktop_channel_name_; |
178 | 178 |
179 // Delegate that is passed to |desktop_channel_|. | 179 // Delegate that is passed to |desktop_channel_|. |
180 MockDaemonListener desktop_listener_; | 180 MockDaemonListener desktop_listener_; |
181 | 181 |
182 FakeDaemonSender daemon_channel_; | 182 FakeDaemonSender daemon_channel_; |
183 | 183 |
184 scoped_ptr<IpcDesktopEnvironmentFactory> desktop_environment_factory_; | 184 scoped_ptr<IpcDesktopEnvironmentFactory> desktop_environment_factory_; |
185 scoped_ptr<DesktopEnvironment> desktop_environment_; | 185 scoped_ptr<DesktopEnvironment> desktop_environment_; |
186 | 186 |
187 // The IPC event executor. | 187 // The IPC input injector. |
188 scoped_ptr<EventExecutor> event_executor_; | 188 scoped_ptr<InputInjector> input_injector_; |
189 | 189 |
190 // The IPC screen capturer. | 190 // The IPC screen capturer. |
191 scoped_ptr<media::ScreenCapturer> video_capturer_; | 191 scoped_ptr<media::ScreenCapturer> video_capturer_; |
192 | 192 |
193 // Represents the desktop process running in a user session. | 193 // Represents the desktop process running in a user session. |
194 scoped_ptr<DesktopProcess> desktop_process_; | 194 scoped_ptr<DesktopProcess> desktop_process_; |
195 | 195 |
196 // Event executor owned by |desktop_process_|. | 196 // Input injector owned by |desktop_process_|. |
197 MockEventExecutor* remote_event_executor_; | 197 MockInputInjector* remote_input_injector_; |
198 | 198 |
199 // The last |terminal_id| passed to ConnectTermina(); | 199 // The last |terminal_id| passed to ConnectTermina(); |
200 int terminal_id_; | 200 int terminal_id_; |
201 | 201 |
202 media::MockScreenCapturerDelegate screen_capturer_delegate_; | 202 media::MockScreenCapturerDelegate screen_capturer_delegate_; |
203 }; | 203 }; |
204 | 204 |
205 IpcDesktopEnvironmentTest::IpcDesktopEnvironmentTest() | 205 IpcDesktopEnvironmentTest::IpcDesktopEnvironmentTest() |
206 : message_loop_(MessageLoop::TYPE_UI), | 206 : message_loop_(MessageLoop::TYPE_UI), |
207 clipboard_stub_(NULL), | 207 clipboard_stub_(NULL), |
208 remote_event_executor_(NULL), | 208 remote_input_injector_(NULL), |
209 terminal_id_(-1) { | 209 terminal_id_(-1) { |
210 } | 210 } |
211 | 211 |
212 IpcDesktopEnvironmentTest::~IpcDesktopEnvironmentTest() { | 212 IpcDesktopEnvironmentTest::~IpcDesktopEnvironmentTest() { |
213 } | 213 } |
214 | 214 |
215 void IpcDesktopEnvironmentTest::SetUp() { | 215 void IpcDesktopEnvironmentTest::SetUp() { |
216 // Arrange to run |message_loop_| until no components depend on it. | 216 // Arrange to run |message_loop_| until no components depend on it. |
217 task_runner_ = new AutoThreadTaskRunner( | 217 task_runner_ = new AutoThreadTaskRunner( |
218 message_loop_.message_loop_proxy(), main_run_loop_.QuitClosure()); | 218 message_loop_.message_loop_proxy(), main_run_loop_.QuitClosure()); |
(...skipping 27 matching lines...) Expand all Loading... |
246 &IpcDesktopEnvironmentTest::DisconnectTerminal)); | 246 &IpcDesktopEnvironmentTest::DisconnectTerminal)); |
247 | 247 |
248 // Create a desktop environment instance. | 248 // Create a desktop environment instance. |
249 desktop_environment_factory_.reset(new IpcDesktopEnvironmentFactory( | 249 desktop_environment_factory_.reset(new IpcDesktopEnvironmentFactory( |
250 task_runner_, io_task_runner_, &daemon_channel_)); | 250 task_runner_, io_task_runner_, &daemon_channel_)); |
251 desktop_environment_ = desktop_environment_factory_->Create( | 251 desktop_environment_ = desktop_environment_factory_->Create( |
252 "user@domain/rest-of-jid", | 252 "user@domain/rest-of-jid", |
253 base::Bind(&IpcDesktopEnvironmentTest::OnDisconnectCallback, | 253 base::Bind(&IpcDesktopEnvironmentTest::OnDisconnectCallback, |
254 base::Unretained(this))); | 254 base::Unretained(this))); |
255 | 255 |
256 // Create the event executor. | 256 // Create the input injector. |
257 event_executor_ = | 257 input_injector_ = |
258 desktop_environment_->CreateEventExecutor(task_runner_, task_runner_); | 258 desktop_environment_->CreateInputInjector(task_runner_, task_runner_); |
259 | 259 |
260 // Create the screen capturer. | 260 // Create the screen capturer. |
261 video_capturer_ = | 261 video_capturer_ = |
262 desktop_environment_->CreateVideoCapturer(task_runner_, task_runner_); | 262 desktop_environment_->CreateVideoCapturer(task_runner_, task_runner_); |
263 } | 263 } |
264 | 264 |
265 void IpcDesktopEnvironmentTest::ConnectTerminal( | 265 void IpcDesktopEnvironmentTest::ConnectTerminal( |
266 int terminal_id, | 266 int terminal_id, |
267 const ScreenResolution& resolution, | 267 const ScreenResolution& resolution, |
268 bool virtual_terminal) { | 268 bool virtual_terminal) { |
269 EXPECT_NE(terminal_id_, terminal_id); | 269 EXPECT_NE(terminal_id_, terminal_id); |
270 | 270 |
271 terminal_id_ = terminal_id; | 271 terminal_id_ = terminal_id; |
272 CreateDesktopProcess(); | 272 CreateDesktopProcess(); |
273 } | 273 } |
274 | 274 |
275 void IpcDesktopEnvironmentTest::DisconnectTerminal(int terminal_id) { | 275 void IpcDesktopEnvironmentTest::DisconnectTerminal(int terminal_id) { |
276 EXPECT_EQ(terminal_id_, terminal_id); | 276 EXPECT_EQ(terminal_id_, terminal_id); |
277 | 277 |
278 // The IPC desktop environment is fully destroyed now. Release the remaining | 278 // The IPC desktop environment is fully destroyed now. Release the remaining |
279 // task runners. | 279 // task runners. |
280 desktop_environment_factory_.reset(); | 280 desktop_environment_factory_.reset(); |
281 } | 281 } |
282 | 282 |
283 DesktopEnvironment* IpcDesktopEnvironmentTest::CreateDesktopEnvironment() { | 283 DesktopEnvironment* IpcDesktopEnvironmentTest::CreateDesktopEnvironment() { |
284 MockDesktopEnvironment* desktop_environment = new MockDesktopEnvironment(); | 284 MockDesktopEnvironment* desktop_environment = new MockDesktopEnvironment(); |
285 EXPECT_CALL(*desktop_environment, CreateAudioCapturerPtr(_)) | 285 EXPECT_CALL(*desktop_environment, CreateAudioCapturerPtr(_)) |
286 .Times(0); | 286 .Times(0); |
287 EXPECT_CALL(*desktop_environment, CreateEventExecutorPtr(_, _)) | 287 EXPECT_CALL(*desktop_environment, CreateInputInjectorPtr(_, _)) |
288 .Times(AnyNumber()) | 288 .Times(AnyNumber()) |
289 .WillRepeatedly( | 289 .WillRepeatedly( |
290 InvokeWithoutArgs(this, | 290 InvokeWithoutArgs(this, |
291 &IpcDesktopEnvironmentTest::CreateEventExecutor)); | 291 &IpcDesktopEnvironmentTest::CreateInputInjector)); |
292 EXPECT_CALL(*desktop_environment, CreateSessionControllerPtr()) | 292 EXPECT_CALL(*desktop_environment, CreateSessionControllerPtr()) |
293 .Times(AnyNumber()) | 293 .Times(AnyNumber()) |
294 .WillRepeatedly(InvokeWithoutArgs( | 294 .WillRepeatedly(InvokeWithoutArgs( |
295 this, &IpcDesktopEnvironmentTest::CreateSessionController)); | 295 this, &IpcDesktopEnvironmentTest::CreateSessionController)); |
296 EXPECT_CALL(*desktop_environment, CreateVideoCapturerPtr(_, _)) | 296 EXPECT_CALL(*desktop_environment, CreateVideoCapturerPtr(_, _)) |
297 .Times(AnyNumber()) | 297 .Times(AnyNumber()) |
298 .WillRepeatedly( | 298 .WillRepeatedly( |
299 InvokeWithoutArgs(this, | 299 InvokeWithoutArgs(this, |
300 &IpcDesktopEnvironmentTest::CreateVideoCapturer)); | 300 &IpcDesktopEnvironmentTest::CreateVideoCapturer)); |
301 | 301 |
302 // Let tests know that the remote desktop environment is created. | 302 // Let tests know that the remote desktop environment is created. |
303 message_loop_.PostTask(FROM_HERE, setup_run_loop_->QuitClosure()); | 303 message_loop_.PostTask(FROM_HERE, setup_run_loop_->QuitClosure()); |
304 | 304 |
305 return desktop_environment; | 305 return desktop_environment; |
306 } | 306 } |
307 | 307 |
308 EventExecutor* IpcDesktopEnvironmentTest::CreateEventExecutor() { | 308 InputInjector* IpcDesktopEnvironmentTest::CreateInputInjector() { |
309 EXPECT_TRUE(remote_event_executor_ == NULL); | 309 EXPECT_TRUE(remote_input_injector_ == NULL); |
310 remote_event_executor_ = new MockEventExecutor(); | 310 remote_input_injector_ = new MockInputInjector(); |
311 | 311 |
312 EXPECT_CALL(*remote_event_executor_, StartPtr(_)); | 312 EXPECT_CALL(*remote_input_injector_, StartPtr(_)); |
313 return remote_event_executor_; | 313 return remote_input_injector_; |
314 } | 314 } |
315 | 315 |
316 SessionController* IpcDesktopEnvironmentTest::CreateSessionController() { | 316 SessionController* IpcDesktopEnvironmentTest::CreateSessionController() { |
317 return new MockSessionController(); | 317 return new MockSessionController(); |
318 } | 318 } |
319 | 319 |
320 media::ScreenCapturer* IpcDesktopEnvironmentTest::CreateVideoCapturer() { | 320 media::ScreenCapturer* IpcDesktopEnvironmentTest::CreateVideoCapturer() { |
321 return new media::ScreenCapturerFake(); | 321 return new media::ScreenCapturerFake(); |
322 } | 322 } |
323 | 323 |
324 void IpcDesktopEnvironmentTest::DeleteDesktopEnvironment() { | 324 void IpcDesktopEnvironmentTest::DeleteDesktopEnvironment() { |
325 event_executor_.reset(); | 325 input_injector_.reset(); |
326 video_capturer_.reset(); | 326 video_capturer_.reset(); |
327 | 327 |
328 // Trigger DisconnectTerminal(). | 328 // Trigger DisconnectTerminal(). |
329 desktop_environment_.reset(); | 329 desktop_environment_.reset(); |
330 } | 330 } |
331 | 331 |
332 void IpcDesktopEnvironmentTest::ReflectClipboardEvent( | 332 void IpcDesktopEnvironmentTest::ReflectClipboardEvent( |
333 const protocol::ClipboardEvent& event) { | 333 const protocol::ClipboardEvent& event) { |
334 clipboard_stub_->InjectClipboardEvent(event); | 334 clipboard_stub_->InjectClipboardEvent(event); |
335 } | 335 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 EXPECT_TRUE(desktop_process_->Start( | 368 EXPECT_TRUE(desktop_process_->Start( |
369 desktop_environment_factory.PassAs<DesktopEnvironmentFactory>())); | 369 desktop_environment_factory.PassAs<DesktopEnvironmentFactory>())); |
370 } | 370 } |
371 | 371 |
372 void IpcDesktopEnvironmentTest::DestoyDesktopProcess() { | 372 void IpcDesktopEnvironmentTest::DestoyDesktopProcess() { |
373 desktop_channel_.reset(); | 373 desktop_channel_.reset(); |
374 if (desktop_process_) { | 374 if (desktop_process_) { |
375 desktop_process_->OnChannelError(); | 375 desktop_process_->OnChannelError(); |
376 desktop_process_.reset(); | 376 desktop_process_.reset(); |
377 } | 377 } |
378 remote_event_executor_ = NULL; | 378 remote_input_injector_ = NULL; |
379 } | 379 } |
380 | 380 |
381 void IpcDesktopEnvironmentTest::OnDisconnectCallback() { | 381 void IpcDesktopEnvironmentTest::OnDisconnectCallback() { |
382 DeleteDesktopEnvironment(); | 382 DeleteDesktopEnvironment(); |
383 } | 383 } |
384 | 384 |
385 void IpcDesktopEnvironmentTest::OnDesktopAttached( | 385 void IpcDesktopEnvironmentTest::OnDesktopAttached( |
386 IPC::PlatformFileForTransit desktop_pipe) { | 386 IPC::PlatformFileForTransit desktop_pipe) { |
387 | 387 |
388 // Instruct DesktopSessionProxy to connect to the network-to-desktop pipe. | 388 // Instruct DesktopSessionProxy to connect to the network-to-desktop pipe. |
389 desktop_environment_factory_->OnDesktopSessionAgentAttached( | 389 desktop_environment_factory_->OnDesktopSessionAgentAttached( |
390 terminal_id_, base::GetCurrentProcessHandle(), desktop_pipe); | 390 terminal_id_, base::GetCurrentProcessHandle(), desktop_pipe); |
391 } | 391 } |
392 | 392 |
393 // Runs until the desktop is attached and exits immediately after that. | 393 // Runs until the desktop is attached and exits immediately after that. |
394 TEST_F(IpcDesktopEnvironmentTest, Basic) { | 394 TEST_F(IpcDesktopEnvironmentTest, Basic) { |
395 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( | 395 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( |
396 new protocol::MockClipboardStub()); | 396 new protocol::MockClipboardStub()); |
397 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) | 397 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
398 .Times(0); | 398 .Times(0); |
399 | 399 |
400 // Start the event executor and screen capturer. | 400 // Start the input injector and screen capturer. |
401 event_executor_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); | 401 input_injector_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); |
402 | 402 |
403 // Run the message loop until the desktop is attached. | 403 // Run the message loop until the desktop is attached. |
404 setup_run_loop_->Run(); | 404 setup_run_loop_->Run(); |
405 | 405 |
406 // Event executor should receive no events. | 406 // Input injector should receive no events. |
407 EXPECT_CALL(*remote_event_executor_, InjectClipboardEvent(_)) | 407 EXPECT_CALL(*remote_input_injector_, InjectClipboardEvent(_)) |
408 .Times(0); | 408 .Times(0); |
409 EXPECT_CALL(*remote_event_executor_, InjectKeyEvent(_)) | 409 EXPECT_CALL(*remote_input_injector_, InjectKeyEvent(_)) |
410 .Times(0); | 410 .Times(0); |
411 EXPECT_CALL(*remote_event_executor_, InjectMouseEvent(_)) | 411 EXPECT_CALL(*remote_input_injector_, InjectMouseEvent(_)) |
412 .Times(0); | 412 .Times(0); |
413 | 413 |
414 // Stop the test. | 414 // Stop the test. |
415 DeleteDesktopEnvironment(); | 415 DeleteDesktopEnvironment(); |
416 | 416 |
417 task_runner_ = NULL; | 417 task_runner_ = NULL; |
418 io_task_runner_ = NULL; | 418 io_task_runner_ = NULL; |
419 main_run_loop_.Run(); | 419 main_run_loop_.Run(); |
420 } | 420 } |
421 | 421 |
422 // Tests that the video capturer receives a frame over IPC. | 422 // Tests that the video capturer receives a frame over IPC. |
423 TEST_F(IpcDesktopEnvironmentTest, CaptureFrame) { | 423 TEST_F(IpcDesktopEnvironmentTest, CaptureFrame) { |
424 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( | 424 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( |
425 new protocol::MockClipboardStub()); | 425 new protocol::MockClipboardStub()); |
426 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) | 426 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
427 .Times(0); | 427 .Times(0); |
428 | 428 |
429 // Start the event executor and screen capturer. | 429 // Start the input injector and screen capturer. |
430 event_executor_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); | 430 input_injector_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); |
431 video_capturer_->Start(&screen_capturer_delegate_); | 431 video_capturer_->Start(&screen_capturer_delegate_); |
432 | 432 |
433 // Run the message loop until the desktop is attached. | 433 // Run the message loop until the desktop is attached. |
434 setup_run_loop_->Run(); | 434 setup_run_loop_->Run(); |
435 | 435 |
436 // Event executor should receive no events. | 436 // Input injector should receive no events. |
437 EXPECT_CALL(*remote_event_executor_, InjectClipboardEvent(_)) | 437 EXPECT_CALL(*remote_input_injector_, InjectClipboardEvent(_)) |
438 .Times(0); | 438 .Times(0); |
439 EXPECT_CALL(*remote_event_executor_, InjectKeyEvent(_)) | 439 EXPECT_CALL(*remote_input_injector_, InjectKeyEvent(_)) |
440 .Times(0); | 440 .Times(0); |
441 EXPECT_CALL(*remote_event_executor_, InjectMouseEvent(_)) | 441 EXPECT_CALL(*remote_input_injector_, InjectMouseEvent(_)) |
442 .Times(0); | 442 .Times(0); |
443 | 443 |
444 // Stop the test when the first frame is captured. | 444 // Stop the test when the first frame is captured. |
445 EXPECT_CALL(screen_capturer_delegate_, OnCaptureCompleted(_)) | 445 EXPECT_CALL(screen_capturer_delegate_, OnCaptureCompleted(_)) |
446 .WillOnce(InvokeWithoutArgs( | 446 .WillOnce(InvokeWithoutArgs( |
447 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); | 447 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
448 | 448 |
449 // Capture a single frame. | 449 // Capture a single frame. |
450 video_capturer_->CaptureFrame(); | 450 video_capturer_->CaptureFrame(); |
451 | 451 |
452 task_runner_ = NULL; | 452 task_runner_ = NULL; |
453 io_task_runner_ = NULL; | 453 io_task_runner_ = NULL; |
454 main_run_loop_.Run(); | 454 main_run_loop_.Run(); |
455 } | 455 } |
456 | 456 |
457 // Tests that attaching to a new desktop works. | 457 // Tests that attaching to a new desktop works. |
458 TEST_F(IpcDesktopEnvironmentTest, Reattach) { | 458 TEST_F(IpcDesktopEnvironmentTest, Reattach) { |
459 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( | 459 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( |
460 new protocol::MockClipboardStub()); | 460 new protocol::MockClipboardStub()); |
461 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) | 461 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
462 .Times(0); | 462 .Times(0); |
463 | 463 |
464 // Start the event executor and screen capturer. | 464 // Start the input injector and screen capturer. |
465 event_executor_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); | 465 input_injector_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); |
466 video_capturer_->Start(&screen_capturer_delegate_); | 466 video_capturer_->Start(&screen_capturer_delegate_); |
467 | 467 |
468 // Run the message loop until the desktop is attached. | 468 // Run the message loop until the desktop is attached. |
469 setup_run_loop_->Run(); | 469 setup_run_loop_->Run(); |
470 | 470 |
471 // Create and start a new desktop process object. | 471 // Create and start a new desktop process object. |
472 setup_run_loop_.reset(new base::RunLoop()); | 472 setup_run_loop_.reset(new base::RunLoop()); |
473 DestoyDesktopProcess(); | 473 DestoyDesktopProcess(); |
474 CreateDesktopProcess(); | 474 CreateDesktopProcess(); |
475 setup_run_loop_->Run(); | 475 setup_run_loop_->Run(); |
476 | 476 |
477 // Event executor should receive no events. | 477 // Input injector should receive no events. |
478 EXPECT_CALL(*remote_event_executor_, InjectClipboardEvent(_)) | 478 EXPECT_CALL(*remote_input_injector_, InjectClipboardEvent(_)) |
479 .Times(0); | 479 .Times(0); |
480 EXPECT_CALL(*remote_event_executor_, InjectKeyEvent(_)) | 480 EXPECT_CALL(*remote_input_injector_, InjectKeyEvent(_)) |
481 .Times(0); | 481 .Times(0); |
482 EXPECT_CALL(*remote_event_executor_, InjectMouseEvent(_)) | 482 EXPECT_CALL(*remote_input_injector_, InjectMouseEvent(_)) |
483 .Times(0); | 483 .Times(0); |
484 | 484 |
485 // Stop the test. | 485 // Stop the test. |
486 DeleteDesktopEnvironment(); | 486 DeleteDesktopEnvironment(); |
487 | 487 |
488 task_runner_ = NULL; | 488 task_runner_ = NULL; |
489 io_task_runner_ = NULL; | 489 io_task_runner_ = NULL; |
490 main_run_loop_.Run(); | 490 main_run_loop_.Run(); |
491 } | 491 } |
492 | 492 |
493 // Tests InvalidateRegion(). | 493 // Tests InvalidateRegion(). |
494 TEST_F(IpcDesktopEnvironmentTest, InvalidateRegion) { | 494 TEST_F(IpcDesktopEnvironmentTest, InvalidateRegion) { |
495 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( | 495 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( |
496 new protocol::MockClipboardStub()); | 496 new protocol::MockClipboardStub()); |
497 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) | 497 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
498 .Times(0); | 498 .Times(0); |
499 | 499 |
500 // Start the event executor and screen capturer. | 500 // Start the input injector and screen capturer. |
501 event_executor_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); | 501 input_injector_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); |
502 video_capturer_->Start(&screen_capturer_delegate_); | 502 video_capturer_->Start(&screen_capturer_delegate_); |
503 | 503 |
504 // Run the message loop until the desktop is attached. | 504 // Run the message loop until the desktop is attached. |
505 setup_run_loop_->Run(); | 505 setup_run_loop_->Run(); |
506 | 506 |
507 // Event executor should receive no events. | 507 // Input injector should receive no events. |
508 EXPECT_CALL(*remote_event_executor_, InjectClipboardEvent(_)) | 508 EXPECT_CALL(*remote_input_injector_, InjectClipboardEvent(_)) |
509 .Times(0); | 509 .Times(0); |
510 EXPECT_CALL(*remote_event_executor_, InjectKeyEvent(_)) | 510 EXPECT_CALL(*remote_input_injector_, InjectKeyEvent(_)) |
511 .Times(0); | 511 .Times(0); |
512 EXPECT_CALL(*remote_event_executor_, InjectMouseEvent(_)) | 512 EXPECT_CALL(*remote_input_injector_, InjectMouseEvent(_)) |
513 .Times(0); | 513 .Times(0); |
514 | 514 |
515 // Stop the test when the first frame is captured. | 515 // Stop the test when the first frame is captured. |
516 EXPECT_CALL(screen_capturer_delegate_, OnCaptureCompleted(_)) | 516 EXPECT_CALL(screen_capturer_delegate_, OnCaptureCompleted(_)) |
517 .WillOnce(InvokeWithoutArgs( | 517 .WillOnce(InvokeWithoutArgs( |
518 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); | 518 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
519 | 519 |
520 // Invalidate a region that is larger than the screen. | 520 // Invalidate a region that is larger than the screen. |
521 SkIRect horizontal_rect = SkIRect::MakeXYWH( | 521 SkIRect horizontal_rect = SkIRect::MakeXYWH( |
522 -100, | 522 -100, |
(...skipping 24 matching lines...) Expand all Loading... |
547 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( | 547 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( |
548 new protocol::MockClipboardStub()); | 548 new protocol::MockClipboardStub()); |
549 clipboard_stub_ = clipboard_stub.get(); | 549 clipboard_stub_ = clipboard_stub.get(); |
550 | 550 |
551 // Stop the test when a clipboard event is received from the desktop process. | 551 // Stop the test when a clipboard event is received from the desktop process. |
552 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) | 552 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
553 .Times(1) | 553 .Times(1) |
554 .WillOnce(InvokeWithoutArgs( | 554 .WillOnce(InvokeWithoutArgs( |
555 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); | 555 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
556 | 556 |
557 // Start the event executor and screen capturer. | 557 // Start the input injector and screen capturer. |
558 event_executor_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); | 558 input_injector_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); |
559 video_capturer_->Start(&screen_capturer_delegate_); | 559 video_capturer_->Start(&screen_capturer_delegate_); |
560 | 560 |
561 // Run the message loop until the desktop is attached. | 561 // Run the message loop until the desktop is attached. |
562 setup_run_loop_->Run(); | 562 setup_run_loop_->Run(); |
563 | 563 |
564 // Expect a single clipboard event. | 564 // Expect a single clipboard event. |
565 EXPECT_CALL(*remote_event_executor_, InjectClipboardEvent(_)) | 565 EXPECT_CALL(*remote_input_injector_, InjectClipboardEvent(_)) |
566 .Times(1) | 566 .Times(1) |
567 .WillOnce(Invoke(this, | 567 .WillOnce(Invoke(this, |
568 &IpcDesktopEnvironmentTest::ReflectClipboardEvent)); | 568 &IpcDesktopEnvironmentTest::ReflectClipboardEvent)); |
569 EXPECT_CALL(*remote_event_executor_, InjectKeyEvent(_)) | 569 EXPECT_CALL(*remote_input_injector_, InjectKeyEvent(_)) |
570 .Times(0); | 570 .Times(0); |
571 EXPECT_CALL(*remote_event_executor_, InjectMouseEvent(_)) | 571 EXPECT_CALL(*remote_input_injector_, InjectMouseEvent(_)) |
572 .Times(0); | 572 .Times(0); |
573 | 573 |
574 // Send a clipboard event. | 574 // Send a clipboard event. |
575 protocol::ClipboardEvent event; | 575 protocol::ClipboardEvent event; |
576 event.set_mime_type(kMimeTypeTextUtf8); | 576 event.set_mime_type(kMimeTypeTextUtf8); |
577 event.set_data("a"); | 577 event.set_data("a"); |
578 event_executor_->InjectClipboardEvent(event); | 578 input_injector_->InjectClipboardEvent(event); |
579 | 579 |
580 task_runner_ = NULL; | 580 task_runner_ = NULL; |
581 io_task_runner_ = NULL; | 581 io_task_runner_ = NULL; |
582 main_run_loop_.Run(); | 582 main_run_loop_.Run(); |
583 } | 583 } |
584 | 584 |
585 // Tests injection of key events. | 585 // Tests injection of key events. |
586 TEST_F(IpcDesktopEnvironmentTest, InjectKeyEvent) { | 586 TEST_F(IpcDesktopEnvironmentTest, InjectKeyEvent) { |
587 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( | 587 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( |
588 new protocol::MockClipboardStub()); | 588 new protocol::MockClipboardStub()); |
589 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) | 589 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
590 .Times(0); | 590 .Times(0); |
591 | 591 |
592 // Start the event executor and screen capturer. | 592 // Start the input injector and screen capturer. |
593 event_executor_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); | 593 input_injector_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); |
594 video_capturer_->Start(&screen_capturer_delegate_); | 594 video_capturer_->Start(&screen_capturer_delegate_); |
595 | 595 |
596 // Run the message loop until the desktop is attached. | 596 // Run the message loop until the desktop is attached. |
597 setup_run_loop_->Run(); | 597 setup_run_loop_->Run(); |
598 | 598 |
599 // Expect a single key event. | 599 // Expect a single key event. |
600 EXPECT_CALL(*remote_event_executor_, InjectClipboardEvent(_)) | 600 EXPECT_CALL(*remote_input_injector_, InjectClipboardEvent(_)) |
601 .Times(0); | 601 .Times(0); |
602 EXPECT_CALL(*remote_event_executor_, InjectKeyEvent(_)) | 602 EXPECT_CALL(*remote_input_injector_, InjectKeyEvent(_)) |
603 .Times(AtLeast(1)) | 603 .Times(AtLeast(1)) |
604 .WillRepeatedly(InvokeWithoutArgs( | 604 .WillRepeatedly(InvokeWithoutArgs( |
605 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); | 605 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
606 EXPECT_CALL(*remote_event_executor_, InjectMouseEvent(_)) | 606 EXPECT_CALL(*remote_input_injector_, InjectMouseEvent(_)) |
607 .Times(0); | 607 .Times(0); |
608 | 608 |
609 // Send a key event. | 609 // Send a key event. |
610 protocol::KeyEvent event; | 610 protocol::KeyEvent event; |
611 event.set_usb_keycode(0x070004); | 611 event.set_usb_keycode(0x070004); |
612 event.set_pressed(true); | 612 event.set_pressed(true); |
613 event_executor_->InjectKeyEvent(event); | 613 input_injector_->InjectKeyEvent(event); |
614 | 614 |
615 task_runner_ = NULL; | 615 task_runner_ = NULL; |
616 io_task_runner_ = NULL; | 616 io_task_runner_ = NULL; |
617 main_run_loop_.Run(); | 617 main_run_loop_.Run(); |
618 } | 618 } |
619 | 619 |
620 // Tests injection of mouse events. | 620 // Tests injection of mouse events. |
621 TEST_F(IpcDesktopEnvironmentTest, InjectMouseEvent) { | 621 TEST_F(IpcDesktopEnvironmentTest, InjectMouseEvent) { |
622 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( | 622 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( |
623 new protocol::MockClipboardStub()); | 623 new protocol::MockClipboardStub()); |
624 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) | 624 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
625 .Times(0); | 625 .Times(0); |
626 | 626 |
627 // Start the event executor and screen capturer. | 627 // Start the input injector and screen capturer. |
628 event_executor_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); | 628 input_injector_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); |
629 video_capturer_->Start(&screen_capturer_delegate_); | 629 video_capturer_->Start(&screen_capturer_delegate_); |
630 | 630 |
631 // Run the message loop until the desktop is attached. | 631 // Run the message loop until the desktop is attached. |
632 setup_run_loop_->Run(); | 632 setup_run_loop_->Run(); |
633 | 633 |
634 // Expect a single mouse event. | 634 // Expect a single mouse event. |
635 EXPECT_CALL(*remote_event_executor_, InjectClipboardEvent(_)) | 635 EXPECT_CALL(*remote_input_injector_, InjectClipboardEvent(_)) |
636 .Times(0); | 636 .Times(0); |
637 EXPECT_CALL(*remote_event_executor_, InjectKeyEvent(_)) | 637 EXPECT_CALL(*remote_input_injector_, InjectKeyEvent(_)) |
638 .Times(0); | 638 .Times(0); |
639 EXPECT_CALL(*remote_event_executor_, InjectMouseEvent(_)) | 639 EXPECT_CALL(*remote_input_injector_, InjectMouseEvent(_)) |
640 .Times(1) | 640 .Times(1) |
641 .WillOnce(InvokeWithoutArgs( | 641 .WillOnce(InvokeWithoutArgs( |
642 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); | 642 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
643 | 643 |
644 // Send a mouse event. | 644 // Send a mouse event. |
645 protocol::MouseEvent event; | 645 protocol::MouseEvent event; |
646 event.set_x(0); | 646 event.set_x(0); |
647 event.set_y(0); | 647 event.set_y(0); |
648 event_executor_->InjectMouseEvent(event); | 648 input_injector_->InjectMouseEvent(event); |
649 | 649 |
650 task_runner_ = NULL; | 650 task_runner_ = NULL; |
651 io_task_runner_ = NULL; | 651 io_task_runner_ = NULL; |
652 main_run_loop_.Run(); | 652 main_run_loop_.Run(); |
653 } | 653 } |
654 | 654 |
655 } // namespace remoting | 655 } // namespace remoting |
OLD | NEW |