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

Side by Side Diff: ui/base/ime/input_method_chromeos_unittest.cc

Issue 142043006: Refactors ui::internal::InputMethodDelegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed an issue of unsigned/signed comparison. Created 6 years, 10 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
« no previous file with comments | « ui/base/ime/input_method_base.cc ('k') | ui/base/ime/input_method_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/base/ime/input_method_chromeos.h"
6
5 #include <X11/Xlib.h> 7 #include <X11/Xlib.h>
6 #undef Bool 8 #undef Bool
7 #undef FocusIn 9 #undef FocusIn
8 #undef FocusOut 10 #undef FocusOut
9 #undef None 11 #undef None
10 12
11 #include <cstring> 13 #include <cstring>
12 14
13 #include "base/i18n/char_iterator.h" 15 #include "base/i18n/char_iterator.h"
14 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
16 #include "chromeos/ime/ibus_keymap.h" 18 #include "chromeos/ime/ibus_keymap.h"
17 #include "chromeos/ime/ibus_text.h" 19 #include "chromeos/ime/ibus_text.h"
18 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/base/ime/chromeos/ime_bridge.h" 21 #include "ui/base/ime/chromeos/ime_bridge.h"
20 #include "ui/base/ime/chromeos/mock_ime_candidate_window_handler.h" 22 #include "ui/base/ime/chromeos/mock_ime_candidate_window_handler.h"
21 #include "ui/base/ime/chromeos/mock_ime_engine_handler.h" 23 #include "ui/base/ime/chromeos/mock_ime_engine_handler.h"
22 #include "ui/base/ime/input_method_chromeos.h"
23 #include "ui/base/ime/input_method_delegate.h" 24 #include "ui/base/ime/input_method_delegate.h"
24 #include "ui/base/ime/text_input_client.h" 25 #include "ui/base/ime/text_input_client.h"
25 #include "ui/events/event.h" 26 #include "ui/events/event.h"
26 #include "ui/events/test/events_test_utils_x11.h" 27 #include "ui/events/test/events_test_utils_x11.h"
27 #include "ui/gfx/rect.h" 28 #include "ui/gfx/geometry/rect.h"
28 29
29 using base::UTF8ToUTF16; 30 using base::UTF8ToUTF16;
30 using base::UTF16ToUTF8; 31 using base::UTF16ToUTF8;
31 32
32 namespace ui { 33 namespace ui {
33 namespace { 34 namespace {
34 typedef chromeos::IMEEngineHandlerInterface::KeyEventDoneCallback 35 typedef chromeos::IMEEngineHandlerInterface::KeyEventDoneCallback
35 KeyEventCallback; 36 KeyEventCallback;
36 37
37 uint32 GetOffsetInUTF16(const std::string& utf8_string, uint32 utf8_offset) { 38 uint32 GetOffsetInUTF16(const std::string& utf8_string, uint32 utf8_offset) {
(...skipping 27 matching lines...) Expand all
65 : InputMethodChromeOS(delegate), 66 : InputMethodChromeOS(delegate),
66 process_key_event_post_ime_call_count_(0) { 67 process_key_event_post_ime_call_count_(0) {
67 } 68 }
68 69
69 struct ProcessKeyEventPostIMEArgs { 70 struct ProcessKeyEventPostIMEArgs {
70 ProcessKeyEventPostIMEArgs() : event(NULL), handled(false) {} 71 ProcessKeyEventPostIMEArgs() : event(NULL), handled(false) {}
71 const ui::KeyEvent* event; 72 const ui::KeyEvent* event;
72 bool handled; 73 bool handled;
73 }; 74 };
74 75
75 // InputMethodChromeOS override. 76 // Overridden from InputMethodChromeOS:
76 virtual void ProcessKeyEventPostIME(const ui::KeyEvent& key_event, 77 virtual void ProcessKeyEventPostIME(const ui::KeyEvent& key_event,
77 bool handled) OVERRIDE { 78 bool handled) OVERRIDE {
78 process_key_event_post_ime_args_.event = &key_event; 79 process_key_event_post_ime_args_.event = &key_event;
79 process_key_event_post_ime_args_.handled = handled; 80 process_key_event_post_ime_args_.handled = handled;
80 ++process_key_event_post_ime_call_count_; 81 ++process_key_event_post_ime_call_count_;
81 } 82 }
82 83
83 void ResetCallCount() { 84 void ResetCallCount() {
84 process_key_event_post_ime_call_count_ = 0; 85 process_key_event_post_ime_call_count_ = 0;
85 } 86 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 187
187 private: 188 private:
188 const std::string expected_surrounding_text_; 189 const std::string expected_surrounding_text_;
189 const uint32 expected_cursor_position_; 190 const uint32 expected_cursor_position_;
190 const uint32 expected_anchor_position_; 191 const uint32 expected_anchor_position_;
191 192
192 DISALLOW_COPY_AND_ASSIGN(SetSurroundingTextVerifier); 193 DISALLOW_COPY_AND_ASSIGN(SetSurroundingTextVerifier);
193 }; 194 };
194 195
195 class InputMethodChromeOSTest : public internal::InputMethodDelegate, 196 class InputMethodChromeOSTest : public internal::InputMethodDelegate,
196 public testing::Test, 197 public testing::Test,
197 public TextInputClient { 198 public TextInputClient {
198 public: 199 public:
199 InputMethodChromeOSTest() { 200 InputMethodChromeOSTest()
201 : dispatched_key_event_(ui::ET_UNKNOWN, ui::VKEY_UNKNOWN, 0, false) {
200 ResetFlags(); 202 ResetFlags();
201 } 203 }
202 204
203 virtual ~InputMethodChromeOSTest() { 205 virtual ~InputMethodChromeOSTest() {
204 } 206 }
205 207
206 // testing::Test overrides:
207 virtual void SetUp() OVERRIDE { 208 virtual void SetUp() OVERRIDE {
208 chromeos::IMEBridge::Initialize(); 209 chromeos::IMEBridge::Initialize();
209 210
210 mock_ime_engine_handler_.reset( 211 mock_ime_engine_handler_.reset(
211 new chromeos::MockIMEEngineHandler()); 212 new chromeos::MockIMEEngineHandler());
212 chromeos::IMEBridge::Get()->SetCurrentEngineHandler( 213 chromeos::IMEBridge::Get()->SetCurrentEngineHandler(
213 mock_ime_engine_handler_.get()); 214 mock_ime_engine_handler_.get());
214 215
215 mock_ime_candidate_window_handler_.reset( 216 mock_ime_candidate_window_handler_.reset(
216 new chromeos::MockIMECandidateWindowHandler()); 217 new chromeos::MockIMECandidateWindowHandler());
217 chromeos::IMEBridge::Get()->SetCandidateWindowHandler( 218 chromeos::IMEBridge::Get()->SetCandidateWindowHandler(
218 mock_ime_candidate_window_handler_.get()); 219 mock_ime_candidate_window_handler_.get());
219 220
220 ime_.reset(new TestableInputMethodChromeOS(this)); 221 ime_.reset(new TestableInputMethodChromeOS(this));
221 ime_->SetFocusedTextInputClient(this); 222 ime_->SetFocusedTextInputClient(this);
222 } 223 }
223 224
224 virtual void TearDown() OVERRIDE { 225 virtual void TearDown() OVERRIDE {
225 if (ime_.get()) 226 if (ime_.get())
226 ime_->SetFocusedTextInputClient(NULL); 227 ime_->SetFocusedTextInputClient(NULL);
227 ime_.reset(); 228 ime_.reset();
228 chromeos::IMEBridge::Get()->SetCurrentEngineHandler(NULL); 229 chromeos::IMEBridge::Get()->SetCurrentEngineHandler(NULL);
229 chromeos::IMEBridge::Get()->SetCandidateWindowHandler(NULL); 230 chromeos::IMEBridge::Get()->SetCandidateWindowHandler(NULL);
230 mock_ime_engine_handler_.reset(); 231 mock_ime_engine_handler_.reset();
231 mock_ime_candidate_window_handler_.reset(); 232 mock_ime_candidate_window_handler_.reset();
232 chromeos::IMEBridge::Shutdown(); 233 chromeos::IMEBridge::Shutdown();
233 } 234 }
234 235
235 // ui::internal::InputMethodDelegate overrides: 236 // Overridden from ui::internal::InputMethodDelegate:
236 virtual bool DispatchKeyEventPostIME( 237 virtual bool DispatchKeyEventPostIME(const ui::KeyEvent& event) OVERRIDE {
237 const base::NativeEvent& native_key_event) OVERRIDE { 238 dispatched_key_event_ = event;
238 dispatched_native_event_ = native_key_event;
239 return false;
240 }
241 virtual bool DispatchFabricatedKeyEventPostIME(ui::EventType type,
242 ui::KeyboardCode key_code,
243 int flags) OVERRIDE {
244 dispatched_fabricated_event_type_ = type;
245 dispatched_fabricated_event_key_code_ = key_code;
246 dispatched_fabricated_event_flags_ = flags;
247 return false; 239 return false;
248 } 240 }
249 241
250 // ui::TextInputClient overrides: 242 // Overridden from ui::TextInputClient:
251 virtual void SetCompositionText( 243 virtual void SetCompositionText(
252 const CompositionText& composition) OVERRIDE { 244 const CompositionText& composition) OVERRIDE {
253 composition_text_ = composition; 245 composition_text_ = composition;
254 } 246 }
255 virtual void ConfirmCompositionText() OVERRIDE { 247 virtual void ConfirmCompositionText() OVERRIDE {
256 confirmed_text_ = composition_text_; 248 confirmed_text_ = composition_text_;
257 composition_text_.Clear(); 249 composition_text_.Clear();
258 } 250 }
259 virtual void ClearCompositionText() OVERRIDE { 251 virtual void ClearCompositionText() OVERRIDE {
260 composition_text_.Clear(); 252 composition_text_.Clear();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 base::string16* text) const OVERRIDE { 301 base::string16* text) const OVERRIDE {
310 *text = surrounding_text_.substr(range.GetMin(), range.length()); 302 *text = surrounding_text_.substr(range.GetMin(), range.length());
311 return true; 303 return true;
312 } 304 }
313 virtual void OnInputMethodChanged() OVERRIDE { 305 virtual void OnInputMethodChanged() OVERRIDE {
314 ++on_input_method_changed_call_count_; 306 ++on_input_method_changed_call_count_;
315 } 307 }
316 virtual bool ChangeTextDirectionAndLayoutAlignment( 308 virtual bool ChangeTextDirectionAndLayoutAlignment(
317 base::i18n::TextDirection direction) OVERRIDE { return false; } 309 base::i18n::TextDirection direction) OVERRIDE { return false; }
318 virtual void ExtendSelectionAndDelete(size_t before, 310 virtual void ExtendSelectionAndDelete(size_t before,
319 size_t after) OVERRIDE { } 311 size_t after) OVERRIDE {}
320 virtual void EnsureCaretInRect(const gfx::Rect& rect) OVERRIDE { } 312 virtual void EnsureCaretInRect(const gfx::Rect& rect) OVERRIDE {}
321 virtual void OnCandidateWindowShown() OVERRIDE { } 313 virtual void OnCandidateWindowShown() OVERRIDE {}
322 virtual void OnCandidateWindowUpdated() OVERRIDE { } 314 virtual void OnCandidateWindowUpdated() OVERRIDE {}
323 virtual void OnCandidateWindowHidden() OVERRIDE { } 315 virtual void OnCandidateWindowHidden() OVERRIDE {}
324 316
325 bool HasNativeEvent() const { 317 bool HasNativeEvent() const {
326 base::NativeEvent empty; 318 return dispatched_key_event_.HasNativeEvent();
327 std::memset(&empty, 0, sizeof(empty));
328 return !!std::memcmp(&dispatched_native_event_,
329 &empty,
330 sizeof(dispatched_native_event_));
331 } 319 }
332 320
333 void ResetFlags() { 321 void ResetFlags() {
334 std::memset(&dispatched_native_event_, 0, sizeof(dispatched_native_event_)); 322 dispatched_key_event_ = ui::KeyEvent(ui::ET_UNKNOWN, ui::VKEY_UNKNOWN, 0,
335 DCHECK(!HasNativeEvent()); 323 false);
336 dispatched_fabricated_event_type_ = ET_UNKNOWN;
337 dispatched_fabricated_event_key_code_ = VKEY_UNKNOWN;
338 dispatched_fabricated_event_flags_ = 0;
339 324
340 composition_text_.Clear(); 325 composition_text_.Clear();
341 confirmed_text_.Clear(); 326 confirmed_text_.Clear();
342 inserted_text_.clear(); 327 inserted_text_.clear();
343 inserted_char_ = 0; 328 inserted_char_ = 0;
344 inserted_char_flags_ = 0; 329 inserted_char_flags_ = 0;
345 on_input_method_changed_call_count_ = 0; 330 on_input_method_changed_call_count_ = 0;
346 331
347 input_type_ = TEXT_INPUT_TYPE_NONE; 332 input_type_ = TEXT_INPUT_TYPE_NONE;
348 input_mode_ = TEXT_INPUT_MODE_DEFAULT; 333 input_mode_ = TEXT_INPUT_MODE_DEFAULT;
349 can_compose_inline_ = true; 334 can_compose_inline_ = true;
350 caret_bounds_ = gfx::Rect(); 335 caret_bounds_ = gfx::Rect();
351 } 336 }
352 337
353 scoped_ptr<TestableInputMethodChromeOS> ime_; 338 scoped_ptr<TestableInputMethodChromeOS> ime_;
354 339
355 // Variables for remembering the parameters that are passed to 340 // Copy of the dispatched key event.
356 // ui::internal::InputMethodDelegate functions. 341 ui::KeyEvent dispatched_key_event_;
357 base::NativeEvent dispatched_native_event_;
358 ui::EventType dispatched_fabricated_event_type_;
359 ui::KeyboardCode dispatched_fabricated_event_key_code_;
360 int dispatched_fabricated_event_flags_;
361 342
362 // Variables for remembering the parameters that are passed to 343 // Variables for remembering the parameters that are passed to
363 // ui::TextInputClient functions. 344 // ui::TextInputClient functions.
364 CompositionText composition_text_; 345 CompositionText composition_text_;
365 CompositionText confirmed_text_; 346 CompositionText confirmed_text_;
366 base::string16 inserted_text_; 347 base::string16 inserted_text_;
367 base::char16 inserted_char_; 348 base::char16 inserted_char_;
368 unsigned int on_input_method_changed_call_count_; 349 unsigned int on_input_method_changed_call_count_;
369 int inserted_char_flags_; 350 int inserted_char_flags_;
370 351
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 ime_->ResetContext(); 998 ime_->ResetContext();
1018 999
1019 // Do callback. 1000 // Do callback.
1020 mock_ime_engine_handler_->last_passed_callback().Run(true); 1001 mock_ime_engine_handler_->last_passed_callback().Run(true);
1021 1002
1022 EXPECT_EQ(0, ime_->process_key_event_post_ime_call_count()); 1003 EXPECT_EQ(0, ime_->process_key_event_post_ime_call_count());
1023 } 1004 }
1024 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593). 1005 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593).
1025 1006
1026 } // namespace ui 1007 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/ime/input_method_base.cc ('k') | ui/base/ime/input_method_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698