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

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

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

Powered by Google App Engine
This is Rietveld 408576698