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

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

Issue 23766008: Delete IBusEngineServiceImpl which is no longer used for production. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 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
« no previous file with comments | « chromeos/dbus/ibus/ibus_engine_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "chromeos/dbus/ibus/ibus_engine_service.h"
6
7 #include <map>
8 #include "base/bind.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/values.h"
11 #include "chromeos/dbus/ibus/ibus_constants.h"
12 #include "chromeos/dbus/ibus/ibus_lookup_table.h"
13 #include "chromeos/dbus/ibus/ibus_property.h"
14 #include "chromeos/dbus/ibus/ibus_text.h"
15 #include "chromeos/ime/ibus_bridge.h"
16 #include "dbus/message.h"
17 #include "dbus/mock_bus.h"
18 #include "dbus/mock_exported_object.h"
19 #include "dbus/object_path.h"
20 #include "dbus/values_util.h"
21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23
24 using testing::Invoke;
25 using testing::Return;
26 using testing::_;
27
28 namespace chromeos {
29
30 namespace {
31 const std::string kObjectPath = "/org/freedesktop/IBus/Engine/1";
32
33 class MockIBusEngineHandler : public IBusEngineHandlerInterface {
34 public:
35 MOCK_METHOD0(FocusIn, void());
36 MOCK_METHOD0(FocusOut, void());
37 MOCK_METHOD0(Enable, void());
38 MOCK_METHOD0(Disable, void());
39 MOCK_METHOD2(PropertyActivate, void(const std::string& property_name,
40 ibus::IBusPropertyState property_state));
41 MOCK_METHOD1(PropertyShow, void(const std::string& property_name));
42 MOCK_METHOD1(PropertyHide, void(const std::string& property_name));
43 MOCK_METHOD1(SetCapability, void(IBusCapability capability));
44 MOCK_METHOD0(Reset, void());
45 MOCK_METHOD4(ProcessKeyEvent, void(
46 uint32 keysym,
47 uint32 keycode,
48 uint32 state,
49 const KeyEventDoneCallback& callback));
50 MOCK_METHOD3(CandidateClicked, void(uint32 index,
51 ibus::IBusMouseButton button,
52 uint32 state));
53 MOCK_METHOD3(SetSurroundingText, void(const std::string& text,
54 uint32 cursor_pos,
55 uint32 anchor_pos));
56 };
57
58 class MockResponseSender {
59 public:
60 // GMock doesn't support mocking methods which take scoped_ptr<>.
61 MOCK_METHOD1(MockRun, void(dbus::Response* reponse));
62 void Run(scoped_ptr<dbus::Response> response) {
63 MockRun(response.get());
64 }
65 };
66
67 // Used for method call empty response evaluation.
68 class EmptyResponseExpectation {
69 public:
70 explicit EmptyResponseExpectation(const uint32 serial_no)
71 : serial_no_(serial_no) {}
72
73 // Evaluates the given |response| has no argument.
74 void Evaluate(dbus::Response* response) {
75 EXPECT_EQ(serial_no_, response->GetReplySerial());
76 dbus::MessageReader reader(response);
77 EXPECT_FALSE(reader.HasMoreData());
78 }
79
80 private:
81 const uint32 serial_no_;
82
83 DISALLOW_COPY_AND_ASSIGN(EmptyResponseExpectation);
84 };
85
86 // Used for method call a boolean response evaluation.
87 class BoolResponseExpectation {
88 public:
89 explicit BoolResponseExpectation(uint32 serial_no, bool result)
90 : serial_no_(serial_no),
91 result_(result) {}
92
93 // Evaluates the given |response| has only one boolean and which is equals to
94 // |result_| which is given in ctor.
95 void Evaluate(dbus::Response* response) {
96 EXPECT_EQ(serial_no_, response->GetReplySerial());
97 dbus::MessageReader reader(response);
98 bool result = false;
99 EXPECT_TRUE(reader.PopBool(&result));
100 EXPECT_EQ(result_, result);
101 EXPECT_FALSE(reader.HasMoreData());
102 }
103
104 private:
105 uint32 serial_no_;
106 bool result_;
107
108 DISALLOW_COPY_AND_ASSIGN(BoolResponseExpectation);
109 };
110
111 // Used for RegisterProperties signal message evaluation.
112 class RegisterPropertiesExpectation {
113 public:
114 explicit RegisterPropertiesExpectation(
115 const IBusPropertyList& property_list)
116 : property_list_(property_list) {}
117
118 // Evaluates the given |signal| is a valid message.
119 void Evaluate(dbus::Signal* signal) {
120 IBusPropertyList property_list;
121
122 // Read a signal argument.
123 dbus::MessageReader reader(signal);
124 EXPECT_TRUE(PopIBusPropertyList(&reader, &property_list));
125 EXPECT_FALSE(reader.HasMoreData());
126
127 // Check an argument.
128 EXPECT_EQ(property_list_.size(), property_list.size());
129 for (size_t i = 0; i < property_list_.size(); ++i) {
130 EXPECT_EQ(property_list_[i]->key(), property_list[i]->key());
131 EXPECT_EQ(property_list_[i]->type(), property_list[i]->type());
132 EXPECT_EQ(property_list_[i]->label(), property_list[i]->label());
133 EXPECT_EQ(property_list_[i]->tooltip(), property_list[i]->tooltip());
134 EXPECT_EQ(property_list_[i]->visible(), property_list[i]->visible());
135 EXPECT_EQ(property_list_[i]->checked(), property_list[i]->checked());
136 }
137 }
138
139 private:
140 const IBusPropertyList& property_list_;
141
142 DISALLOW_COPY_AND_ASSIGN(RegisterPropertiesExpectation);
143 };
144
145 // Used for mocking ProcessKeyEventHandler.
146 class ProcessKeyEventHandler {
147 public:
148 explicit ProcessKeyEventHandler(bool expected_value)
149 : expected_value_(expected_value) {
150 }
151
152 void ProcessKeyEvent(
153 uint32 keysym,
154 uint32 keycode,
155 uint32 state,
156 const IBusEngineHandlerInterface::KeyEventDoneCallback& callback) {
157 callback.Run(expected_value_);
158 }
159
160 private:
161 bool expected_value_;
162
163 DISALLOW_COPY_AND_ASSIGN(ProcessKeyEventHandler);
164 };
165
166 // Used for mocking asynchronous ProcessKeyEventHandler.
167 class DelayProcessKeyEventHandler {
168 public:
169 DelayProcessKeyEventHandler(bool expected_value,
170 base::MessageLoop* message_loop)
171 : expected_value_(expected_value),
172 message_loop_(message_loop) {
173 }
174
175 void ProcessKeyEvent(
176 uint32 keysym,
177 uint32 keycode,
178 uint32 state,
179 const IBusEngineHandlerInterface::KeyEventDoneCallback& callback) {
180 message_loop_->PostTask(FROM_HERE, base::Bind(callback, expected_value_));
181 }
182
183 private:
184 bool expected_value_;
185 base::MessageLoop* message_loop_;
186
187 DISALLOW_COPY_AND_ASSIGN(DelayProcessKeyEventHandler);
188 };
189
190 // Used for UpdatePreedit signal message evaluation.
191 class UpdatePreeditExpectation {
192 public:
193 UpdatePreeditExpectation(
194 const IBusText& ibus_text,
195 uint32 cursor_pos,
196 bool is_visible,
197 IBusEngineService::IBusEnginePreeditFocusOutMode mode)
198 : ibus_text_(ibus_text),
199 cursor_pos_(cursor_pos),
200 is_visible_(is_visible),
201 mode_(mode) {}
202
203 // Evaluates the given |signal| is a valid message.
204 void Evaluate(dbus::Signal* signal) {
205 IBusText ibus_text;
206 uint32 cursor_pos = 0;
207 bool is_visible = false;
208 uint32 preedit_mode = 0;
209
210 // Read signal arguments.
211 dbus::MessageReader reader(signal);
212 EXPECT_TRUE(PopIBusText(&reader, &ibus_text));
213 EXPECT_TRUE(reader.PopUint32(&cursor_pos));
214 EXPECT_TRUE(reader.PopBool(&is_visible));
215 EXPECT_TRUE(reader.PopUint32(&preedit_mode));
216 EXPECT_FALSE(reader.HasMoreData());
217
218 // Check arguments.
219 EXPECT_EQ(ibus_text_.text(), ibus_text.text());
220 EXPECT_EQ(cursor_pos_, cursor_pos);
221 EXPECT_EQ(is_visible_, is_visible);
222 EXPECT_EQ(mode_,
223 static_cast<IBusEngineService::IBusEnginePreeditFocusOutMode>(
224 preedit_mode));
225 }
226
227 private:
228 const IBusText& ibus_text_;
229 uint32 cursor_pos_;
230 bool is_visible_;
231 IBusEngineService::IBusEnginePreeditFocusOutMode mode_;
232
233 DISALLOW_COPY_AND_ASSIGN(UpdatePreeditExpectation);
234 };
235
236 // Used for UpdateAuxiliaryText signal message evaluation.
237 class UpdateAuxiliaryTextExpectation {
238 public:
239 UpdateAuxiliaryTextExpectation(const IBusText& ibus_text,
240 bool is_visible)
241 : ibus_text_(ibus_text), is_visible_(is_visible) {}
242
243 // Evaluates the given |signal| is a valid message.
244 void Evaluate(dbus::Signal* signal) {
245 IBusText ibus_text;
246 bool is_visible = false;
247
248 // Read signal arguments.
249 dbus::MessageReader reader(signal);
250 EXPECT_TRUE(PopIBusText(&reader, &ibus_text));
251 EXPECT_TRUE(reader.PopBool(&is_visible));
252 EXPECT_FALSE(reader.HasMoreData());
253
254 // Check arguments.
255 EXPECT_EQ(ibus_text_.text(), ibus_text.text());
256 EXPECT_EQ(is_visible_, is_visible);
257 }
258
259 private:
260 const IBusText& ibus_text_;
261 bool is_visible_;
262
263 DISALLOW_COPY_AND_ASSIGN(UpdateAuxiliaryTextExpectation);
264 };
265
266 // Used for UpdateLookupTable signal message evaluation.
267 class UpdateLookupTableExpectation {
268 public:
269 UpdateLookupTableExpectation(const IBusLookupTable& lookup_table,
270 bool is_visible)
271 : lookup_table_(lookup_table), is_visible_(is_visible) {}
272
273 // Evaluates the given |signal| is a valid message.
274 void Evaluate(dbus::Signal* signal) {
275 IBusLookupTable lookup_table;
276 bool is_visible = false;
277
278 // Read signal arguments.
279 dbus::MessageReader reader(signal);
280 EXPECT_TRUE(PopIBusLookupTable(&reader, &lookup_table));
281 EXPECT_TRUE(reader.PopBool(&is_visible));
282 EXPECT_FALSE(reader.HasMoreData());
283
284 // Check arguments.
285 EXPECT_EQ(lookup_table_.page_size(), lookup_table.page_size());
286 EXPECT_EQ(lookup_table_.cursor_position(), lookup_table.cursor_position());
287 EXPECT_EQ(lookup_table_.is_cursor_visible(),
288 lookup_table.is_cursor_visible());
289 EXPECT_EQ(is_visible_, is_visible);
290 }
291
292 private:
293 const IBusLookupTable& lookup_table_;
294 bool is_visible_;
295
296 DISALLOW_COPY_AND_ASSIGN(UpdateLookupTableExpectation);
297 };
298
299 // Used for UpdateProperty signal message evaluation.
300 class UpdatePropertyExpectation {
301 public:
302 explicit UpdatePropertyExpectation(const IBusProperty& property)
303 : property_(property) {}
304
305 // Evaluates the given |signal| is a valid message.
306 void Evaluate(dbus::Signal* signal) {
307 IBusProperty property;
308
309 // Read a signal argument.
310 dbus::MessageReader reader(signal);
311 EXPECT_TRUE(PopIBusProperty(&reader, &property));
312 EXPECT_FALSE(reader.HasMoreData());
313
314 // Check the argument.
315 EXPECT_EQ(property_.key(), property.key());
316 EXPECT_EQ(property_.type(), property.type());
317 EXPECT_EQ(property_.label(), property.label());
318 EXPECT_EQ(property_.tooltip(), property.tooltip());
319 EXPECT_EQ(property_.visible(), property.visible());
320 EXPECT_EQ(property_.checked(), property.checked());
321 }
322
323 private:
324 const IBusProperty& property_;
325
326 DISALLOW_COPY_AND_ASSIGN(UpdatePropertyExpectation);
327 };
328
329 // Used for ForwardKeyEvent signal message evaluation.
330 class ForwardKeyEventExpectation {
331 public:
332 ForwardKeyEventExpectation(uint32 keyval, uint32 keycode, uint32 state)
333 : keyval_(keyval),
334 keycode_(keycode),
335 state_(state) {}
336
337 // Evaluates the given |signal| is a valid message.
338 void Evaluate(dbus::Signal* signal) {
339 uint32 keyval = 0;
340 uint32 keycode = 0;
341 uint32 state = 0;
342
343 // Read signal arguments.
344 dbus::MessageReader reader(signal);
345 EXPECT_TRUE(reader.PopUint32(&keyval));
346 EXPECT_TRUE(reader.PopUint32(&keycode));
347 EXPECT_TRUE(reader.PopUint32(&state));
348 EXPECT_FALSE(reader.HasMoreData());
349
350 // Check arguments.
351 EXPECT_EQ(keyval_, keyval);
352 EXPECT_EQ(keycode_, keycode);
353 EXPECT_EQ(state_, state);
354 }
355
356 private:
357 uint32 keyval_;
358 uint32 keycode_;
359 uint32 state_;
360
361 DISALLOW_COPY_AND_ASSIGN(ForwardKeyEventExpectation);
362 };
363
364 // Used for RequireSurroundingText signal message evaluation.
365 class RequireSurroundingTextExpectation {
366 public:
367 RequireSurroundingTextExpectation() {}
368
369 // Evaluates the given |signal| is a valid message.
370 void Evaluate(dbus::Signal* signal) {
371 dbus::MessageReader reader(signal);
372 EXPECT_FALSE(reader.HasMoreData());
373 }
374
375 private:
376 DISALLOW_COPY_AND_ASSIGN(RequireSurroundingTextExpectation);
377 };
378
379 } // namespace
380
381 class IBusEngineServiceTest : public testing::Test {
382 public:
383 IBusEngineServiceTest() {}
384
385 virtual void SetUp() OVERRIDE {
386 // Create a mock bus.
387 dbus::Bus::Options options;
388 options.bus_type = dbus::Bus::SYSTEM;
389 mock_bus_ = new dbus::MockBus(options);
390
391 // Create a mock exported object.
392 mock_exported_object_ = new dbus::MockExportedObject(
393 mock_bus_.get(),
394 dbus::ObjectPath(kObjectPath));
395
396 EXPECT_CALL(*mock_bus_.get(),
397 GetExportedObject(dbus::ObjectPath(kObjectPath)))
398 .WillOnce(Return(mock_exported_object_.get()));
399
400 EXPECT_CALL(*mock_exported_object_.get(),
401 ExportMethod(ibus::engine::kServiceInterface,
402 ibus::engine::kFocusInMethod,
403 _,
404 _))
405 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported));
406
407 EXPECT_CALL(*mock_exported_object_.get(),
408 ExportMethod(ibus::engine::kServiceInterface,
409 ibus::engine::kFocusOutMethod,
410 _,
411 _))
412 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported));
413
414 EXPECT_CALL(
415 *mock_exported_object_.get(),
416 ExportMethod(
417 ibus::engine::kServiceInterface, ibus::engine::kEnableMethod, _, _))
418 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported));
419
420 EXPECT_CALL(*mock_exported_object_.get(),
421 ExportMethod(ibus::engine::kServiceInterface,
422 ibus::engine::kDisableMethod,
423 _,
424 _))
425 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported));
426
427 EXPECT_CALL(*mock_exported_object_.get(),
428 ExportMethod(ibus::engine::kServiceInterface,
429 ibus::engine::kPropertyActivateMethod,
430 _,
431 _))
432 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported));
433
434 EXPECT_CALL(*mock_exported_object_.get(),
435 ExportMethod(ibus::engine::kServiceInterface,
436 ibus::engine::kPropertyShowMethod,
437 _,
438 _))
439 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported));
440
441 EXPECT_CALL(*mock_exported_object_.get(),
442 ExportMethod(ibus::engine::kServiceInterface,
443 ibus::engine::kPropertyHideMethod,
444 _,
445 _))
446 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported));
447
448 EXPECT_CALL(*mock_exported_object_.get(),
449 ExportMethod(ibus::engine::kServiceInterface,
450 ibus::engine::kSetCapabilityMethod,
451 _,
452 _))
453 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported));
454
455 EXPECT_CALL(
456 *mock_exported_object_.get(),
457 ExportMethod(
458 ibus::engine::kServiceInterface, ibus::engine::kResetMethod, _, _))
459 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported));
460
461 EXPECT_CALL(*mock_exported_object_.get(),
462 ExportMethod(ibus::engine::kServiceInterface,
463 ibus::engine::kProcessKeyEventMethod,
464 _,
465 _))
466 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported));
467
468 EXPECT_CALL(*mock_exported_object_.get(),
469 ExportMethod(ibus::engine::kServiceInterface,
470 ibus::engine::kCandidateClickedMethod,
471 _,
472 _))
473 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported));
474
475 EXPECT_CALL(*mock_exported_object_.get(),
476 ExportMethod(ibus::engine::kServiceInterface,
477 ibus::engine::kSetSurroundingTextMethod,
478 _,
479 _))
480 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported));
481
482 // Suppress uninteresting mock function call warning.
483 EXPECT_CALL(*mock_bus_.get(),
484 AssertOnOriginThread())
485 .WillRepeatedly(Return());
486
487 // Create a service
488 service_.reset(IBusEngineService::Create(
489 REAL_DBUS_CLIENT_IMPLEMENTATION,
490 mock_bus_.get(),
491 dbus::ObjectPath(kObjectPath)));
492
493 // Set engine handler.
494 engine_handler_.reset(new MockIBusEngineHandler());
495 service_->SetEngine(engine_handler_.get());
496 }
497
498 protected:
499 // The service to be tested.
500 scoped_ptr<IBusEngineService> service_;
501 // The mock engine handler. Do not free, this is owned by IBusEngineService.
502 scoped_ptr<MockIBusEngineHandler> engine_handler_;
503 // The mock bus.
504 scoped_refptr<dbus::MockBus> mock_bus_;
505 // The mock exported object.
506 scoped_refptr<dbus::MockExportedObject> mock_exported_object_;
507 // A message loop to emulate asynchronous behavior.
508 base::MessageLoop message_loop_;
509 // The map from method call to method call handler.
510 std::map<std::string, dbus::ExportedObject::MethodCallCallback>
511 method_callback_map_;
512
513 private:
514 // Used to implement the mock method call.
515 void OnMethodExported(
516 const std::string& interface_name,
517 const std::string& method_name,
518 const dbus::ExportedObject::MethodCallCallback& method_callback,
519 const dbus::ExportedObject::OnExportedCallback& on_exported_callback) {
520 method_callback_map_[method_name] = method_callback;
521 const bool success = true;
522 message_loop_.PostTask(FROM_HERE, base::Bind(on_exported_callback,
523 interface_name,
524 method_name,
525 success));
526 }
527 };
528
529 TEST_F(IBusEngineServiceTest, FocusInTest) {
530 // Set expectations.
531 const uint32 kSerialNo = 1;
532 EXPECT_CALL(*engine_handler_, FocusIn());
533 MockResponseSender response_sender;
534 EmptyResponseExpectation response_expectation(kSerialNo);
535 EXPECT_CALL(response_sender, MockRun(_))
536 .WillOnce(Invoke(&response_expectation,
537 &EmptyResponseExpectation::Evaluate));
538
539 // Create method call;
540 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
541 ibus::engine::kFocusInMethod);
542 method_call.SetSerial(kSerialNo);
543
544 // Call exported function.
545 EXPECT_NE(method_callback_map_.find(ibus::engine::kFocusInMethod),
546 method_callback_map_.end());
547 method_callback_map_[ibus::engine::kFocusInMethod].Run(
548 &method_call,
549 base::Bind(&MockResponseSender::Run,
550 base::Unretained(&response_sender)));
551
552 // Call exported function without engine.
553 service_->UnsetEngine(engine_handler_.get());
554 EXPECT_CALL(*engine_handler_, FocusIn()).Times(0);
555 EXPECT_CALL(response_sender, MockRun(_)).Times(0);
556 method_callback_map_[ibus::engine::kFocusInMethod].Run(
557 &method_call,
558 base::Bind(&MockResponseSender::Run,
559 base::Unretained(&response_sender)));
560 }
561
562 TEST_F(IBusEngineServiceTest, FocusOutTest) {
563 // Set expectations.
564 const uint32 kSerialNo = 1;
565 EXPECT_CALL(*engine_handler_, FocusOut());
566 MockResponseSender response_sender;
567 EmptyResponseExpectation response_expectation(kSerialNo);
568 EXPECT_CALL(response_sender, MockRun(_))
569 .WillOnce(Invoke(&response_expectation,
570 &EmptyResponseExpectation::Evaluate));
571
572 // Create method call;
573 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
574 ibus::engine::kFocusOutMethod);
575 method_call.SetSerial(kSerialNo);
576
577 // Call exported function.
578 EXPECT_NE(method_callback_map_.find(ibus::engine::kFocusOutMethod),
579 method_callback_map_.end());
580 method_callback_map_[ibus::engine::kFocusOutMethod].Run(
581 &method_call,
582 base::Bind(&MockResponseSender::Run,
583 base::Unretained(&response_sender)));
584
585 // Call exported function without engine.
586 service_->UnsetEngine(engine_handler_.get());
587 EXPECT_CALL(*engine_handler_, FocusOut()).Times(0);
588 EXPECT_CALL(response_sender, MockRun(_)).Times(0);
589 method_callback_map_[ibus::engine::kFocusOutMethod].Run(
590 &method_call,
591 base::Bind(&MockResponseSender::Run,
592 base::Unretained(&response_sender)));
593 }
594
595 TEST_F(IBusEngineServiceTest, EnableTest) {
596 // Set expectations.
597 const uint32 kSerialNo = 1;
598 EXPECT_CALL(*engine_handler_, Enable());
599 MockResponseSender response_sender;
600 EmptyResponseExpectation response_expectation(kSerialNo);
601 EXPECT_CALL(response_sender, MockRun(_))
602 .WillOnce(Invoke(&response_expectation,
603 &EmptyResponseExpectation::Evaluate));
604
605 // Create method call;
606 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
607 ibus::engine::kEnableMethod);
608 method_call.SetSerial(kSerialNo);
609
610 // Call exported function.
611 EXPECT_NE(method_callback_map_.find(ibus::engine::kEnableMethod),
612 method_callback_map_.end());
613 method_callback_map_[ibus::engine::kEnableMethod].Run(
614 &method_call,
615 base::Bind(&MockResponseSender::Run,
616 base::Unretained(&response_sender)));
617
618 // Call exported function without engine.
619 service_->UnsetEngine(engine_handler_.get());
620 EXPECT_CALL(*engine_handler_, Enable()).Times(0);
621 EXPECT_CALL(response_sender, MockRun(_)).Times(0);
622 method_callback_map_[ibus::engine::kEnableMethod].Run(
623 &method_call,
624 base::Bind(&MockResponseSender::Run,
625 base::Unretained(&response_sender)));
626 }
627
628 TEST_F(IBusEngineServiceTest, DisableTest) {
629 // Set expectations.
630 const uint32 kSerialNo = 1;
631 EXPECT_CALL(*engine_handler_, Disable());
632 MockResponseSender response_sender;
633 EmptyResponseExpectation response_expectation(kSerialNo);
634 EXPECT_CALL(response_sender, MockRun(_))
635 .WillOnce(Invoke(&response_expectation,
636 &EmptyResponseExpectation::Evaluate));
637
638 // Create method call;
639 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
640 ibus::engine::kDisableMethod);
641 method_call.SetSerial(kSerialNo);
642
643 // Call exported function.
644 EXPECT_NE(method_callback_map_.find(ibus::engine::kDisableMethod),
645 method_callback_map_.end());
646 method_callback_map_[ibus::engine::kDisableMethod].Run(
647 &method_call,
648 base::Bind(&MockResponseSender::Run,
649 base::Unretained(&response_sender)));
650
651 // Call exported function without engine.
652 service_->UnsetEngine(engine_handler_.get());
653 EXPECT_CALL(*engine_handler_, Disable()).Times(0);
654 EXPECT_CALL(response_sender, MockRun(_)).Times(0);
655 method_callback_map_[ibus::engine::kDisableMethod].Run(
656 &method_call,
657 base::Bind(&MockResponseSender::Run,
658 base::Unretained(&response_sender)));
659 }
660
661 TEST_F(IBusEngineServiceTest, PropertyActivateTest) {
662 // Set expectations.
663 const uint32 kSerialNo = 1;
664 const std::string kPropertyName = "Property Name";
665 const ibus::IBusPropertyState kIBusPropertyState =
666 ibus::IBUS_PROPERTY_STATE_UNCHECKED;
667 EXPECT_CALL(*engine_handler_, PropertyActivate(kPropertyName,
668 kIBusPropertyState));
669 MockResponseSender response_sender;
670 EmptyResponseExpectation response_expectation(kSerialNo);
671 EXPECT_CALL(response_sender, MockRun(_))
672 .WillOnce(Invoke(&response_expectation,
673 &EmptyResponseExpectation::Evaluate));
674
675 // Create method call;
676 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
677 ibus::engine::kPropertyActivateMethod);
678 method_call.SetSerial(kSerialNo);
679 dbus::MessageWriter writer(&method_call);
680 writer.AppendString(kPropertyName);
681 writer.AppendUint32(static_cast<uint32>(kIBusPropertyState));
682
683 // Call exported function.
684 EXPECT_NE(method_callback_map_.find(ibus::engine::kPropertyActivateMethod),
685 method_callback_map_.end());
686 method_callback_map_[ibus::engine::kPropertyActivateMethod].Run(
687 &method_call,
688 base::Bind(&MockResponseSender::Run,
689 base::Unretained(&response_sender)));
690
691 // Call exported function without engine.
692 service_->UnsetEngine(engine_handler_.get());
693 EXPECT_CALL(*engine_handler_, PropertyActivate(kPropertyName,
694 kIBusPropertyState)).Times(0);
695 EXPECT_CALL(response_sender, MockRun(_)).Times(0);
696 method_callback_map_[ibus::engine::kPropertyActivateMethod].Run(
697 &method_call,
698 base::Bind(&MockResponseSender::Run,
699 base::Unretained(&response_sender)));
700 }
701
702 TEST_F(IBusEngineServiceTest, ResetTest) {
703 // Set expectations.
704 const uint32 kSerialNo = 1;
705 EXPECT_CALL(*engine_handler_, Reset());
706 MockResponseSender response_sender;
707 EmptyResponseExpectation response_expectation(kSerialNo);
708 EXPECT_CALL(response_sender, MockRun(_))
709 .WillOnce(Invoke(&response_expectation,
710 &EmptyResponseExpectation::Evaluate));
711
712 // Create method call;
713 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
714 ibus::engine::kResetMethod);
715 method_call.SetSerial(kSerialNo);
716
717 // Call exported function.
718 EXPECT_NE(method_callback_map_.find(ibus::engine::kResetMethod),
719 method_callback_map_.end());
720 method_callback_map_[ibus::engine::kResetMethod].Run(
721 &method_call,
722 base::Bind(&MockResponseSender::Run,
723 base::Unretained(&response_sender)));
724
725 // Call exported function without engine.
726 service_->UnsetEngine(engine_handler_.get());
727 EXPECT_CALL(*engine_handler_, Reset()).Times(0);
728 EXPECT_CALL(response_sender, MockRun(_)).Times(0);
729 method_callback_map_[ibus::engine::kResetMethod].Run(
730 &method_call,
731 base::Bind(&MockResponseSender::Run,
732 base::Unretained(&response_sender)));
733 }
734
735 TEST_F(IBusEngineServiceTest, PropertyShowTest) {
736 // Set expectations.
737 const uint32 kSerialNo = 1;
738 const std::string kPropertyName = "Property Name";
739 EXPECT_CALL(*engine_handler_, PropertyShow(kPropertyName));
740 MockResponseSender response_sender;
741 EmptyResponseExpectation response_expectation(kSerialNo);
742 EXPECT_CALL(response_sender, MockRun(_))
743 .WillOnce(Invoke(&response_expectation,
744 &EmptyResponseExpectation::Evaluate));
745
746 // Create method call;
747 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
748 ibus::engine::kPropertyShowMethod);
749 method_call.SetSerial(kSerialNo);
750 dbus::MessageWriter writer(&method_call);
751 writer.AppendString(kPropertyName);
752
753 // Call exported function.
754 EXPECT_NE(method_callback_map_.find(ibus::engine::kPropertyShowMethod),
755 method_callback_map_.end());
756 method_callback_map_[ibus::engine::kPropertyShowMethod].Run(
757 &method_call,
758 base::Bind(&MockResponseSender::Run,
759 base::Unretained(&response_sender)));
760
761 // Call exported function without engine.
762 service_->UnsetEngine(engine_handler_.get());
763 EXPECT_CALL(*engine_handler_, PropertyShow(kPropertyName)).Times(0);
764 EXPECT_CALL(response_sender, MockRun(_)).Times(0);
765 method_callback_map_[ibus::engine::kPropertyShowMethod].Run(
766 &method_call,
767 base::Bind(&MockResponseSender::Run,
768 base::Unretained(&response_sender)));
769 }
770
771 TEST_F(IBusEngineServiceTest, PropertyHideTest) {
772 // Set expectations.
773 const uint32 kSerialNo = 1;
774 const std::string kPropertyName = "Property Name";
775 EXPECT_CALL(*engine_handler_, PropertyHide(kPropertyName));
776 MockResponseSender response_sender;
777 EmptyResponseExpectation response_expectation(kSerialNo);
778 EXPECT_CALL(response_sender, MockRun(_))
779 .WillOnce(Invoke(&response_expectation,
780 &EmptyResponseExpectation::Evaluate));
781
782 // Create method call;
783 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
784 ibus::engine::kPropertyHideMethod);
785 method_call.SetSerial(kSerialNo);
786 dbus::MessageWriter writer(&method_call);
787 writer.AppendString(kPropertyName);
788
789 // Call exported function.
790 EXPECT_NE(method_callback_map_.find(ibus::engine::kPropertyHideMethod),
791 method_callback_map_.end());
792 method_callback_map_[ibus::engine::kPropertyHideMethod].Run(
793 &method_call,
794 base::Bind(&MockResponseSender::Run,
795 base::Unretained(&response_sender)));
796
797 // Call exported function without engine.
798 service_->UnsetEngine(engine_handler_.get());
799 EXPECT_CALL(*engine_handler_, PropertyHide(kPropertyName)).Times(0);
800 EXPECT_CALL(response_sender, MockRun(_)).Times(0);
801 method_callback_map_[ibus::engine::kPropertyHideMethod].Run(
802 &method_call,
803 base::Bind(&MockResponseSender::Run,
804 base::Unretained(&response_sender)));
805 }
806
807 TEST_F(IBusEngineServiceTest, SetCapabilityTest) {
808 // Set expectations.
809 const uint32 kSerialNo = 1;
810 const IBusEngineHandlerInterface::IBusCapability kIBusCapability =
811 IBusEngineHandlerInterface::IBUS_CAPABILITY_PREEDIT_TEXT;
812 EXPECT_CALL(*engine_handler_, SetCapability(kIBusCapability));
813 MockResponseSender response_sender;
814 EmptyResponseExpectation response_expectation(kSerialNo);
815 EXPECT_CALL(response_sender, MockRun(_))
816 .WillOnce(Invoke(&response_expectation,
817 &EmptyResponseExpectation::Evaluate));
818
819 // Create method call;
820 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
821 ibus::engine::kSetCapabilityMethod);
822 method_call.SetSerial(kSerialNo);
823 dbus::MessageWriter writer(&method_call);
824 writer.AppendUint32(static_cast<uint32>(kIBusCapability));
825
826 // Call exported function.
827 EXPECT_NE(method_callback_map_.find(ibus::engine::kSetCapabilityMethod),
828 method_callback_map_.end());
829 method_callback_map_[ibus::engine::kSetCapabilityMethod].Run(
830 &method_call,
831 base::Bind(&MockResponseSender::Run,
832 base::Unretained(&response_sender)));
833
834 // Call exported function without engine.
835 service_->UnsetEngine(engine_handler_.get());
836 EXPECT_CALL(*engine_handler_, SetCapability(kIBusCapability)).Times(0);
837 EXPECT_CALL(response_sender, MockRun(_)).Times(0);
838 method_callback_map_[ibus::engine::kSetCapabilityMethod].Run(
839 &method_call,
840 base::Bind(&MockResponseSender::Run,
841 base::Unretained(&response_sender)));
842 }
843
844 TEST_F(IBusEngineServiceTest, ProcessKeyEventTest) {
845 // Set expectations.
846 const uint32 kSerialNo = 1;
847 const uint32 kKeySym = 0x64;
848 const uint32 kKeyCode = 0x20;
849 const uint32 kState = 0x00;
850 const bool kResult = true;
851
852 ProcessKeyEventHandler handler(kResult);
853 EXPECT_CALL(*engine_handler_, ProcessKeyEvent(kKeySym, kKeyCode, kState, _))
854 .WillOnce(Invoke(&handler,
855 &ProcessKeyEventHandler::ProcessKeyEvent));
856 MockResponseSender response_sender;
857 BoolResponseExpectation response_expectation(kSerialNo, kResult);
858 EXPECT_CALL(response_sender, MockRun(_))
859 .WillOnce(Invoke(&response_expectation,
860 &BoolResponseExpectation::Evaluate));
861
862 // Create method call;
863 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
864 ibus::engine::kProcessKeyEventMethod);
865 method_call.SetSerial(kSerialNo);
866 dbus::MessageWriter writer(&method_call);
867 writer.AppendUint32(kKeySym);
868 writer.AppendUint32(kKeyCode);
869 writer.AppendUint32(kState);
870
871 // Call exported function.
872 EXPECT_NE(method_callback_map_.find(ibus::engine::kProcessKeyEventMethod),
873 method_callback_map_.end());
874 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run(
875 &method_call,
876 base::Bind(&MockResponseSender::Run,
877 base::Unretained(&response_sender)));
878
879 // Call exported function without engine.
880 service_->UnsetEngine(engine_handler_.get());
881 EXPECT_CALL(*engine_handler_,
882 ProcessKeyEvent(kKeySym, kKeyCode, kState, _)).Times(0);
883 EXPECT_CALL(response_sender, MockRun(_)).Times(0);
884 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run(
885 &method_call,
886 base::Bind(&MockResponseSender::Run,
887 base::Unretained(&response_sender)));
888 }
889
890 TEST_F(IBusEngineServiceTest, DelayProcessKeyEventTest) {
891 // Set expectations.
892 const uint32 kSerialNo = 1;
893 const uint32 kKeySym = 0x64;
894 const uint32 kKeyCode = 0x20;
895 const uint32 kState = 0x00;
896 const bool kResult = true;
897
898 DelayProcessKeyEventHandler handler(kResult, &message_loop_);
899 EXPECT_CALL(*engine_handler_, ProcessKeyEvent(kKeySym, kKeyCode, kState, _))
900 .WillOnce(Invoke(&handler,
901 &DelayProcessKeyEventHandler::ProcessKeyEvent));
902 MockResponseSender response_sender;
903 BoolResponseExpectation response_expectation(kSerialNo, kResult);
904 EXPECT_CALL(response_sender, MockRun(_))
905 .WillOnce(Invoke(&response_expectation,
906 &BoolResponseExpectation::Evaluate));
907
908 // Create method call;
909 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
910 ibus::engine::kProcessKeyEventMethod);
911 method_call.SetSerial(kSerialNo);
912 dbus::MessageWriter writer(&method_call);
913 writer.AppendUint32(kKeySym);
914 writer.AppendUint32(kKeyCode);
915 writer.AppendUint32(kState);
916
917 // Call exported function.
918 EXPECT_NE(method_callback_map_.find(ibus::engine::kProcessKeyEventMethod),
919 method_callback_map_.end());
920 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run(
921 &method_call,
922 base::Bind(&MockResponseSender::Run,
923 base::Unretained(&response_sender)));
924
925 // Call KeyEventDone callback.
926 message_loop_.RunUntilIdle();
927
928 // Call exported function without engine.
929 service_->UnsetEngine(engine_handler_.get());
930 EXPECT_CALL(*engine_handler_,
931 ProcessKeyEvent(kKeySym, kKeyCode, kState, _)).Times(0);
932 EXPECT_CALL(response_sender, MockRun(_)).Times(0);
933 method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run(
934 &method_call,
935 base::Bind(&MockResponseSender::Run,
936 base::Unretained(&response_sender)));
937 }
938
939 TEST_F(IBusEngineServiceTest, CandidateClickedTest) {
940 // Set expectations.
941 const uint32 kSerialNo = 1;
942 const uint32 kIndex = 4;
943 const ibus::IBusMouseButton kIBusMouseButton = ibus::IBUS_MOUSE_BUTTON_MIDDLE;
944 const uint32 kState = 3;
945 EXPECT_CALL(*engine_handler_, CandidateClicked(kIndex, kIBusMouseButton,
946 kState));
947 MockResponseSender response_sender;
948 EmptyResponseExpectation response_expectation(kSerialNo);
949 EXPECT_CALL(response_sender, MockRun(_))
950 .WillOnce(Invoke(&response_expectation,
951 &EmptyResponseExpectation::Evaluate));
952
953 // Create method call;
954 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
955 ibus::engine::kCandidateClickedMethod);
956 method_call.SetSerial(kSerialNo);
957 dbus::MessageWriter writer(&method_call);
958 writer.AppendUint32(kIndex);
959 writer.AppendUint32(static_cast<uint32>(kIBusMouseButton));
960 writer.AppendUint32(kState);
961
962 // Call exported function.
963 EXPECT_NE(method_callback_map_.find(ibus::engine::kCandidateClickedMethod),
964 method_callback_map_.end());
965 method_callback_map_[ibus::engine::kCandidateClickedMethod].Run(
966 &method_call,
967 base::Bind(&MockResponseSender::Run,
968 base::Unretained(&response_sender)));
969
970 // Call exported function without engine.
971 service_->UnsetEngine(engine_handler_.get());
972 EXPECT_CALL(*engine_handler_, CandidateClicked(kIndex, kIBusMouseButton,
973 kState)).Times(0);
974 EXPECT_CALL(response_sender, MockRun(_)).Times(0);
975 method_callback_map_[ibus::engine::kCandidateClickedMethod].Run(
976 &method_call,
977 base::Bind(&MockResponseSender::Run,
978 base::Unretained(&response_sender)));
979 }
980
981 TEST_F(IBusEngineServiceTest, SetSurroundingTextTest) {
982 // Set expectations.
983 const uint32 kSerialNo = 1;
984 const std::string kText = "Sample Text";
985 const uint32 kCursorPos = 3;
986 const uint32 kAnchorPos = 4;
987 EXPECT_CALL(*engine_handler_, SetSurroundingText(kText, kCursorPos,
988 kAnchorPos));
989 MockResponseSender response_sender;
990 EmptyResponseExpectation response_expectation(kSerialNo);
991 EXPECT_CALL(response_sender, MockRun(_))
992 .WillOnce(Invoke(&response_expectation,
993 &EmptyResponseExpectation::Evaluate));
994
995 // Create method call;
996 dbus::MethodCall method_call(ibus::engine::kServiceInterface,
997 ibus::engine::kSetSurroundingTextMethod);
998 method_call.SetSerial(kSerialNo);
999 dbus::MessageWriter writer(&method_call);
1000 AppendStringAsIBusText(kText, &writer);
1001 writer.AppendUint32(kCursorPos);
1002 writer.AppendUint32(kAnchorPos);
1003
1004 // Call exported function.
1005 EXPECT_NE(method_callback_map_.find(ibus::engine::kSetSurroundingTextMethod),
1006 method_callback_map_.end());
1007 method_callback_map_[ibus::engine::kSetSurroundingTextMethod].Run(
1008 &method_call,
1009 base::Bind(&MockResponseSender::Run,
1010 base::Unretained(&response_sender)));
1011
1012 // Call exported function without engine.
1013 service_->UnsetEngine(engine_handler_.get());
1014 EXPECT_CALL(*engine_handler_, SetSurroundingText(kText, kCursorPos,
1015 kAnchorPos)).Times(0);
1016 EXPECT_CALL(response_sender, MockRun(_)).Times(0);
1017 method_callback_map_[ibus::engine::kSetSurroundingTextMethod].Run(
1018 &method_call,
1019 base::Bind(&MockResponseSender::Run,
1020 base::Unretained(&response_sender)));
1021 }
1022
1023 TEST_F(IBusEngineServiceTest, RegisterProperties) {
1024 // Set expectations.
1025 IBusPropertyList property_list;
1026 property_list.push_back(new IBusProperty());
1027 property_list[0]->set_key("Sample Key");
1028 property_list[0]->set_type(IBusProperty::IBUS_PROPERTY_TYPE_MENU);
1029 property_list[0]->set_label("Sample Label");
1030 property_list[0]->set_tooltip("Sample Tooltip");
1031 property_list[0]->set_visible(true);
1032 property_list[0]->set_checked(true);
1033
1034 RegisterPropertiesExpectation expectation(property_list);
1035 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_))
1036 .WillOnce(Invoke(&expectation, &RegisterPropertiesExpectation::Evaluate));
1037 // Emit signal.
1038 service_->RegisterProperties(property_list);
1039 }
1040
1041 TEST_F(IBusEngineServiceTest, UpdatePreeditTest) {
1042 // Set expectations.
1043 IBusText ibus_text;
1044 ibus_text.set_text("Sample Text");
1045 const uint32 kCursorPos = 9;
1046 const bool kIsVisible = false;
1047 const IBusEngineService::IBusEnginePreeditFocusOutMode kPreeditMode =
1048 IBusEngineService::IBUS_ENGINE_PREEEDIT_FOCUS_OUT_MODE_CLEAR;
1049 UpdatePreeditExpectation expectation(ibus_text, kCursorPos, kIsVisible,
1050 kPreeditMode);
1051 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_))
1052 .WillOnce(Invoke(&expectation, &UpdatePreeditExpectation::Evaluate));
1053
1054 // Emit signal.
1055 service_->UpdatePreedit(ibus_text, kCursorPos, kIsVisible, kPreeditMode);
1056 }
1057
1058 TEST_F(IBusEngineServiceTest, UpdateAuxiliaryText) {
1059 IBusText ibus_text;
1060 ibus_text.set_text("Sample Text");
1061 const bool kIsVisible = false;
1062 UpdateAuxiliaryTextExpectation expectation(ibus_text, kIsVisible);
1063
1064 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_)).WillOnce(
1065 Invoke(&expectation, &UpdateAuxiliaryTextExpectation::Evaluate));
1066
1067 // Emit signal.
1068 service_->UpdateAuxiliaryText(ibus_text, kIsVisible);
1069 }
1070
1071 TEST_F(IBusEngineServiceTest, UpdateLookupTableTest) {
1072 IBusLookupTable lookup_table;
1073 lookup_table.set_page_size(10);
1074 lookup_table.set_cursor_position(2);
1075 lookup_table.set_is_cursor_visible(false);
1076 const bool kIsVisible = true;
1077
1078 UpdateLookupTableExpectation expectation(lookup_table, kIsVisible);
1079 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_))
1080 .WillOnce(Invoke(&expectation, &UpdateLookupTableExpectation::Evaluate));
1081
1082 // Emit signal.
1083 service_->UpdateLookupTable(lookup_table, kIsVisible);
1084 }
1085
1086 TEST_F(IBusEngineServiceTest, UpdatePropertyTest) {
1087 IBusProperty property;
1088 property.set_key("Sample Key");
1089 property.set_type(IBusProperty::IBUS_PROPERTY_TYPE_MENU);
1090 property.set_label("Sample Label");
1091 property.set_tooltip("Sample Tooltip");
1092 property.set_visible(true);
1093 property.set_checked(true);
1094
1095 UpdatePropertyExpectation expectation(property);
1096 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_))
1097 .WillOnce(Invoke(&expectation, &UpdatePropertyExpectation::Evaluate));
1098
1099 // Emit signal.
1100 service_->UpdateProperty(property);
1101 }
1102
1103 TEST_F(IBusEngineServiceTest, ForwardKeyEventTest) {
1104 uint32 keyval = 0x20;
1105 uint32 keycode = 0x64;
1106 uint32 state = 0x00;
1107
1108 ForwardKeyEventExpectation expectation(keyval, keycode, state);
1109
1110 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_))
1111 .WillOnce(Invoke(&expectation, &ForwardKeyEventExpectation::Evaluate));
1112
1113 // Emit signal.
1114 service_->ForwardKeyEvent(keyval, keycode, state);
1115 }
1116
1117 TEST_F(IBusEngineServiceTest, RequireSurroundingTextTest) {
1118 RequireSurroundingTextExpectation expectation;
1119 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_)).WillOnce(
1120 Invoke(&expectation, &RequireSurroundingTextExpectation::Evaluate));
1121
1122 // Emit signal.
1123 service_->RequireSurroundingText();
1124 }
1125
1126 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/ibus/ibus_engine_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698