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

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

Issue 10835003: Revise IBusEngineService. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 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 23 matching lines...) Expand all
34 MOCK_METHOD0(FocusIn, void()); 34 MOCK_METHOD0(FocusIn, void());
35 MOCK_METHOD0(FocusOut, void()); 35 MOCK_METHOD0(FocusOut, void());
36 MOCK_METHOD0(Enable, void()); 36 MOCK_METHOD0(Enable, void());
37 MOCK_METHOD0(Disable, void()); 37 MOCK_METHOD0(Disable, void());
38 MOCK_METHOD2(PropertyActivate, void(const std::string& property_name, 38 MOCK_METHOD2(PropertyActivate, void(const std::string& property_name,
39 IBusPropertyState property_state)); 39 IBusPropertyState property_state));
40 MOCK_METHOD1(PropertyShow, void(const std::string& property_name)); 40 MOCK_METHOD1(PropertyShow, void(const std::string& property_name));
41 MOCK_METHOD1(PropertyHide, void(const std::string& property_name)); 41 MOCK_METHOD1(PropertyHide, void(const std::string& property_name));
42 MOCK_METHOD1(SetCapability, void(IBusCapability capability)); 42 MOCK_METHOD1(SetCapability, void(IBusCapability capability));
43 MOCK_METHOD0(Reset, void()); 43 MOCK_METHOD0(Reset, void());
44 MOCK_METHOD3(ProcessKeyEvent, bool(uint32 keysym, uint32 keycode, 44 MOCK_METHOD4(ProcessKeyEvent, void(
45 uint32 state)); 45 uint32 keysym,
46 uint32 keycode,
47 uint32 state,
48 const KeyEventDoneCallback& callback));
46 MOCK_METHOD3(CandidateClicked, void(uint32 index, IBusMouseButton button, 49 MOCK_METHOD3(CandidateClicked, void(uint32 index, IBusMouseButton button,
47 uint32 state)); 50 uint32 state));
48 MOCK_METHOD3(SetSurroundingText, void(const std::string& text, 51 MOCK_METHOD3(SetSurroundingText, void(const std::string& text,
49 uint32 cursor_pos, 52 uint32 cursor_pos,
50 uint32 anchor_pos)); 53 uint32 anchor_pos));
51 }; 54 };
52 55
53 class MockResponseSender { 56 class MockResponseSender {
54 public: 57 public:
55 MOCK_METHOD1(Run, void(dbus::Response* reponse)); 58 MOCK_METHOD1(Run, void(dbus::Response* reponse));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 EXPECT_EQ(property_list_[i]->checked(), property_list[i]->checked()); 131 EXPECT_EQ(property_list_[i]->checked(), property_list[i]->checked());
129 } 132 }
130 } 133 }
131 134
132 private: 135 private:
133 const ibus::IBusPropertyList& property_list_; 136 const ibus::IBusPropertyList& property_list_;
134 137
135 DISALLOW_COPY_AND_ASSIGN(RegisterPropertiesExpectation); 138 DISALLOW_COPY_AND_ASSIGN(RegisterPropertiesExpectation);
136 }; 139 };
137 140
141 // Used for mocking ProcessKeyEventHandler.
142 class ProcessKeyEventHandler {
143 public:
144 explicit ProcessKeyEventHandler(bool expected_value)
145 : expected_value_(expected_value) {
146 }
147
148 void ProcessKeyEvent(
149 uint32 keysym,
150 uint32 keycode,
151 uint32 state,
152 const IBusEngineHandlerInterface::KeyEventDoneCallback& callback) {
153 callback.Run(expected_value_);
154 }
155
156 private:
157 bool expected_value_;
158
159 DISALLOW_COPY_AND_ASSIGN(ProcessKeyEventHandler);
160 };
161
162 // Used for mocking asynchronous ProcessKeyEventHandler.
163 class DelayProcessKeyEventHandler {
164 public:
165 DelayProcessKeyEventHandler(bool expected_value,
166 MessageLoop* message_loop)
167 : expected_value_(expected_value),
168 message_loop_(message_loop) {
169 }
170
171 void ProcessKeyEvent(
172 uint32 keysym,
173 uint32 keycode,
174 uint32 state,
175 const IBusEngineHandlerInterface::KeyEventDoneCallback& callback) {
176 message_loop_->PostTask(FROM_HERE, base::Bind(callback, expected_value_));
177 }
178
179 private:
180 bool expected_value_;
181 MessageLoop* message_loop_;
182
183 DISALLOW_COPY_AND_ASSIGN(DelayProcessKeyEventHandler);
184 };
185
138 // Used for UpdatePreedit signal message evaluation. 186 // Used for UpdatePreedit signal message evaluation.
139 class UpdatePreeditExpectation { 187 class UpdatePreeditExpectation {
140 public: 188 public:
141 UpdatePreeditExpectation( 189 UpdatePreeditExpectation(
142 const ibus::IBusText& ibus_text, 190 const ibus::IBusText& ibus_text,
143 uint32 cursor_pos, 191 uint32 cursor_pos,
144 bool is_visible, 192 bool is_visible,
145 IBusEngineService::IBusEnginePreeditFocusOutMode mode) 193 IBusEngineService::IBusEnginePreeditFocusOutMode mode)
146 : ibus_text_(ibus_text), 194 : ibus_text_(ibus_text),
147 cursor_pos_(cursor_pos), 195 cursor_pos_(cursor_pos),
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 } 746 }
699 747
700 TEST_F(IBusEngineServiceTest, ProcessKeyEventTest) { 748 TEST_F(IBusEngineServiceTest, ProcessKeyEventTest) {
701 // Set expectations. 749 // Set expectations.
702 const uint32 kSerialNo = 1; 750 const uint32 kSerialNo = 1;
703 const uint32 kKeySym = 0x64; 751 const uint32 kKeySym = 0x64;
704 const uint32 kKeyCode = 0x20; 752 const uint32 kKeyCode = 0x20;
705 const uint32 kState = 0x00; 753 const uint32 kState = 0x00;
706 const bool kResult = true; 754 const bool kResult = true;
707 755
708 EXPECT_CALL(*engine_handler_, ProcessKeyEvent(kKeySym, kKeyCode, kState)) 756 ProcessKeyEventHandler handler(kResult);
709 .WillOnce(Return(kResult)); 757 EXPECT_CALL(*engine_handler_, ProcessKeyEvent(kKeySym, kKeyCode, kState, _))
758 .WillOnce(Invoke(&handler,
759 &ProcessKeyEventHandler::ProcessKeyEvent));
710 MockResponseSender response_sender; 760 MockResponseSender response_sender;
711 BoolResponseExpectation response_expectation(kSerialNo, kResult); 761 BoolResponseExpectation response_expectation(kSerialNo, kResult);
712 EXPECT_CALL(response_sender, Run(_)) 762 EXPECT_CALL(response_sender, Run(_))
763 .WillOnce(Invoke(&response_expectation,
764 &BoolResponseExpectation::Evaluate));
765
766 // Create method call;
767 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
768 ibus::engine::kProcessKeyEventMethod);
769 method_call.SetSerial(kSerialNo);
770 dbus::MessageWriter writer(&method_call);
771 writer.AppendUint32(kKeySym);
772 writer.AppendUint32(kKeyCode);
773 writer.AppendUint32(kState);
774
775 // Call exported function.
776 EXPECT_NE(method_callback_map_.find(ibus::engine::kProcessKeyEventMethod),
777 method_callback_map_.end());
778 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run(
779 &method_call,
780 base::Bind(&MockResponseSender::Run,
781 base::Unretained(&response_sender)));
782 }
783
784 TEST_F(IBusEngineServiceTest, DelayProcessKeyEventTest) {
785 // Set expectations.
786 const uint32 kSerialNo = 1;
787 const uint32 kKeySym = 0x64;
788 const uint32 kKeyCode = 0x20;
789 const uint32 kState = 0x00;
790 const bool kResult = true;
791
792 DelayProcessKeyEventHandler handler(kResult, &message_loop_);
793 EXPECT_CALL(*engine_handler_, ProcessKeyEvent(kKeySym, kKeyCode, kState, _))
794 .WillOnce(Invoke(&handler,
795 &DelayProcessKeyEventHandler::ProcessKeyEvent));
796 MockResponseSender response_sender;
797 BoolResponseExpectation response_expectation(kSerialNo, kResult);
798 EXPECT_CALL(response_sender, Run(_))
713 .WillOnce(Invoke(&response_expectation, 799 .WillOnce(Invoke(&response_expectation,
714 &BoolResponseExpectation::Evaluate)); 800 &BoolResponseExpectation::Evaluate));
715 801
716 // Create method call; 802 // Create method call;
717 dbus::MethodCall method_call(ibus::engine::kServiceInterface, 803 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
718 ibus::engine::kProcessKeyEventMethod); 804 ibus::engine::kProcessKeyEventMethod);
719 method_call.SetSerial(kSerialNo); 805 method_call.SetSerial(kSerialNo);
720 dbus::MessageWriter writer(&method_call); 806 dbus::MessageWriter writer(&method_call);
721 writer.AppendUint32(kKeySym); 807 writer.AppendUint32(kKeySym);
722 writer.AppendUint32(kKeyCode); 808 writer.AppendUint32(kKeyCode);
723 writer.AppendUint32(kState); 809 writer.AppendUint32(kState);
724 810
725 // Call exported function. 811 // Call exported function.
726 EXPECT_NE(method_callback_map_.find(ibus::engine::kProcessKeyEventMethod), 812 EXPECT_NE(method_callback_map_.find(ibus::engine::kProcessKeyEventMethod),
727 method_callback_map_.end()); 813 method_callback_map_.end());
728 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run( 814 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run(
729 &method_call, 815 &method_call,
730 base::Bind(&MockResponseSender::Run, 816 base::Bind(&MockResponseSender::Run,
731 base::Unretained(&response_sender))); 817 base::Unretained(&response_sender)));
818
819 // Call KeyEventDone callback.
820 message_loop_.RunAllPending();
732 } 821 }
733 822
734 TEST_F(IBusEngineServiceTest, CandidateClickedTest) { 823 TEST_F(IBusEngineServiceTest, CandidateClickedTest) {
735 // Set expectations. 824 // Set expectations.
736 const uint32 kSerialNo = 1; 825 const uint32 kSerialNo = 1;
737 const uint32 kIndex = 4; 826 const uint32 kIndex = 4;
738 const IBusEngineHandlerInterface::IBusMouseButton kIBusMouseButton = 827 const IBusEngineHandlerInterface::IBusMouseButton kIBusMouseButton =
739 IBusEngineHandlerInterface::IBUS_MOUSE_BUTTON_MIDDLE; 828 IBusEngineHandlerInterface::IBUS_MOUSE_BUTTON_MIDDLE;
740 const uint32 kState = 3; 829 const uint32 kState = 3;
741 EXPECT_CALL(*engine_handler_, CandidateClicked(kIndex, kIBusMouseButton, 830 EXPECT_CALL(*engine_handler_, CandidateClicked(kIndex, kIBusMouseButton,
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 EXPECT_CALL(*mock_exported_object_, SendSignal(_)) 989 EXPECT_CALL(*mock_exported_object_, SendSignal(_))
901 .WillOnce(Invoke(&expectation, 990 .WillOnce(Invoke(&expectation,
902 &RequireSurroundingTextExpectation::Evaluate)); 991 &RequireSurroundingTextExpectation::Evaluate));
903 992
904 // Emit signal. 993 // Emit signal.
905 service_->RequireSurroundingText(); 994 service_->RequireSurroundingText();
906 } 995 }
907 996
908 997
909 } // namespace chromeos 998 } // 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