| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/dbus/ibus/ibus_engine_service.h" | 5 #include "chromeos/dbus/ibus/ibus_engine_service.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 | 389 |
| 390 // Create a mock exported object. | 390 // Create a mock exported object. |
| 391 mock_exported_object_ = new dbus::MockExportedObject( | 391 mock_exported_object_ = new dbus::MockExportedObject( |
| 392 mock_bus_.get(), | 392 mock_bus_.get(), |
| 393 dbus::ObjectPath(kObjectPath)); | 393 dbus::ObjectPath(kObjectPath)); |
| 394 | 394 |
| 395 EXPECT_CALL(*mock_bus_.get(), | 395 EXPECT_CALL(*mock_bus_.get(), |
| 396 GetExportedObject(dbus::ObjectPath(kObjectPath))) | 396 GetExportedObject(dbus::ObjectPath(kObjectPath))) |
| 397 .WillOnce(Return(mock_exported_object_.get())); | 397 .WillOnce(Return(mock_exported_object_.get())); |
| 398 | 398 |
| 399 EXPECT_CALL(*mock_exported_object_, ExportMethod( | 399 EXPECT_CALL(*mock_exported_object_.get(), |
| 400 ibus::engine::kServiceInterface, | 400 ExportMethod(ibus::engine::kServiceInterface, |
| 401 ibus::engine::kFocusInMethod , _, _)) | 401 ibus::engine::kFocusInMethod, |
| 402 .WillRepeatedly( | 402 _, |
| 403 Invoke(this, &IBusEngineServiceTest::OnMethodExported)); | 403 _)) |
| 404 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported)); |
| 404 | 405 |
| 405 EXPECT_CALL(*mock_exported_object_, ExportMethod( | 406 EXPECT_CALL(*mock_exported_object_.get(), |
| 406 ibus::engine::kServiceInterface, | 407 ExportMethod(ibus::engine::kServiceInterface, |
| 407 ibus::engine::kFocusOutMethod , _, _)) | 408 ibus::engine::kFocusOutMethod, |
| 408 .WillRepeatedly( | 409 _, |
| 409 Invoke(this, &IBusEngineServiceTest::OnMethodExported)); | 410 _)) |
| 411 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported)); |
| 410 | 412 |
| 411 EXPECT_CALL(*mock_exported_object_, ExportMethod( | 413 EXPECT_CALL( |
| 412 ibus::engine::kServiceInterface, | 414 *mock_exported_object_.get(), |
| 413 ibus::engine::kEnableMethod , _, _)) | 415 ExportMethod( |
| 414 .WillRepeatedly( | 416 ibus::engine::kServiceInterface, ibus::engine::kEnableMethod, _, _)) |
| 415 Invoke(this, &IBusEngineServiceTest::OnMethodExported)); | 417 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported)); |
| 416 | 418 |
| 417 EXPECT_CALL(*mock_exported_object_, ExportMethod( | 419 EXPECT_CALL(*mock_exported_object_.get(), |
| 418 ibus::engine::kServiceInterface, | 420 ExportMethod(ibus::engine::kServiceInterface, |
| 419 ibus::engine::kDisableMethod , _, _)) | 421 ibus::engine::kDisableMethod, |
| 420 .WillRepeatedly( | 422 _, |
| 421 Invoke(this, &IBusEngineServiceTest::OnMethodExported)); | 423 _)) |
| 424 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported)); |
| 422 | 425 |
| 423 EXPECT_CALL(*mock_exported_object_, ExportMethod( | 426 EXPECT_CALL(*mock_exported_object_.get(), |
| 424 ibus::engine::kServiceInterface, | 427 ExportMethod(ibus::engine::kServiceInterface, |
| 425 ibus::engine::kPropertyActivateMethod , _, _)) | 428 ibus::engine::kPropertyActivateMethod, |
| 426 .WillRepeatedly( | 429 _, |
| 427 Invoke(this, &IBusEngineServiceTest::OnMethodExported)); | 430 _)) |
| 431 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported)); |
| 428 | 432 |
| 429 EXPECT_CALL(*mock_exported_object_, ExportMethod( | 433 EXPECT_CALL(*mock_exported_object_.get(), |
| 430 ibus::engine::kServiceInterface, | 434 ExportMethod(ibus::engine::kServiceInterface, |
| 431 ibus::engine::kPropertyShowMethod , _, _)) | 435 ibus::engine::kPropertyShowMethod, |
| 432 .WillRepeatedly( | 436 _, |
| 433 Invoke(this, &IBusEngineServiceTest::OnMethodExported)); | 437 _)) |
| 438 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported)); |
| 434 | 439 |
| 435 EXPECT_CALL(*mock_exported_object_, ExportMethod( | 440 EXPECT_CALL(*mock_exported_object_.get(), |
| 436 ibus::engine::kServiceInterface, | 441 ExportMethod(ibus::engine::kServiceInterface, |
| 437 ibus::engine::kPropertyHideMethod , _, _)) | 442 ibus::engine::kPropertyHideMethod, |
| 438 .WillRepeatedly( | 443 _, |
| 439 Invoke(this, &IBusEngineServiceTest::OnMethodExported)); | 444 _)) |
| 445 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported)); |
| 440 | 446 |
| 441 EXPECT_CALL(*mock_exported_object_, ExportMethod( | 447 EXPECT_CALL(*mock_exported_object_.get(), |
| 442 ibus::engine::kServiceInterface, | 448 ExportMethod(ibus::engine::kServiceInterface, |
| 443 ibus::engine::kSetCapabilityMethod , _, _)) | 449 ibus::engine::kSetCapabilityMethod, |
| 444 .WillRepeatedly( | 450 _, |
| 445 Invoke(this, &IBusEngineServiceTest::OnMethodExported)); | 451 _)) |
| 452 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported)); |
| 446 | 453 |
| 447 EXPECT_CALL(*mock_exported_object_, ExportMethod( | 454 EXPECT_CALL( |
| 448 ibus::engine::kServiceInterface, | 455 *mock_exported_object_.get(), |
| 449 ibus::engine::kResetMethod , _, _)) | 456 ExportMethod( |
| 450 .WillRepeatedly( | 457 ibus::engine::kServiceInterface, ibus::engine::kResetMethod, _, _)) |
| 451 Invoke(this, &IBusEngineServiceTest::OnMethodExported)); | 458 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported)); |
| 452 | 459 |
| 453 EXPECT_CALL(*mock_exported_object_, ExportMethod( | 460 EXPECT_CALL(*mock_exported_object_.get(), |
| 454 ibus::engine::kServiceInterface, | 461 ExportMethod(ibus::engine::kServiceInterface, |
| 455 ibus::engine::kProcessKeyEventMethod , _, _)) | 462 ibus::engine::kProcessKeyEventMethod, |
| 456 .WillRepeatedly( | 463 _, |
| 457 Invoke(this, &IBusEngineServiceTest::OnMethodExported)); | 464 _)) |
| 465 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported)); |
| 458 | 466 |
| 459 EXPECT_CALL(*mock_exported_object_, ExportMethod( | 467 EXPECT_CALL(*mock_exported_object_.get(), |
| 460 ibus::engine::kServiceInterface, | 468 ExportMethod(ibus::engine::kServiceInterface, |
| 461 ibus::engine::kCandidateClickedMethod , _, _)) | 469 ibus::engine::kCandidateClickedMethod, |
| 462 .WillRepeatedly( | 470 _, |
| 463 Invoke(this, &IBusEngineServiceTest::OnMethodExported)); | 471 _)) |
| 472 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported)); |
| 464 | 473 |
| 465 EXPECT_CALL(*mock_exported_object_, ExportMethod( | 474 EXPECT_CALL(*mock_exported_object_.get(), |
| 466 ibus::engine::kServiceInterface, | 475 ExportMethod(ibus::engine::kServiceInterface, |
| 467 ibus::engine::kSetSurroundingTextMethod , _, _)) | 476 ibus::engine::kSetSurroundingTextMethod, |
| 468 .WillRepeatedly( | 477 _, |
| 469 Invoke(this, &IBusEngineServiceTest::OnMethodExported)); | 478 _)) |
| 479 .WillRepeatedly(Invoke(this, &IBusEngineServiceTest::OnMethodExported)); |
| 470 | 480 |
| 471 // Suppress uninteresting mock function call warning. | 481 // Suppress uninteresting mock function call warning. |
| 472 EXPECT_CALL(*mock_bus_.get(), | 482 EXPECT_CALL(*mock_bus_.get(), |
| 473 AssertOnOriginThread()) | 483 AssertOnOriginThread()) |
| 474 .WillRepeatedly(Return()); | 484 .WillRepeatedly(Return()); |
| 475 | 485 |
| 476 // Create a service | 486 // Create a service |
| 477 service_.reset(IBusEngineService::Create( | 487 service_.reset(IBusEngineService::Create( |
| 478 REAL_DBUS_CLIENT_IMPLEMENTATION, | 488 REAL_DBUS_CLIENT_IMPLEMENTATION, |
| 479 mock_bus_.get(), | 489 mock_bus_.get(), |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 IBusPropertyList property_list; | 1024 IBusPropertyList property_list; |
| 1015 property_list.push_back(new IBusProperty()); | 1025 property_list.push_back(new IBusProperty()); |
| 1016 property_list[0]->set_key("Sample Key"); | 1026 property_list[0]->set_key("Sample Key"); |
| 1017 property_list[0]->set_type(IBusProperty::IBUS_PROPERTY_TYPE_MENU); | 1027 property_list[0]->set_type(IBusProperty::IBUS_PROPERTY_TYPE_MENU); |
| 1018 property_list[0]->set_label("Sample Label"); | 1028 property_list[0]->set_label("Sample Label"); |
| 1019 property_list[0]->set_tooltip("Sample Tooltip"); | 1029 property_list[0]->set_tooltip("Sample Tooltip"); |
| 1020 property_list[0]->set_visible(true); | 1030 property_list[0]->set_visible(true); |
| 1021 property_list[0]->set_checked(true); | 1031 property_list[0]->set_checked(true); |
| 1022 | 1032 |
| 1023 RegisterPropertiesExpectation expectation(property_list); | 1033 RegisterPropertiesExpectation expectation(property_list); |
| 1024 EXPECT_CALL(*mock_exported_object_, SendSignal(_)) | 1034 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_)) |
| 1025 .WillOnce(Invoke(&expectation, | 1035 .WillOnce(Invoke(&expectation, &RegisterPropertiesExpectation::Evaluate)); |
| 1026 &RegisterPropertiesExpectation::Evaluate)); | |
| 1027 // Emit signal. | 1036 // Emit signal. |
| 1028 service_->RegisterProperties(property_list); | 1037 service_->RegisterProperties(property_list); |
| 1029 } | 1038 } |
| 1030 | 1039 |
| 1031 TEST_F(IBusEngineServiceTest, UpdatePreeditTest) { | 1040 TEST_F(IBusEngineServiceTest, UpdatePreeditTest) { |
| 1032 // Set expectations. | 1041 // Set expectations. |
| 1033 IBusText ibus_text; | 1042 IBusText ibus_text; |
| 1034 ibus_text.set_text("Sample Text"); | 1043 ibus_text.set_text("Sample Text"); |
| 1035 const uint32 kCursorPos = 9; | 1044 const uint32 kCursorPos = 9; |
| 1036 const bool kIsVisible = false; | 1045 const bool kIsVisible = false; |
| 1037 const IBusEngineService::IBusEnginePreeditFocusOutMode kPreeditMode = | 1046 const IBusEngineService::IBusEnginePreeditFocusOutMode kPreeditMode = |
| 1038 IBusEngineService::IBUS_ENGINE_PREEEDIT_FOCUS_OUT_MODE_CLEAR; | 1047 IBusEngineService::IBUS_ENGINE_PREEEDIT_FOCUS_OUT_MODE_CLEAR; |
| 1039 UpdatePreeditExpectation expectation(ibus_text, kCursorPos, kIsVisible, | 1048 UpdatePreeditExpectation expectation(ibus_text, kCursorPos, kIsVisible, |
| 1040 kPreeditMode); | 1049 kPreeditMode); |
| 1041 EXPECT_CALL(*mock_exported_object_, SendSignal(_)) | 1050 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_)) |
| 1042 .WillOnce(Invoke(&expectation, &UpdatePreeditExpectation::Evaluate)); | 1051 .WillOnce(Invoke(&expectation, &UpdatePreeditExpectation::Evaluate)); |
| 1043 | 1052 |
| 1044 // Emit signal. | 1053 // Emit signal. |
| 1045 service_->UpdatePreedit(ibus_text, kCursorPos, kIsVisible, kPreeditMode); | 1054 service_->UpdatePreedit(ibus_text, kCursorPos, kIsVisible, kPreeditMode); |
| 1046 } | 1055 } |
| 1047 | 1056 |
| 1048 TEST_F(IBusEngineServiceTest, UpdateAuxiliaryText) { | 1057 TEST_F(IBusEngineServiceTest, UpdateAuxiliaryText) { |
| 1049 IBusText ibus_text; | 1058 IBusText ibus_text; |
| 1050 ibus_text.set_text("Sample Text"); | 1059 ibus_text.set_text("Sample Text"); |
| 1051 const bool kIsVisible = false; | 1060 const bool kIsVisible = false; |
| 1052 UpdateAuxiliaryTextExpectation expectation(ibus_text, kIsVisible); | 1061 UpdateAuxiliaryTextExpectation expectation(ibus_text, kIsVisible); |
| 1053 | 1062 |
| 1054 EXPECT_CALL(*mock_exported_object_, SendSignal(_)) | 1063 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_)).WillOnce( |
| 1055 .WillOnce(Invoke(&expectation, | 1064 Invoke(&expectation, &UpdateAuxiliaryTextExpectation::Evaluate)); |
| 1056 &UpdateAuxiliaryTextExpectation::Evaluate)); | |
| 1057 | 1065 |
| 1058 // Emit signal. | 1066 // Emit signal. |
| 1059 service_->UpdateAuxiliaryText(ibus_text, kIsVisible); | 1067 service_->UpdateAuxiliaryText(ibus_text, kIsVisible); |
| 1060 } | 1068 } |
| 1061 | 1069 |
| 1062 TEST_F(IBusEngineServiceTest, UpdateLookupTableTest) { | 1070 TEST_F(IBusEngineServiceTest, UpdateLookupTableTest) { |
| 1063 IBusLookupTable lookup_table; | 1071 IBusLookupTable lookup_table; |
| 1064 lookup_table.set_page_size(10); | 1072 lookup_table.set_page_size(10); |
| 1065 lookup_table.set_cursor_position(2); | 1073 lookup_table.set_cursor_position(2); |
| 1066 lookup_table.set_is_cursor_visible(false); | 1074 lookup_table.set_is_cursor_visible(false); |
| 1067 const bool kIsVisible = true; | 1075 const bool kIsVisible = true; |
| 1068 | 1076 |
| 1069 UpdateLookupTableExpectation expectation(lookup_table, kIsVisible); | 1077 UpdateLookupTableExpectation expectation(lookup_table, kIsVisible); |
| 1070 EXPECT_CALL(*mock_exported_object_, SendSignal(_)) | 1078 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_)) |
| 1071 .WillOnce(Invoke(&expectation, | 1079 .WillOnce(Invoke(&expectation, &UpdateLookupTableExpectation::Evaluate)); |
| 1072 &UpdateLookupTableExpectation::Evaluate)); | |
| 1073 | 1080 |
| 1074 // Emit signal. | 1081 // Emit signal. |
| 1075 service_->UpdateLookupTable(lookup_table, kIsVisible); | 1082 service_->UpdateLookupTable(lookup_table, kIsVisible); |
| 1076 } | 1083 } |
| 1077 | 1084 |
| 1078 TEST_F(IBusEngineServiceTest, UpdatePropertyTest) { | 1085 TEST_F(IBusEngineServiceTest, UpdatePropertyTest) { |
| 1079 IBusProperty property; | 1086 IBusProperty property; |
| 1080 property.set_key("Sample Key"); | 1087 property.set_key("Sample Key"); |
| 1081 property.set_type(IBusProperty::IBUS_PROPERTY_TYPE_MENU); | 1088 property.set_type(IBusProperty::IBUS_PROPERTY_TYPE_MENU); |
| 1082 property.set_label("Sample Label"); | 1089 property.set_label("Sample Label"); |
| 1083 property.set_tooltip("Sample Tooltip"); | 1090 property.set_tooltip("Sample Tooltip"); |
| 1084 property.set_visible(true); | 1091 property.set_visible(true); |
| 1085 property.set_checked(true); | 1092 property.set_checked(true); |
| 1086 | 1093 |
| 1087 UpdatePropertyExpectation expectation(property); | 1094 UpdatePropertyExpectation expectation(property); |
| 1088 EXPECT_CALL(*mock_exported_object_, SendSignal(_)) | 1095 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_)) |
| 1089 .WillOnce(Invoke(&expectation, | 1096 .WillOnce(Invoke(&expectation, &UpdatePropertyExpectation::Evaluate)); |
| 1090 &UpdatePropertyExpectation::Evaluate)); | |
| 1091 | 1097 |
| 1092 // Emit signal. | 1098 // Emit signal. |
| 1093 service_->UpdateProperty(property); | 1099 service_->UpdateProperty(property); |
| 1094 } | 1100 } |
| 1095 | 1101 |
| 1096 TEST_F(IBusEngineServiceTest, ForwardKeyEventTest) { | 1102 TEST_F(IBusEngineServiceTest, ForwardKeyEventTest) { |
| 1097 uint32 keyval = 0x20; | 1103 uint32 keyval = 0x20; |
| 1098 uint32 keycode = 0x64; | 1104 uint32 keycode = 0x64; |
| 1099 uint32 state = 0x00; | 1105 uint32 state = 0x00; |
| 1100 | 1106 |
| 1101 ForwardKeyEventExpectation expectation(keyval, keycode, state); | 1107 ForwardKeyEventExpectation expectation(keyval, keycode, state); |
| 1102 | 1108 |
| 1103 EXPECT_CALL(*mock_exported_object_, SendSignal(_)) | 1109 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_)) |
| 1104 .WillOnce(Invoke(&expectation, | 1110 .WillOnce(Invoke(&expectation, &ForwardKeyEventExpectation::Evaluate)); |
| 1105 &ForwardKeyEventExpectation::Evaluate)); | |
| 1106 | 1111 |
| 1107 // Emit signal. | 1112 // Emit signal. |
| 1108 service_->ForwardKeyEvent(keyval, keycode, state); | 1113 service_->ForwardKeyEvent(keyval, keycode, state); |
| 1109 } | 1114 } |
| 1110 | 1115 |
| 1111 TEST_F(IBusEngineServiceTest, RequireSurroundingTextTest) { | 1116 TEST_F(IBusEngineServiceTest, RequireSurroundingTextTest) { |
| 1112 RequireSurroundingTextExpectation expectation; | 1117 RequireSurroundingTextExpectation expectation; |
| 1113 EXPECT_CALL(*mock_exported_object_, SendSignal(_)) | 1118 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_)).WillOnce( |
| 1114 .WillOnce(Invoke(&expectation, | 1119 Invoke(&expectation, &RequireSurroundingTextExpectation::Evaluate)); |
| 1115 &RequireSurroundingTextExpectation::Evaluate)); | |
| 1116 | 1120 |
| 1117 // Emit signal. | 1121 // Emit signal. |
| 1118 service_->RequireSurroundingText(); | 1122 service_->RequireSurroundingText(); |
| 1119 } | 1123 } |
| 1120 | 1124 |
| 1121 } // namespace chromeos | 1125 } // namespace chromeos |
| OLD | NEW |