| 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 "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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 MOCK_METHOD3(CandidateClicked, void(uint32 index, | 49 MOCK_METHOD3(CandidateClicked, void(uint32 index, |
| 50 ibus::IBusMouseButton button, | 50 ibus::IBusMouseButton button, |
| 51 uint32 state)); | 51 uint32 state)); |
| 52 MOCK_METHOD3(SetSurroundingText, void(const std::string& text, | 52 MOCK_METHOD3(SetSurroundingText, void(const std::string& text, |
| 53 uint32 cursor_pos, | 53 uint32 cursor_pos, |
| 54 uint32 anchor_pos)); | 54 uint32 anchor_pos)); |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 class MockResponseSender { | 57 class MockResponseSender { |
| 58 public: | 58 public: |
| 59 MOCK_METHOD1(Run, void(dbus::Response* reponse)); | 59 // GMock doesn't support mocking methods which take scoped_ptr<>. |
| 60 MOCK_METHOD1(MockRun, void(dbus::Response* reponse)); |
| 61 void Run(scoped_ptr<dbus::Response> response) { |
| 62 MockRun(response.get()); |
| 63 } |
| 60 }; | 64 }; |
| 61 | 65 |
| 62 // Used for method call empty response evaluation. | 66 // Used for method call empty response evaluation. |
| 63 class EmptyResponseExpectation { | 67 class EmptyResponseExpectation { |
| 64 public: | 68 public: |
| 65 explicit EmptyResponseExpectation(const uint32 serial_no) | 69 explicit EmptyResponseExpectation(const uint32 serial_no) |
| 66 : serial_no_(serial_no) {} | 70 : serial_no_(serial_no) {} |
| 67 | 71 |
| 68 // Evaluates the given |response| has no argument. | 72 // Evaluates the given |response| has no argument. |
| 69 void Evaluate(dbus::Response* response) { | 73 void Evaluate(dbus::Response* response) { |
| 70 scoped_ptr<dbus::Response> response_deleter(response); | |
| 71 EXPECT_EQ(serial_no_, response->GetReplySerial()); | 74 EXPECT_EQ(serial_no_, response->GetReplySerial()); |
| 72 dbus::MessageReader reader(response); | 75 dbus::MessageReader reader(response); |
| 73 EXPECT_FALSE(reader.HasMoreData()); | 76 EXPECT_FALSE(reader.HasMoreData()); |
| 74 } | 77 } |
| 75 | 78 |
| 76 private: | 79 private: |
| 77 const uint32 serial_no_; | 80 const uint32 serial_no_; |
| 78 | 81 |
| 79 DISALLOW_COPY_AND_ASSIGN(EmptyResponseExpectation); | 82 DISALLOW_COPY_AND_ASSIGN(EmptyResponseExpectation); |
| 80 }; | 83 }; |
| 81 | 84 |
| 82 // Used for method call a boolean response evaluation. | 85 // Used for method call a boolean response evaluation. |
| 83 class BoolResponseExpectation { | 86 class BoolResponseExpectation { |
| 84 public: | 87 public: |
| 85 explicit BoolResponseExpectation(uint32 serial_no, bool result) | 88 explicit BoolResponseExpectation(uint32 serial_no, bool result) |
| 86 : serial_no_(serial_no), | 89 : serial_no_(serial_no), |
| 87 result_(result) {} | 90 result_(result) {} |
| 88 | 91 |
| 89 // Evaluates the given |response| has only one boolean and which is equals to | 92 // Evaluates the given |response| has only one boolean and which is equals to |
| 90 // |result_| which is given in ctor. | 93 // |result_| which is given in ctor. |
| 91 void Evaluate(dbus::Response* response) { | 94 void Evaluate(dbus::Response* response) { |
| 92 scoped_ptr<dbus::Response> response_deleter(response); | |
| 93 EXPECT_EQ(serial_no_, response->GetReplySerial()); | 95 EXPECT_EQ(serial_no_, response->GetReplySerial()); |
| 94 dbus::MessageReader reader(response); | 96 dbus::MessageReader reader(response); |
| 95 bool result = false; | 97 bool result = false; |
| 96 EXPECT_TRUE(reader.PopBool(&result)); | 98 EXPECT_TRUE(reader.PopBool(&result)); |
| 97 EXPECT_EQ(result_, result); | 99 EXPECT_EQ(result_, result); |
| 98 EXPECT_FALSE(reader.HasMoreData()); | 100 EXPECT_FALSE(reader.HasMoreData()); |
| 99 } | 101 } |
| 100 | 102 |
| 101 private: | 103 private: |
| 102 uint32 serial_no_; | 104 uint32 serial_no_; |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 success)); | 514 success)); |
| 513 } | 515 } |
| 514 }; | 516 }; |
| 515 | 517 |
| 516 TEST_F(IBusEngineServiceTest, FocusInTest) { | 518 TEST_F(IBusEngineServiceTest, FocusInTest) { |
| 517 // Set expectations. | 519 // Set expectations. |
| 518 const uint32 kSerialNo = 1; | 520 const uint32 kSerialNo = 1; |
| 519 EXPECT_CALL(*engine_handler_, FocusIn()); | 521 EXPECT_CALL(*engine_handler_, FocusIn()); |
| 520 MockResponseSender response_sender; | 522 MockResponseSender response_sender; |
| 521 EmptyResponseExpectation response_expectation(kSerialNo); | 523 EmptyResponseExpectation response_expectation(kSerialNo); |
| 522 EXPECT_CALL(response_sender, Run(_)) | 524 EXPECT_CALL(response_sender, MockRun(_)) |
| 523 .WillOnce(Invoke(&response_expectation, | 525 .WillOnce(Invoke(&response_expectation, |
| 524 &EmptyResponseExpectation::Evaluate)); | 526 &EmptyResponseExpectation::Evaluate)); |
| 525 | 527 |
| 526 // Create method call; | 528 // Create method call; |
| 527 dbus::MethodCall method_call(ibus::engine::kServiceInterface, | 529 dbus::MethodCall method_call(ibus::engine::kServiceInterface, |
| 528 ibus::engine::kFocusInMethod); | 530 ibus::engine::kFocusInMethod); |
| 529 method_call.SetSerial(kSerialNo); | 531 method_call.SetSerial(kSerialNo); |
| 530 | 532 |
| 531 // Call exported function. | 533 // Call exported function. |
| 532 EXPECT_NE(method_callback_map_.find(ibus::engine::kFocusInMethod), | 534 EXPECT_NE(method_callback_map_.find(ibus::engine::kFocusInMethod), |
| 533 method_callback_map_.end()); | 535 method_callback_map_.end()); |
| 534 method_callback_map_[ibus::engine::kFocusInMethod].Run( | 536 method_callback_map_[ibus::engine::kFocusInMethod].Run( |
| 535 &method_call, | 537 &method_call, |
| 536 base::Bind(&MockResponseSender::Run, | 538 base::Bind(&MockResponseSender::Run, |
| 537 base::Unretained(&response_sender))); | 539 base::Unretained(&response_sender))); |
| 538 | 540 |
| 539 // Call exported function without engine. | 541 // Call exported function without engine. |
| 540 service_->UnsetEngine(); | 542 service_->UnsetEngine(); |
| 541 EXPECT_CALL(*engine_handler_, FocusIn()).Times(0); | 543 EXPECT_CALL(*engine_handler_, FocusIn()).Times(0); |
| 542 EXPECT_CALL(response_sender, Run(_)).Times(0); | 544 EXPECT_CALL(response_sender, MockRun(_)).Times(0); |
| 543 method_callback_map_[ibus::engine::kFocusInMethod].Run( | 545 method_callback_map_[ibus::engine::kFocusInMethod].Run( |
| 544 &method_call, | 546 &method_call, |
| 545 base::Bind(&MockResponseSender::Run, | 547 base::Bind(&MockResponseSender::Run, |
| 546 base::Unretained(&response_sender))); | 548 base::Unretained(&response_sender))); |
| 547 } | 549 } |
| 548 | 550 |
| 549 TEST_F(IBusEngineServiceTest, FocusOutTest) { | 551 TEST_F(IBusEngineServiceTest, FocusOutTest) { |
| 550 // Set expectations. | 552 // Set expectations. |
| 551 const uint32 kSerialNo = 1; | 553 const uint32 kSerialNo = 1; |
| 552 EXPECT_CALL(*engine_handler_, FocusOut()); | 554 EXPECT_CALL(*engine_handler_, FocusOut()); |
| 553 MockResponseSender response_sender; | 555 MockResponseSender response_sender; |
| 554 EmptyResponseExpectation response_expectation(kSerialNo); | 556 EmptyResponseExpectation response_expectation(kSerialNo); |
| 555 EXPECT_CALL(response_sender, Run(_)) | 557 EXPECT_CALL(response_sender, MockRun(_)) |
| 556 .WillOnce(Invoke(&response_expectation, | 558 .WillOnce(Invoke(&response_expectation, |
| 557 &EmptyResponseExpectation::Evaluate)); | 559 &EmptyResponseExpectation::Evaluate)); |
| 558 | 560 |
| 559 // Create method call; | 561 // Create method call; |
| 560 dbus::MethodCall method_call(ibus::engine::kServiceInterface, | 562 dbus::MethodCall method_call(ibus::engine::kServiceInterface, |
| 561 ibus::engine::kFocusOutMethod); | 563 ibus::engine::kFocusOutMethod); |
| 562 method_call.SetSerial(kSerialNo); | 564 method_call.SetSerial(kSerialNo); |
| 563 | 565 |
| 564 // Call exported function. | 566 // Call exported function. |
| 565 EXPECT_NE(method_callback_map_.find(ibus::engine::kFocusOutMethod), | 567 EXPECT_NE(method_callback_map_.find(ibus::engine::kFocusOutMethod), |
| 566 method_callback_map_.end()); | 568 method_callback_map_.end()); |
| 567 method_callback_map_[ibus::engine::kFocusOutMethod].Run( | 569 method_callback_map_[ibus::engine::kFocusOutMethod].Run( |
| 568 &method_call, | 570 &method_call, |
| 569 base::Bind(&MockResponseSender::Run, | 571 base::Bind(&MockResponseSender::Run, |
| 570 base::Unretained(&response_sender))); | 572 base::Unretained(&response_sender))); |
| 571 | 573 |
| 572 // Call exported function without engine. | 574 // Call exported function without engine. |
| 573 service_->UnsetEngine(); | 575 service_->UnsetEngine(); |
| 574 EXPECT_CALL(*engine_handler_, FocusOut()).Times(0); | 576 EXPECT_CALL(*engine_handler_, FocusOut()).Times(0); |
| 575 EXPECT_CALL(response_sender, Run(_)).Times(0); | 577 EXPECT_CALL(response_sender, MockRun(_)).Times(0); |
| 576 method_callback_map_[ibus::engine::kFocusOutMethod].Run( | 578 method_callback_map_[ibus::engine::kFocusOutMethod].Run( |
| 577 &method_call, | 579 &method_call, |
| 578 base::Bind(&MockResponseSender::Run, | 580 base::Bind(&MockResponseSender::Run, |
| 579 base::Unretained(&response_sender))); | 581 base::Unretained(&response_sender))); |
| 580 } | 582 } |
| 581 | 583 |
| 582 TEST_F(IBusEngineServiceTest, EnableTest) { | 584 TEST_F(IBusEngineServiceTest, EnableTest) { |
| 583 // Set expectations. | 585 // Set expectations. |
| 584 const uint32 kSerialNo = 1; | 586 const uint32 kSerialNo = 1; |
| 585 EXPECT_CALL(*engine_handler_, Enable()); | 587 EXPECT_CALL(*engine_handler_, Enable()); |
| 586 MockResponseSender response_sender; | 588 MockResponseSender response_sender; |
| 587 EmptyResponseExpectation response_expectation(kSerialNo); | 589 EmptyResponseExpectation response_expectation(kSerialNo); |
| 588 EXPECT_CALL(response_sender, Run(_)) | 590 EXPECT_CALL(response_sender, MockRun(_)) |
| 589 .WillOnce(Invoke(&response_expectation, | 591 .WillOnce(Invoke(&response_expectation, |
| 590 &EmptyResponseExpectation::Evaluate)); | 592 &EmptyResponseExpectation::Evaluate)); |
| 591 | 593 |
| 592 // Create method call; | 594 // Create method call; |
| 593 dbus::MethodCall method_call(ibus::engine::kServiceInterface, | 595 dbus::MethodCall method_call(ibus::engine::kServiceInterface, |
| 594 ibus::engine::kEnableMethod); | 596 ibus::engine::kEnableMethod); |
| 595 method_call.SetSerial(kSerialNo); | 597 method_call.SetSerial(kSerialNo); |
| 596 | 598 |
| 597 // Call exported function. | 599 // Call exported function. |
| 598 EXPECT_NE(method_callback_map_.find(ibus::engine::kEnableMethod), | 600 EXPECT_NE(method_callback_map_.find(ibus::engine::kEnableMethod), |
| 599 method_callback_map_.end()); | 601 method_callback_map_.end()); |
| 600 method_callback_map_[ibus::engine::kEnableMethod].Run( | 602 method_callback_map_[ibus::engine::kEnableMethod].Run( |
| 601 &method_call, | 603 &method_call, |
| 602 base::Bind(&MockResponseSender::Run, | 604 base::Bind(&MockResponseSender::Run, |
| 603 base::Unretained(&response_sender))); | 605 base::Unretained(&response_sender))); |
| 604 | 606 |
| 605 // Call exported function without engine. | 607 // Call exported function without engine. |
| 606 service_->UnsetEngine(); | 608 service_->UnsetEngine(); |
| 607 EXPECT_CALL(*engine_handler_, Enable()).Times(0); | 609 EXPECT_CALL(*engine_handler_, Enable()).Times(0); |
| 608 EXPECT_CALL(response_sender, Run(_)).Times(0); | 610 EXPECT_CALL(response_sender, MockRun(_)).Times(0); |
| 609 method_callback_map_[ibus::engine::kEnableMethod].Run( | 611 method_callback_map_[ibus::engine::kEnableMethod].Run( |
| 610 &method_call, | 612 &method_call, |
| 611 base::Bind(&MockResponseSender::Run, | 613 base::Bind(&MockResponseSender::Run, |
| 612 base::Unretained(&response_sender))); | 614 base::Unretained(&response_sender))); |
| 613 } | 615 } |
| 614 | 616 |
| 615 TEST_F(IBusEngineServiceTest, DisableTest) { | 617 TEST_F(IBusEngineServiceTest, DisableTest) { |
| 616 // Set expectations. | 618 // Set expectations. |
| 617 const uint32 kSerialNo = 1; | 619 const uint32 kSerialNo = 1; |
| 618 EXPECT_CALL(*engine_handler_, Disable()); | 620 EXPECT_CALL(*engine_handler_, Disable()); |
| 619 MockResponseSender response_sender; | 621 MockResponseSender response_sender; |
| 620 EmptyResponseExpectation response_expectation(kSerialNo); | 622 EmptyResponseExpectation response_expectation(kSerialNo); |
| 621 EXPECT_CALL(response_sender, Run(_)) | 623 EXPECT_CALL(response_sender, MockRun(_)) |
| 622 .WillOnce(Invoke(&response_expectation, | 624 .WillOnce(Invoke(&response_expectation, |
| 623 &EmptyResponseExpectation::Evaluate)); | 625 &EmptyResponseExpectation::Evaluate)); |
| 624 | 626 |
| 625 // Create method call; | 627 // Create method call; |
| 626 dbus::MethodCall method_call(ibus::engine::kServiceInterface, | 628 dbus::MethodCall method_call(ibus::engine::kServiceInterface, |
| 627 ibus::engine::kDisableMethod); | 629 ibus::engine::kDisableMethod); |
| 628 method_call.SetSerial(kSerialNo); | 630 method_call.SetSerial(kSerialNo); |
| 629 | 631 |
| 630 // Call exported function. | 632 // Call exported function. |
| 631 EXPECT_NE(method_callback_map_.find(ibus::engine::kDisableMethod), | 633 EXPECT_NE(method_callback_map_.find(ibus::engine::kDisableMethod), |
| 632 method_callback_map_.end()); | 634 method_callback_map_.end()); |
| 633 method_callback_map_[ibus::engine::kDisableMethod].Run( | 635 method_callback_map_[ibus::engine::kDisableMethod].Run( |
| 634 &method_call, | 636 &method_call, |
| 635 base::Bind(&MockResponseSender::Run, | 637 base::Bind(&MockResponseSender::Run, |
| 636 base::Unretained(&response_sender))); | 638 base::Unretained(&response_sender))); |
| 637 | 639 |
| 638 // Call exported function without engine. | 640 // Call exported function without engine. |
| 639 service_->UnsetEngine(); | 641 service_->UnsetEngine(); |
| 640 EXPECT_CALL(*engine_handler_, Disable()).Times(0); | 642 EXPECT_CALL(*engine_handler_, Disable()).Times(0); |
| 641 EXPECT_CALL(response_sender, Run(_)).Times(0); | 643 EXPECT_CALL(response_sender, MockRun(_)).Times(0); |
| 642 method_callback_map_[ibus::engine::kDisableMethod].Run( | 644 method_callback_map_[ibus::engine::kDisableMethod].Run( |
| 643 &method_call, | 645 &method_call, |
| 644 base::Bind(&MockResponseSender::Run, | 646 base::Bind(&MockResponseSender::Run, |
| 645 base::Unretained(&response_sender))); | 647 base::Unretained(&response_sender))); |
| 646 } | 648 } |
| 647 | 649 |
| 648 TEST_F(IBusEngineServiceTest, PropertyActivateTest) { | 650 TEST_F(IBusEngineServiceTest, PropertyActivateTest) { |
| 649 // Set expectations. | 651 // Set expectations. |
| 650 const uint32 kSerialNo = 1; | 652 const uint32 kSerialNo = 1; |
| 651 const std::string kPropertyName = "Property Name"; | 653 const std::string kPropertyName = "Property Name"; |
| 652 const ibus::IBusPropertyState kIBusPropertyState = | 654 const ibus::IBusPropertyState kIBusPropertyState = |
| 653 ibus::IBUS_PROPERTY_STATE_UNCHECKED; | 655 ibus::IBUS_PROPERTY_STATE_UNCHECKED; |
| 654 EXPECT_CALL(*engine_handler_, PropertyActivate(kPropertyName, | 656 EXPECT_CALL(*engine_handler_, PropertyActivate(kPropertyName, |
| 655 kIBusPropertyState)); | 657 kIBusPropertyState)); |
| 656 MockResponseSender response_sender; | 658 MockResponseSender response_sender; |
| 657 EmptyResponseExpectation response_expectation(kSerialNo); | 659 EmptyResponseExpectation response_expectation(kSerialNo); |
| 658 EXPECT_CALL(response_sender, Run(_)) | 660 EXPECT_CALL(response_sender, MockRun(_)) |
| 659 .WillOnce(Invoke(&response_expectation, | 661 .WillOnce(Invoke(&response_expectation, |
| 660 &EmptyResponseExpectation::Evaluate)); | 662 &EmptyResponseExpectation::Evaluate)); |
| 661 | 663 |
| 662 // Create method call; | 664 // Create method call; |
| 663 dbus::MethodCall method_call(ibus::engine::kServiceInterface, | 665 dbus::MethodCall method_call(ibus::engine::kServiceInterface, |
| 664 ibus::engine::kPropertyActivateMethod); | 666 ibus::engine::kPropertyActivateMethod); |
| 665 method_call.SetSerial(kSerialNo); | 667 method_call.SetSerial(kSerialNo); |
| 666 dbus::MessageWriter writer(&method_call); | 668 dbus::MessageWriter writer(&method_call); |
| 667 writer.AppendString(kPropertyName); | 669 writer.AppendString(kPropertyName); |
| 668 writer.AppendUint32(static_cast<uint32>(kIBusPropertyState)); | 670 writer.AppendUint32(static_cast<uint32>(kIBusPropertyState)); |
| 669 | 671 |
| 670 // Call exported function. | 672 // Call exported function. |
| 671 EXPECT_NE(method_callback_map_.find(ibus::engine::kPropertyActivateMethod), | 673 EXPECT_NE(method_callback_map_.find(ibus::engine::kPropertyActivateMethod), |
| 672 method_callback_map_.end()); | 674 method_callback_map_.end()); |
| 673 method_callback_map_[ibus::engine::kPropertyActivateMethod].Run( | 675 method_callback_map_[ibus::engine::kPropertyActivateMethod].Run( |
| 674 &method_call, | 676 &method_call, |
| 675 base::Bind(&MockResponseSender::Run, | 677 base::Bind(&MockResponseSender::Run, |
| 676 base::Unretained(&response_sender))); | 678 base::Unretained(&response_sender))); |
| 677 | 679 |
| 678 // Call exported function without engine. | 680 // Call exported function without engine. |
| 679 service_->UnsetEngine(); | 681 service_->UnsetEngine(); |
| 680 EXPECT_CALL(*engine_handler_, PropertyActivate(kPropertyName, | 682 EXPECT_CALL(*engine_handler_, PropertyActivate(kPropertyName, |
| 681 kIBusPropertyState)).Times(0); | 683 kIBusPropertyState)).Times(0); |
| 682 EXPECT_CALL(response_sender, Run(_)).Times(0); | 684 EXPECT_CALL(response_sender, MockRun(_)).Times(0); |
| 683 method_callback_map_[ibus::engine::kPropertyActivateMethod].Run( | 685 method_callback_map_[ibus::engine::kPropertyActivateMethod].Run( |
| 684 &method_call, | 686 &method_call, |
| 685 base::Bind(&MockResponseSender::Run, | 687 base::Bind(&MockResponseSender::Run, |
| 686 base::Unretained(&response_sender))); | 688 base::Unretained(&response_sender))); |
| 687 } | 689 } |
| 688 | 690 |
| 689 TEST_F(IBusEngineServiceTest, ResetTest) { | 691 TEST_F(IBusEngineServiceTest, ResetTest) { |
| 690 // Set expectations. | 692 // Set expectations. |
| 691 const uint32 kSerialNo = 1; | 693 const uint32 kSerialNo = 1; |
| 692 EXPECT_CALL(*engine_handler_, Reset()); | 694 EXPECT_CALL(*engine_handler_, Reset()); |
| 693 MockResponseSender response_sender; | 695 MockResponseSender response_sender; |
| 694 EmptyResponseExpectation response_expectation(kSerialNo); | 696 EmptyResponseExpectation response_expectation(kSerialNo); |
| 695 EXPECT_CALL(response_sender, Run(_)) | 697 EXPECT_CALL(response_sender, MockRun(_)) |
| 696 .WillOnce(Invoke(&response_expectation, | 698 .WillOnce(Invoke(&response_expectation, |
| 697 &EmptyResponseExpectation::Evaluate)); | 699 &EmptyResponseExpectation::Evaluate)); |
| 698 | 700 |
| 699 // Create method call; | 701 // Create method call; |
| 700 dbus::MethodCall method_call(ibus::engine::kServiceInterface, | 702 dbus::MethodCall method_call(ibus::engine::kServiceInterface, |
| 701 ibus::engine::kResetMethod); | 703 ibus::engine::kResetMethod); |
| 702 method_call.SetSerial(kSerialNo); | 704 method_call.SetSerial(kSerialNo); |
| 703 | 705 |
| 704 // Call exported function. | 706 // Call exported function. |
| 705 EXPECT_NE(method_callback_map_.find(ibus::engine::kResetMethod), | 707 EXPECT_NE(method_callback_map_.find(ibus::engine::kResetMethod), |
| 706 method_callback_map_.end()); | 708 method_callback_map_.end()); |
| 707 method_callback_map_[ibus::engine::kResetMethod].Run( | 709 method_callback_map_[ibus::engine::kResetMethod].Run( |
| 708 &method_call, | 710 &method_call, |
| 709 base::Bind(&MockResponseSender::Run, | 711 base::Bind(&MockResponseSender::Run, |
| 710 base::Unretained(&response_sender))); | 712 base::Unretained(&response_sender))); |
| 711 | 713 |
| 712 // Call exported function without engine. | 714 // Call exported function without engine. |
| 713 service_->UnsetEngine(); | 715 service_->UnsetEngine(); |
| 714 EXPECT_CALL(*engine_handler_, Reset()).Times(0); | 716 EXPECT_CALL(*engine_handler_, Reset()).Times(0); |
| 715 EXPECT_CALL(response_sender, Run(_)).Times(0); | 717 EXPECT_CALL(response_sender, MockRun(_)).Times(0); |
| 716 method_callback_map_[ibus::engine::kResetMethod].Run( | 718 method_callback_map_[ibus::engine::kResetMethod].Run( |
| 717 &method_call, | 719 &method_call, |
| 718 base::Bind(&MockResponseSender::Run, | 720 base::Bind(&MockResponseSender::Run, |
| 719 base::Unretained(&response_sender))); | 721 base::Unretained(&response_sender))); |
| 720 } | 722 } |
| 721 | 723 |
| 722 TEST_F(IBusEngineServiceTest, PropertyShowTest) { | 724 TEST_F(IBusEngineServiceTest, PropertyShowTest) { |
| 723 // Set expectations. | 725 // Set expectations. |
| 724 const uint32 kSerialNo = 1; | 726 const uint32 kSerialNo = 1; |
| 725 const std::string kPropertyName = "Property Name"; | 727 const std::string kPropertyName = "Property Name"; |
| 726 EXPECT_CALL(*engine_handler_, PropertyShow(kPropertyName)); | 728 EXPECT_CALL(*engine_handler_, PropertyShow(kPropertyName)); |
| 727 MockResponseSender response_sender; | 729 MockResponseSender response_sender; |
| 728 EmptyResponseExpectation response_expectation(kSerialNo); | 730 EmptyResponseExpectation response_expectation(kSerialNo); |
| 729 EXPECT_CALL(response_sender, Run(_)) | 731 EXPECT_CALL(response_sender, MockRun(_)) |
| 730 .WillOnce(Invoke(&response_expectation, | 732 .WillOnce(Invoke(&response_expectation, |
| 731 &EmptyResponseExpectation::Evaluate)); | 733 &EmptyResponseExpectation::Evaluate)); |
| 732 | 734 |
| 733 // Create method call; | 735 // Create method call; |
| 734 dbus::MethodCall method_call(ibus::engine::kServiceInterface, | 736 dbus::MethodCall method_call(ibus::engine::kServiceInterface, |
| 735 ibus::engine::kPropertyShowMethod); | 737 ibus::engine::kPropertyShowMethod); |
| 736 method_call.SetSerial(kSerialNo); | 738 method_call.SetSerial(kSerialNo); |
| 737 dbus::MessageWriter writer(&method_call); | 739 dbus::MessageWriter writer(&method_call); |
| 738 writer.AppendString(kPropertyName); | 740 writer.AppendString(kPropertyName); |
| 739 | 741 |
| 740 // Call exported function. | 742 // Call exported function. |
| 741 EXPECT_NE(method_callback_map_.find(ibus::engine::kPropertyShowMethod), | 743 EXPECT_NE(method_callback_map_.find(ibus::engine::kPropertyShowMethod), |
| 742 method_callback_map_.end()); | 744 method_callback_map_.end()); |
| 743 method_callback_map_[ibus::engine::kPropertyShowMethod].Run( | 745 method_callback_map_[ibus::engine::kPropertyShowMethod].Run( |
| 744 &method_call, | 746 &method_call, |
| 745 base::Bind(&MockResponseSender::Run, | 747 base::Bind(&MockResponseSender::Run, |
| 746 base::Unretained(&response_sender))); | 748 base::Unretained(&response_sender))); |
| 747 | 749 |
| 748 // Call exported function without engine. | 750 // Call exported function without engine. |
| 749 service_->UnsetEngine(); | 751 service_->UnsetEngine(); |
| 750 EXPECT_CALL(*engine_handler_, PropertyShow(kPropertyName)).Times(0); | 752 EXPECT_CALL(*engine_handler_, PropertyShow(kPropertyName)).Times(0); |
| 751 EXPECT_CALL(response_sender, Run(_)).Times(0); | 753 EXPECT_CALL(response_sender, MockRun(_)).Times(0); |
| 752 method_callback_map_[ibus::engine::kPropertyShowMethod].Run( | 754 method_callback_map_[ibus::engine::kPropertyShowMethod].Run( |
| 753 &method_call, | 755 &method_call, |
| 754 base::Bind(&MockResponseSender::Run, | 756 base::Bind(&MockResponseSender::Run, |
| 755 base::Unretained(&response_sender))); | 757 base::Unretained(&response_sender))); |
| 756 } | 758 } |
| 757 | 759 |
| 758 TEST_F(IBusEngineServiceTest, PropertyHideTest) { | 760 TEST_F(IBusEngineServiceTest, PropertyHideTest) { |
| 759 // Set expectations. | 761 // Set expectations. |
| 760 const uint32 kSerialNo = 1; | 762 const uint32 kSerialNo = 1; |
| 761 const std::string kPropertyName = "Property Name"; | 763 const std::string kPropertyName = "Property Name"; |
| 762 EXPECT_CALL(*engine_handler_, PropertyHide(kPropertyName)); | 764 EXPECT_CALL(*engine_handler_, PropertyHide(kPropertyName)); |
| 763 MockResponseSender response_sender; | 765 MockResponseSender response_sender; |
| 764 EmptyResponseExpectation response_expectation(kSerialNo); | 766 EmptyResponseExpectation response_expectation(kSerialNo); |
| 765 EXPECT_CALL(response_sender, Run(_)) | 767 EXPECT_CALL(response_sender, MockRun(_)) |
| 766 .WillOnce(Invoke(&response_expectation, | 768 .WillOnce(Invoke(&response_expectation, |
| 767 &EmptyResponseExpectation::Evaluate)); | 769 &EmptyResponseExpectation::Evaluate)); |
| 768 | 770 |
| 769 // Create method call; | 771 // Create method call; |
| 770 dbus::MethodCall method_call(ibus::engine::kServiceInterface, | 772 dbus::MethodCall method_call(ibus::engine::kServiceInterface, |
| 771 ibus::engine::kPropertyHideMethod); | 773 ibus::engine::kPropertyHideMethod); |
| 772 method_call.SetSerial(kSerialNo); | 774 method_call.SetSerial(kSerialNo); |
| 773 dbus::MessageWriter writer(&method_call); | 775 dbus::MessageWriter writer(&method_call); |
| 774 writer.AppendString(kPropertyName); | 776 writer.AppendString(kPropertyName); |
| 775 | 777 |
| 776 // Call exported function. | 778 // Call exported function. |
| 777 EXPECT_NE(method_callback_map_.find(ibus::engine::kPropertyHideMethod), | 779 EXPECT_NE(method_callback_map_.find(ibus::engine::kPropertyHideMethod), |
| 778 method_callback_map_.end()); | 780 method_callback_map_.end()); |
| 779 method_callback_map_[ibus::engine::kPropertyHideMethod].Run( | 781 method_callback_map_[ibus::engine::kPropertyHideMethod].Run( |
| 780 &method_call, | 782 &method_call, |
| 781 base::Bind(&MockResponseSender::Run, | 783 base::Bind(&MockResponseSender::Run, |
| 782 base::Unretained(&response_sender))); | 784 base::Unretained(&response_sender))); |
| 783 | 785 |
| 784 // Call exported function without engine. | 786 // Call exported function without engine. |
| 785 service_->UnsetEngine(); | 787 service_->UnsetEngine(); |
| 786 EXPECT_CALL(*engine_handler_, PropertyHide(kPropertyName)).Times(0); | 788 EXPECT_CALL(*engine_handler_, PropertyHide(kPropertyName)).Times(0); |
| 787 EXPECT_CALL(response_sender, Run(_)).Times(0); | 789 EXPECT_CALL(response_sender, MockRun(_)).Times(0); |
| 788 method_callback_map_[ibus::engine::kPropertyHideMethod].Run( | 790 method_callback_map_[ibus::engine::kPropertyHideMethod].Run( |
| 789 &method_call, | 791 &method_call, |
| 790 base::Bind(&MockResponseSender::Run, | 792 base::Bind(&MockResponseSender::Run, |
| 791 base::Unretained(&response_sender))); | 793 base::Unretained(&response_sender))); |
| 792 } | 794 } |
| 793 | 795 |
| 794 TEST_F(IBusEngineServiceTest, SetCapabilityTest) { | 796 TEST_F(IBusEngineServiceTest, SetCapabilityTest) { |
| 795 // Set expectations. | 797 // Set expectations. |
| 796 const uint32 kSerialNo = 1; | 798 const uint32 kSerialNo = 1; |
| 797 const IBusEngineHandlerInterface::IBusCapability kIBusCapability = | 799 const IBusEngineHandlerInterface::IBusCapability kIBusCapability = |
| 798 IBusEngineHandlerInterface::IBUS_CAPABILITY_PREEDIT_TEXT; | 800 IBusEngineHandlerInterface::IBUS_CAPABILITY_PREEDIT_TEXT; |
| 799 EXPECT_CALL(*engine_handler_, SetCapability(kIBusCapability)); | 801 EXPECT_CALL(*engine_handler_, SetCapability(kIBusCapability)); |
| 800 MockResponseSender response_sender; | 802 MockResponseSender response_sender; |
| 801 EmptyResponseExpectation response_expectation(kSerialNo); | 803 EmptyResponseExpectation response_expectation(kSerialNo); |
| 802 EXPECT_CALL(response_sender, Run(_)) | 804 EXPECT_CALL(response_sender, MockRun(_)) |
| 803 .WillOnce(Invoke(&response_expectation, | 805 .WillOnce(Invoke(&response_expectation, |
| 804 &EmptyResponseExpectation::Evaluate)); | 806 &EmptyResponseExpectation::Evaluate)); |
| 805 | 807 |
| 806 // Create method call; | 808 // Create method call; |
| 807 dbus::MethodCall method_call(ibus::engine::kServiceInterface, | 809 dbus::MethodCall method_call(ibus::engine::kServiceInterface, |
| 808 ibus::engine::kSetCapabilityMethod); | 810 ibus::engine::kSetCapabilityMethod); |
| 809 method_call.SetSerial(kSerialNo); | 811 method_call.SetSerial(kSerialNo); |
| 810 dbus::MessageWriter writer(&method_call); | 812 dbus::MessageWriter writer(&method_call); |
| 811 writer.AppendUint32(static_cast<uint32>(kIBusCapability)); | 813 writer.AppendUint32(static_cast<uint32>(kIBusCapability)); |
| 812 | 814 |
| 813 // Call exported function. | 815 // Call exported function. |
| 814 EXPECT_NE(method_callback_map_.find(ibus::engine::kSetCapabilityMethod), | 816 EXPECT_NE(method_callback_map_.find(ibus::engine::kSetCapabilityMethod), |
| 815 method_callback_map_.end()); | 817 method_callback_map_.end()); |
| 816 method_callback_map_[ibus::engine::kSetCapabilityMethod].Run( | 818 method_callback_map_[ibus::engine::kSetCapabilityMethod].Run( |
| 817 &method_call, | 819 &method_call, |
| 818 base::Bind(&MockResponseSender::Run, | 820 base::Bind(&MockResponseSender::Run, |
| 819 base::Unretained(&response_sender))); | 821 base::Unretained(&response_sender))); |
| 820 | 822 |
| 821 // Call exported function without engine. | 823 // Call exported function without engine. |
| 822 service_->UnsetEngine(); | 824 service_->UnsetEngine(); |
| 823 EXPECT_CALL(*engine_handler_, SetCapability(kIBusCapability)).Times(0); | 825 EXPECT_CALL(*engine_handler_, SetCapability(kIBusCapability)).Times(0); |
| 824 EXPECT_CALL(response_sender, Run(_)).Times(0); | 826 EXPECT_CALL(response_sender, MockRun(_)).Times(0); |
| 825 method_callback_map_[ibus::engine::kSetCapabilityMethod].Run( | 827 method_callback_map_[ibus::engine::kSetCapabilityMethod].Run( |
| 826 &method_call, | 828 &method_call, |
| 827 base::Bind(&MockResponseSender::Run, | 829 base::Bind(&MockResponseSender::Run, |
| 828 base::Unretained(&response_sender))); | 830 base::Unretained(&response_sender))); |
| 829 } | 831 } |
| 830 | 832 |
| 831 TEST_F(IBusEngineServiceTest, ProcessKeyEventTest) { | 833 TEST_F(IBusEngineServiceTest, ProcessKeyEventTest) { |
| 832 // Set expectations. | 834 // Set expectations. |
| 833 const uint32 kSerialNo = 1; | 835 const uint32 kSerialNo = 1; |
| 834 const uint32 kKeySym = 0x64; | 836 const uint32 kKeySym = 0x64; |
| 835 const uint32 kKeyCode = 0x20; | 837 const uint32 kKeyCode = 0x20; |
| 836 const uint32 kState = 0x00; | 838 const uint32 kState = 0x00; |
| 837 const bool kResult = true; | 839 const bool kResult = true; |
| 838 | 840 |
| 839 ProcessKeyEventHandler handler(kResult); | 841 ProcessKeyEventHandler handler(kResult); |
| 840 EXPECT_CALL(*engine_handler_, ProcessKeyEvent(kKeySym, kKeyCode, kState, _)) | 842 EXPECT_CALL(*engine_handler_, ProcessKeyEvent(kKeySym, kKeyCode, kState, _)) |
| 841 .WillOnce(Invoke(&handler, | 843 .WillOnce(Invoke(&handler, |
| 842 &ProcessKeyEventHandler::ProcessKeyEvent)); | 844 &ProcessKeyEventHandler::ProcessKeyEvent)); |
| 843 MockResponseSender response_sender; | 845 MockResponseSender response_sender; |
| 844 BoolResponseExpectation response_expectation(kSerialNo, kResult); | 846 BoolResponseExpectation response_expectation(kSerialNo, kResult); |
| 845 EXPECT_CALL(response_sender, Run(_)) | 847 EXPECT_CALL(response_sender, MockRun(_)) |
| 846 .WillOnce(Invoke(&response_expectation, | 848 .WillOnce(Invoke(&response_expectation, |
| 847 &BoolResponseExpectation::Evaluate)); | 849 &BoolResponseExpectation::Evaluate)); |
| 848 | 850 |
| 849 // Create method call; | 851 // Create method call; |
| 850 dbus::MethodCall method_call(ibus::engine::kServiceInterface, | 852 dbus::MethodCall method_call(ibus::engine::kServiceInterface, |
| 851 ibus::engine::kProcessKeyEventMethod); | 853 ibus::engine::kProcessKeyEventMethod); |
| 852 method_call.SetSerial(kSerialNo); | 854 method_call.SetSerial(kSerialNo); |
| 853 dbus::MessageWriter writer(&method_call); | 855 dbus::MessageWriter writer(&method_call); |
| 854 writer.AppendUint32(kKeySym); | 856 writer.AppendUint32(kKeySym); |
| 855 writer.AppendUint32(kKeyCode); | 857 writer.AppendUint32(kKeyCode); |
| 856 writer.AppendUint32(kState); | 858 writer.AppendUint32(kState); |
| 857 | 859 |
| 858 // Call exported function. | 860 // Call exported function. |
| 859 EXPECT_NE(method_callback_map_.find(ibus::engine::kProcessKeyEventMethod), | 861 EXPECT_NE(method_callback_map_.find(ibus::engine::kProcessKeyEventMethod), |
| 860 method_callback_map_.end()); | 862 method_callback_map_.end()); |
| 861 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run( | 863 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run( |
| 862 &method_call, | 864 &method_call, |
| 863 base::Bind(&MockResponseSender::Run, | 865 base::Bind(&MockResponseSender::Run, |
| 864 base::Unretained(&response_sender))); | 866 base::Unretained(&response_sender))); |
| 865 | 867 |
| 866 // Call exported function without engine. | 868 // Call exported function without engine. |
| 867 service_->UnsetEngine(); | 869 service_->UnsetEngine(); |
| 868 EXPECT_CALL(*engine_handler_, | 870 EXPECT_CALL(*engine_handler_, |
| 869 ProcessKeyEvent(kKeySym, kKeyCode, kState, _)).Times(0); | 871 ProcessKeyEvent(kKeySym, kKeyCode, kState, _)).Times(0); |
| 870 EXPECT_CALL(response_sender, Run(_)).Times(0); | 872 EXPECT_CALL(response_sender, MockRun(_)).Times(0); |
| 871 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run( | 873 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run( |
| 872 &method_call, | 874 &method_call, |
| 873 base::Bind(&MockResponseSender::Run, | 875 base::Bind(&MockResponseSender::Run, |
| 874 base::Unretained(&response_sender))); | 876 base::Unretained(&response_sender))); |
| 875 } | 877 } |
| 876 | 878 |
| 877 TEST_F(IBusEngineServiceTest, DelayProcessKeyEventTest) { | 879 TEST_F(IBusEngineServiceTest, DelayProcessKeyEventTest) { |
| 878 // Set expectations. | 880 // Set expectations. |
| 879 const uint32 kSerialNo = 1; | 881 const uint32 kSerialNo = 1; |
| 880 const uint32 kKeySym = 0x64; | 882 const uint32 kKeySym = 0x64; |
| 881 const uint32 kKeyCode = 0x20; | 883 const uint32 kKeyCode = 0x20; |
| 882 const uint32 kState = 0x00; | 884 const uint32 kState = 0x00; |
| 883 const bool kResult = true; | 885 const bool kResult = true; |
| 884 | 886 |
| 885 DelayProcessKeyEventHandler handler(kResult, &message_loop_); | 887 DelayProcessKeyEventHandler handler(kResult, &message_loop_); |
| 886 EXPECT_CALL(*engine_handler_, ProcessKeyEvent(kKeySym, kKeyCode, kState, _)) | 888 EXPECT_CALL(*engine_handler_, ProcessKeyEvent(kKeySym, kKeyCode, kState, _)) |
| 887 .WillOnce(Invoke(&handler, | 889 .WillOnce(Invoke(&handler, |
| 888 &DelayProcessKeyEventHandler::ProcessKeyEvent)); | 890 &DelayProcessKeyEventHandler::ProcessKeyEvent)); |
| 889 MockResponseSender response_sender; | 891 MockResponseSender response_sender; |
| 890 BoolResponseExpectation response_expectation(kSerialNo, kResult); | 892 BoolResponseExpectation response_expectation(kSerialNo, kResult); |
| 891 EXPECT_CALL(response_sender, Run(_)) | 893 EXPECT_CALL(response_sender, MockRun(_)) |
| 892 .WillOnce(Invoke(&response_expectation, | 894 .WillOnce(Invoke(&response_expectation, |
| 893 &BoolResponseExpectation::Evaluate)); | 895 &BoolResponseExpectation::Evaluate)); |
| 894 | 896 |
| 895 // Create method call; | 897 // Create method call; |
| 896 dbus::MethodCall method_call(ibus::engine::kServiceInterface, | 898 dbus::MethodCall method_call(ibus::engine::kServiceInterface, |
| 897 ibus::engine::kProcessKeyEventMethod); | 899 ibus::engine::kProcessKeyEventMethod); |
| 898 method_call.SetSerial(kSerialNo); | 900 method_call.SetSerial(kSerialNo); |
| 899 dbus::MessageWriter writer(&method_call); | 901 dbus::MessageWriter writer(&method_call); |
| 900 writer.AppendUint32(kKeySym); | 902 writer.AppendUint32(kKeySym); |
| 901 writer.AppendUint32(kKeyCode); | 903 writer.AppendUint32(kKeyCode); |
| 902 writer.AppendUint32(kState); | 904 writer.AppendUint32(kState); |
| 903 | 905 |
| 904 // Call exported function. | 906 // Call exported function. |
| 905 EXPECT_NE(method_callback_map_.find(ibus::engine::kProcessKeyEventMethod), | 907 EXPECT_NE(method_callback_map_.find(ibus::engine::kProcessKeyEventMethod), |
| 906 method_callback_map_.end()); | 908 method_callback_map_.end()); |
| 907 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run( | 909 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run( |
| 908 &method_call, | 910 &method_call, |
| 909 base::Bind(&MockResponseSender::Run, | 911 base::Bind(&MockResponseSender::Run, |
| 910 base::Unretained(&response_sender))); | 912 base::Unretained(&response_sender))); |
| 911 | 913 |
| 912 // Call KeyEventDone callback. | 914 // Call KeyEventDone callback. |
| 913 message_loop_.RunUntilIdle(); | 915 message_loop_.RunUntilIdle(); |
| 914 | 916 |
| 915 // Call exported function without engine. | 917 // Call exported function without engine. |
| 916 service_->UnsetEngine(); | 918 service_->UnsetEngine(); |
| 917 EXPECT_CALL(*engine_handler_, | 919 EXPECT_CALL(*engine_handler_, |
| 918 ProcessKeyEvent(kKeySym, kKeyCode, kState, _)).Times(0); | 920 ProcessKeyEvent(kKeySym, kKeyCode, kState, _)).Times(0); |
| 919 EXPECT_CALL(response_sender, Run(_)).Times(0); | 921 EXPECT_CALL(response_sender, MockRun(_)).Times(0); |
| 920 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run( | 922 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run( |
| 921 &method_call, | 923 &method_call, |
| 922 base::Bind(&MockResponseSender::Run, | 924 base::Bind(&MockResponseSender::Run, |
| 923 base::Unretained(&response_sender))); | 925 base::Unretained(&response_sender))); |
| 924 } | 926 } |
| 925 | 927 |
| 926 TEST_F(IBusEngineServiceTest, CandidateClickedTest) { | 928 TEST_F(IBusEngineServiceTest, CandidateClickedTest) { |
| 927 // Set expectations. | 929 // Set expectations. |
| 928 const uint32 kSerialNo = 1; | 930 const uint32 kSerialNo = 1; |
| 929 const uint32 kIndex = 4; | 931 const uint32 kIndex = 4; |
| 930 const ibus::IBusMouseButton kIBusMouseButton = ibus::IBUS_MOUSE_BUTTON_MIDDLE; | 932 const ibus::IBusMouseButton kIBusMouseButton = ibus::IBUS_MOUSE_BUTTON_MIDDLE; |
| 931 const uint32 kState = 3; | 933 const uint32 kState = 3; |
| 932 EXPECT_CALL(*engine_handler_, CandidateClicked(kIndex, kIBusMouseButton, | 934 EXPECT_CALL(*engine_handler_, CandidateClicked(kIndex, kIBusMouseButton, |
| 933 kState)); | 935 kState)); |
| 934 MockResponseSender response_sender; | 936 MockResponseSender response_sender; |
| 935 EmptyResponseExpectation response_expectation(kSerialNo); | 937 EmptyResponseExpectation response_expectation(kSerialNo); |
| 936 EXPECT_CALL(response_sender, Run(_)) | 938 EXPECT_CALL(response_sender, MockRun(_)) |
| 937 .WillOnce(Invoke(&response_expectation, | 939 .WillOnce(Invoke(&response_expectation, |
| 938 &EmptyResponseExpectation::Evaluate)); | 940 &EmptyResponseExpectation::Evaluate)); |
| 939 | 941 |
| 940 // Create method call; | 942 // Create method call; |
| 941 dbus::MethodCall method_call(ibus::engine::kServiceInterface, | 943 dbus::MethodCall method_call(ibus::engine::kServiceInterface, |
| 942 ibus::engine::kCandidateClickedMethod); | 944 ibus::engine::kCandidateClickedMethod); |
| 943 method_call.SetSerial(kSerialNo); | 945 method_call.SetSerial(kSerialNo); |
| 944 dbus::MessageWriter writer(&method_call); | 946 dbus::MessageWriter writer(&method_call); |
| 945 writer.AppendUint32(kIndex); | 947 writer.AppendUint32(kIndex); |
| 946 writer.AppendUint32(static_cast<uint32>(kIBusMouseButton)); | 948 writer.AppendUint32(static_cast<uint32>(kIBusMouseButton)); |
| 947 writer.AppendUint32(kState); | 949 writer.AppendUint32(kState); |
| 948 | 950 |
| 949 // Call exported function. | 951 // Call exported function. |
| 950 EXPECT_NE(method_callback_map_.find(ibus::engine::kCandidateClickedMethod), | 952 EXPECT_NE(method_callback_map_.find(ibus::engine::kCandidateClickedMethod), |
| 951 method_callback_map_.end()); | 953 method_callback_map_.end()); |
| 952 method_callback_map_[ibus::engine::kCandidateClickedMethod].Run( | 954 method_callback_map_[ibus::engine::kCandidateClickedMethod].Run( |
| 953 &method_call, | 955 &method_call, |
| 954 base::Bind(&MockResponseSender::Run, | 956 base::Bind(&MockResponseSender::Run, |
| 955 base::Unretained(&response_sender))); | 957 base::Unretained(&response_sender))); |
| 956 | 958 |
| 957 // Call exported function without engine. | 959 // Call exported function without engine. |
| 958 service_->UnsetEngine(); | 960 service_->UnsetEngine(); |
| 959 EXPECT_CALL(*engine_handler_, CandidateClicked(kIndex, kIBusMouseButton, | 961 EXPECT_CALL(*engine_handler_, CandidateClicked(kIndex, kIBusMouseButton, |
| 960 kState)).Times(0); | 962 kState)).Times(0); |
| 961 EXPECT_CALL(response_sender, Run(_)).Times(0); | 963 EXPECT_CALL(response_sender, MockRun(_)).Times(0); |
| 962 method_callback_map_[ibus::engine::kCandidateClickedMethod].Run( | 964 method_callback_map_[ibus::engine::kCandidateClickedMethod].Run( |
| 963 &method_call, | 965 &method_call, |
| 964 base::Bind(&MockResponseSender::Run, | 966 base::Bind(&MockResponseSender::Run, |
| 965 base::Unretained(&response_sender))); | 967 base::Unretained(&response_sender))); |
| 966 } | 968 } |
| 967 | 969 |
| 968 TEST_F(IBusEngineServiceTest, SetSurroundingTextTest) { | 970 TEST_F(IBusEngineServiceTest, SetSurroundingTextTest) { |
| 969 // Set expectations. | 971 // Set expectations. |
| 970 const uint32 kSerialNo = 1; | 972 const uint32 kSerialNo = 1; |
| 971 const std::string kText = "Sample Text"; | 973 const std::string kText = "Sample Text"; |
| 972 const uint32 kCursorPos = 3; | 974 const uint32 kCursorPos = 3; |
| 973 const uint32 kAnchorPos = 4; | 975 const uint32 kAnchorPos = 4; |
| 974 EXPECT_CALL(*engine_handler_, SetSurroundingText(kText, kCursorPos, | 976 EXPECT_CALL(*engine_handler_, SetSurroundingText(kText, kCursorPos, |
| 975 kAnchorPos)); | 977 kAnchorPos)); |
| 976 MockResponseSender response_sender; | 978 MockResponseSender response_sender; |
| 977 EmptyResponseExpectation response_expectation(kSerialNo); | 979 EmptyResponseExpectation response_expectation(kSerialNo); |
| 978 EXPECT_CALL(response_sender, Run(_)) | 980 EXPECT_CALL(response_sender, MockRun(_)) |
| 979 .WillOnce(Invoke(&response_expectation, | 981 .WillOnce(Invoke(&response_expectation, |
| 980 &EmptyResponseExpectation::Evaluate)); | 982 &EmptyResponseExpectation::Evaluate)); |
| 981 | 983 |
| 982 // Create method call; | 984 // Create method call; |
| 983 dbus::MethodCall method_call(ibus::engine::kServiceInterface, | 985 dbus::MethodCall method_call(ibus::engine::kServiceInterface, |
| 984 ibus::engine::kSetSurroundingTextMethod); | 986 ibus::engine::kSetSurroundingTextMethod); |
| 985 method_call.SetSerial(kSerialNo); | 987 method_call.SetSerial(kSerialNo); |
| 986 dbus::MessageWriter writer(&method_call); | 988 dbus::MessageWriter writer(&method_call); |
| 987 writer.AppendString(kText); | 989 writer.AppendString(kText); |
| 988 writer.AppendUint32(kCursorPos); | 990 writer.AppendUint32(kCursorPos); |
| 989 writer.AppendUint32(kAnchorPos); | 991 writer.AppendUint32(kAnchorPos); |
| 990 | 992 |
| 991 // Call exported function. | 993 // Call exported function. |
| 992 EXPECT_NE(method_callback_map_.find(ibus::engine::kSetSurroundingTextMethod), | 994 EXPECT_NE(method_callback_map_.find(ibus::engine::kSetSurroundingTextMethod), |
| 993 method_callback_map_.end()); | 995 method_callback_map_.end()); |
| 994 method_callback_map_[ibus::engine::kSetSurroundingTextMethod].Run( | 996 method_callback_map_[ibus::engine::kSetSurroundingTextMethod].Run( |
| 995 &method_call, | 997 &method_call, |
| 996 base::Bind(&MockResponseSender::Run, | 998 base::Bind(&MockResponseSender::Run, |
| 997 base::Unretained(&response_sender))); | 999 base::Unretained(&response_sender))); |
| 998 | 1000 |
| 999 // Call exported function without engine. | 1001 // Call exported function without engine. |
| 1000 service_->UnsetEngine(); | 1002 service_->UnsetEngine(); |
| 1001 EXPECT_CALL(*engine_handler_, SetSurroundingText(kText, kCursorPos, | 1003 EXPECT_CALL(*engine_handler_, SetSurroundingText(kText, kCursorPos, |
| 1002 kAnchorPos)).Times(0); | 1004 kAnchorPos)).Times(0); |
| 1003 EXPECT_CALL(response_sender, Run(_)).Times(0); | 1005 EXPECT_CALL(response_sender, MockRun(_)).Times(0); |
| 1004 method_callback_map_[ibus::engine::kSetSurroundingTextMethod].Run( | 1006 method_callback_map_[ibus::engine::kSetSurroundingTextMethod].Run( |
| 1005 &method_call, | 1007 &method_call, |
| 1006 base::Bind(&MockResponseSender::Run, | 1008 base::Bind(&MockResponseSender::Run, |
| 1007 base::Unretained(&response_sender))); | 1009 base::Unretained(&response_sender))); |
| 1008 } | 1010 } |
| 1009 | 1011 |
| 1010 TEST_F(IBusEngineServiceTest, RegisterProperties) { | 1012 TEST_F(IBusEngineServiceTest, RegisterProperties) { |
| 1011 // Set expectations. | 1013 // Set expectations. |
| 1012 IBusPropertyList property_list; | 1014 IBusPropertyList property_list; |
| 1013 property_list.push_back(new IBusProperty()); | 1015 property_list.push_back(new IBusProperty()); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 RequireSurroundingTextExpectation expectation; | 1112 RequireSurroundingTextExpectation expectation; |
| 1111 EXPECT_CALL(*mock_exported_object_, SendSignal(_)) | 1113 EXPECT_CALL(*mock_exported_object_, SendSignal(_)) |
| 1112 .WillOnce(Invoke(&expectation, | 1114 .WillOnce(Invoke(&expectation, |
| 1113 &RequireSurroundingTextExpectation::Evaluate)); | 1115 &RequireSurroundingTextExpectation::Evaluate)); |
| 1114 | 1116 |
| 1115 // Emit signal. | 1117 // Emit signal. |
| 1116 service_->RequireSurroundingText(); | 1118 service_->RequireSurroundingText(); |
| 1117 } | 1119 } |
| 1118 | 1120 |
| 1119 } // namespace chromeos | 1121 } // namespace chromeos |
| OLD | NEW |