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

Side by Side Diff: chromeos/dbus/ibus/ibus_engine_service_unittest.cc

Issue 10968056: Fix crash bug of IME extension API. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix nits Created 8 years, 2 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) 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 "chromeos/dbus/ibus/ibus_engine_service.h" 5 #include "chromeos/dbus/ibus/ibus_engine_service.h"
6 6
7 #include <map> 7 #include <map>
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 EXPECT_CALL(*mock_bus_.get(), 469 EXPECT_CALL(*mock_bus_.get(),
470 AssertOnOriginThread()) 470 AssertOnOriginThread())
471 .WillRepeatedly(Return()); 471 .WillRepeatedly(Return());
472 472
473 // Create a service 473 // Create a service
474 service_.reset(IBusEngineService::Create( 474 service_.reset(IBusEngineService::Create(
475 REAL_DBUS_CLIENT_IMPLEMENTATION, 475 REAL_DBUS_CLIENT_IMPLEMENTATION,
476 mock_bus_.get(), 476 mock_bus_.get(),
477 dbus::ObjectPath(kObjectPath))); 477 dbus::ObjectPath(kObjectPath)));
478 478
479 // Call Initialize to set engine handler. 479 // Set engine handler.
480 engine_handler_ = new MockIBusEngineHandler(); 480 engine_handler_.reset(new MockIBusEngineHandler());
481 service_->Initialize(engine_handler_); 481 service_->SetEngine(engine_handler_.get());
482 } 482 }
483 483
484 protected: 484 protected:
485 // The service to be tested. 485 // The service to be tested.
486 scoped_ptr<IBusEngineService> service_; 486 scoped_ptr<IBusEngineService> service_;
487 // The mock engine handler. Do not free, this is owned by IBusEngineService. 487 // The mock engine handler. Do not free, this is owned by IBusEngineService.
488 MockIBusEngineHandler* engine_handler_; 488 scoped_ptr<MockIBusEngineHandler> engine_handler_;
489 // The mock bus. 489 // The mock bus.
490 scoped_refptr<dbus::MockBus> mock_bus_; 490 scoped_refptr<dbus::MockBus> mock_bus_;
491 // The mock exported object. 491 // The mock exported object.
492 scoped_refptr<dbus::MockExportedObject> mock_exported_object_; 492 scoped_refptr<dbus::MockExportedObject> mock_exported_object_;
493 // A message loop to emulate asynchronous behavior. 493 // A message loop to emulate asynchronous behavior.
494 MessageLoop message_loop_; 494 MessageLoop message_loop_;
495 // The map from method call to method call handler. 495 // The map from method call to method call handler.
496 std::map<std::string, dbus::ExportedObject::MethodCallCallback> 496 std::map<std::string, dbus::ExportedObject::MethodCallCallback>
497 method_callback_map_; 497 method_callback_map_;
498 498
(...skipping 28 matching lines...) Expand all
527 ibus::engine::kFocusInMethod); 527 ibus::engine::kFocusInMethod);
528 method_call.SetSerial(kSerialNo); 528 method_call.SetSerial(kSerialNo);
529 529
530 // Call exported function. 530 // Call exported function.
531 EXPECT_NE(method_callback_map_.find(ibus::engine::kFocusInMethod), 531 EXPECT_NE(method_callback_map_.find(ibus::engine::kFocusInMethod),
532 method_callback_map_.end()); 532 method_callback_map_.end());
533 method_callback_map_[ibus::engine::kFocusInMethod].Run( 533 method_callback_map_[ibus::engine::kFocusInMethod].Run(
534 &method_call, 534 &method_call,
535 base::Bind(&MockResponseSender::Run, 535 base::Bind(&MockResponseSender::Run,
536 base::Unretained(&response_sender))); 536 base::Unretained(&response_sender)));
537
538 // Call exported function without engine.
539 service_->UnsetEngine();
540 EXPECT_CALL(*engine_handler_, FocusIn()).Times(0);
541 EXPECT_CALL(response_sender, Run(_)).Times(0);
542 method_callback_map_[ibus::engine::kFocusInMethod].Run(
543 &method_call,
544 base::Bind(&MockResponseSender::Run,
545 base::Unretained(&response_sender)));
537 } 546 }
538 547
539 TEST_F(IBusEngineServiceTest, FocusOutTest) { 548 TEST_F(IBusEngineServiceTest, FocusOutTest) {
540 // Set expectations. 549 // Set expectations.
541 const uint32 kSerialNo = 1; 550 const uint32 kSerialNo = 1;
542 EXPECT_CALL(*engine_handler_, FocusOut()); 551 EXPECT_CALL(*engine_handler_, FocusOut());
543 MockResponseSender response_sender; 552 MockResponseSender response_sender;
544 EmptyResponseExpectation response_expectation(kSerialNo); 553 EmptyResponseExpectation response_expectation(kSerialNo);
545 EXPECT_CALL(response_sender, Run(_)) 554 EXPECT_CALL(response_sender, Run(_))
546 .WillOnce(Invoke(&response_expectation, 555 .WillOnce(Invoke(&response_expectation,
547 &EmptyResponseExpectation::Evaluate)); 556 &EmptyResponseExpectation::Evaluate));
548 557
549 // Create method call; 558 // Create method call;
550 dbus::MethodCall method_call(ibus::engine::kServiceInterface, 559 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
551 ibus::engine::kFocusOutMethod); 560 ibus::engine::kFocusOutMethod);
552 method_call.SetSerial(kSerialNo); 561 method_call.SetSerial(kSerialNo);
553 562
554 // Call exported function. 563 // Call exported function.
555 EXPECT_NE(method_callback_map_.find(ibus::engine::kFocusOutMethod), 564 EXPECT_NE(method_callback_map_.find(ibus::engine::kFocusOutMethod),
556 method_callback_map_.end()); 565 method_callback_map_.end());
557 method_callback_map_[ibus::engine::kFocusOutMethod].Run( 566 method_callback_map_[ibus::engine::kFocusOutMethod].Run(
558 &method_call, 567 &method_call,
559 base::Bind(&MockResponseSender::Run, 568 base::Bind(&MockResponseSender::Run,
560 base::Unretained(&response_sender))); 569 base::Unretained(&response_sender)));
570
571 // Call exported function without engine.
572 service_->UnsetEngine();
573 EXPECT_CALL(*engine_handler_, FocusOut()).Times(0);
574 EXPECT_CALL(response_sender, Run(_)).Times(0);
575 method_callback_map_[ibus::engine::kFocusOutMethod].Run(
576 &method_call,
577 base::Bind(&MockResponseSender::Run,
578 base::Unretained(&response_sender)));
561 } 579 }
562 580
563 TEST_F(IBusEngineServiceTest, EnableTest) { 581 TEST_F(IBusEngineServiceTest, EnableTest) {
564 // Set expectations. 582 // Set expectations.
565 const uint32 kSerialNo = 1; 583 const uint32 kSerialNo = 1;
566 EXPECT_CALL(*engine_handler_, Enable()); 584 EXPECT_CALL(*engine_handler_, Enable());
567 MockResponseSender response_sender; 585 MockResponseSender response_sender;
568 EmptyResponseExpectation response_expectation(kSerialNo); 586 EmptyResponseExpectation response_expectation(kSerialNo);
569 EXPECT_CALL(response_sender, Run(_)) 587 EXPECT_CALL(response_sender, Run(_))
570 .WillOnce(Invoke(&response_expectation, 588 .WillOnce(Invoke(&response_expectation,
571 &EmptyResponseExpectation::Evaluate)); 589 &EmptyResponseExpectation::Evaluate));
572 590
573 // Create method call; 591 // Create method call;
574 dbus::MethodCall method_call(ibus::engine::kServiceInterface, 592 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
575 ibus::engine::kEnableMethod); 593 ibus::engine::kEnableMethod);
576 method_call.SetSerial(kSerialNo); 594 method_call.SetSerial(kSerialNo);
577 595
578 // Call exported function. 596 // Call exported function.
579 EXPECT_NE(method_callback_map_.find(ibus::engine::kEnableMethod), 597 EXPECT_NE(method_callback_map_.find(ibus::engine::kEnableMethod),
580 method_callback_map_.end()); 598 method_callback_map_.end());
581 method_callback_map_[ibus::engine::kEnableMethod].Run( 599 method_callback_map_[ibus::engine::kEnableMethod].Run(
582 &method_call, 600 &method_call,
583 base::Bind(&MockResponseSender::Run, 601 base::Bind(&MockResponseSender::Run,
584 base::Unretained(&response_sender))); 602 base::Unretained(&response_sender)));
603
604 // Call exported function without engine.
605 service_->UnsetEngine();
606 EXPECT_CALL(*engine_handler_, Enable()).Times(0);
607 EXPECT_CALL(response_sender, Run(_)).Times(0);
608 method_callback_map_[ibus::engine::kEnableMethod].Run(
609 &method_call,
610 base::Bind(&MockResponseSender::Run,
611 base::Unretained(&response_sender)));
585 } 612 }
586 613
587 TEST_F(IBusEngineServiceTest, DisableTest) { 614 TEST_F(IBusEngineServiceTest, DisableTest) {
588 // Set expectations. 615 // Set expectations.
589 const uint32 kSerialNo = 1; 616 const uint32 kSerialNo = 1;
590 EXPECT_CALL(*engine_handler_, Disable()); 617 EXPECT_CALL(*engine_handler_, Disable());
591 MockResponseSender response_sender; 618 MockResponseSender response_sender;
592 EmptyResponseExpectation response_expectation(kSerialNo); 619 EmptyResponseExpectation response_expectation(kSerialNo);
593 EXPECT_CALL(response_sender, Run(_)) 620 EXPECT_CALL(response_sender, Run(_))
594 .WillOnce(Invoke(&response_expectation, 621 .WillOnce(Invoke(&response_expectation,
595 &EmptyResponseExpectation::Evaluate)); 622 &EmptyResponseExpectation::Evaluate));
596 623
597 // Create method call; 624 // Create method call;
598 dbus::MethodCall method_call(ibus::engine::kServiceInterface, 625 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
599 ibus::engine::kDisableMethod); 626 ibus::engine::kDisableMethod);
600 method_call.SetSerial(kSerialNo); 627 method_call.SetSerial(kSerialNo);
601 628
602 // Call exported function. 629 // Call exported function.
603 EXPECT_NE(method_callback_map_.find(ibus::engine::kDisableMethod), 630 EXPECT_NE(method_callback_map_.find(ibus::engine::kDisableMethod),
604 method_callback_map_.end()); 631 method_callback_map_.end());
605 method_callback_map_[ibus::engine::kDisableMethod].Run( 632 method_callback_map_[ibus::engine::kDisableMethod].Run(
606 &method_call, 633 &method_call,
607 base::Bind(&MockResponseSender::Run, 634 base::Bind(&MockResponseSender::Run,
608 base::Unretained(&response_sender))); 635 base::Unretained(&response_sender)));
636
637 // Call exported function without engine.
638 service_->UnsetEngine();
639 EXPECT_CALL(*engine_handler_, Disable()).Times(0);
640 EXPECT_CALL(response_sender, Run(_)).Times(0);
641 method_callback_map_[ibus::engine::kDisableMethod].Run(
642 &method_call,
643 base::Bind(&MockResponseSender::Run,
644 base::Unretained(&response_sender)));
609 } 645 }
610 646
611 TEST_F(IBusEngineServiceTest, PropertyActivateTest) { 647 TEST_F(IBusEngineServiceTest, PropertyActivateTest) {
612 // Set expectations. 648 // Set expectations.
613 const uint32 kSerialNo = 1; 649 const uint32 kSerialNo = 1;
614 const std::string kPropertyName = "Property Name"; 650 const std::string kPropertyName = "Property Name";
615 const IBusEngineHandlerInterface::IBusPropertyState kIBusPropertyState = 651 const IBusEngineHandlerInterface::IBusPropertyState kIBusPropertyState =
616 IBusEngineHandlerInterface::IBUS_PROPERTY_STATE_UNCHECKED; 652 IBusEngineHandlerInterface::IBUS_PROPERTY_STATE_UNCHECKED;
617 EXPECT_CALL(*engine_handler_, PropertyActivate(kPropertyName, 653 EXPECT_CALL(*engine_handler_, PropertyActivate(kPropertyName,
618 kIBusPropertyState)); 654 kIBusPropertyState));
(...skipping 11 matching lines...) Expand all
630 writer.AppendString(kPropertyName); 666 writer.AppendString(kPropertyName);
631 writer.AppendUint32(static_cast<uint32>(kIBusPropertyState)); 667 writer.AppendUint32(static_cast<uint32>(kIBusPropertyState));
632 668
633 // Call exported function. 669 // Call exported function.
634 EXPECT_NE(method_callback_map_.find(ibus::engine::kPropertyActivateMethod), 670 EXPECT_NE(method_callback_map_.find(ibus::engine::kPropertyActivateMethod),
635 method_callback_map_.end()); 671 method_callback_map_.end());
636 method_callback_map_[ibus::engine::kPropertyActivateMethod].Run( 672 method_callback_map_[ibus::engine::kPropertyActivateMethod].Run(
637 &method_call, 673 &method_call,
638 base::Bind(&MockResponseSender::Run, 674 base::Bind(&MockResponseSender::Run,
639 base::Unretained(&response_sender))); 675 base::Unretained(&response_sender)));
676
677 // Call exported function without engine.
678 service_->UnsetEngine();
679 EXPECT_CALL(*engine_handler_, PropertyActivate(kPropertyName,
680 kIBusPropertyState)).Times(0);
681 EXPECT_CALL(response_sender, Run(_)).Times(0);
682 method_callback_map_[ibus::engine::kPropertyActivateMethod].Run(
683 &method_call,
684 base::Bind(&MockResponseSender::Run,
685 base::Unretained(&response_sender)));
640 } 686 }
641 687
642 TEST_F(IBusEngineServiceTest, ResetTest) { 688 TEST_F(IBusEngineServiceTest, ResetTest) {
643 // Set expectations. 689 // Set expectations.
644 const uint32 kSerialNo = 1; 690 const uint32 kSerialNo = 1;
645 EXPECT_CALL(*engine_handler_, Reset()); 691 EXPECT_CALL(*engine_handler_, Reset());
646 MockResponseSender response_sender; 692 MockResponseSender response_sender;
647 EmptyResponseExpectation response_expectation(kSerialNo); 693 EmptyResponseExpectation response_expectation(kSerialNo);
648 EXPECT_CALL(response_sender, Run(_)) 694 EXPECT_CALL(response_sender, Run(_))
649 .WillOnce(Invoke(&response_expectation, 695 .WillOnce(Invoke(&response_expectation,
650 &EmptyResponseExpectation::Evaluate)); 696 &EmptyResponseExpectation::Evaluate));
651 697
652 // Create method call; 698 // Create method call;
653 dbus::MethodCall method_call(ibus::engine::kServiceInterface, 699 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
654 ibus::engine::kResetMethod); 700 ibus::engine::kResetMethod);
655 method_call.SetSerial(kSerialNo); 701 method_call.SetSerial(kSerialNo);
656 702
657 // Call exported function. 703 // Call exported function.
658 EXPECT_NE(method_callback_map_.find(ibus::engine::kResetMethod), 704 EXPECT_NE(method_callback_map_.find(ibus::engine::kResetMethod),
659 method_callback_map_.end()); 705 method_callback_map_.end());
660 method_callback_map_[ibus::engine::kResetMethod].Run( 706 method_callback_map_[ibus::engine::kResetMethod].Run(
661 &method_call, 707 &method_call,
662 base::Bind(&MockResponseSender::Run, 708 base::Bind(&MockResponseSender::Run,
663 base::Unretained(&response_sender))); 709 base::Unretained(&response_sender)));
710
711 // Call exported function without engine.
712 service_->UnsetEngine();
713 EXPECT_CALL(*engine_handler_, Reset()).Times(0);
714 EXPECT_CALL(response_sender, Run(_)).Times(0);
715 method_callback_map_[ibus::engine::kResetMethod].Run(
716 &method_call,
717 base::Bind(&MockResponseSender::Run,
718 base::Unretained(&response_sender)));
664 } 719 }
665 720
666 TEST_F(IBusEngineServiceTest, PropertyShowTest) { 721 TEST_F(IBusEngineServiceTest, PropertyShowTest) {
667 // Set expectations. 722 // Set expectations.
668 const uint32 kSerialNo = 1; 723 const uint32 kSerialNo = 1;
669 const std::string kPropertyName = "Property Name"; 724 const std::string kPropertyName = "Property Name";
670 EXPECT_CALL(*engine_handler_, PropertyShow(kPropertyName)); 725 EXPECT_CALL(*engine_handler_, PropertyShow(kPropertyName));
671 MockResponseSender response_sender; 726 MockResponseSender response_sender;
672 EmptyResponseExpectation response_expectation(kSerialNo); 727 EmptyResponseExpectation response_expectation(kSerialNo);
673 EXPECT_CALL(response_sender, Run(_)) 728 EXPECT_CALL(response_sender, Run(_))
674 .WillOnce(Invoke(&response_expectation, 729 .WillOnce(Invoke(&response_expectation,
675 &EmptyResponseExpectation::Evaluate)); 730 &EmptyResponseExpectation::Evaluate));
676 731
677 // Create method call; 732 // Create method call;
678 dbus::MethodCall method_call(ibus::engine::kServiceInterface, 733 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
679 ibus::engine::kPropertyShowMethod); 734 ibus::engine::kPropertyShowMethod);
680 method_call.SetSerial(kSerialNo); 735 method_call.SetSerial(kSerialNo);
681 dbus::MessageWriter writer(&method_call); 736 dbus::MessageWriter writer(&method_call);
682 writer.AppendString(kPropertyName); 737 writer.AppendString(kPropertyName);
683 738
684 // Call exported function. 739 // Call exported function.
685 EXPECT_NE(method_callback_map_.find(ibus::engine::kPropertyShowMethod), 740 EXPECT_NE(method_callback_map_.find(ibus::engine::kPropertyShowMethod),
686 method_callback_map_.end()); 741 method_callback_map_.end());
687 method_callback_map_[ibus::engine::kPropertyShowMethod].Run( 742 method_callback_map_[ibus::engine::kPropertyShowMethod].Run(
688 &method_call, 743 &method_call,
689 base::Bind(&MockResponseSender::Run, 744 base::Bind(&MockResponseSender::Run,
690 base::Unretained(&response_sender))); 745 base::Unretained(&response_sender)));
746
747 // Call exported function without engine.
748 service_->UnsetEngine();
749 EXPECT_CALL(*engine_handler_, PropertyShow(kPropertyName)).Times(0);
750 EXPECT_CALL(response_sender, Run(_)).Times(0);
751 method_callback_map_[ibus::engine::kPropertyShowMethod].Run(
752 &method_call,
753 base::Bind(&MockResponseSender::Run,
754 base::Unretained(&response_sender)));
691 } 755 }
692 756
693 TEST_F(IBusEngineServiceTest, PropertyHideTest) { 757 TEST_F(IBusEngineServiceTest, PropertyHideTest) {
694 // Set expectations. 758 // Set expectations.
695 const uint32 kSerialNo = 1; 759 const uint32 kSerialNo = 1;
696 const std::string kPropertyName = "Property Name"; 760 const std::string kPropertyName = "Property Name";
697 EXPECT_CALL(*engine_handler_, PropertyHide(kPropertyName)); 761 EXPECT_CALL(*engine_handler_, PropertyHide(kPropertyName));
698 MockResponseSender response_sender; 762 MockResponseSender response_sender;
699 EmptyResponseExpectation response_expectation(kSerialNo); 763 EmptyResponseExpectation response_expectation(kSerialNo);
700 EXPECT_CALL(response_sender, Run(_)) 764 EXPECT_CALL(response_sender, Run(_))
701 .WillOnce(Invoke(&response_expectation, 765 .WillOnce(Invoke(&response_expectation,
702 &EmptyResponseExpectation::Evaluate)); 766 &EmptyResponseExpectation::Evaluate));
703 767
704 // Create method call; 768 // Create method call;
705 dbus::MethodCall method_call(ibus::engine::kServiceInterface, 769 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
706 ibus::engine::kPropertyHideMethod); 770 ibus::engine::kPropertyHideMethod);
707 method_call.SetSerial(kSerialNo); 771 method_call.SetSerial(kSerialNo);
708 dbus::MessageWriter writer(&method_call); 772 dbus::MessageWriter writer(&method_call);
709 writer.AppendString(kPropertyName); 773 writer.AppendString(kPropertyName);
710 774
711 // Call exported function. 775 // Call exported function.
712 EXPECT_NE(method_callback_map_.find(ibus::engine::kPropertyHideMethod), 776 EXPECT_NE(method_callback_map_.find(ibus::engine::kPropertyHideMethod),
713 method_callback_map_.end()); 777 method_callback_map_.end());
714 method_callback_map_[ibus::engine::kPropertyHideMethod].Run( 778 method_callback_map_[ibus::engine::kPropertyHideMethod].Run(
715 &method_call, 779 &method_call,
716 base::Bind(&MockResponseSender::Run, 780 base::Bind(&MockResponseSender::Run,
717 base::Unretained(&response_sender))); 781 base::Unretained(&response_sender)));
782
783 // Call exported function without engine.
784 service_->UnsetEngine();
785 EXPECT_CALL(*engine_handler_, PropertyHide(kPropertyName)).Times(0);
786 EXPECT_CALL(response_sender, Run(_)).Times(0);
787 method_callback_map_[ibus::engine::kPropertyHideMethod].Run(
788 &method_call,
789 base::Bind(&MockResponseSender::Run,
790 base::Unretained(&response_sender)));
718 } 791 }
719 792
720 TEST_F(IBusEngineServiceTest, SetCapabilityTest) { 793 TEST_F(IBusEngineServiceTest, SetCapabilityTest) {
721 // Set expectations. 794 // Set expectations.
722 const uint32 kSerialNo = 1; 795 const uint32 kSerialNo = 1;
723 const IBusEngineHandlerInterface::IBusCapability kIBusCapability = 796 const IBusEngineHandlerInterface::IBusCapability kIBusCapability =
724 IBusEngineHandlerInterface::IBUS_CAPABILITY_PREEDIT_TEXT; 797 IBusEngineHandlerInterface::IBUS_CAPABILITY_PREEDIT_TEXT;
725 EXPECT_CALL(*engine_handler_, SetCapability(kIBusCapability)); 798 EXPECT_CALL(*engine_handler_, SetCapability(kIBusCapability));
726 MockResponseSender response_sender; 799 MockResponseSender response_sender;
727 EmptyResponseExpectation response_expectation(kSerialNo); 800 EmptyResponseExpectation response_expectation(kSerialNo);
728 EXPECT_CALL(response_sender, Run(_)) 801 EXPECT_CALL(response_sender, Run(_))
729 .WillOnce(Invoke(&response_expectation, 802 .WillOnce(Invoke(&response_expectation,
730 &EmptyResponseExpectation::Evaluate)); 803 &EmptyResponseExpectation::Evaluate));
731 804
732 // Create method call; 805 // Create method call;
733 dbus::MethodCall method_call(ibus::engine::kServiceInterface, 806 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
734 ibus::engine::kSetCapabilityMethod); 807 ibus::engine::kSetCapabilityMethod);
735 method_call.SetSerial(kSerialNo); 808 method_call.SetSerial(kSerialNo);
736 dbus::MessageWriter writer(&method_call); 809 dbus::MessageWriter writer(&method_call);
737 writer.AppendUint32(static_cast<uint32>(kIBusCapability)); 810 writer.AppendUint32(static_cast<uint32>(kIBusCapability));
738 811
739 // Call exported function. 812 // Call exported function.
740 EXPECT_NE(method_callback_map_.find(ibus::engine::kSetCapabilityMethod), 813 EXPECT_NE(method_callback_map_.find(ibus::engine::kSetCapabilityMethod),
741 method_callback_map_.end()); 814 method_callback_map_.end());
742 method_callback_map_[ibus::engine::kSetCapabilityMethod].Run( 815 method_callback_map_[ibus::engine::kSetCapabilityMethod].Run(
743 &method_call, 816 &method_call,
744 base::Bind(&MockResponseSender::Run, 817 base::Bind(&MockResponseSender::Run,
745 base::Unretained(&response_sender))); 818 base::Unretained(&response_sender)));
819
820 // Call exported function without engine.
821 service_->UnsetEngine();
822 EXPECT_CALL(*engine_handler_, SetCapability(kIBusCapability)).Times(0);
823 EXPECT_CALL(response_sender, Run(_)).Times(0);
824 method_callback_map_[ibus::engine::kSetCapabilityMethod].Run(
825 &method_call,
826 base::Bind(&MockResponseSender::Run,
827 base::Unretained(&response_sender)));
746 } 828 }
747 829
748 TEST_F(IBusEngineServiceTest, ProcessKeyEventTest) { 830 TEST_F(IBusEngineServiceTest, ProcessKeyEventTest) {
749 // Set expectations. 831 // Set expectations.
750 const uint32 kSerialNo = 1; 832 const uint32 kSerialNo = 1;
751 const uint32 kKeySym = 0x64; 833 const uint32 kKeySym = 0x64;
752 const uint32 kKeyCode = 0x20; 834 const uint32 kKeyCode = 0x20;
753 const uint32 kState = 0x00; 835 const uint32 kState = 0x00;
754 const bool kResult = true; 836 const bool kResult = true;
755 837
(...skipping 16 matching lines...) Expand all
772 writer.AppendUint32(kKeyCode); 854 writer.AppendUint32(kKeyCode);
773 writer.AppendUint32(kState); 855 writer.AppendUint32(kState);
774 856
775 // Call exported function. 857 // Call exported function.
776 EXPECT_NE(method_callback_map_.find(ibus::engine::kProcessKeyEventMethod), 858 EXPECT_NE(method_callback_map_.find(ibus::engine::kProcessKeyEventMethod),
777 method_callback_map_.end()); 859 method_callback_map_.end());
778 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run( 860 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run(
779 &method_call, 861 &method_call,
780 base::Bind(&MockResponseSender::Run, 862 base::Bind(&MockResponseSender::Run,
781 base::Unretained(&response_sender))); 863 base::Unretained(&response_sender)));
864
865 // Call exported function without engine.
866 service_->UnsetEngine();
867 EXPECT_CALL(*engine_handler_,
868 ProcessKeyEvent(kKeySym, kKeyCode, kState, _)).Times(0);
869 EXPECT_CALL(response_sender, Run(_)).Times(0);
870 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run(
871 &method_call,
872 base::Bind(&MockResponseSender::Run,
873 base::Unretained(&response_sender)));
782 } 874 }
783 875
784 TEST_F(IBusEngineServiceTest, DelayProcessKeyEventTest) { 876 TEST_F(IBusEngineServiceTest, DelayProcessKeyEventTest) {
785 // Set expectations. 877 // Set expectations.
786 const uint32 kSerialNo = 1; 878 const uint32 kSerialNo = 1;
787 const uint32 kKeySym = 0x64; 879 const uint32 kKeySym = 0x64;
788 const uint32 kKeyCode = 0x20; 880 const uint32 kKeyCode = 0x20;
789 const uint32 kState = 0x00; 881 const uint32 kState = 0x00;
790 const bool kResult = true; 882 const bool kResult = true;
791 883
(...skipping 19 matching lines...) Expand all
811 // Call exported function. 903 // Call exported function.
812 EXPECT_NE(method_callback_map_.find(ibus::engine::kProcessKeyEventMethod), 904 EXPECT_NE(method_callback_map_.find(ibus::engine::kProcessKeyEventMethod),
813 method_callback_map_.end()); 905 method_callback_map_.end());
814 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run( 906 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run(
815 &method_call, 907 &method_call,
816 base::Bind(&MockResponseSender::Run, 908 base::Bind(&MockResponseSender::Run,
817 base::Unretained(&response_sender))); 909 base::Unretained(&response_sender)));
818 910
819 // Call KeyEventDone callback. 911 // Call KeyEventDone callback.
820 message_loop_.RunAllPending(); 912 message_loop_.RunAllPending();
913
914 // Call exported function without engine.
915 service_->UnsetEngine();
916 EXPECT_CALL(*engine_handler_,
917 ProcessKeyEvent(kKeySym, kKeyCode, kState, _)).Times(0);
918 EXPECT_CALL(response_sender, Run(_)).Times(0);
919 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run(
920 &method_call,
921 base::Bind(&MockResponseSender::Run,
922 base::Unretained(&response_sender)));
821 } 923 }
822 924
823 TEST_F(IBusEngineServiceTest, CandidateClickedTest) { 925 TEST_F(IBusEngineServiceTest, CandidateClickedTest) {
824 // Set expectations. 926 // Set expectations.
825 const uint32 kSerialNo = 1; 927 const uint32 kSerialNo = 1;
826 const uint32 kIndex = 4; 928 const uint32 kIndex = 4;
827 const IBusEngineHandlerInterface::IBusMouseButton kIBusMouseButton = 929 const IBusEngineHandlerInterface::IBusMouseButton kIBusMouseButton =
828 IBusEngineHandlerInterface::IBUS_MOUSE_BUTTON_MIDDLE; 930 IBusEngineHandlerInterface::IBUS_MOUSE_BUTTON_MIDDLE;
829 const uint32 kState = 3; 931 const uint32 kState = 3;
830 EXPECT_CALL(*engine_handler_, CandidateClicked(kIndex, kIBusMouseButton, 932 EXPECT_CALL(*engine_handler_, CandidateClicked(kIndex, kIBusMouseButton,
(...skipping 13 matching lines...) Expand all
844 writer.AppendUint32(static_cast<uint32>(kIBusMouseButton)); 946 writer.AppendUint32(static_cast<uint32>(kIBusMouseButton));
845 writer.AppendUint32(kState); 947 writer.AppendUint32(kState);
846 948
847 // Call exported function. 949 // Call exported function.
848 EXPECT_NE(method_callback_map_.find(ibus::engine::kCandidateClickedMethod), 950 EXPECT_NE(method_callback_map_.find(ibus::engine::kCandidateClickedMethod),
849 method_callback_map_.end()); 951 method_callback_map_.end());
850 method_callback_map_[ibus::engine::kCandidateClickedMethod].Run( 952 method_callback_map_[ibus::engine::kCandidateClickedMethod].Run(
851 &method_call, 953 &method_call,
852 base::Bind(&MockResponseSender::Run, 954 base::Bind(&MockResponseSender::Run,
853 base::Unretained(&response_sender))); 955 base::Unretained(&response_sender)));
956
957 // Call exported function without engine.
958 service_->UnsetEngine();
959 EXPECT_CALL(*engine_handler_, CandidateClicked(kIndex, kIBusMouseButton,
960 kState)).Times(0);
961 EXPECT_CALL(response_sender, Run(_)).Times(0);
962 method_callback_map_[ibus::engine::kCandidateClickedMethod].Run(
963 &method_call,
964 base::Bind(&MockResponseSender::Run,
965 base::Unretained(&response_sender)));
854 } 966 }
855 967
856 TEST_F(IBusEngineServiceTest, SetSurroundingTextTest) { 968 TEST_F(IBusEngineServiceTest, SetSurroundingTextTest) {
857 // Set expectations. 969 // Set expectations.
858 const uint32 kSerialNo = 1; 970 const uint32 kSerialNo = 1;
859 const std::string kText = "Sample Text"; 971 const std::string kText = "Sample Text";
860 const uint32 kCursorPos = 3; 972 const uint32 kCursorPos = 3;
861 const uint32 kAnchorPos = 4; 973 const uint32 kAnchorPos = 4;
862 EXPECT_CALL(*engine_handler_, SetSurroundingText(kText, kCursorPos, 974 EXPECT_CALL(*engine_handler_, SetSurroundingText(kText, kCursorPos,
863 kAnchorPos)); 975 kAnchorPos));
(...skipping 12 matching lines...) Expand all
876 writer.AppendUint32(kCursorPos); 988 writer.AppendUint32(kCursorPos);
877 writer.AppendUint32(kAnchorPos); 989 writer.AppendUint32(kAnchorPos);
878 990
879 // Call exported function. 991 // Call exported function.
880 EXPECT_NE(method_callback_map_.find(ibus::engine::kSetSurroundingTextMethod), 992 EXPECT_NE(method_callback_map_.find(ibus::engine::kSetSurroundingTextMethod),
881 method_callback_map_.end()); 993 method_callback_map_.end());
882 method_callback_map_[ibus::engine::kSetSurroundingTextMethod].Run( 994 method_callback_map_[ibus::engine::kSetSurroundingTextMethod].Run(
883 &method_call, 995 &method_call,
884 base::Bind(&MockResponseSender::Run, 996 base::Bind(&MockResponseSender::Run,
885 base::Unretained(&response_sender))); 997 base::Unretained(&response_sender)));
998
999 // Call exported function without engine.
1000 service_->UnsetEngine();
1001 EXPECT_CALL(*engine_handler_, SetSurroundingText(kText, kCursorPos,
1002 kAnchorPos)).Times(0);
1003 EXPECT_CALL(response_sender, Run(_)).Times(0);
1004 method_callback_map_[ibus::engine::kSetSurroundingTextMethod].Run(
1005 &method_call,
1006 base::Bind(&MockResponseSender::Run,
1007 base::Unretained(&response_sender)));
886 } 1008 }
887 1009
888 TEST_F(IBusEngineServiceTest, RegisterProperties) { 1010 TEST_F(IBusEngineServiceTest, RegisterProperties) {
889 // Set expetations. 1011 // Set expetations.
890 ibus::IBusPropertyList property_list; 1012 ibus::IBusPropertyList property_list;
891 property_list.push_back(new ibus::IBusProperty()); 1013 property_list.push_back(new ibus::IBusProperty());
892 property_list[0]->set_key("Sample Key"); 1014 property_list[0]->set_key("Sample Key");
893 property_list[0]->set_type(ibus::IBusProperty::IBUS_PROPERTY_TYPE_MENU); 1015 property_list[0]->set_type(ibus::IBusProperty::IBUS_PROPERTY_TYPE_MENU);
894 property_list[0]->set_label("Sample Label"); 1016 property_list[0]->set_label("Sample Label");
895 property_list[0]->set_tooltip("Sample Tooltip"); 1017 property_list[0]->set_tooltip("Sample Tooltip");
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 TEST_F(IBusEngineServiceTest, RequireSurroundingTextTest) { 1109 TEST_F(IBusEngineServiceTest, RequireSurroundingTextTest) {
988 RequireSurroundingTextExpectation expectation; 1110 RequireSurroundingTextExpectation expectation;
989 EXPECT_CALL(*mock_exported_object_, SendSignal(_)) 1111 EXPECT_CALL(*mock_exported_object_, SendSignal(_))
990 .WillOnce(Invoke(&expectation, 1112 .WillOnce(Invoke(&expectation,
991 &RequireSurroundingTextExpectation::Evaluate)); 1113 &RequireSurroundingTextExpectation::Evaluate));
992 1114
993 // Emit signal. 1115 // Emit signal.
994 service_->RequireSurroundingText(); 1116 service_->RequireSurroundingText();
995 } 1117 }
996 1118
997
998 } // namespace chromeos 1119 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/ibus/ibus_engine_service.cc ('k') | chromeos/dbus/ibus/mock_ibus_engine_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698