Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / chromeos / dbus / ibus / ibus_input_context_client_unittest.cc
blob7ed38ccfe04834503f49726bd49209ca5914446b
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
3 // found in the LICENSE file.
5 #include "chromeos/dbus/ibus/ibus_input_context_client.h"
7 #include <map>
8 #include <string>
9 #include "base/message_loop.h"
10 #include "chromeos/dbus/ibus/ibus_constants.h"
11 #include "chromeos/dbus/ibus/ibus_text.h"
12 #include "dbus/message.h"
13 #include "dbus/mock_bus.h"
14 #include "dbus/mock_object_proxy.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 using ::testing::Invoke;
19 using ::testing::Return;
20 using ::testing::_;
22 namespace chromeos {
24 // TODO(nona): Remove after complete libibus removal.
25 using chromeos::IBusText;
27 namespace {
28 const char kObjectPath[] = "/org/freedesktop/IBus/InputContext_1010";
30 // Following variables are used in callback expectations.
31 const uint32 kCapabilities = 12345;
32 const int32 kCursorX = 30;
33 const int32 kCursorY = 31;
34 const int32 kCursorWidth = 32;
35 const int32 kCursorHeight = 33;
36 const uint32 kKeyval = 34;
37 const uint32 kKeycode = 35;
38 const uint32 kState = 36;
39 const int32 kCompositionX = 37;
40 const int32 kCompositionY = 38;
41 const int32 kCompositionWidth = 39;
42 const int32 kCompositionHeight = 40;
43 const bool kIsKeyHandled = false;
44 const char kSurroundingText[] = "Surrounding Text";
45 const uint32 kCursorPos = 2;
46 const uint32 kAnchorPos = 7;
47 const char kPropertyKey[] = "Property Key";
48 const ibus::IBusPropertyState kPropertyState =
49 ibus::IBUS_PROPERTY_STATE_CHECKED;
51 class MockInputContextHandler : public IBusInputContextHandlerInterface {
52 public:
53 MOCK_METHOD1(CommitText, void(const IBusText& text));
54 MOCK_METHOD3(ForwardKeyEvent,
55 void(uint32 keyval, uint32 keycode, uint32 state));
56 MOCK_METHOD0(ShowPreeditText, void());
57 MOCK_METHOD0(HidePreeditText, void());
58 MOCK_METHOD3(UpdatePreeditText,
59 void(const IBusText& text, uint32 cursor_pos, bool visible));
62 class MockProcessKeyEventHandler {
63 public:
64 MOCK_METHOD1(Run, void(bool is_key_handled));
67 class MockProcessKeyEventErrorHandler {
68 public:
69 MOCK_METHOD0(Run, void());
72 MATCHER_P(IBusTextEq, expected_text, "The expected IBusText does not match") {
73 // TODO(nona): Check attributes.
74 return (arg.text() == expected_text->text());
77 } // namespace
79 class IBusInputContextClientTest : public testing::Test {
80 public:
81 IBusInputContextClientTest()
82 : response_(NULL),
83 on_set_cursor_location_call_count_(0) {}
85 virtual void SetUp() OVERRIDE {
86 // Create a mock bus.
87 dbus::Bus::Options options;
88 options.bus_type = dbus::Bus::SYSTEM;
89 mock_bus_ = new dbus::MockBus(options);
91 // Create a mock proxy.
92 mock_proxy_ = new dbus::MockObjectProxy(mock_bus_.get(),
93 ibus::kServiceName,
94 dbus::ObjectPath(kObjectPath));
96 // Create a client.
97 client_.reset(IBusInputContextClient::Create(
98 REAL_DBUS_CLIENT_IMPLEMENTATION));
100 // Set an expectation so mock_bus's GetObjectProxy() for the given service
101 // name and the object path will return mock_proxy_. The GetObjectProxy
102 // function is called in Initialized function.
103 EXPECT_CALL(*mock_bus_, GetObjectProxy(ibus::kServiceName,
104 dbus::ObjectPath(kObjectPath)))
105 .WillOnce(Return(mock_proxy_.get()));
107 // Set expectations so mock_proxy's ConnectToSignal will use
108 // OnConnectToSignal() to run the callback. The ConnectToSignal is called in
109 // Initialize function.
110 EXPECT_CALL(*mock_proxy_, ConnectToSignal(
111 ibus::input_context::kServiceInterface,
112 ibus::input_context::kCommitTextSignal, _, _))
113 .WillRepeatedly(
114 Invoke(this, &IBusInputContextClientTest::OnConnectToSignal));
115 EXPECT_CALL(*mock_proxy_, ConnectToSignal(
116 ibus::input_context::kServiceInterface,
117 ibus::input_context::kForwardKeyEventSignal, _, _))
118 .WillRepeatedly(
119 Invoke(this, &IBusInputContextClientTest::OnConnectToSignal));
120 EXPECT_CALL(*mock_proxy_, ConnectToSignal(
121 ibus::input_context::kServiceInterface,
122 ibus::input_context::kHidePreeditTextSignal, _, _))
123 .WillRepeatedly(
124 Invoke(this, &IBusInputContextClientTest::OnConnectToSignal));
125 EXPECT_CALL(*mock_proxy_, ConnectToSignal(
126 ibus::input_context::kServiceInterface,
127 ibus::input_context::kShowPreeditTextSignal, _, _))
128 .WillRepeatedly(
129 Invoke(this, &IBusInputContextClientTest::OnConnectToSignal));
130 EXPECT_CALL(*mock_proxy_, ConnectToSignal(
131 ibus::input_context::kServiceInterface,
132 ibus::input_context::kUpdatePreeditTextSignal, _, _))
133 .WillRepeatedly(
134 Invoke(this, &IBusInputContextClientTest::OnConnectToSignal));
136 // Call Initialize to create object proxy and connect signals.
137 client_->Initialize(mock_bus_.get(), dbus::ObjectPath(kObjectPath));
140 virtual void TearDown() OVERRIDE {
141 EXPECT_TRUE(client_->IsObjectProxyReady());
142 client_->ResetObjectProxy();
143 EXPECT_FALSE(client_->IsObjectProxyReady());
146 // Handles FocusIn method call.
147 void OnFocusIn(dbus::MethodCall* method_call,
148 int timeout_ms,
149 const dbus::ObjectProxy::ResponseCallback& callback,
150 const dbus::ObjectProxy::ErrorCallback& error_callback) {
151 EXPECT_EQ(ibus::input_context::kServiceInterface,
152 method_call->GetInterface());
153 EXPECT_EQ(ibus::input_context::kFocusInMethod, method_call->GetMember());
154 dbus::MessageReader reader(method_call);
155 EXPECT_FALSE(reader.HasMoreData());
157 message_loop_.PostTask(FROM_HERE, base::Bind(callback, response_));
160 // Handles FocusOut method call.
161 void OnFocusOut(dbus::MethodCall* method_call,
162 int timeout_ms,
163 const dbus::ObjectProxy::ResponseCallback& callback,
164 const dbus::ObjectProxy::ErrorCallback& error_callback) {
165 EXPECT_EQ(ibus::input_context::kServiceInterface,
166 method_call->GetInterface());
167 EXPECT_EQ(ibus::input_context::kFocusOutMethod, method_call->GetMember());
168 dbus::MessageReader reader(method_call);
169 EXPECT_FALSE(reader.HasMoreData());
171 message_loop_.PostTask(FROM_HERE, base::Bind(callback, response_));
174 // Handles Reset method call.
175 void OnReset(dbus::MethodCall* method_call,
176 int timeout_ms,
177 const dbus::ObjectProxy::ResponseCallback& callback,
178 const dbus::ObjectProxy::ErrorCallback& error_callback) {
179 EXPECT_EQ(ibus::input_context::kServiceInterface,
180 method_call->GetInterface());
181 EXPECT_EQ(ibus::input_context::kResetMethod, method_call->GetMember());
182 dbus::MessageReader reader(method_call);
183 EXPECT_FALSE(reader.HasMoreData());
185 message_loop_.PostTask(FROM_HERE, base::Bind(callback, response_));
188 // Handles SetCursorLocation method call.
189 void OnSetCursorLocation(const ibus::Rect& cursor_location,
190 const ibus::Rect& composition_head) {
191 ++on_set_cursor_location_call_count_;
194 // Handles SetCapabilities method call.
195 void OnSetCapabilities(
196 dbus::MethodCall* method_call,
197 int timeout_ms,
198 const dbus::ObjectProxy::ResponseCallback& callback,
199 const dbus::ObjectProxy::ErrorCallback& error_callback) {
200 EXPECT_EQ(ibus::input_context::kServiceInterface,
201 method_call->GetInterface());
202 EXPECT_EQ(ibus::input_context::kSetCapabilitiesMethod,
203 method_call->GetMember());
204 uint32 capabilities;
205 dbus::MessageReader reader(method_call);
206 EXPECT_TRUE(reader.PopUint32(&capabilities));
207 EXPECT_EQ(kCapabilities, capabilities);
208 EXPECT_FALSE(reader.HasMoreData());
210 message_loop_.PostTask(FROM_HERE, base::Bind(callback, response_));
213 // Handles ProcessKeyEvent method call.
214 void OnProcessKeyEvent(
215 dbus::MethodCall* method_call,
216 int timeout_ms,
217 const dbus::ObjectProxy::ResponseCallback& callback,
218 const dbus::ObjectProxy::ErrorCallback& error_callback) {
219 EXPECT_EQ(ibus::input_context::kServiceInterface,
220 method_call->GetInterface());
221 EXPECT_EQ(ibus::input_context::kProcessKeyEventMethod,
222 method_call->GetMember());
223 uint32 keyval, keycode, state;
224 dbus::MessageReader reader(method_call);
225 EXPECT_TRUE(reader.PopUint32(&keyval));
226 EXPECT_TRUE(reader.PopUint32(&keycode));
227 EXPECT_TRUE(reader.PopUint32(&state));
228 EXPECT_FALSE(reader.HasMoreData());
230 message_loop_.PostTask(FROM_HERE, base::Bind(callback, response_));
233 void OnProcessKeyEventFail(
234 dbus::MethodCall* method_call,
235 int timeout_ms,
236 const dbus::ObjectProxy::ResponseCallback& callback,
237 const dbus::ObjectProxy::ErrorCallback& error_callback) {
238 EXPECT_EQ(ibus::input_context::kServiceInterface,
239 method_call->GetInterface());
240 EXPECT_EQ(ibus::input_context::kProcessKeyEventMethod,
241 method_call->GetMember());
242 uint32 keyval, keycode, state;
243 dbus::MessageReader reader(method_call);
244 EXPECT_TRUE(reader.PopUint32(&keyval));
245 EXPECT_TRUE(reader.PopUint32(&keycode));
246 EXPECT_TRUE(reader.PopUint32(&state));
247 EXPECT_FALSE(reader.HasMoreData());
249 message_loop_.PostTask(FROM_HERE, base::Bind(error_callback,
250 error_response_));
253 // Handles SetSurroudingText method call.
254 void OnSetSurroundingText(
255 dbus::MethodCall* method_call,
256 int timeout_ms,
257 const dbus::ObjectProxy::ResponseCallback& callback,
258 const dbus::ObjectProxy::ErrorCallback& error_callback) {
259 EXPECT_EQ(ibus::input_context::kServiceInterface,
260 method_call->GetInterface());
261 EXPECT_EQ(ibus::input_context::kSetSurroundingTextMethod,
262 method_call->GetMember());
263 dbus::MessageReader reader(method_call);
264 std::string text;
265 uint32 cursor_pos = 0;
266 uint32 anchor_pos = 0;
268 EXPECT_TRUE(PopStringFromIBusText(&reader, &text));
269 EXPECT_TRUE(reader.PopUint32(&cursor_pos));
270 EXPECT_TRUE(reader.PopUint32(&anchor_pos));
271 EXPECT_FALSE(reader.HasMoreData());
273 EXPECT_EQ(kSurroundingText, text);
274 EXPECT_EQ(kCursorPos, cursor_pos);
275 EXPECT_EQ(kAnchorPos, anchor_pos);
277 message_loop_.PostTask(FROM_HERE, base::Bind(callback, response_));
280 // Handles PropertyActivate method call.
281 void OnPropertyActivate(
282 dbus::MethodCall* method_call,
283 int timeout_ms,
284 const dbus::ObjectProxy::ResponseCallback& callback,
285 const dbus::ObjectProxy::ErrorCallback& error_callback) {
286 EXPECT_EQ(ibus::input_context::kServiceInterface,
287 method_call->GetInterface());
288 EXPECT_EQ(ibus::input_context::kPropertyActivateMethod,
289 method_call->GetMember());
290 dbus::MessageReader reader(method_call);
291 std::string key;
292 uint32 state = 0;
294 EXPECT_TRUE(reader.PopString(&key));
295 EXPECT_TRUE(reader.PopUint32(&state));
296 EXPECT_FALSE(reader.HasMoreData());
298 EXPECT_EQ(kPropertyKey, key);
299 EXPECT_EQ(kPropertyState, static_cast<ibus::IBusPropertyState>(state));
301 message_loop_.PostTask(FROM_HERE, base::Bind(callback, response_));
304 protected:
305 // The client to be tested.
306 scoped_ptr<IBusInputContextClient> client_;
307 // The mock bus.
308 scoped_refptr<dbus::MockBus> mock_bus_;
309 // The mock object proxy.
310 scoped_refptr<dbus::MockObjectProxy> mock_proxy_;
311 // Response returned by mock methods.
312 dbus::Response* response_;
313 dbus::ErrorResponse* error_response_;
314 // A message loop to emulate asynchronous behavior.
315 MessageLoop message_loop_;
316 // The map from signal to signal handler.
317 std::map<std::string, dbus::ObjectProxy::SignalCallback> signal_callback_map_;
318 // Call count of OnSetCursorLocation.
319 int on_set_cursor_location_call_count_;
321 private:
322 // Used to implement the mock proxy.
323 void OnConnectToSignal(
324 const std::string& interface_name,
325 const std::string& signal_name,
326 const dbus::ObjectProxy::SignalCallback& signal_callback,
327 const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback) {
328 signal_callback_map_[signal_name] = signal_callback;
329 const bool success = true;
330 message_loop_.PostTask(FROM_HERE, base::Bind(on_connected_callback,
331 interface_name,
332 signal_name,
333 success));
337 TEST_F(IBusInputContextClientTest, CommitTextHandler) {
338 const char kSampleText[] = "Sample Text";
339 IBusText ibus_text;
340 ibus_text.set_text(kSampleText);
342 // Set handler expectations.
343 MockInputContextHandler mock_handler;
344 EXPECT_CALL(mock_handler, CommitText(IBusTextEq(&ibus_text)));
345 client_->SetInputContextHandler(&mock_handler);
346 message_loop_.RunUntilIdle();
348 // Emit signal.
349 dbus::Signal signal(ibus::input_context::kServiceInterface,
350 ibus::input_context::kCommitTextSignal);
351 dbus::MessageWriter writer(&signal);
352 AppendIBusText(ibus_text, &writer);
353 ASSERT_FALSE(
354 signal_callback_map_[ibus::input_context::kCommitTextSignal].is_null());
355 signal_callback_map_[ibus::input_context::kCommitTextSignal].Run(&signal);
357 // Unset the handler so expect not calling handler.
358 client_->SetInputContextHandler(NULL);
359 signal_callback_map_[ibus::input_context::kCommitTextSignal].Run(&signal);
362 TEST_F(IBusInputContextClientTest, ForwardKeyEventHandlerTest) {
363 // Set handler expectations.
364 MockInputContextHandler mock_handler;
365 EXPECT_CALL(mock_handler, ForwardKeyEvent(kKeyval, kKeycode, kState));
366 client_->SetInputContextHandler(&mock_handler);
367 message_loop_.RunUntilIdle();
369 // Emit signal.
370 dbus::Signal signal(ibus::input_context::kServiceInterface,
371 ibus::input_context::kForwardKeyEventSignal);
372 dbus::MessageWriter writer(&signal);
373 writer.AppendUint32(kKeyval);
374 writer.AppendUint32(kKeycode);
375 writer.AppendUint32(kState);
376 ASSERT_FALSE(
377 signal_callback_map_[ibus::input_context::kForwardKeyEventSignal]
378 .is_null());
379 signal_callback_map_[ibus::input_context::kForwardKeyEventSignal].Run(
380 &signal);
382 // Unset the handler so expect not calling handler.
383 client_->SetInputContextHandler(NULL);
384 signal_callback_map_[ibus::input_context::kForwardKeyEventSignal].Run(
385 &signal);
388 TEST_F(IBusInputContextClientTest, HidePreeditTextHandlerTest) {
389 // Set handler expectations.
390 MockInputContextHandler mock_handler;
391 EXPECT_CALL(mock_handler, HidePreeditText());
392 client_->SetInputContextHandler(&mock_handler);
393 message_loop_.RunUntilIdle();
395 // Emit signal.
396 dbus::Signal signal(ibus::input_context::kServiceInterface,
397 ibus::input_context::kHidePreeditTextSignal);
398 ASSERT_FALSE(
399 signal_callback_map_[ibus::input_context::kHidePreeditTextSignal]
400 .is_null());
401 signal_callback_map_[ibus::input_context::kHidePreeditTextSignal].Run(
402 &signal);
404 // Unset the handler so expect not calling handler.
405 client_->SetInputContextHandler(NULL);
406 signal_callback_map_[ibus::input_context::kHidePreeditTextSignal].Run(
407 &signal);
410 TEST_F(IBusInputContextClientTest, ShowPreeditTextHandlerTest) {
411 // Set handler expectations.
412 MockInputContextHandler mock_handler;
413 EXPECT_CALL(mock_handler, ShowPreeditText());
414 client_->SetInputContextHandler(&mock_handler);
415 message_loop_.RunUntilIdle();
417 // Emit signal.
418 dbus::Signal signal(ibus::input_context::kServiceInterface,
419 ibus::input_context::kShowPreeditTextSignal);
420 ASSERT_FALSE(
421 signal_callback_map_[ibus::input_context::kShowPreeditTextSignal]
422 .is_null());
423 signal_callback_map_[ibus::input_context::kShowPreeditTextSignal].Run(
424 &signal);
426 // Unset the handler so expect not calling handler.
427 client_->SetInputContextHandler(NULL);
428 signal_callback_map_[ibus::input_context::kShowPreeditTextSignal].Run(
429 &signal);
432 TEST_F(IBusInputContextClientTest, UpdatePreeditTextHandlerTest) {
433 const uint32 kCursorPos = 20;
434 const bool kVisible = false;
435 const char kSampleText[] = "Sample Text";
436 IBusText ibus_text;
437 ibus_text.set_text(kSampleText);
439 // Set handler expectations.
440 MockInputContextHandler mock_handler;
441 EXPECT_CALL(mock_handler,
442 UpdatePreeditText(IBusTextEq(&ibus_text), kCursorPos, kVisible));
443 client_->SetInputContextHandler(&mock_handler);
444 message_loop_.RunUntilIdle();
446 // Emit signal.
447 dbus::Signal signal(ibus::input_context::kServiceInterface,
448 ibus::input_context::kUpdatePreeditTextSignal);
449 dbus::MessageWriter writer(&signal);
450 AppendIBusText(ibus_text, &writer);
451 writer.AppendUint32(kCursorPos);
452 writer.AppendBool(kVisible);
453 ASSERT_FALSE(
454 signal_callback_map_[ibus::input_context::kUpdatePreeditTextSignal]
455 .is_null());
456 signal_callback_map_[ibus::input_context::kUpdatePreeditTextSignal].Run(
457 &signal);
459 // Unset the handler so expect not calling handler.
460 client_->SetInputContextHandler(NULL);
461 signal_callback_map_[ibus::input_context::kUpdatePreeditTextSignal].Run(
462 &signal);
465 TEST_F(IBusInputContextClientTest, FocusInTest) {
466 // Set expectations.
467 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _))
468 .WillOnce(Invoke(this, &IBusInputContextClientTest::OnFocusIn));
469 // Create response.
470 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
471 response_ = response.get();
473 // Call FocusIn.
474 client_->FocusIn();
475 // Run the message loop.
476 message_loop_.RunUntilIdle();
479 TEST_F(IBusInputContextClientTest, FocusOutTest) {
480 // Set expectations.
481 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _))
482 .WillOnce(Invoke(this, &IBusInputContextClientTest::OnFocusOut));
483 // Create response.
484 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
485 response_ = response.get();
487 // Call FocusOut.
488 client_->FocusOut();
489 // Run the message loop.
490 message_loop_.RunUntilIdle();
493 TEST_F(IBusInputContextClientTest, ResetTest) {
494 // Set expectations.
495 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _))
496 .WillOnce(Invoke(this, &IBusInputContextClientTest::OnReset));
497 // Create response.
498 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
499 response_ = response.get();
501 // Call Reset.
502 client_->Reset();
503 // Run the message loop.
504 message_loop_.RunUntilIdle();
507 TEST_F(IBusInputContextClientTest, SetCapabilitiesTest) {
508 // Set expectations.
509 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _))
510 .WillOnce(Invoke(this, &IBusInputContextClientTest::OnSetCapabilities));
511 // Create response.
512 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
513 response_ = response.get();
515 // Call SetCapabilities.
516 client_->SetCapabilities(kCapabilities);
517 // Run the message loop.
518 message_loop_.RunUntilIdle();
521 TEST_F(IBusInputContextClientTest, SetCursorLocationTest) {
522 on_set_cursor_location_call_count_ = 0;
523 client_->SetSetCursorLocationHandler(
524 base::Bind(&IBusInputContextClientTest::OnSetCursorLocation,
525 base::Unretained(this)));
526 const ibus::Rect cursor_location(kCursorX,
527 kCursorY,
528 kCursorWidth,
529 kCursorHeight);
530 const ibus::Rect composition_location(kCompositionX,
531 kCompositionY,
532 kCompositionWidth,
533 kCompositionHeight);
534 // Call SetCursorLocation.
535 client_->SetCursorLocation(cursor_location, composition_location);
537 EXPECT_EQ(1, on_set_cursor_location_call_count_);
538 client_->UnsetSetCursorLocationHandler();
541 TEST_F(IBusInputContextClientTest, OnProcessKeyEvent) {
542 // Set expectations.
543 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _))
544 .WillOnce(Invoke(this, &IBusInputContextClientTest::OnProcessKeyEvent));
545 MockProcessKeyEventHandler callback;
546 MockProcessKeyEventErrorHandler error_callback;
548 EXPECT_CALL(callback, Run(kIsKeyHandled));
549 EXPECT_CALL(error_callback, Run()).Times(0);
550 // Create response.
551 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
552 dbus::MessageWriter writer(response.get());
553 writer.AppendBool(kIsKeyHandled);
554 response_ = response.get();
556 // Call ProcessKeyEvent.
557 client_->ProcessKeyEvent(kKeyval,
558 kKeycode,
559 kState,
560 base::Bind(&MockProcessKeyEventHandler::Run,
561 base::Unretained(&callback)),
562 base::Bind(&MockProcessKeyEventErrorHandler::Run,
563 base::Unretained(&error_callback)));
564 // Run the message loop.
565 message_loop_.RunUntilIdle();
568 TEST_F(IBusInputContextClientTest, OnProcessKeyEventFail) {
569 // Set expectations.
570 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _))
571 .WillOnce(Invoke(this,
572 &IBusInputContextClientTest::OnProcessKeyEventFail));
573 MockProcessKeyEventHandler callback;
574 MockProcessKeyEventErrorHandler error_callback;
576 EXPECT_CALL(callback, Run(_)).Times(0);
577 EXPECT_CALL(error_callback, Run());
578 // Create response.
579 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
580 dbus::MessageWriter writer(response.get());
581 writer.AppendBool(kIsKeyHandled);
582 response_ = response.get();
584 // Call ProcessKeyEvent.
585 client_->ProcessKeyEvent(kKeyval,
586 kKeycode,
587 kState,
588 base::Bind(&MockProcessKeyEventHandler::Run,
589 base::Unretained(&callback)),
590 base::Bind(&MockProcessKeyEventErrorHandler::Run,
591 base::Unretained(&error_callback)));
592 // Run the message loop.
593 message_loop_.RunUntilIdle();
596 TEST_F(IBusInputContextClientTest, SetSurroundingTextTest) {
597 // Set expectations.
598 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _))
599 .WillOnce(Invoke(this,
600 &IBusInputContextClientTest::OnSetSurroundingText));
601 // Create response.
602 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
603 response_ = response.get();
605 // Call SetCursorLocation.
606 client_->SetSurroundingText(kSurroundingText, kCursorPos, kAnchorPos);
607 // Run the message loop.
608 message_loop_.RunUntilIdle();
611 TEST_F(IBusInputContextClientTest, PropertyActivateTest) {
612 // Set expectations.
613 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _))
614 .WillOnce(Invoke(this,
615 &IBusInputContextClientTest::OnPropertyActivate));
616 // Create response.
617 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
618 response_ = response.get();
620 // Call SetCursorLocation.
621 client_->PropertyActivate(kPropertyKey, kPropertyState);
622 // Run the message loop.
623 message_loop_.RunUntilIdle();
625 } // namespace chromeos