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

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

Issue 1068093002: Refactoring for InputMethodAuraLinux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed a bug and add tests. Created 5 years, 8 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
OLDNEW
(Empty)
1 // Copyright 2015 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 "ui/base/ime/input_method_auralinux.h"
6
7 #include "base/strings/string_split.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/base/ime/dummy_text_input_client.h"
11 #include "ui/base/ime/input_method_delegate.h"
12 #include "ui/base/ime/input_method_initializer.h"
13 #include "ui/base/ime/linux/fake_input_method_context.h"
14 #include "ui/base/ime/linux/linux_input_method_context_factory.h"
15 #include "ui/events/event.h"
16
17 namespace ui {
18 namespace {
19
20 const base::char16 kActionCommit = L'C';
21 const base::char16 kActionCompositionStart = L'S';
22 const base::char16 kActionCompositionUpdate = L'U';
23 const base::char16 kActionCompositionEnd = L'E';
24
25 class LinuxInputMethodContextForTesting : public LinuxInputMethodContext {
26 public:
27 LinuxInputMethodContextForTesting(LinuxInputMethodContextDelegate* delegate,
28 bool is_simple)
29 : delegate_(delegate),
30 is_simple_(is_simple),
31 is_sync_mode_(false),
32 eat_key_(false),
33 focused_(false) {}
34
35 void SetSyncMode(bool is_sync_mode) { is_sync_mode_ = is_sync_mode; }
36 void SetEatKey(bool eat_key) { eat_key_ = eat_key; }
37
38 void AddCommitAction(const std::string& text) {
39 actions_.push_back(base::ASCIIToUTF16("C:" + text));
40 }
41
42 void AddCompositionUpdateAction(const std::string& text) {
43 actions_.push_back(base::ASCIIToUTF16("U:" + text));
44 }
45
46 void AddCompositionStartAction() {
47 actions_.push_back(base::ASCIIToUTF16("S"));
48 }
49
50 void AddCompositionEndAction() {
51 actions_.push_back(base::ASCIIToUTF16("E"));
52 }
53
54 protected:
55 bool DispatchKeyEvent(const ui::KeyEvent& key_event) override {
56 if (!is_sync_mode_) {
57 actions_.clear();
58 return eat_key_;
59 }
60
61 for (const auto& action : actions_) {
62 std::vector<base::string16> parts;
63 base::SplitString(action, L':', &parts);
64 base::char16 id = parts[0][0];
65 base::string16 param;
66 if (parts.size() > 1)
67 param = parts[1];
68 if (id == kActionCommit) {
69 delegate_->OnCommit(param);
70 } else if (id == kActionCompositionStart) {
71 delegate_->OnPreeditStart();
72 } else if (id == kActionCompositionUpdate) {
73 CompositionText comp;
74 comp.text = param;
75 delegate_->OnPreeditChanged(comp);
76 } else if (id == kActionCompositionEnd) {
77 delegate_->OnPreeditEnd();
78 }
79 }
80
81 actions_.clear();
82 return eat_key_;
83 }
84
85 void Reset() override {}
86
87 void Focus() override { focused_ = true; }
88
89 void Blur() override { focused_ = false; }
90
91 void SetCursorLocation(const gfx::Rect& rect) override {
92 cursor_position_ = rect;
93 }
94
95 private:
96 LinuxInputMethodContextDelegate* delegate_;
97 std::vector<base::string16> actions_;
98 bool is_simple_;
99 bool is_sync_mode_;
100 bool eat_key_;
101 bool focused_;
102 gfx::Rect cursor_position_;
103
104 DISALLOW_COPY_AND_ASSIGN(LinuxInputMethodContextForTesting);
105 };
106
107 class LinuxInputMethodContextFactoryForTesting
108 : public LinuxInputMethodContextFactory {
109 public:
110 LinuxInputMethodContextFactoryForTesting(){};
111
112 scoped_ptr<LinuxInputMethodContext> CreateInputMethodContext(
113 LinuxInputMethodContextDelegate* delegate,
114 bool is_simple) const override {
115 return scoped_ptr<ui::LinuxInputMethodContext>(
116 new LinuxInputMethodContextForTesting(delegate, is_simple));
117 };
118
119 private:
120 DISALLOW_COPY_AND_ASSIGN(LinuxInputMethodContextFactoryForTesting);
121 };
122
123 class InputMethodDelegateForTesting : public internal::InputMethodDelegate {
124 public:
125 InputMethodDelegateForTesting()
126 : key_type(ET_UNKNOWN), key_code(VKEY_UNKNOWN), key_flags(0){};
127 ~InputMethodDelegateForTesting() override{};
128
129 bool DispatchKeyEventPostIME(const ui::KeyEvent& key_event) override {
130 key_type = key_event.type();
131 key_code = key_event.key_code();
132 key_flags = key_event.flags();
133 return false;
134 }
135
136 void Clear() {
137 key_type = ET_UNKNOWN;
138 key_code = VKEY_UNKNOWN;
139 key_flags = 0;
140 }
141
142 EventType key_type;
143 KeyboardCode key_code;
144 int key_flags;
145
146 private:
147 DISALLOW_COPY_AND_ASSIGN(InputMethodDelegateForTesting);
148 };
149
150 class TextInputClientForTesting : public DummyTextInputClient {
151 public:
152 explicit TextInputClientForTesting(TextInputType text_input_type)
153 : DummyTextInputClient(text_input_type),
154 called_clear_composition(false),
155 called_confirm_composition(false),
156 called_set_composition(false),
157 called_insert_text(false),
158 called_insert_char(false){};
159
160 void Clear() {
161 composition_text.clear();
162 result_text.clear();
163 called_clear_composition = called_confirm_composition =
164 called_set_composition = called_insert_text = called_insert_char =
165 false;
166 }
167
168 base::string16 composition_text;
169 base::string16 result_text;
170 bool called_clear_composition;
171 bool called_confirm_composition;
172 bool called_set_composition;
173 bool called_insert_text;
174 bool called_insert_char;
175
176 protected:
177 void SetCompositionText(const CompositionText& composition) override {
178 composition_text = composition.text;
179 called_set_composition = true;
180 }
181
182 bool HasCompositionText() const override { return !composition_text.empty(); }
183
184 void ConfirmCompositionText() override {
185 composition_text.clear();
186 called_confirm_composition = true;
187 }
188
189 void ClearCompositionText() override {
190 composition_text.clear();
191 called_clear_composition = true;
192 }
193
194 void InsertText(const base::string16& text) override {
195 composition_text.clear();
196 result_text = text;
197 called_insert_text = true;
198 }
199
200 void InsertChar(base::char16 ch, int flags) override {
201 result_text = ch;
202 called_insert_char = true;
203 }
204 };
205
206 class InputMethodAuraLinuxTest : public testing::Test {
207 protected:
208 InputMethodAuraLinuxTest()
209 : factory_(NULL),
210 input_method_auralinux_(NULL),
211 delegate_(NULL),
212 context_(NULL),
213 context_simple_(NULL) {
214 factory_ = new LinuxInputMethodContextFactoryForTesting();
215 LinuxInputMethodContextFactory::SetInstance(factory_);
216 }
217 ~InputMethodAuraLinuxTest() override {
218 delete factory_;
219 factory_ = NULL;
220 }
221
222 void SetUp() override {
223 delegate_ = new InputMethodDelegateForTesting();
224 input_method_auralinux_ = new InputMethodAuraLinux(delegate_);
225 input_method_auralinux_->OnFocus();
226 context_ = static_cast<LinuxInputMethodContextForTesting*>(
227 input_method_auralinux_->GetContextForTesting(false));
228 context_simple_ = static_cast<LinuxInputMethodContextForTesting*>(
229 input_method_auralinux_->GetContextForTesting(true));
230 }
231
232 void TearDown() override {
233 context_->SetSyncMode(false);
234 context_->SetEatKey(false);
235
236 context_simple_->SetSyncMode(false);
237 context_simple_->SetEatKey(false);
238
239 context_ = NULL;
240 context_simple_ = NULL;
241
242 delete input_method_auralinux_;
243 input_method_auralinux_ = NULL;
244 delete delegate_;
245 delegate_ = NULL;
246 }
247
248 LinuxInputMethodContextFactoryForTesting* factory_;
249 InputMethodAuraLinux* input_method_auralinux_;
250 InputMethodDelegateForTesting* delegate_;
251 LinuxInputMethodContextForTesting* context_;
252 LinuxInputMethodContextForTesting* context_simple_;
253
254 DISALLOW_COPY_AND_ASSIGN(InputMethodAuraLinuxTest);
255 };
256
257 TEST_F(InputMethodAuraLinuxTest, BasicSyncModeTest) {
258 context_->SetSyncMode(true);
259 context_->SetEatKey(true);
260 context_->AddCommitAction("a");
261
262 scoped_ptr<TextInputClientForTesting> client(
263 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
264 input_method_auralinux_->SetFocusedTextInputClient(client.get());
265 input_method_auralinux_->OnTextInputTypeChanged(client.get());
266
267 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0);
268 key.set_character(L'a');
269 input_method_auralinux_->DispatchKeyEvent(key);
270
271 EXPECT_EQ(key.type(), delegate_->key_type);
272 EXPECT_EQ(key.key_code(), delegate_->key_code);
273 EXPECT_EQ(key.flags(), delegate_->key_flags);
274 EXPECT_FALSE(client->called_insert_text);
275 EXPECT_TRUE(client->called_insert_char);
276 EXPECT_EQ(1U, client->result_text.size());
277 EXPECT_EQ(key.GetCharacter(), client->result_text[0]);
278
279 input_method_auralinux_->DetachTextInputClient(client.get());
280 client.reset(new TextInputClientForTesting(TEXT_INPUT_TYPE_PASSWORD));
281 context_simple_->SetSyncMode(true);
282 context_simple_->SetEatKey(false);
283
284 input_method_auralinux_->SetFocusedTextInputClient(client.get());
285 input_method_auralinux_->OnTextInputTypeChanged(client.get());
286 input_method_auralinux_->DispatchKeyEvent(key);
287
288 EXPECT_EQ(key.type(), delegate_->key_type);
289 EXPECT_EQ(key.key_code(), delegate_->key_code);
290 EXPECT_EQ(key.flags(), delegate_->key_flags);
291 EXPECT_FALSE(client->called_insert_text);
292 EXPECT_TRUE(client->called_insert_char);
293 EXPECT_EQ(1U, client->result_text.size());
294 EXPECT_EQ(key.GetCharacter(), client->result_text[0]);
295 }
296
297 TEST_F(InputMethodAuraLinuxTest, BasicAsyncModeTest) {
298 context_->SetSyncMode(false);
299 context_->SetEatKey(true);
300
301 scoped_ptr<TextInputClientForTesting> client(
302 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
303 input_method_auralinux_->SetFocusedTextInputClient(client.get());
304 input_method_auralinux_->OnTextInputTypeChanged(client.get());
305 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0);
306 key.set_character(L'a');
307 input_method_auralinux_->DispatchKeyEvent(key);
308 input_method_auralinux_->OnCommit(base::ASCIIToUTF16("a"));
309
310 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
311 EXPECT_EQ(VKEY_PROCESSKEY, delegate_->key_code);
312 EXPECT_EQ(0, delegate_->key_flags);
313 EXPECT_TRUE(client->called_insert_text);
314 EXPECT_FALSE(client->called_insert_char);
315 EXPECT_EQ(1U, client->result_text.size());
316 EXPECT_EQ(key.GetCharacter(), client->result_text[0]);
317
318 input_method_auralinux_->DetachTextInputClient(client.get());
319 client.reset(new TextInputClientForTesting(TEXT_INPUT_TYPE_PASSWORD));
320 context_simple_->SetSyncMode(false);
321 context_simple_->SetEatKey(false);
322
323 input_method_auralinux_->SetFocusedTextInputClient(client.get());
324 input_method_auralinux_->OnTextInputTypeChanged(client.get());
325 input_method_auralinux_->DispatchKeyEvent(key);
326
327 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
328 EXPECT_EQ(VKEY_A, delegate_->key_code);
329 EXPECT_EQ(0, delegate_->key_flags);
330 EXPECT_FALSE(client->called_insert_text);
331 EXPECT_TRUE(client->called_insert_char);
332 EXPECT_EQ(1U, client->result_text.size());
333 EXPECT_EQ(key.GetCharacter(), client->result_text[0]);
334 }
335
336 TEST_F(InputMethodAuraLinuxTest, IBusUSTest) {
337 context_->SetSyncMode(false);
338 context_->SetEatKey(true);
339
340 scoped_ptr<TextInputClientForTesting> client(
341 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
342 input_method_auralinux_->SetFocusedTextInputClient(client.get());
343 input_method_auralinux_->OnTextInputTypeChanged(client.get());
344 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0);
345 key.set_character(L'a');
346 input_method_auralinux_->DispatchKeyEvent(key);
347
348 // IBus mutes the key down.
349 EXPECT_EQ(VKEY_UNKNOWN, delegate_->key_code);
350 EXPECT_FALSE(client->called_insert_text);
351 EXPECT_FALSE(client->called_insert_char);
352
353 // IBus simulates a faked key down and handle it in sync mode.
354 context_->SetSyncMode(true);
355 context_->AddCommitAction("a");
356 input_method_auralinux_->DispatchKeyEvent(key);
357
358 EXPECT_EQ(VKEY_A, delegate_->key_code);
359 EXPECT_FALSE(client->called_insert_text);
360 EXPECT_TRUE(client->called_insert_char);
361 EXPECT_EQ(1U, client->result_text.size());
362 EXPECT_EQ(key.GetCharacter(), client->result_text[0]);
363
364 // IBus does NOT handle the key up.
365 client->Clear();
366 context_->SetEatKey(false);
367 input_method_auralinux_->DispatchKeyEvent(
368 KeyEvent(ET_KEY_RELEASED, VKEY_A, 0));
369
370 EXPECT_EQ(ET_KEY_RELEASED, delegate_->key_type);
371 EXPECT_EQ(VKEY_A, delegate_->key_code);
372 EXPECT_FALSE(client->called_insert_text);
373 EXPECT_FALSE(client->called_insert_char);
374 }
375
376 TEST_F(InputMethodAuraLinuxTest, IBusPinyinTest) {
377 context_->SetSyncMode(false);
378 context_->SetEatKey(true);
379
380 scoped_ptr<TextInputClientForTesting> client(
381 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
382 input_method_auralinux_->SetFocusedTextInputClient(client.get());
383 input_method_auralinux_->OnTextInputTypeChanged(client.get());
384 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0);
385 key.set_character(L'a');
386 input_method_auralinux_->DispatchKeyEvent(key);
387
388 // IBus mutes the key down.
389 EXPECT_EQ(VKEY_UNKNOWN, delegate_->key_code);
390 EXPECT_FALSE(client->called_insert_text);
391 EXPECT_FALSE(client->called_insert_char);
392 delegate_->Clear();
393
394 // IBus issues a standalone set_composition action.
395 input_method_auralinux_->OnPreeditStart();
396 CompositionText comp;
397 comp.text = base::ASCIIToUTF16("a");
398 input_method_auralinux_->OnPreeditChanged(comp);
399
400 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
401 EXPECT_EQ(VKEY_PROCESSKEY, delegate_->key_code);
402 EXPECT_TRUE(client->called_set_composition);
403 EXPECT_EQ(1U, client->composition_text.size());
404 EXPECT_EQ(L'a', client->composition_text[0]);
405 delegate_->Clear();
406
407 // IBus issues a commit text with composition after muting the space key down.
408 input_method_auralinux_->DispatchKeyEvent(
409 KeyEvent(ET_KEY_PRESSED, VKEY_SPACE, 0));
410 EXPECT_EQ(VKEY_UNKNOWN, delegate_->key_code);
411 EXPECT_FALSE(client->called_insert_text);
412 EXPECT_FALSE(client->called_insert_char);
413 delegate_->Clear();
414
415 input_method_auralinux_->OnPreeditEnd();
416 input_method_auralinux_->OnCommit(base::ASCIIToUTF16("A"));
417
418 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
419 EXPECT_EQ(VKEY_PROCESSKEY, delegate_->key_code);
420 EXPECT_TRUE(client->called_clear_composition);
421 EXPECT_TRUE(client->called_insert_text);
422 EXPECT_EQ(1U, client->result_text.size());
423 EXPECT_EQ(L'A', client->result_text[0]);
424 }
425
426 // crbug.com/463491
427 TEST_F(InputMethodAuraLinuxTest, DeadKeyTest) {
428 context_simple_->SetSyncMode(true);
429 context_simple_->SetEatKey(true);
430
431 scoped_ptr<TextInputClientForTesting> client(
432 new TextInputClientForTesting(TEXT_INPUT_TYPE_NONE));
433 input_method_auralinux_->SetFocusedTextInputClient(client.get());
434 input_method_auralinux_->OnTextInputTypeChanged(client.get());
435 KeyEvent dead_key(ET_KEY_PRESSED, VKEY_OEM_7, 0);
436 dead_key.set_character(L'\'');
437 input_method_auralinux_->DispatchKeyEvent(dead_key);
438
439 // The single quote key is muted.
440 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
441 EXPECT_EQ(VKEY_OEM_7, delegate_->key_code);
442 EXPECT_FALSE(client->called_insert_text);
443 EXPECT_FALSE(client->called_insert_char);
444 delegate_->Clear();
445
446 context_simple_->AddCommitAction("X");
447 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0);
448 key.set_character(L'a');
449 input_method_auralinux_->DispatchKeyEvent(key);
450
451 // The following A key generates the accent key: รก.
452 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
453 EXPECT_EQ(VKEY_A, delegate_->key_code);
454 EXPECT_FALSE(client->called_insert_text);
455 EXPECT_TRUE(client->called_insert_char);
456 EXPECT_EQ(1U, client->result_text.size());
457 EXPECT_EQ(L'X', client->result_text[0]);
458 }
459
460 TEST_F(InputMethodAuraLinuxTest, MultiCommitsTest) {
461 context_->SetSyncMode(true);
462 context_->SetEatKey(true);
463 context_->AddCommitAction("a");
464 context_->AddCommitAction("b");
465 context_->AddCommitAction("c");
466
467 scoped_ptr<TextInputClientForTesting> client(
468 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
469 input_method_auralinux_->SetFocusedTextInputClient(client.get());
470 input_method_auralinux_->OnTextInputTypeChanged(client.get());
471
472 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0);
473 key.set_character(L'a');
474 input_method_auralinux_->DispatchKeyEvent(key);
475
476 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
477 EXPECT_EQ(VKEY_PROCESSKEY, delegate_->key_code);
478 EXPECT_TRUE(client->called_insert_text);
479 EXPECT_FALSE(client->called_insert_char);
480 EXPECT_EQ(base::ASCIIToUTF16("abc"), client->result_text);
481 }
482
483 TEST_F(InputMethodAuraLinuxTest, MixedCompositionAndCommitTest) {
484 context_->SetSyncMode(true);
485 context_->SetEatKey(true);
486 context_->AddCommitAction("a");
487 context_->AddCompositionStartAction();
488 context_->AddCompositionUpdateAction("b");
489 context_->AddCommitAction("c");
490 context_->AddCompositionUpdateAction("d");
491
492 scoped_ptr<TextInputClientForTesting> client(
493 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
494 input_method_auralinux_->SetFocusedTextInputClient(client.get());
495 input_method_auralinux_->OnTextInputTypeChanged(client.get());
496
497 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0);
498 key.set_character(L'a');
499 input_method_auralinux_->DispatchKeyEvent(key);
500
501 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
502 EXPECT_EQ(VKEY_PROCESSKEY, delegate_->key_code);
503 EXPECT_TRUE(client->called_set_composition);
504 EXPECT_TRUE(client->called_insert_text);
505 EXPECT_FALSE(client->called_insert_char);
506 EXPECT_EQ(base::ASCIIToUTF16("d"), client->composition_text);
507 EXPECT_EQ(base::ASCIIToUTF16("ac"), client->result_text);
508 }
509
510 TEST_F(InputMethodAuraLinuxTest, CompositionEndWithoutCommitTest) {
511 context_->SetSyncMode(true);
512 context_->SetEatKey(true);
513 context_->AddCompositionStartAction();
514 context_->AddCompositionUpdateAction("a");
515
516 scoped_ptr<TextInputClientForTesting> client(
517 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
518 input_method_auralinux_->SetFocusedTextInputClient(client.get());
519 input_method_auralinux_->OnTextInputTypeChanged(client.get());
520
521 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0);
522 key.set_character(L'a');
523 input_method_auralinux_->DispatchKeyEvent(key);
524
525 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
526 EXPECT_EQ(VKEY_PROCESSKEY, delegate_->key_code);
527 EXPECT_TRUE(client->called_set_composition);
528 EXPECT_FALSE(client->called_insert_text);
529 EXPECT_FALSE(client->called_insert_char);
530 EXPECT_EQ(base::ASCIIToUTF16("a"), client->composition_text);
531
532 delegate_->Clear();
533 context_->AddCompositionEndAction();
534 input_method_auralinux_->DispatchKeyEvent(key);
535
536 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
537 EXPECT_EQ(VKEY_PROCESSKEY, delegate_->key_code);
538 EXPECT_TRUE(client->called_clear_composition);
539 EXPECT_EQ(0U, client->composition_text.length());
540 }
541
542 TEST_F(InputMethodAuraLinuxTest, CompositionEndWithEmptyCommitTest) {
543 context_->SetSyncMode(true);
544 context_->SetEatKey(true);
545 context_->AddCompositionStartAction();
546 context_->AddCompositionUpdateAction("a");
547
548 scoped_ptr<TextInputClientForTesting> client(
549 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
550 input_method_auralinux_->SetFocusedTextInputClient(client.get());
551 input_method_auralinux_->OnTextInputTypeChanged(client.get());
552
553 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0);
554 key.set_character(L'a');
555 input_method_auralinux_->DispatchKeyEvent(key);
556
557 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
558 EXPECT_EQ(VKEY_PROCESSKEY, delegate_->key_code);
559 EXPECT_TRUE(client->called_set_composition);
560 EXPECT_FALSE(client->called_insert_text);
561 EXPECT_FALSE(client->called_insert_char);
562 EXPECT_EQ(base::ASCIIToUTF16("a"), client->composition_text);
563
564 delegate_->Clear();
565 context_->AddCompositionEndAction();
566 context_->AddCommitAction("");
567 input_method_auralinux_->DispatchKeyEvent(key);
568
569 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
570 EXPECT_EQ(VKEY_PROCESSKEY, delegate_->key_code);
571 EXPECT_TRUE(client->called_clear_composition);
572 EXPECT_EQ(0U, client->composition_text.length());
573 EXPECT_EQ(0U, client->result_text.length());
574 }
575
576 TEST_F(InputMethodAuraLinuxTest, CompositionEndWithCommitTest) {
577 context_->SetSyncMode(true);
578 context_->SetEatKey(true);
579 context_->AddCompositionStartAction();
580 context_->AddCompositionUpdateAction("a");
581
582 scoped_ptr<TextInputClientForTesting> client(
583 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
584 input_method_auralinux_->SetFocusedTextInputClient(client.get());
585 input_method_auralinux_->OnTextInputTypeChanged(client.get());
586
587 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0);
588 key.set_character(L'a');
589 input_method_auralinux_->DispatchKeyEvent(key);
590
591 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
592 EXPECT_EQ(VKEY_PROCESSKEY, delegate_->key_code);
593 EXPECT_TRUE(client->called_set_composition);
594 EXPECT_FALSE(client->called_insert_text);
595 EXPECT_FALSE(client->called_insert_char);
596 EXPECT_EQ(base::ASCIIToUTF16("a"), client->composition_text);
597
598 delegate_->Clear();
599 context_->AddCompositionEndAction();
600 context_->AddCommitAction("b");
601 input_method_auralinux_->DispatchKeyEvent(key);
602
603 // Verifies single char commit under composition mode will call InsertText
604 // intead of InsertChar.
605 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
606 EXPECT_EQ(VKEY_PROCESSKEY, delegate_->key_code);
607 // No need to clear composition with commit.
608 EXPECT_FALSE(client->called_clear_composition);
609 EXPECT_EQ(0U, client->composition_text.length());
610 EXPECT_EQ(base::ASCIIToUTF16("b"), client->result_text);
611 }
612
613 TEST_F(InputMethodAuraLinuxTest, CompositionUpdateWithCommitTest) {
614 context_->SetSyncMode(true);
615 context_->SetEatKey(true);
616 context_->AddCompositionStartAction();
617 context_->AddCompositionUpdateAction("a");
618 context_->AddCommitAction("b");
619
620 scoped_ptr<TextInputClientForTesting> client(
621 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
622 input_method_auralinux_->SetFocusedTextInputClient(client.get());
623 input_method_auralinux_->OnTextInputTypeChanged(client.get());
624
625 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0);
626 key.set_character(L'a');
627 input_method_auralinux_->DispatchKeyEvent(key);
628
629 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
630 EXPECT_EQ(VKEY_PROCESSKEY, delegate_->key_code);
631 EXPECT_TRUE(client->called_set_composition);
632 EXPECT_TRUE(client->called_insert_text);
633 EXPECT_FALSE(client->called_insert_char);
634 EXPECT_EQ(base::ASCIIToUTF16("b"), client->result_text);
635 EXPECT_EQ(base::ASCIIToUTF16("a"), client->composition_text);
636 }
637
638 TEST_F(InputMethodAuraLinuxTest, MixedAsyncAndSyncTest) {
639 context_->SetSyncMode(false);
640 context_->SetEatKey(true);
641
642 scoped_ptr<TextInputClientForTesting> client(
643 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
644 input_method_auralinux_->SetFocusedTextInputClient(client.get());
645 input_method_auralinux_->OnTextInputTypeChanged(client.get());
646
647 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0);
648 key.set_character(L'a');
649 input_method_auralinux_->DispatchKeyEvent(key);
650 CompositionText comp;
651 comp.text = base::ASCIIToUTF16("a");
652 input_method_auralinux_->OnPreeditChanged(comp);
653
654 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
655 EXPECT_EQ(VKEY_PROCESSKEY, delegate_->key_code);
656 EXPECT_TRUE(client->called_set_composition);
657 EXPECT_FALSE(client->called_insert_text);
658 EXPECT_EQ(base::ASCIIToUTF16("a"), client->composition_text);
659
660 delegate_->Clear();
661 context_->SetSyncMode(true);
662 context_->AddCompositionEndAction();
663 context_->AddCommitAction("b");
664
665 input_method_auralinux_->DispatchKeyEvent(key);
666
667 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
668 EXPECT_EQ(VKEY_PROCESSKEY, delegate_->key_code);
669 EXPECT_TRUE(client->called_insert_text);
670 EXPECT_FALSE(client->called_insert_char);
671 EXPECT_EQ(base::ASCIIToUTF16("b"), client->result_text);
672 EXPECT_EQ(base::ASCIIToUTF16(""), client->composition_text);
673 }
674
675 TEST_F(InputMethodAuraLinuxTest, MixedSyncAndAsyncTest) {
676 context_->SetSyncMode(true);
677 context_->SetEatKey(true);
678 context_->AddCompositionStartAction();
679 context_->AddCompositionUpdateAction("a");
680
681 scoped_ptr<TextInputClientForTesting> client(
682 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
683 input_method_auralinux_->SetFocusedTextInputClient(client.get());
684 input_method_auralinux_->OnTextInputTypeChanged(client.get());
685
686 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0);
687 key.set_character(L'a');
688 input_method_auralinux_->DispatchKeyEvent(key);
689
690 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
691 EXPECT_EQ(VKEY_PROCESSKEY, delegate_->key_code);
692 EXPECT_TRUE(client->called_set_composition);
693 EXPECT_FALSE(client->called_insert_text);
694 EXPECT_EQ(base::ASCIIToUTF16("a"), client->composition_text);
695
696 delegate_->Clear();
697 context_->SetSyncMode(false);
698
699 input_method_auralinux_->DispatchKeyEvent(key);
700 input_method_auralinux_->OnCommit(base::ASCIIToUTF16("b"));
701
702 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
703 EXPECT_EQ(VKEY_PROCESSKEY, delegate_->key_code);
704 EXPECT_TRUE(client->called_insert_text);
705 EXPECT_FALSE(client->called_insert_char);
706 EXPECT_EQ(base::ASCIIToUTF16("b"), client->result_text);
707 EXPECT_EQ(base::ASCIIToUTF16(""), client->composition_text);
708
709 delegate_->Clear();
710 client->Clear();
711 context_->SetSyncMode(true);
712 context_->AddCommitAction("c");
713 input_method_auralinux_->DispatchKeyEvent(key);
714
715 EXPECT_EQ(ET_KEY_PRESSED, delegate_->key_type);
716 EXPECT_EQ(VKEY_A, delegate_->key_code);
717 EXPECT_FALSE(client->called_insert_text);
718 EXPECT_TRUE(client->called_insert_char);
719 EXPECT_EQ(base::ASCIIToUTF16("c"), client->result_text);
720 }
721
722 } // namespace
723 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698