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

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

Issue 16998003: Update CrOS to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
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_input_context_client.h" 5 #include "chromeos/dbus/ibus/ibus_input_context_client.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "chromeos/dbus/ibus/ibus_constants.h" 10 #include "chromeos/dbus/ibus/ibus_constants.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 ibus::kServiceName, 94 ibus::kServiceName,
95 dbus::ObjectPath(kObjectPath)); 95 dbus::ObjectPath(kObjectPath));
96 96
97 // Create a client. 97 // Create a client.
98 client_.reset(IBusInputContextClient::Create( 98 client_.reset(IBusInputContextClient::Create(
99 REAL_DBUS_CLIENT_IMPLEMENTATION)); 99 REAL_DBUS_CLIENT_IMPLEMENTATION));
100 100
101 // Set an expectation so mock_bus's GetObjectProxy() for the given service 101 // Set an expectation so mock_bus's GetObjectProxy() for the given service
102 // name and the object path will return mock_proxy_. The GetObjectProxy 102 // name and the object path will return mock_proxy_. The GetObjectProxy
103 // function is called in Initialized function. 103 // function is called in Initialized function.
104 EXPECT_CALL(*mock_bus_, GetObjectProxy(ibus::kServiceName, 104 EXPECT_CALL(
105 dbus::ObjectPath(kObjectPath))) 105 *mock_bus_.get(),
106 GetObjectProxy(ibus::kServiceName, dbus::ObjectPath(kObjectPath)))
106 .WillOnce(Return(mock_proxy_.get())); 107 .WillOnce(Return(mock_proxy_.get()));
107 108
108 // Set expectations so mock_proxy's ConnectToSignal will use 109 // Set expectations so mock_proxy's ConnectToSignal will use
109 // OnConnectToSignal() to run the callback. The ConnectToSignal is called in 110 // OnConnectToSignal() to run the callback. The ConnectToSignal is called in
110 // Initialize function. 111 // Initialize function.
111 EXPECT_CALL(*mock_proxy_, ConnectToSignal( 112 EXPECT_CALL(*mock_proxy_.get(),
112 ibus::input_context::kServiceInterface, 113 ConnectToSignal(ibus::input_context::kServiceInterface,
113 ibus::input_context::kCommitTextSignal, _, _)) 114 ibus::input_context::kCommitTextSignal,
115 _,
116 _))
114 .WillRepeatedly( 117 .WillRepeatedly(
115 Invoke(this, &IBusInputContextClientTest::OnConnectToSignal)); 118 Invoke(this, &IBusInputContextClientTest::OnConnectToSignal));
116 EXPECT_CALL(*mock_proxy_, ConnectToSignal( 119 EXPECT_CALL(*mock_proxy_.get(),
117 ibus::input_context::kServiceInterface, 120 ConnectToSignal(ibus::input_context::kServiceInterface,
118 ibus::input_context::kForwardKeyEventSignal, _, _)) 121 ibus::input_context::kForwardKeyEventSignal,
122 _,
123 _))
119 .WillRepeatedly( 124 .WillRepeatedly(
120 Invoke(this, &IBusInputContextClientTest::OnConnectToSignal)); 125 Invoke(this, &IBusInputContextClientTest::OnConnectToSignal));
121 EXPECT_CALL(*mock_proxy_, ConnectToSignal( 126 EXPECT_CALL(*mock_proxy_.get(),
122 ibus::input_context::kServiceInterface, 127 ConnectToSignal(ibus::input_context::kServiceInterface,
123 ibus::input_context::kHidePreeditTextSignal, _, _)) 128 ibus::input_context::kHidePreeditTextSignal,
129 _,
130 _))
124 .WillRepeatedly( 131 .WillRepeatedly(
125 Invoke(this, &IBusInputContextClientTest::OnConnectToSignal)); 132 Invoke(this, &IBusInputContextClientTest::OnConnectToSignal));
126 EXPECT_CALL(*mock_proxy_, ConnectToSignal( 133 EXPECT_CALL(*mock_proxy_.get(),
127 ibus::input_context::kServiceInterface, 134 ConnectToSignal(ibus::input_context::kServiceInterface,
128 ibus::input_context::kShowPreeditTextSignal, _, _)) 135 ibus::input_context::kShowPreeditTextSignal,
136 _,
137 _))
129 .WillRepeatedly( 138 .WillRepeatedly(
130 Invoke(this, &IBusInputContextClientTest::OnConnectToSignal)); 139 Invoke(this, &IBusInputContextClientTest::OnConnectToSignal));
131 EXPECT_CALL(*mock_proxy_, ConnectToSignal( 140 EXPECT_CALL(*mock_proxy_.get(),
132 ibus::input_context::kServiceInterface, 141 ConnectToSignal(ibus::input_context::kServiceInterface,
133 ibus::input_context::kUpdatePreeditTextSignal, _, _)) 142 ibus::input_context::kUpdatePreeditTextSignal,
143 _,
144 _))
134 .WillRepeatedly( 145 .WillRepeatedly(
135 Invoke(this, &IBusInputContextClientTest::OnConnectToSignal)); 146 Invoke(this, &IBusInputContextClientTest::OnConnectToSignal));
136 EXPECT_CALL(*mock_proxy_, ConnectToSignal( 147 EXPECT_CALL(
137 ibus::input_context::kServiceInterface, 148 *mock_proxy_.get(),
138 ibus::input_context::kDeleteSurroundingTextSignal, _, _)) 149 ConnectToSignal(ibus::input_context::kServiceInterface,
150 ibus::input_context::kDeleteSurroundingTextSignal,
151 _,
152 _))
139 .WillRepeatedly( 153 .WillRepeatedly(
140 Invoke(this, &IBusInputContextClientTest::OnConnectToSignal)); 154 Invoke(this, &IBusInputContextClientTest::OnConnectToSignal));
141 155
142 // Call Initialize to create object proxy and connect signals. 156 // Call Initialize to create object proxy and connect signals.
143 client_->Initialize(mock_bus_.get(), dbus::ObjectPath(kObjectPath)); 157 client_->Initialize(mock_bus_.get(), dbus::ObjectPath(kObjectPath));
144 } 158 }
145 159
146 virtual void TearDown() OVERRIDE { 160 virtual void TearDown() OVERRIDE {
147 EXPECT_TRUE(client_->IsObjectProxyReady()); 161 EXPECT_TRUE(client_->IsObjectProxyReady());
148 client_->ResetObjectProxy(); 162 client_->ResetObjectProxy();
149 EXPECT_FALSE(client_->IsObjectProxyReady()); 163 EXPECT_FALSE(client_->IsObjectProxyReady());
150 } 164 }
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 &signal); 477 &signal);
464 478
465 // Unset the handler so expect not calling handler. 479 // Unset the handler so expect not calling handler.
466 client_->SetInputContextHandler(NULL); 480 client_->SetInputContextHandler(NULL);
467 signal_callback_map_[ibus::input_context::kUpdatePreeditTextSignal].Run( 481 signal_callback_map_[ibus::input_context::kUpdatePreeditTextSignal].Run(
468 &signal); 482 &signal);
469 } 483 }
470 484
471 TEST_F(IBusInputContextClientTest, FocusInTest) { 485 TEST_F(IBusInputContextClientTest, FocusInTest) {
472 // Set expectations. 486 // Set expectations.
473 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) 487 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _))
474 .WillOnce(Invoke(this, &IBusInputContextClientTest::OnFocusIn)); 488 .WillOnce(Invoke(this, &IBusInputContextClientTest::OnFocusIn));
475 // Create response. 489 // Create response.
476 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 490 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
477 response_ = response.get(); 491 response_ = response.get();
478 492
479 // Call FocusIn. 493 // Call FocusIn.
480 client_->FocusIn(); 494 client_->FocusIn();
481 // Run the message loop. 495 // Run the message loop.
482 message_loop_.RunUntilIdle(); 496 message_loop_.RunUntilIdle();
483 } 497 }
484 498
485 TEST_F(IBusInputContextClientTest, FocusOutTest) { 499 TEST_F(IBusInputContextClientTest, FocusOutTest) {
486 // Set expectations. 500 // Set expectations.
487 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) 501 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _))
488 .WillOnce(Invoke(this, &IBusInputContextClientTest::OnFocusOut)); 502 .WillOnce(Invoke(this, &IBusInputContextClientTest::OnFocusOut));
489 // Create response. 503 // Create response.
490 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 504 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
491 response_ = response.get(); 505 response_ = response.get();
492 506
493 // Call FocusOut. 507 // Call FocusOut.
494 client_->FocusOut(); 508 client_->FocusOut();
495 // Run the message loop. 509 // Run the message loop.
496 message_loop_.RunUntilIdle(); 510 message_loop_.RunUntilIdle();
497 } 511 }
498 512
499 TEST_F(IBusInputContextClientTest, ResetTest) { 513 TEST_F(IBusInputContextClientTest, ResetTest) {
500 // Set expectations. 514 // Set expectations.
501 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) 515 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _))
502 .WillOnce(Invoke(this, &IBusInputContextClientTest::OnReset)); 516 .WillOnce(Invoke(this, &IBusInputContextClientTest::OnReset));
503 // Create response. 517 // Create response.
504 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 518 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
505 response_ = response.get(); 519 response_ = response.get();
506 520
507 // Call Reset. 521 // Call Reset.
508 client_->Reset(); 522 client_->Reset();
509 // Run the message loop. 523 // Run the message loop.
510 message_loop_.RunUntilIdle(); 524 message_loop_.RunUntilIdle();
511 } 525 }
512 526
513 TEST_F(IBusInputContextClientTest, SetCapabilitiesTest) { 527 TEST_F(IBusInputContextClientTest, SetCapabilitiesTest) {
514 // Set expectations. 528 // Set expectations.
515 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) 529 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _))
516 .WillOnce(Invoke(this, &IBusInputContextClientTest::OnSetCapabilities)); 530 .WillOnce(Invoke(this, &IBusInputContextClientTest::OnSetCapabilities));
517 // Create response. 531 // Create response.
518 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 532 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
519 response_ = response.get(); 533 response_ = response.get();
520 534
521 // Call SetCapabilities. 535 // Call SetCapabilities.
522 client_->SetCapabilities(kCapabilities); 536 client_->SetCapabilities(kCapabilities);
523 // Run the message loop. 537 // Run the message loop.
524 message_loop_.RunUntilIdle(); 538 message_loop_.RunUntilIdle();
525 } 539 }
(...skipping 13 matching lines...) Expand all
539 kCompositionHeight); 553 kCompositionHeight);
540 // Call SetCursorLocation. 554 // Call SetCursorLocation.
541 client_->SetCursorLocation(cursor_location, composition_location); 555 client_->SetCursorLocation(cursor_location, composition_location);
542 556
543 EXPECT_EQ(1, on_set_cursor_location_call_count_); 557 EXPECT_EQ(1, on_set_cursor_location_call_count_);
544 client_->UnsetSetCursorLocationHandler(); 558 client_->UnsetSetCursorLocationHandler();
545 } 559 }
546 560
547 TEST_F(IBusInputContextClientTest, OnProcessKeyEvent) { 561 TEST_F(IBusInputContextClientTest, OnProcessKeyEvent) {
548 // Set expectations. 562 // Set expectations.
549 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) 563 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _))
550 .WillOnce(Invoke(this, &IBusInputContextClientTest::OnProcessKeyEvent)); 564 .WillOnce(Invoke(this, &IBusInputContextClientTest::OnProcessKeyEvent));
551 MockProcessKeyEventHandler callback; 565 MockProcessKeyEventHandler callback;
552 MockProcessKeyEventErrorHandler error_callback; 566 MockProcessKeyEventErrorHandler error_callback;
553 567
554 EXPECT_CALL(callback, Run(kIsKeyHandled)); 568 EXPECT_CALL(callback, Run(kIsKeyHandled));
555 EXPECT_CALL(error_callback, Run()).Times(0); 569 EXPECT_CALL(error_callback, Run()).Times(0);
556 // Create response. 570 // Create response.
557 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 571 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
558 dbus::MessageWriter writer(response.get()); 572 dbus::MessageWriter writer(response.get());
559 writer.AppendBool(kIsKeyHandled); 573 writer.AppendBool(kIsKeyHandled);
560 response_ = response.get(); 574 response_ = response.get();
561 575
562 // Call ProcessKeyEvent. 576 // Call ProcessKeyEvent.
563 client_->ProcessKeyEvent(kKeyval, 577 client_->ProcessKeyEvent(kKeyval,
564 kKeycode, 578 kKeycode,
565 kState, 579 kState,
566 base::Bind(&MockProcessKeyEventHandler::Run, 580 base::Bind(&MockProcessKeyEventHandler::Run,
567 base::Unretained(&callback)), 581 base::Unretained(&callback)),
568 base::Bind(&MockProcessKeyEventErrorHandler::Run, 582 base::Bind(&MockProcessKeyEventErrorHandler::Run,
569 base::Unretained(&error_callback))); 583 base::Unretained(&error_callback)));
570 // Run the message loop. 584 // Run the message loop.
571 message_loop_.RunUntilIdle(); 585 message_loop_.RunUntilIdle();
572 } 586 }
573 587
574 TEST_F(IBusInputContextClientTest, OnProcessKeyEventFail) { 588 TEST_F(IBusInputContextClientTest, OnProcessKeyEventFail) {
575 // Set expectations. 589 // Set expectations.
576 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) 590 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _))
577 .WillOnce(Invoke(this, 591 .WillOnce(
578 &IBusInputContextClientTest::OnProcessKeyEventFail)); 592 Invoke(this, &IBusInputContextClientTest::OnProcessKeyEventFail));
579 MockProcessKeyEventHandler callback; 593 MockProcessKeyEventHandler callback;
580 MockProcessKeyEventErrorHandler error_callback; 594 MockProcessKeyEventErrorHandler error_callback;
581 595
582 EXPECT_CALL(callback, Run(_)).Times(0); 596 EXPECT_CALL(callback, Run(_)).Times(0);
583 EXPECT_CALL(error_callback, Run()); 597 EXPECT_CALL(error_callback, Run());
584 // Create response. 598 // Create response.
585 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 599 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
586 dbus::MessageWriter writer(response.get()); 600 dbus::MessageWriter writer(response.get());
587 writer.AppendBool(kIsKeyHandled); 601 writer.AppendBool(kIsKeyHandled);
588 response_ = response.get(); 602 response_ = response.get();
589 603
590 // Call ProcessKeyEvent. 604 // Call ProcessKeyEvent.
591 client_->ProcessKeyEvent(kKeyval, 605 client_->ProcessKeyEvent(kKeyval,
592 kKeycode, 606 kKeycode,
593 kState, 607 kState,
594 base::Bind(&MockProcessKeyEventHandler::Run, 608 base::Bind(&MockProcessKeyEventHandler::Run,
595 base::Unretained(&callback)), 609 base::Unretained(&callback)),
596 base::Bind(&MockProcessKeyEventErrorHandler::Run, 610 base::Bind(&MockProcessKeyEventErrorHandler::Run,
597 base::Unretained(&error_callback))); 611 base::Unretained(&error_callback)));
598 // Run the message loop. 612 // Run the message loop.
599 message_loop_.RunUntilIdle(); 613 message_loop_.RunUntilIdle();
600 } 614 }
601 615
602 TEST_F(IBusInputContextClientTest, SetSurroundingTextTest) { 616 TEST_F(IBusInputContextClientTest, SetSurroundingTextTest) {
603 // Set expectations. 617 // Set expectations.
604 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) 618 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _))
605 .WillOnce(Invoke(this, 619 .WillOnce(
606 &IBusInputContextClientTest::OnSetSurroundingText)); 620 Invoke(this, &IBusInputContextClientTest::OnSetSurroundingText));
607 // Create response. 621 // Create response.
608 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 622 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
609 response_ = response.get(); 623 response_ = response.get();
610 624
611 // Call SetCursorLocation. 625 // Call SetCursorLocation.
612 client_->SetSurroundingText(kSurroundingText, kCursorPos, kAnchorPos); 626 client_->SetSurroundingText(kSurroundingText, kCursorPos, kAnchorPos);
613 // Run the message loop. 627 // Run the message loop.
614 message_loop_.RunUntilIdle(); 628 message_loop_.RunUntilIdle();
615 } 629 }
616 630
617 TEST_F(IBusInputContextClientTest, PropertyActivateTest) { 631 TEST_F(IBusInputContextClientTest, PropertyActivateTest) {
618 // Set expectations. 632 // Set expectations.
619 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) 633 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _))
620 .WillOnce(Invoke(this, 634 .WillOnce(Invoke(this, &IBusInputContextClientTest::OnPropertyActivate));
621 &IBusInputContextClientTest::OnPropertyActivate));
622 // Create response. 635 // Create response.
623 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 636 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
624 response_ = response.get(); 637 response_ = response.get();
625 638
626 // Call SetCursorLocation. 639 // Call SetCursorLocation.
627 client_->PropertyActivate(kPropertyKey, kPropertyState); 640 client_->PropertyActivate(kPropertyKey, kPropertyState);
628 // Run the message loop. 641 // Run the message loop.
629 message_loop_.RunUntilIdle(); 642 message_loop_.RunUntilIdle();
630 } 643 }
631 } // namespace chromeos 644 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/ibus/ibus_engine_service_unittest.cc ('k') | chromeos/dbus/ibus/ibus_panel_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698