Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: remoting/host/ipc_desktop_environment_unittest.cc

Issue 810133003: replace NULL->nullptr in src/remoting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 int terminal_id_; 214 int terminal_id_;
215 215
216 webrtc::MockScreenCapturerCallback desktop_capturer_callback_; 216 webrtc::MockScreenCapturerCallback desktop_capturer_callback_;
217 217
218 MockClientSessionControl client_session_control_; 218 MockClientSessionControl client_session_control_;
219 base::WeakPtrFactory<ClientSessionControl> client_session_control_factory_; 219 base::WeakPtrFactory<ClientSessionControl> client_session_control_factory_;
220 }; 220 };
221 221
222 IpcDesktopEnvironmentTest::IpcDesktopEnvironmentTest() 222 IpcDesktopEnvironmentTest::IpcDesktopEnvironmentTest()
223 : client_jid_("user@domain/rest-of-jid"), 223 : client_jid_("user@domain/rest-of-jid"),
224 clipboard_stub_(NULL), 224 clipboard_stub_(nullptr),
225 remote_input_injector_(NULL), 225 remote_input_injector_(nullptr),
226 terminal_id_(-1), 226 terminal_id_(-1),
227 client_session_control_factory_(&client_session_control_) { 227 client_session_control_factory_(&client_session_control_) {
228 } 228 }
229 229
230 IpcDesktopEnvironmentTest::~IpcDesktopEnvironmentTest() { 230 IpcDesktopEnvironmentTest::~IpcDesktopEnvironmentTest() {
231 } 231 }
232 232
233 void IpcDesktopEnvironmentTest::SetUp() { 233 void IpcDesktopEnvironmentTest::SetUp() {
234 // Arrange to run |message_loop_| until no components depend on it. 234 // Arrange to run |message_loop_| until no components depend on it.
235 task_runner_ = new AutoThreadTaskRunner( 235 task_runner_ = new AutoThreadTaskRunner(
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 EXPECT_CALL(*desktop_environment, SetCapabilities(_)) 338 EXPECT_CALL(*desktop_environment, SetCapabilities(_))
339 .Times(AtMost(1)); 339 .Times(AtMost(1));
340 340
341 // Let tests know that the remote desktop environment is created. 341 // Let tests know that the remote desktop environment is created.
342 message_loop_.PostTask(FROM_HERE, setup_run_loop_->QuitClosure()); 342 message_loop_.PostTask(FROM_HERE, setup_run_loop_->QuitClosure());
343 343
344 return desktop_environment; 344 return desktop_environment;
345 } 345 }
346 346
347 InputInjector* IpcDesktopEnvironmentTest::CreateInputInjector() { 347 InputInjector* IpcDesktopEnvironmentTest::CreateInputInjector() {
348 EXPECT_TRUE(remote_input_injector_ == NULL); 348 EXPECT_TRUE(remote_input_injector_ == nullptr);
349 remote_input_injector_ = new testing::StrictMock<MockInputInjector>(); 349 remote_input_injector_ = new testing::StrictMock<MockInputInjector>();
350 350
351 EXPECT_CALL(*remote_input_injector_, StartPtr(_)); 351 EXPECT_CALL(*remote_input_injector_, StartPtr(_));
352 return remote_input_injector_; 352 return remote_input_injector_;
353 } 353 }
354 354
355 webrtc::DesktopCapturer* IpcDesktopEnvironmentTest::CreateVideoCapturer() { 355 webrtc::DesktopCapturer* IpcDesktopEnvironmentTest::CreateVideoCapturer() {
356 return new FakeDesktopCapturer(); 356 return new FakeDesktopCapturer();
357 } 357 }
358 358
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 404
405 EXPECT_TRUE(desktop_process_->Start(desktop_environment_factory.Pass())); 405 EXPECT_TRUE(desktop_process_->Start(desktop_environment_factory.Pass()));
406 } 406 }
407 407
408 void IpcDesktopEnvironmentTest::DestoyDesktopProcess() { 408 void IpcDesktopEnvironmentTest::DestoyDesktopProcess() {
409 desktop_channel_.reset(); 409 desktop_channel_.reset();
410 if (desktop_process_) { 410 if (desktop_process_) {
411 desktop_process_->OnChannelError(); 411 desktop_process_->OnChannelError();
412 desktop_process_.reset(); 412 desktop_process_.reset();
413 } 413 }
414 remote_input_injector_ = NULL; 414 remote_input_injector_ = nullptr;
415 } 415 }
416 416
417 void IpcDesktopEnvironmentTest::OnDisconnectCallback() { 417 void IpcDesktopEnvironmentTest::OnDisconnectCallback() {
418 DeleteDesktopEnvironment(); 418 DeleteDesktopEnvironment();
419 } 419 }
420 420
421 void IpcDesktopEnvironmentTest::OnDesktopAttached( 421 void IpcDesktopEnvironmentTest::OnDesktopAttached(
422 IPC::PlatformFileForTransit desktop_pipe) { 422 IPC::PlatformFileForTransit desktop_pipe) {
423 423
424 // Instruct DesktopSessionProxy to connect to the network-to-desktop pipe. 424 // Instruct DesktopSessionProxy to connect to the network-to-desktop pipe.
(...skipping 10 matching lines...) Expand all
435 435
436 // Start the input injector and screen capturer. 436 // Start the input injector and screen capturer.
437 input_injector_->Start(clipboard_stub.Pass()); 437 input_injector_->Start(clipboard_stub.Pass());
438 438
439 // Run the message loop until the desktop is attached. 439 // Run the message loop until the desktop is attached.
440 setup_run_loop_->Run(); 440 setup_run_loop_->Run();
441 441
442 // Stop the test. 442 // Stop the test.
443 DeleteDesktopEnvironment(); 443 DeleteDesktopEnvironment();
444 444
445 task_runner_ = NULL; 445 task_runner_ = nullptr;
446 io_task_runner_ = NULL; 446 io_task_runner_ = nullptr;
447 main_run_loop_.Run(); 447 main_run_loop_.Run();
448 } 448 }
449 449
450 // Tests that the video capturer receives a frame over IPC. 450 // Tests that the video capturer receives a frame over IPC.
451 TEST_F(IpcDesktopEnvironmentTest, CaptureFrame) { 451 TEST_F(IpcDesktopEnvironmentTest, CaptureFrame) {
452 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( 452 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
453 new protocol::MockClipboardStub()); 453 new protocol::MockClipboardStub());
454 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) 454 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
455 .Times(0); 455 .Times(0);
456 456
457 // Start the input injector and screen capturer. 457 // Start the input injector and screen capturer.
458 input_injector_->Start(clipboard_stub.Pass()); 458 input_injector_->Start(clipboard_stub.Pass());
459 video_capturer_->Start(&desktop_capturer_callback_); 459 video_capturer_->Start(&desktop_capturer_callback_);
460 460
461 // Run the message loop until the desktop is attached. 461 // Run the message loop until the desktop is attached.
462 setup_run_loop_->Run(); 462 setup_run_loop_->Run();
463 463
464 // Stop the test when the first frame is captured. 464 // Stop the test when the first frame is captured.
465 EXPECT_CALL(desktop_capturer_callback_, OnCaptureCompleted(_)) 465 EXPECT_CALL(desktop_capturer_callback_, OnCaptureCompleted(_))
466 .WillOnce(DoAll( 466 .WillOnce(DoAll(
467 DeleteArg<0>(), 467 DeleteArg<0>(),
468 InvokeWithoutArgs( 468 InvokeWithoutArgs(
469 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment))); 469 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)));
470 470
471 // Capture a single frame. 471 // Capture a single frame.
472 video_capturer_->Capture(webrtc::DesktopRegion()); 472 video_capturer_->Capture(webrtc::DesktopRegion());
473 473
474 task_runner_ = NULL; 474 task_runner_ = nullptr;
475 io_task_runner_ = NULL; 475 io_task_runner_ = nullptr;
476 main_run_loop_.Run(); 476 main_run_loop_.Run();
477 } 477 }
478 478
479 // Tests that attaching to a new desktop works. 479 // Tests that attaching to a new desktop works.
480 TEST_F(IpcDesktopEnvironmentTest, Reattach) { 480 TEST_F(IpcDesktopEnvironmentTest, Reattach) {
481 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( 481 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
482 new protocol::MockClipboardStub()); 482 new protocol::MockClipboardStub());
483 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) 483 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
484 .Times(0); 484 .Times(0);
485 485
486 // Start the input injector and screen capturer. 486 // Start the input injector and screen capturer.
487 input_injector_->Start(clipboard_stub.Pass()); 487 input_injector_->Start(clipboard_stub.Pass());
488 video_capturer_->Start(&desktop_capturer_callback_); 488 video_capturer_->Start(&desktop_capturer_callback_);
489 489
490 // Run the message loop until the desktop is attached. 490 // Run the message loop until the desktop is attached.
491 setup_run_loop_->Run(); 491 setup_run_loop_->Run();
492 492
493 // Create and start a new desktop process object. 493 // Create and start a new desktop process object.
494 setup_run_loop_.reset(new base::RunLoop()); 494 setup_run_loop_.reset(new base::RunLoop());
495 DestoyDesktopProcess(); 495 DestoyDesktopProcess();
496 CreateDesktopProcess(); 496 CreateDesktopProcess();
497 setup_run_loop_->Run(); 497 setup_run_loop_->Run();
498 498
499 // Stop the test. 499 // Stop the test.
500 DeleteDesktopEnvironment(); 500 DeleteDesktopEnvironment();
501 501
502 task_runner_ = NULL; 502 task_runner_ = nullptr;
503 io_task_runner_ = NULL; 503 io_task_runner_ = nullptr;
504 main_run_loop_.Run(); 504 main_run_loop_.Run();
505 } 505 }
506 506
507 // Tests injection of clipboard events. 507 // Tests injection of clipboard events.
508 TEST_F(IpcDesktopEnvironmentTest, InjectClipboardEvent) { 508 TEST_F(IpcDesktopEnvironmentTest, InjectClipboardEvent) {
509 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( 509 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
510 new protocol::MockClipboardStub()); 510 new protocol::MockClipboardStub());
511 clipboard_stub_ = clipboard_stub.get(); 511 clipboard_stub_ = clipboard_stub.get();
512 512
513 // Stop the test when a clipboard event is received from the desktop process. 513 // Stop the test when a clipboard event is received from the desktop process.
(...skipping 14 matching lines...) Expand all
528 .Times(1) 528 .Times(1)
529 .WillOnce(Invoke(this, 529 .WillOnce(Invoke(this,
530 &IpcDesktopEnvironmentTest::ReflectClipboardEvent)); 530 &IpcDesktopEnvironmentTest::ReflectClipboardEvent));
531 531
532 // Send a clipboard event. 532 // Send a clipboard event.
533 protocol::ClipboardEvent event; 533 protocol::ClipboardEvent event;
534 event.set_mime_type(kMimeTypeTextUtf8); 534 event.set_mime_type(kMimeTypeTextUtf8);
535 event.set_data("a"); 535 event.set_data("a");
536 input_injector_->InjectClipboardEvent(event); 536 input_injector_->InjectClipboardEvent(event);
537 537
538 task_runner_ = NULL; 538 task_runner_ = nullptr;
539 io_task_runner_ = NULL; 539 io_task_runner_ = nullptr;
540 main_run_loop_.Run(); 540 main_run_loop_.Run();
541 } 541 }
542 542
543 // Tests injection of key events. 543 // Tests injection of key events.
544 TEST_F(IpcDesktopEnvironmentTest, InjectKeyEvent) { 544 TEST_F(IpcDesktopEnvironmentTest, InjectKeyEvent) {
545 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( 545 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
546 new protocol::MockClipboardStub()); 546 new protocol::MockClipboardStub());
547 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) 547 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
548 .Times(0); 548 .Times(0);
549 549
550 // Start the input injector and screen capturer. 550 // Start the input injector and screen capturer.
551 input_injector_->Start(clipboard_stub.Pass()); 551 input_injector_->Start(clipboard_stub.Pass());
552 video_capturer_->Start(&desktop_capturer_callback_); 552 video_capturer_->Start(&desktop_capturer_callback_);
553 553
554 // Run the message loop until the desktop is attached. 554 // Run the message loop until the desktop is attached.
555 setup_run_loop_->Run(); 555 setup_run_loop_->Run();
556 556
557 // Expect a single key event. 557 // Expect a single key event.
558 EXPECT_CALL(*remote_input_injector_, InjectKeyEvent(_)) 558 EXPECT_CALL(*remote_input_injector_, InjectKeyEvent(_))
559 .Times(AtLeast(1)) 559 .Times(AtLeast(1))
560 .WillRepeatedly(InvokeWithoutArgs( 560 .WillRepeatedly(InvokeWithoutArgs(
561 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); 561 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
562 562
563 // Send a key event. 563 // Send a key event.
564 protocol::KeyEvent event; 564 protocol::KeyEvent event;
565 event.set_usb_keycode(0x070004); 565 event.set_usb_keycode(0x070004);
566 event.set_pressed(true); 566 event.set_pressed(true);
567 input_injector_->InjectKeyEvent(event); 567 input_injector_->InjectKeyEvent(event);
568 568
569 task_runner_ = NULL; 569 task_runner_ = nullptr;
570 io_task_runner_ = NULL; 570 io_task_runner_ = nullptr;
571 main_run_loop_.Run(); 571 main_run_loop_.Run();
572 } 572 }
573 573
574 // Tests injection of text events. 574 // Tests injection of text events.
575 TEST_F(IpcDesktopEnvironmentTest, InjectTextEvent) { 575 TEST_F(IpcDesktopEnvironmentTest, InjectTextEvent) {
576 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( 576 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
577 new protocol::MockClipboardStub()); 577 new protocol::MockClipboardStub());
578 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) 578 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
579 .Times(0); 579 .Times(0);
580 580
581 // Start the input injector and screen capturer. 581 // Start the input injector and screen capturer.
582 input_injector_->Start(clipboard_stub.Pass()); 582 input_injector_->Start(clipboard_stub.Pass());
583 video_capturer_->Start(&desktop_capturer_callback_); 583 video_capturer_->Start(&desktop_capturer_callback_);
584 584
585 // Run the message loop until the desktop is attached. 585 // Run the message loop until the desktop is attached.
586 setup_run_loop_->Run(); 586 setup_run_loop_->Run();
587 587
588 // Expect a single text event. 588 // Expect a single text event.
589 EXPECT_CALL(*remote_input_injector_, InjectTextEvent(_)) 589 EXPECT_CALL(*remote_input_injector_, InjectTextEvent(_))
590 .Times(AtLeast(1)) 590 .Times(AtLeast(1))
591 .WillRepeatedly(InvokeWithoutArgs( 591 .WillRepeatedly(InvokeWithoutArgs(
592 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); 592 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
593 593
594 // Send a text event. 594 // Send a text event.
595 protocol::TextEvent event; 595 protocol::TextEvent event;
596 event.set_text("hello"); 596 event.set_text("hello");
597 input_injector_->InjectTextEvent(event); 597 input_injector_->InjectTextEvent(event);
598 598
599 task_runner_ = NULL; 599 task_runner_ = nullptr;
600 io_task_runner_ = NULL; 600 io_task_runner_ = nullptr;
601 main_run_loop_.Run(); 601 main_run_loop_.Run();
602 } 602 }
603 603
604 // Tests injection of mouse events. 604 // Tests injection of mouse events.
605 TEST_F(IpcDesktopEnvironmentTest, InjectMouseEvent) { 605 TEST_F(IpcDesktopEnvironmentTest, InjectMouseEvent) {
606 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( 606 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
607 new protocol::MockClipboardStub()); 607 new protocol::MockClipboardStub());
608 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) 608 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
609 .Times(0); 609 .Times(0);
610 610
611 // Start the input injector and screen capturer. 611 // Start the input injector and screen capturer.
612 input_injector_->Start(clipboard_stub.Pass()); 612 input_injector_->Start(clipboard_stub.Pass());
613 video_capturer_->Start(&desktop_capturer_callback_); 613 video_capturer_->Start(&desktop_capturer_callback_);
614 614
615 // Run the message loop until the desktop is attached. 615 // Run the message loop until the desktop is attached.
616 setup_run_loop_->Run(); 616 setup_run_loop_->Run();
617 617
618 // Expect a single mouse event. 618 // Expect a single mouse event.
619 EXPECT_CALL(*remote_input_injector_, InjectMouseEvent(_)) 619 EXPECT_CALL(*remote_input_injector_, InjectMouseEvent(_))
620 .Times(1) 620 .Times(1)
621 .WillOnce(InvokeWithoutArgs( 621 .WillOnce(InvokeWithoutArgs(
622 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); 622 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
623 623
624 // Send a mouse event. 624 // Send a mouse event.
625 protocol::MouseEvent event; 625 protocol::MouseEvent event;
626 event.set_x(0); 626 event.set_x(0);
627 event.set_y(0); 627 event.set_y(0);
628 input_injector_->InjectMouseEvent(event); 628 input_injector_->InjectMouseEvent(event);
629 629
630 task_runner_ = NULL; 630 task_runner_ = nullptr;
631 io_task_runner_ = NULL; 631 io_task_runner_ = nullptr;
632 main_run_loop_.Run(); 632 main_run_loop_.Run();
633 } 633 }
634 634
635 // Tests that setting the desktop resolution works. 635 // Tests that setting the desktop resolution works.
636 TEST_F(IpcDesktopEnvironmentTest, SetScreenResolution) { 636 TEST_F(IpcDesktopEnvironmentTest, SetScreenResolution) {
637 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( 637 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
638 new protocol::MockClipboardStub()); 638 new protocol::MockClipboardStub());
639 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) 639 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
640 .Times(0); 640 .Times(0);
641 641
642 // Start the input injector and screen capturer. 642 // Start the input injector and screen capturer.
643 input_injector_->Start(clipboard_stub.Pass()); 643 input_injector_->Start(clipboard_stub.Pass());
644 video_capturer_->Start(&desktop_capturer_callback_); 644 video_capturer_->Start(&desktop_capturer_callback_);
645 645
646 // Run the message loop until the desktop is attached. 646 // Run the message loop until the desktop is attached.
647 setup_run_loop_->Run(); 647 setup_run_loop_->Run();
648 648
649 EXPECT_CALL(daemon_channel_, SetScreenResolution(_, _)) 649 EXPECT_CALL(daemon_channel_, SetScreenResolution(_, _))
650 .Times(1) 650 .Times(1)
651 .WillOnce(InvokeWithoutArgs( 651 .WillOnce(InvokeWithoutArgs(
652 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); 652 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
653 653
654 // Change the desktop resolution. 654 // Change the desktop resolution.
655 screen_controls_->SetScreenResolution(ScreenResolution( 655 screen_controls_->SetScreenResolution(ScreenResolution(
656 webrtc::DesktopSize(100, 100), 656 webrtc::DesktopSize(100, 100),
657 webrtc::DesktopVector(96, 96))); 657 webrtc::DesktopVector(96, 96)));
658 658
659 task_runner_ = NULL; 659 task_runner_ = nullptr;
660 io_task_runner_ = NULL; 660 io_task_runner_ = nullptr;
661 main_run_loop_.Run(); 661 main_run_loop_.Run();
662 } 662 }
663 663
664 } // namespace remoting 664 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/installer/mac/uninstaller/remoting_uninstaller_app.mm ('k') | remoting/host/ipc_mouse_cursor_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698