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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/dbus/ibus/ibus_engine_service_unittest.cc
diff --git a/chromeos/dbus/ibus/ibus_engine_service_unittest.cc b/chromeos/dbus/ibus/ibus_engine_service_unittest.cc
index 9ae2c4b62dedc25f247a4def5ab5cd6d52aa05d8..3800087d2946b10b288475bf6dbe72fad809a161 100644
--- a/chromeos/dbus/ibus/ibus_engine_service_unittest.cc
+++ b/chromeos/dbus/ibus/ibus_engine_service_unittest.cc
@@ -41,8 +41,11 @@ class MockIBusEngineHandler : public IBusEngineHandlerInterface {
MOCK_METHOD1(PropertyHide, void(const std::string& property_name));
MOCK_METHOD1(SetCapability, void(IBusCapability capability));
MOCK_METHOD0(Reset, void());
- MOCK_METHOD3(ProcessKeyEvent, bool(uint32 keysym, uint32 keycode,
- uint32 state));
+ MOCK_METHOD4(ProcessKeyEvent, void(
+ uint32 keysym,
+ uint32 keycode,
+ uint32 state,
+ const KeyEventDoneCallback& callback));
MOCK_METHOD3(CandidateClicked, void(uint32 index, IBusMouseButton button,
uint32 state));
MOCK_METHOD3(SetSurroundingText, void(const std::string& text,
@@ -135,6 +138,51 @@ class RegisterPropertiesExpectation {
DISALLOW_COPY_AND_ASSIGN(RegisterPropertiesExpectation);
};
+// Used for mocking ProcessKeyEventHandler.
+class ProcessKeyEventHandler {
+ public:
+ explicit ProcessKeyEventHandler(bool expected_value)
+ : expected_value_(expected_value) {
+ }
+
+ void ProcessKeyEvent(
+ uint32 keysym,
+ uint32 keycode,
+ uint32 state,
+ const IBusEngineHandlerInterface::KeyEventDoneCallback& callback) {
+ callback.Run(expected_value_);
+ }
+
+ private:
+ bool expected_value_;
+
+ DISALLOW_COPY_AND_ASSIGN(ProcessKeyEventHandler);
+};
+
+// Used for mocking asynchronous ProcessKeyEventHandler.
+class DelayProcessKeyEventHandler {
+ public:
+ DelayProcessKeyEventHandler(bool expected_value,
+ MessageLoop* message_loop)
+ : expected_value_(expected_value),
+ message_loop_(message_loop) {
+ }
+
+ void ProcessKeyEvent(
+ uint32 keysym,
+ uint32 keycode,
+ uint32 state,
+ const IBusEngineHandlerInterface::KeyEventDoneCallback& callback) {
+ message_loop_->PostTask(FROM_HERE, base::Bind(callback, expected_value_));
+ }
+
+ private:
+ bool expected_value_;
+ MessageLoop* message_loop_;
+
+ DISALLOW_COPY_AND_ASSIGN(DelayProcessKeyEventHandler);
+};
+
// Used for UpdatePreedit signal message evaluation.
class UpdatePreeditExpectation {
public:
@@ -705,8 +753,46 @@ TEST_F(IBusEngineServiceTest, ProcessKeyEventTest) {
const uint32 kState = 0x00;
const bool kResult = true;
- EXPECT_CALL(*engine_handler_, ProcessKeyEvent(kKeySym, kKeyCode, kState))
- .WillOnce(Return(kResult));
+ ProcessKeyEventHandler handler(kResult);
+ EXPECT_CALL(*engine_handler_, ProcessKeyEvent(kKeySym, kKeyCode, kState, _))
+ .WillOnce(Invoke(&handler,
+ &ProcessKeyEventHandler::ProcessKeyEvent));
+ MockResponseSender response_sender;
+ BoolResponseExpectation response_expectation(kSerialNo, kResult);
+ EXPECT_CALL(response_sender, Run(_))
+ .WillOnce(Invoke(&response_expectation,
+ &BoolResponseExpectation::Evaluate));
+
+ // Create method call;
+ dbus::MethodCall method_call(ibus::engine::kServiceInterface,
+ ibus::engine::kProcessKeyEventMethod);
+ method_call.SetSerial(kSerialNo);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendUint32(kKeySym);
+ writer.AppendUint32(kKeyCode);
+ writer.AppendUint32(kState);
+
+ // Call exported function.
+ EXPECT_NE(method_callback_map_.find(ibus::engine::kProcessKeyEventMethod),
+ method_callback_map_.end());
+ method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run(
+ &method_call,
+ base::Bind(&MockResponseSender::Run,
+ base::Unretained(&response_sender)));
+}
+
+TEST_F(IBusEngineServiceTest, DelayProcessKeyEventTest) {
+ // Set expectations.
+ const uint32 kSerialNo = 1;
+ const uint32 kKeySym = 0x64;
+ const uint32 kKeyCode = 0x20;
+ const uint32 kState = 0x00;
+ const bool kResult = true;
+
+ DelayProcessKeyEventHandler handler(kResult, &message_loop_);
+ EXPECT_CALL(*engine_handler_, ProcessKeyEvent(kKeySym, kKeyCode, kState, _))
+ .WillOnce(Invoke(&handler,
+ &DelayProcessKeyEventHandler::ProcessKeyEvent));
MockResponseSender response_sender;
BoolResponseExpectation response_expectation(kSerialNo, kResult);
EXPECT_CALL(response_sender, Run(_))
@@ -729,6 +815,9 @@ TEST_F(IBusEngineServiceTest, ProcessKeyEventTest) {
&method_call,
base::Bind(&MockResponseSender::Run,
base::Unretained(&response_sender)));
+
+ // Call KeyEventDone callback.
+ message_loop_.RunAllPending();
}
TEST_F(IBusEngineServiceTest, CandidateClickedTest) {
« 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