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_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 19 matching lines...) Expand all Loading... |
30 // Following variables are used in callback expectations. | 30 // Following variables are used in callback expectations. |
31 const uint32 kCapabilities = 12345; | 31 const uint32 kCapabilities = 12345; |
32 const int32 kCursorX = 30; | 32 const int32 kCursorX = 30; |
33 const int32 kCursorY = 31; | 33 const int32 kCursorY = 31; |
34 const int32 kCursorWidth = 32; | 34 const int32 kCursorWidth = 32; |
35 const int32 kCursorHeight = 33; | 35 const int32 kCursorHeight = 33; |
36 const uint32 kKeyval = 34; | 36 const uint32 kKeyval = 34; |
37 const uint32 kKeycode = 35; | 37 const uint32 kKeycode = 35; |
38 const uint32 kState = 36; | 38 const uint32 kState = 36; |
39 const bool kIsKeyHandled = false; | 39 const bool kIsKeyHandled = false; |
| 40 const char kSurroundingText[] = "Surrounding Text"; |
| 41 const uint32 kCursorPos = 2; |
| 42 const uint32 kAnchorPos = 7; |
40 | 43 |
41 class MockCommitTextHandler { | 44 class MockCommitTextHandler { |
42 public: | 45 public: |
43 MOCK_METHOD1(Run, void(const IBusText& text)); | 46 MOCK_METHOD1(Run, void(const IBusText& text)); |
44 }; | 47 }; |
45 | 48 |
46 class MockForwardKeyEventHandler { | 49 class MockForwardKeyEventHandler { |
47 public: | 50 public: |
48 MOCK_METHOD3(Run, void(uint32 keyval, uint32 keycode, uint32 state)); | 51 MOCK_METHOD3(Run, void(uint32 keyval, uint32 keycode, uint32 state)); |
49 }; | 52 }; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 dbus::MessageReader reader(method_call); | 264 dbus::MessageReader reader(method_call); |
262 EXPECT_TRUE(reader.PopUint32(&keyval)); | 265 EXPECT_TRUE(reader.PopUint32(&keyval)); |
263 EXPECT_TRUE(reader.PopUint32(&keycode)); | 266 EXPECT_TRUE(reader.PopUint32(&keycode)); |
264 EXPECT_TRUE(reader.PopUint32(&state)); | 267 EXPECT_TRUE(reader.PopUint32(&state)); |
265 EXPECT_FALSE(reader.HasMoreData()); | 268 EXPECT_FALSE(reader.HasMoreData()); |
266 | 269 |
267 message_loop_.PostTask(FROM_HERE, base::Bind(error_callback, | 270 message_loop_.PostTask(FROM_HERE, base::Bind(error_callback, |
268 error_response_)); | 271 error_response_)); |
269 } | 272 } |
270 | 273 |
| 274 // Handles SetSurroudingText method call. |
| 275 void OnSetSurroundingText( |
| 276 dbus::MethodCall* method_call, |
| 277 int timeout_ms, |
| 278 const dbus::ObjectProxy::ResponseCallback& callback, |
| 279 const dbus::ObjectProxy::ErrorCallback& error_callback) { |
| 280 EXPECT_EQ(ibus::input_context::kServiceInterface, |
| 281 method_call->GetInterface()); |
| 282 EXPECT_EQ(ibus::input_context::kSetSurroundingText, |
| 283 method_call->GetMember()); |
| 284 dbus::MessageReader reader(method_call); |
| 285 std::string text; |
| 286 uint32 cursor_pos = 0; |
| 287 uint32 anchor_pos = 0; |
| 288 |
| 289 EXPECT_TRUE(ibus::PopStringFromIBusText(&reader, &text)); |
| 290 EXPECT_TRUE(reader.PopUint32(&cursor_pos)); |
| 291 EXPECT_TRUE(reader.PopUint32(&anchor_pos)); |
| 292 EXPECT_FALSE(reader.HasMoreData()); |
| 293 |
| 294 EXPECT_EQ(kSurroundingText, text); |
| 295 EXPECT_EQ(kCursorPos, cursor_pos); |
| 296 EXPECT_EQ(kAnchorPos, anchor_pos); |
| 297 |
| 298 message_loop_.PostTask(FROM_HERE, base::Bind(callback, response_)); |
| 299 } |
| 300 |
271 protected: | 301 protected: |
272 // The client to be tested. | 302 // The client to be tested. |
273 scoped_ptr<IBusInputContextClient> client_; | 303 scoped_ptr<IBusInputContextClient> client_; |
274 // The mock bus. | 304 // The mock bus. |
275 scoped_refptr<dbus::MockBus> mock_bus_; | 305 scoped_refptr<dbus::MockBus> mock_bus_; |
276 // The mock object proxy. | 306 // The mock object proxy. |
277 scoped_refptr<dbus::MockObjectProxy> mock_proxy_; | 307 scoped_refptr<dbus::MockObjectProxy> mock_proxy_; |
278 // Response returned by mock methods. | 308 // Response returned by mock methods. |
279 dbus::Response* response_; | 309 dbus::Response* response_; |
280 dbus::ErrorResponse* error_response_; | 310 dbus::ErrorResponse* error_response_; |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 kKeycode, | 584 kKeycode, |
555 kState, | 585 kState, |
556 base::Bind(&MockProcessKeyEventHandler::Run, | 586 base::Bind(&MockProcessKeyEventHandler::Run, |
557 base::Unretained(&callback)), | 587 base::Unretained(&callback)), |
558 base::Bind(&MockProcessKeyEventErrorHandler::Run, | 588 base::Bind(&MockProcessKeyEventErrorHandler::Run, |
559 base::Unretained(&error_callback))); | 589 base::Unretained(&error_callback))); |
560 // Run the message loop. | 590 // Run the message loop. |
561 message_loop_.RunAllPending(); | 591 message_loop_.RunAllPending(); |
562 } | 592 } |
563 | 593 |
| 594 TEST_F(IBusInputContextClientTest, SetSurroundingTextTest) { |
| 595 // Set expectations. |
| 596 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) |
| 597 .WillOnce(Invoke(this, |
| 598 &IBusInputContextClientTest::OnSetSurroundingText)); |
| 599 // Create response. |
| 600 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 601 response_ = response.get(); |
| 602 |
| 603 // Call SetCursorLocation. |
| 604 client_->SetSurroundingText(kSurroundingText, kCursorPos, kAnchorPos); |
| 605 // Run the message loop. |
| 606 message_loop_.RunAllPending(); |
| 607 } |
| 608 |
564 } // namespace chromeos | 609 } // namespace chromeos |
OLD | NEW |