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_panel_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_input_context_client.h" 13 #include "chromeos/dbus/ibus/ibus_lookup_table.h" 14 #include "chromeos/dbus/ibus/ibus_property.h" 15 #include "chromeos/dbus/ibus/ibus_text.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 32 class MockIBusPanelCandidateWindowHandler 33 : public IBusPanelCandidateWindowHandlerInterface { 34 public: 35 MockIBusPanelCandidateWindowHandler() {} 36 MOCK_METHOD2(UpdateLookupTable, void(const IBusLookupTable& table, 37 bool visible)); 38 MOCK_METHOD0(HideLookupTable, void()); 39 MOCK_METHOD2(UpdateAuxiliaryText, void(const std::string& text, 40 bool visible)); 41 MOCK_METHOD0(HideAuxiliaryText, void()); 42 MOCK_METHOD3(UpdatePreeditText, void(const std::string& text, 43 uint32 cursor_pos, 44 bool visible) ); 45 MOCK_METHOD0(HidePreeditText, void()); 46 MOCK_METHOD2(SetCursorLocation, void(const ibus::Rect& cursor_location, 47 const ibus::Rect& composition_head)); 48 49 private: 50 DISALLOW_COPY_AND_ASSIGN(MockIBusPanelCandidateWindowHandler); 51 }; 52 53 class MockIBusPanelPropertyHandler : public IBusPanelPropertyHandlerInterface { 54 public: 55 MockIBusPanelPropertyHandler() {} 56 MOCK_METHOD1(RegisterProperties, 57 void(const IBusPropertyList& properties)); 58 MOCK_METHOD1(UpdateProperty, void(const IBusProperty& property)); 59 60 private: 61 DISALLOW_COPY_AND_ASSIGN(MockIBusPanelPropertyHandler); 62 }; 63 64 class MockResponseSender { 65 public: 66 // GMock doesn't support mocking methods which take scoped_ptr<>. 67 MOCK_METHOD1(MockRun, void(dbus::Response* reponse)); 68 void Run(scoped_ptr<dbus::Response> response) { 69 MockRun(response.get()); 70 } 71 }; 72 73 // This class is used to verify that a method call response is empty. This class 74 // verifies the response has correct message serial number and has no entry in 75 // response. 76 class EmptyResponseVerifier { 77 public: 78 explicit EmptyResponseVerifier(uint32 expected_serial_number) 79 : expected_serial_number_(expected_serial_number) {} 80 81 // Verifies the given |response| has no argument. 82 void Verify(dbus::Response* response) { 83 EXPECT_EQ(expected_serial_number_, response->GetReplySerial()); 84 dbus::MessageReader reader(response); 85 EXPECT_FALSE(reader.HasMoreData()); 86 } 87 88 private: 89 const uint32 expected_serial_number_; 90 91 DISALLOW_COPY_AND_ASSIGN(EmptyResponseVerifier); 92 }; 93 94 // This class is used to verify the CandidateClicked method call arguments. 95 class CandidateClickedVerifier { 96 public: 97 CandidateClickedVerifier(uint32 expected_index, 98 ibus::IBusMouseButton expected_button, 99 uint32 expected_state) 100 : expected_index_(expected_index), 101 expected_button_(expected_button), 102 expected_state_(expected_state) {} 103 104 // Verifies the given |signal| is a valid message. 105 void Verify(dbus::Signal* signal) { 106 uint32 index = 0; 107 uint32 button = 0; 108 uint32 state = 0; 109 110 // Read signal arguments. 111 dbus::MessageReader reader(signal); 112 EXPECT_TRUE(reader.PopUint32(&index)); 113 EXPECT_TRUE(reader.PopUint32(&button)); 114 EXPECT_TRUE(reader.PopUint32(&state)); 115 EXPECT_FALSE(reader.HasMoreData()); 116 117 // Check arguments. 118 EXPECT_EQ(expected_index_, index); 119 EXPECT_EQ(expected_button_, static_cast<ibus::IBusMouseButton>(button)); 120 EXPECT_EQ(expected_state_, state); 121 } 122 123 private: 124 uint32 expected_index_; 125 ibus::IBusMouseButton expected_button_; 126 uint32 expected_state_; 127 128 DISALLOW_COPY_AND_ASSIGN(CandidateClickedVerifier); 129 }; 130 131 // This class is used to verify that a method call has empty argument. 132 class NullArgumentVerifier { 133 public: 134 explicit NullArgumentVerifier(const std::string& expected_signal_name) 135 : expected_signal_name_(expected_signal_name) {} 136 137 // Verifies the given |signal| is a valid message. 138 void Verify(dbus::Signal* signal) { 139 EXPECT_EQ(expected_signal_name_, signal->GetMember()); 140 dbus::MessageReader reader(signal); 141 EXPECT_FALSE(reader.HasMoreData()); 142 } 143 144 private: 145 std::string expected_signal_name_; 146 DISALLOW_COPY_AND_ASSIGN(NullArgumentVerifier); 147 }; 148 149 class UpdateLookupTableVerifier { 150 public: 151 UpdateLookupTableVerifier(const IBusLookupTable& table, bool visible) 152 : table_(table), 153 visible_(visible) {} 154 155 void Verify(const IBusLookupTable& table, bool visible) { 156 EXPECT_EQ(table_.page_size(), table.page_size()); 157 EXPECT_EQ(table_.cursor_position(), table.cursor_position()); 158 EXPECT_EQ(visible_, visible); 159 } 160 161 private: 162 const IBusLookupTable& table_; 163 const bool visible_; 164 165 DISALLOW_COPY_AND_ASSIGN(UpdateLookupTableVerifier); 166 }; 167 168 // This class is used to verify that a method call which has a PropertyList 169 // object. This class verifies a method call has correct arguments based on 170 // checking given |keys|. 171 class PropertyListVerifier { 172 public: 173 explicit PropertyListVerifier(const std::vector<std::string>& expected_keys) 174 : expected_keys_(expected_keys) { 175 } 176 177 // Verifies the given |resposne| has IBusPropertyList. 178 void Verify(const IBusPropertyList& properties) { 179 ASSERT_EQ(expected_keys_.size(), properties.size()); 180 for (size_t i = 0; i < properties.size(); ++i) { 181 EXPECT_EQ(expected_keys_[i], properties[i]->key()); 182 } 183 } 184 185 private: 186 const std::vector<std::string> expected_keys_; 187 }; 188 189 // This class is used to verify that a method call which has a Property object. 190 // This class verifies a method call has correct argument based on |key|. 191 class PropertyVerifier { 192 public: 193 explicit PropertyVerifier(const std::string& key) : key_(key) {} 194 195 // Verifies the given |resposne| has IBusPropertyList. 196 void Verify(const IBusProperty& property) { 197 EXPECT_EQ(key_, property.key()); 198 } 199 200 private: 201 const std::string key_; 202 }; 203 204 } // namespace 205 206 class IBusPanelServiceTest : public testing::Test { 207 public: 208 IBusPanelServiceTest() {} 209 210 virtual void SetUp() OVERRIDE { 211 // Create a mock bus. 212 dbus::Bus::Options options; 213 options.bus_type = dbus::Bus::SYSTEM; 214 mock_bus_ = new dbus::MockBus(options); 215 216 // Create a mock exported object. 217 mock_exported_object_ = new dbus::MockExportedObject( 218 mock_bus_.get(), 219 dbus::ObjectPath(ibus::panel::kServicePath)); 220 221 EXPECT_CALL(*mock_bus_.get(), 222 GetExportedObject(dbus::ObjectPath( 223 ibus::panel::kServicePath))) 224 .WillOnce(Return(mock_exported_object_.get())); 225 226 EXPECT_CALL(*mock_exported_object_.get(), 227 ExportMethod(ibus::panel::kServiceInterface, 228 ibus::panel::kUpdateLookupTableMethod, 229 _, 230 _)) 231 .WillRepeatedly(Invoke(this, &IBusPanelServiceTest::OnMethodExported)); 232 233 EXPECT_CALL(*mock_exported_object_.get(), 234 ExportMethod(ibus::panel::kServiceInterface, 235 ibus::panel::kHideLookupTableMethod, 236 _, 237 _)) 238 .WillRepeatedly(Invoke(this, &IBusPanelServiceTest::OnMethodExported)); 239 240 EXPECT_CALL(*mock_exported_object_.get(), 241 ExportMethod(ibus::panel::kServiceInterface, 242 ibus::panel::kUpdateAuxiliaryTextMethod, 243 _, 244 _)) 245 .WillRepeatedly(Invoke(this, &IBusPanelServiceTest::OnMethodExported)); 246 247 EXPECT_CALL(*mock_exported_object_.get(), 248 ExportMethod(ibus::panel::kServiceInterface, 249 ibus::panel::kHideAuxiliaryTextMethod, 250 _, 251 _)) 252 .WillRepeatedly(Invoke(this, &IBusPanelServiceTest::OnMethodExported)); 253 254 EXPECT_CALL(*mock_exported_object_.get(), 255 ExportMethod(ibus::panel::kServiceInterface, 256 ibus::panel::kUpdatePreeditTextMethod, 257 _, 258 _)) 259 .WillRepeatedly(Invoke(this, &IBusPanelServiceTest::OnMethodExported)); 260 261 EXPECT_CALL(*mock_exported_object_.get(), 262 ExportMethod(ibus::panel::kServiceInterface, 263 ibus::panel::kHidePreeditTextMethod, 264 _, 265 _)) 266 .WillRepeatedly(Invoke(this, &IBusPanelServiceTest::OnMethodExported)); 267 268 EXPECT_CALL(*mock_exported_object_.get(), 269 ExportMethod(ibus::panel::kServiceInterface, 270 ibus::panel::kRegisterPropertiesMethod, 271 _, 272 _)) 273 .WillRepeatedly(Invoke(this, &IBusPanelServiceTest::OnMethodExported)); 274 275 EXPECT_CALL(*mock_exported_object_.get(), 276 ExportMethod(ibus::panel::kServiceInterface, 277 ibus::panel::kUpdatePropertyMethod, 278 _, 279 _)) 280 .WillRepeatedly(Invoke(this, &IBusPanelServiceTest::OnMethodExported)); 281 282 EXPECT_CALL( 283 *mock_exported_object_.get(), 284 ExportMethod( 285 ibus::panel::kServiceInterface, ibus::panel::kFocusInMethod, _, _)) 286 .WillRepeatedly(Invoke(this, &IBusPanelServiceTest::OnMethodExported)); 287 288 EXPECT_CALL( 289 *mock_exported_object_.get(), 290 ExportMethod( 291 ibus::panel::kServiceInterface, ibus::panel::kFocusOutMethod, _, _)) 292 .WillRepeatedly(Invoke(this, &IBusPanelServiceTest::OnMethodExported)); 293 294 EXPECT_CALL(*mock_exported_object_.get(), 295 ExportMethod(ibus::panel::kServiceInterface, 296 ibus::panel::kStateChangedMethod, 297 _, 298 _)) 299 .WillRepeatedly(Invoke(this, &IBusPanelServiceTest::OnMethodExported)); 300 301 // Suppress uninteresting mock function call warning. 302 EXPECT_CALL(*mock_bus_.get(), 303 AssertOnOriginThread()) 304 .WillRepeatedly(Return()); 305 306 stub_input_context_client_.reset(IBusInputContextClient::Create( 307 STUB_DBUS_CLIENT_IMPLEMENTATION)); 308 309 // Create a service 310 service_.reset(IBusPanelService::Create( 311 REAL_DBUS_CLIENT_IMPLEMENTATION, 312 mock_bus_.get(), 313 stub_input_context_client_.get())); 314 315 // Set panel handler. 316 candidate_window_handler_.reset(new MockIBusPanelCandidateWindowHandler()); 317 service_->SetUpCandidateWindowHandler(candidate_window_handler_.get()); 318 property_handler_.reset(new MockIBusPanelPropertyHandler()); 319 service_->SetUpPropertyHandler(property_handler_.get()); 320 } 321 322 protected: 323 // The service to be tested. 324 scoped_ptr<IBusPanelService> service_; 325 // The mock candidate window panel handler. Do not free, this is owned by 326 // IBusPanelService. 327 scoped_ptr<MockIBusPanelCandidateWindowHandler> candidate_window_handler_; 328 // The mock property handler. Do not free, this is owned by IBusPanelService. 329 scoped_ptr<MockIBusPanelPropertyHandler> property_handler_; 330 // The stub input context client. 331 scoped_ptr<IBusInputContextClient> stub_input_context_client_; 332 // The mock bus. 333 scoped_refptr<dbus::MockBus> mock_bus_; 334 // The mock exported object. 335 scoped_refptr<dbus::MockExportedObject> mock_exported_object_; 336 // A message loop to emulate asynchronous behavior. 337 base::MessageLoop message_loop_; 338 // The map from method call to method call handler. 339 std::map<std::string, dbus::ExportedObject::MethodCallCallback> 340 method_callback_map_; 341 342 private: 343 // Used to implement the mock method call. 344 void OnMethodExported( 345 const std::string& interface_name, 346 const std::string& method_name, 347 const dbus::ExportedObject::MethodCallCallback& method_callback, 348 const dbus::ExportedObject::OnExportedCallback& on_exported_callback) { 349 method_callback_map_[method_name] = method_callback; 350 const bool success = true; 351 message_loop_.PostTask(FROM_HERE, base::Bind(on_exported_callback, 352 interface_name, 353 method_name, 354 success)); 355 } 356 }; 357 358 TEST_F(IBusPanelServiceTest, HideLookupTableTest) { 359 // Set expectations. 360 const uint32 kSerialNo = 1; 361 EXPECT_CALL(*candidate_window_handler_, HideLookupTable()); 362 MockResponseSender response_sender; 363 EmptyResponseVerifier response_expectation(kSerialNo); 364 EXPECT_CALL(response_sender, MockRun(_)) 365 .WillOnce(Invoke(&response_expectation, 366 &EmptyResponseVerifier::Verify)); 367 368 // Create method call; 369 dbus::MethodCall method_call(ibus::panel::kServiceInterface, 370 ibus::panel::kHideLookupTableMethod); 371 method_call.SetSerial(kSerialNo); 372 373 // Call exported function. 374 EXPECT_NE(method_callback_map_.find(ibus::panel::kHideLookupTableMethod), 375 method_callback_map_.end()); 376 method_callback_map_[ibus::panel::kHideLookupTableMethod].Run( 377 &method_call, 378 base::Bind(&MockResponseSender::Run, 379 base::Unretained(&response_sender))); 380 } 381 382 TEST_F(IBusPanelServiceTest, HideAuxiliaryTextTest) { 383 // Set expectations. 384 const uint32 kSerialNo = 1; 385 EXPECT_CALL(*candidate_window_handler_, HideAuxiliaryText()); 386 MockResponseSender response_sender; 387 EmptyResponseVerifier response_expectation(kSerialNo); 388 EXPECT_CALL(response_sender, MockRun(_)) 389 .WillOnce(Invoke(&response_expectation, 390 &EmptyResponseVerifier::Verify)); 391 392 // Create method call; 393 dbus::MethodCall method_call(ibus::panel::kServiceInterface, 394 ibus::panel::kHideAuxiliaryTextMethod); 395 method_call.SetSerial(kSerialNo); 396 397 // Call exported function. 398 EXPECT_NE(method_callback_map_.find(ibus::panel::kHideAuxiliaryTextMethod), 399 method_callback_map_.end()); 400 method_callback_map_[ibus::panel::kHideAuxiliaryTextMethod].Run( 401 &method_call, 402 base::Bind(&MockResponseSender::Run, 403 base::Unretained(&response_sender))); 404 } 405 406 TEST_F(IBusPanelServiceTest, HidePreeditTextTest) { 407 // Set expectations. 408 const uint32 kSerialNo = 1; 409 EXPECT_CALL(*candidate_window_handler_, HidePreeditText()); 410 MockResponseSender response_sender; 411 EmptyResponseVerifier response_expectation(kSerialNo); 412 EXPECT_CALL(response_sender, MockRun(_)) 413 .WillOnce(Invoke(&response_expectation, 414 &EmptyResponseVerifier::Verify)); 415 416 // Create method call; 417 dbus::MethodCall method_call(ibus::panel::kServiceInterface, 418 ibus::panel::kHidePreeditTextMethod); 419 method_call.SetSerial(kSerialNo); 420 421 // Call exported function. 422 EXPECT_NE(method_callback_map_.find(ibus::panel::kHidePreeditTextMethod), 423 method_callback_map_.end()); 424 method_callback_map_[ibus::panel::kHidePreeditTextMethod].Run( 425 &method_call, 426 base::Bind(&MockResponseSender::Run, 427 base::Unretained(&response_sender))); 428 } 429 430 TEST_F(IBusPanelServiceTest, UpdateLookupTableTest) { 431 // Set expectations. 432 const uint32 kSerialNo = 1; 433 IBusLookupTable table; 434 table.set_page_size(3); 435 table.set_cursor_position(4); 436 const bool kVisible = false; 437 438 439 UpdateLookupTableVerifier evaluator(table, kVisible); 440 EXPECT_CALL(*candidate_window_handler_, UpdateLookupTable(_, _)) 441 .WillOnce(Invoke(&evaluator, 442 &UpdateLookupTableVerifier::Verify)); 443 MockResponseSender response_sender; 444 EmptyResponseVerifier response_expectation(kSerialNo); 445 EXPECT_CALL(response_sender, MockRun(_)) 446 .WillOnce(Invoke(&response_expectation, 447 &EmptyResponseVerifier::Verify)); 448 449 // Create method call; 450 dbus::MethodCall method_call(ibus::panel::kServiceInterface, 451 ibus::panel::kUpdateLookupTableMethod); 452 method_call.SetSerial(kSerialNo); 453 dbus::MessageWriter writer(&method_call); 454 AppendIBusLookupTable(table, &writer); 455 writer.AppendBool(kVisible); 456 457 // Call exported function. 458 EXPECT_NE(method_callback_map_.find(ibus::panel::kUpdateLookupTableMethod), 459 method_callback_map_.end()); 460 method_callback_map_[ibus::panel::kUpdateLookupTableMethod].Run( 461 &method_call, 462 base::Bind(&MockResponseSender::Run, 463 base::Unretained(&response_sender))); 464 } 465 466 TEST_F(IBusPanelServiceTest, UpdateAuxiliaryTextTest) { 467 // Set expectations. 468 const uint32 kSerialNo = 1; 469 const std::string text = "Sample text"; 470 const bool kVisible = false; 471 472 EXPECT_CALL(*candidate_window_handler_, UpdateAuxiliaryText(text, kVisible)); 473 MockResponseSender response_sender; 474 EmptyResponseVerifier response_expectation(kSerialNo); 475 EXPECT_CALL(response_sender, MockRun(_)) 476 .WillOnce(Invoke(&response_expectation, 477 &EmptyResponseVerifier::Verify)); 478 479 // Create method call; 480 dbus::MethodCall method_call(ibus::panel::kServiceInterface, 481 ibus::panel::kUpdateAuxiliaryTextMethod); 482 method_call.SetSerial(kSerialNo); 483 dbus::MessageWriter writer(&method_call); 484 AppendStringAsIBusText(text, &writer); 485 writer.AppendBool(kVisible); 486 487 // Call exported function. 488 EXPECT_NE(method_callback_map_.find(ibus::panel::kUpdateAuxiliaryTextMethod), 489 method_callback_map_.end()); 490 method_callback_map_[ibus::panel::kUpdateAuxiliaryTextMethod].Run( 491 &method_call, 492 base::Bind(&MockResponseSender::Run, 493 base::Unretained(&response_sender))); 494 } 495 496 TEST_F(IBusPanelServiceTest, UpdatePreeditTextTest) { 497 // Set expectations. 498 const uint32 kSerialNo = 1; 499 const std::string text = "Sample text"; 500 const uint32 kCursorPos = 4; 501 const bool kVisible = false; 502 503 EXPECT_CALL(*candidate_window_handler_, 504 UpdatePreeditText(text, kCursorPos, kVisible)); 505 MockResponseSender response_sender; 506 EmptyResponseVerifier response_expectation(kSerialNo); 507 EXPECT_CALL(response_sender, MockRun(_)) 508 .WillOnce(Invoke(&response_expectation, 509 &EmptyResponseVerifier::Verify)); 510 511 // Create method call; 512 dbus::MethodCall method_call(ibus::panel::kServiceInterface, 513 ibus::panel::kUpdatePreeditTextMethod); 514 method_call.SetSerial(kSerialNo); 515 dbus::MessageWriter writer(&method_call); 516 AppendStringAsIBusText(text, &writer); 517 writer.AppendUint32(kCursorPos); 518 writer.AppendBool(kVisible); 519 520 // Call exported function. 521 EXPECT_NE(method_callback_map_.find(ibus::panel::kUpdatePreeditTextMethod), 522 method_callback_map_.end()); 523 method_callback_map_[ibus::panel::kUpdatePreeditTextMethod].Run( 524 &method_call, 525 base::Bind(&MockResponseSender::Run, 526 base::Unretained(&response_sender))); 527 } 528 529 TEST_F(IBusPanelServiceTest, CursorUpTest) { 530 // Set expectations. 531 NullArgumentVerifier evaluator(ibus::panel::kCursorUpSignal); 532 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_)) 533 .WillOnce(Invoke(&evaluator, &NullArgumentVerifier::Verify)); 534 535 // Emit signal. 536 service_->CursorUp(); 537 } 538 539 TEST_F(IBusPanelServiceTest, CursorDownTest) { 540 // Set expectations. 541 NullArgumentVerifier evaluator(ibus::panel::kCursorDownSignal); 542 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_)) 543 .WillOnce(Invoke(&evaluator, &NullArgumentVerifier::Verify)); 544 545 // Emit signal. 546 service_->CursorDown(); 547 } 548 549 TEST_F(IBusPanelServiceTest, PageUpTest) { 550 // Set expectations. 551 NullArgumentVerifier evaluator(ibus::panel::kPageUpSignal); 552 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_)) 553 .WillOnce(Invoke(&evaluator, &NullArgumentVerifier::Verify)); 554 555 // Emit signal. 556 service_->PageUp(); 557 } 558 559 TEST_F(IBusPanelServiceTest, PageDownTest) { 560 // Set expectations. 561 NullArgumentVerifier evaluator(ibus::panel::kPageDownSignal); 562 EXPECT_CALL(*mock_exported_object_.get(), SendSignal(_)) 563 .WillOnce(Invoke(&evaluator, &NullArgumentVerifier::Verify)); 564 565 // Emit signal. 566 service_->PageDown(); 567 } 568 569 TEST_F(IBusPanelServiceTest, RegisterPropertiesTest) { 570 // Set expectations. 571 std::vector<std::string> keys; 572 keys.push_back("key1"); 573 keys.push_back("key2"); 574 keys.push_back("key3"); 575 IBusPropertyList properties; 576 for (size_t i = 0; i < keys.size(); ++i) { 577 IBusProperty* property = new IBusProperty; 578 property->set_key(keys[i]); 579 properties.push_back(property); 580 } 581 582 PropertyListVerifier response_expectation(keys); 583 EXPECT_CALL(*property_handler_, RegisterProperties(_)) 584 .WillOnce(Invoke(&response_expectation, 585 &PropertyListVerifier::Verify)); 586 587 MockResponseSender response_sender; 588 EXPECT_CALL(response_sender, MockRun(_)); 589 590 // Create method call; 591 dbus::MethodCall method_call(ibus::panel::kServiceInterface, 592 ibus::panel::kRegisterPropertiesMethod); 593 method_call.SetSerial(1UL); 594 dbus::MessageWriter writer(&method_call); 595 AppendIBusPropertyList(properties, &writer); 596 597 // Call exported function. 598 EXPECT_NE(method_callback_map_.find(ibus::panel::kRegisterPropertiesMethod), 599 method_callback_map_.end()); 600 method_callback_map_[ibus::panel::kRegisterPropertiesMethod].Run( 601 &method_call, 602 base::Bind(&MockResponseSender::Run, base::Unretained(&response_sender))); 603 } 604 605 TEST_F(IBusPanelServiceTest, UpdatePropertyTest) { 606 // Set expectations. 607 const char kKey[] = "key"; 608 IBusProperty property; 609 property.set_key(kKey); 610 611 PropertyVerifier response_expectation(kKey); 612 EXPECT_CALL(*property_handler_, UpdateProperty(_)) 613 .WillOnce(Invoke(&response_expectation, &PropertyVerifier::Verify)); 614 615 MockResponseSender response_sender; 616 EXPECT_CALL(response_sender, MockRun(_)); 617 618 // Create method call; 619 dbus::MethodCall method_call(ibus::panel::kServiceInterface, 620 ibus::panel::kUpdatePropertyMethod); 621 method_call.SetSerial(1UL); 622 dbus::MessageWriter writer(&method_call); 623 AppendIBusProperty(property, &writer); 624 625 // Call exported function. 626 EXPECT_NE(method_callback_map_.find(ibus::panel::kUpdatePropertyMethod), 627 method_callback_map_.end()); 628 method_callback_map_[ibus::panel::kUpdatePropertyMethod].Run( 629 &method_call, 630 base::Bind(&MockResponseSender::Run, 631 base::Unretained(&response_sender))); 632 } 633 634 } // namespace chromeos 635