OLD | NEW |
| (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 // TODO(nona): Remove this file. | |
5 | |
6 #include "ui/base/ime/mock_ibus_client.h" | |
7 | |
8 #include "base/logging.h" | |
9 #include "base/utf_string_conversions.h" | |
10 | |
11 namespace ui { | |
12 namespace internal { | |
13 | |
14 MockIBusClient::MockIBusClient() { | |
15 ResetFlags(); | |
16 } | |
17 | |
18 MockIBusClient::~MockIBusClient() { | |
19 if (create_ic_request_.get() && | |
20 (create_context_result_ == kCreateContextDelayed)) { | |
21 // The destructor is called after ui::InputMethodIBus is destructed. Check | |
22 // whether the new context created by CreateContextObject() is immediately | |
23 // destroyed by checking the counter in MockIBusClient::DestroyProxy(). | |
24 const unsigned int initial_call_count = destroy_proxy_call_count_; | |
25 create_ic_request_->InitOrAbandonInputContext(); | |
26 DCHECK_EQ(initial_call_count + 1, destroy_proxy_call_count_); | |
27 } | |
28 } | |
29 | |
30 bool MockIBusClient::IsConnected() { | |
31 return is_connected_; | |
32 } | |
33 | |
34 bool MockIBusClient::IsContextReady() { | |
35 return is_context_ready_; | |
36 } | |
37 | |
38 void MockIBusClient::CreateContext(PendingCreateICRequest* request) { | |
39 ++create_context_call_count_; | |
40 switch (create_context_result_) { | |
41 case kCreateContextSuccess: | |
42 // Create a new context immediately. | |
43 is_context_ready_ = true; | |
44 request->InitOrAbandonInputContext(); | |
45 delete request; | |
46 break; | |
47 case kCreateContextFail: | |
48 // Emulate an IPC failure. Pass NULL to the request object. | |
49 request->OnCreateInputContextFailed(); | |
50 delete request; | |
51 break; | |
52 case kCreateContextNoResponse: | |
53 // Emulate ibus-daemon hang-up. Do not call StoreOrAbandonInputContext. | |
54 create_ic_request_.reset(request); | |
55 break; | |
56 case kCreateContextDelayed: | |
57 // Emulate overloaded ibus-daemon. Call StoreOrAbandonInputContext later. | |
58 create_ic_request_.reset(request); | |
59 break; | |
60 } | |
61 } | |
62 | |
63 void MockIBusClient::DestroyProxy() { | |
64 ++destroy_proxy_call_count_; | |
65 is_context_ready_ = false; | |
66 } | |
67 | |
68 void MockIBusClient::SetCapabilities(InlineCompositionCapability inline_type) { | |
69 ++set_capabilities_call_count_; | |
70 } | |
71 | |
72 void MockIBusClient::FocusIn() { | |
73 ++focus_in_call_count_; | |
74 } | |
75 | |
76 void MockIBusClient::FocusOut() { | |
77 ++focus_out_call_count_; | |
78 } | |
79 | |
80 void MockIBusClient::Reset() { | |
81 ++reset_call_count_; | |
82 } | |
83 | |
84 IBusClient::InputMethodType MockIBusClient::GetInputMethodType() { | |
85 return input_method_type_; | |
86 } | |
87 | |
88 void MockIBusClient::SetCursorLocation(const gfx::Rect& cursor_location, | |
89 const gfx::Rect& composition_head) { | |
90 ++set_cursor_location_call_count_; | |
91 } | |
92 | |
93 void MockIBusClient::SendKeyEvent( | |
94 uint32 keyval, | |
95 uint32 keycode, | |
96 uint32 state, | |
97 const chromeos::IBusInputContextClient::ProcessKeyEventCallback& callback) { | |
98 // TODO(yusukes): implement this function. | |
99 } | |
100 | |
101 void MockIBusClient::ResetFlags() { | |
102 create_context_result_ = kCreateContextSuccess; | |
103 create_ic_request_.reset(); | |
104 | |
105 is_connected_ = false; | |
106 is_context_ready_ = false; | |
107 input_method_type_ = INPUT_METHOD_NORMAL; | |
108 commit_text_.clear(); | |
109 | |
110 create_context_call_count_ = 0; | |
111 destroy_proxy_call_count_ = 0; | |
112 set_capabilities_call_count_ = 0; | |
113 focus_in_call_count_ = 0; | |
114 focus_out_call_count_ = 0; | |
115 reset_call_count_ = 0; | |
116 set_cursor_location_call_count_ = 0; | |
117 } | |
118 | |
119 } // namespace internal | |
120 } // namespace ui | |
OLD | NEW |