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.
5 #include "ui/base/ime/input_method_auralinux.h"
7 #include "base/memory/singleton.h"
8 #include "base/strings/string_split.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/base/ime/dummy_text_input_client.h"
12 #include "ui/base/ime/input_method_delegate.h"
13 #include "ui/base/ime/input_method_initializer.h"
14 #include "ui/base/ime/linux/fake_input_method_context.h"
15 #include "ui/base/ime/linux/linux_input_method_context_factory.h"
16 #include "ui/events/event.h"
21 const base::char16 kActionCommit
= L
'C';
22 const base::char16 kActionCompositionStart
= L
'S';
23 const base::char16 kActionCompositionUpdate
= L
'U';
24 const base::char16 kActionCompositionEnd
= L
'E';
28 static TestResult
* GetInstance() {
29 return base::Singleton
<TestResult
>::get();
32 void RecordAction(const base::string16
& action
) {
33 recorded_actions_
.push_back(action
);
36 void ExpectAction(const std::string
& action
) {
37 expected_actions_
.push_back(base::ASCIIToUTF16(action
));
41 size_t len
= recorded_actions_
.size();
42 size_t len_exp
= expected_actions_
.size();
43 EXPECT_EQ(len_exp
, len
);
44 for (size_t i
= 0; i
< len
; i
++)
45 EXPECT_EQ(expected_actions_
[i
], recorded_actions_
[i
]);
46 recorded_actions_
.clear();
47 expected_actions_
.clear();
51 std::vector
<base::string16
> recorded_actions_
;
52 std::vector
<base::string16
> expected_actions_
;
55 class LinuxInputMethodContextForTesting
: public LinuxInputMethodContext
{
57 LinuxInputMethodContextForTesting(LinuxInputMethodContextDelegate
* delegate
,
59 : delegate_(delegate
),
60 is_simple_(is_simple
),
65 void SetSyncMode(bool is_sync_mode
) { is_sync_mode_
= is_sync_mode
; }
66 void SetEatKey(bool eat_key
) { eat_key_
= eat_key
; }
68 void AddCommitAction(const std::string
& text
) {
69 actions_
.push_back(base::ASCIIToUTF16("C:" + text
));
72 void AddCompositionUpdateAction(const std::string
& text
) {
73 actions_
.push_back(base::ASCIIToUTF16("U:" + text
));
76 void AddCompositionStartAction() {
77 actions_
.push_back(base::ASCIIToUTF16("S"));
80 void AddCompositionEndAction() {
81 actions_
.push_back(base::ASCIIToUTF16("E"));
85 bool DispatchKeyEvent(const ui::KeyEvent
& key_event
) override
{
91 for (const auto& action
: actions_
) {
92 std::vector
<base::string16
> parts
= base::SplitString(
93 action
, base::string16(1, ':'), base::TRIM_WHITESPACE
,
94 base::SPLIT_WANT_ALL
);
95 base::char16 id
= parts
[0][0];
99 if (id
== kActionCommit
) {
100 delegate_
->OnCommit(param
);
101 } else if (id
== kActionCompositionStart
) {
102 delegate_
->OnPreeditStart();
103 } else if (id
== kActionCompositionUpdate
) {
104 CompositionText comp
;
106 delegate_
->OnPreeditChanged(comp
);
107 } else if (id
== kActionCompositionEnd
) {
108 delegate_
->OnPreeditEnd();
116 void Reset() override
{}
118 void Focus() override
{ focused_
= true; }
120 void Blur() override
{ focused_
= false; }
122 void SetCursorLocation(const gfx::Rect
& rect
) override
{
123 cursor_position_
= rect
;
127 LinuxInputMethodContextDelegate
* delegate_
;
128 std::vector
<base::string16
> actions_
;
133 gfx::Rect cursor_position_
;
135 DISALLOW_COPY_AND_ASSIGN(LinuxInputMethodContextForTesting
);
138 class LinuxInputMethodContextFactoryForTesting
139 : public LinuxInputMethodContextFactory
{
141 LinuxInputMethodContextFactoryForTesting(){};
143 scoped_ptr
<LinuxInputMethodContext
> CreateInputMethodContext(
144 LinuxInputMethodContextDelegate
* delegate
,
145 bool is_simple
) const override
{
146 return scoped_ptr
<ui::LinuxInputMethodContext
>(
147 new LinuxInputMethodContextForTesting(delegate
, is_simple
));
151 DISALLOW_COPY_AND_ASSIGN(LinuxInputMethodContextFactoryForTesting
);
154 class InputMethodDelegateForTesting
: public internal::InputMethodDelegate
{
156 InputMethodDelegateForTesting(){};
157 ~InputMethodDelegateForTesting() override
{};
159 ui::EventDispatchDetails
DispatchKeyEventPostIME(
160 ui::KeyEvent
* key_event
) override
{
162 switch (key_event
->type()) {
166 case ET_KEY_RELEASED
:
172 std::stringstream ss
;
173 ss
<< key_event
->key_code();
174 action
+= std::string(ss
.str());
175 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16(action
));
176 return ui::EventDispatchDetails();
180 DISALLOW_COPY_AND_ASSIGN(InputMethodDelegateForTesting
);
183 class TextInputClientForTesting
: public DummyTextInputClient
{
185 explicit TextInputClientForTesting(TextInputType text_input_type
)
186 : DummyTextInputClient(text_input_type
){};
188 base::string16 composition_text
;
191 void SetCompositionText(const CompositionText
& composition
) override
{
192 composition_text
= composition
.text
;
193 TestResult::GetInstance()->RecordAction(
194 base::ASCIIToUTF16("compositionstart"));
195 TestResult::GetInstance()->RecordAction(
196 base::ASCIIToUTF16("compositionupdate:") + composition
.text
);
199 bool HasCompositionText() const override
{ return !composition_text
.empty(); }
201 void ConfirmCompositionText() override
{
202 TestResult::GetInstance()->RecordAction(
203 base::ASCIIToUTF16("compositionend"));
204 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16("textinput:") +
206 composition_text
.clear();
209 void ClearCompositionText() override
{
210 TestResult::GetInstance()->RecordAction(
211 base::ASCIIToUTF16("compositionend"));
212 composition_text
.clear();
215 void InsertText(const base::string16
& text
) override
{
216 if (HasCompositionText()) {
217 TestResult::GetInstance()->RecordAction(
218 base::ASCIIToUTF16("compositionend"));
220 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16("textinput:") +
222 composition_text
.clear();
225 void InsertChar(base::char16 ch
, int flags
) override
{
226 std::stringstream ss
;
228 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16("keypress:") +
229 base::ASCIIToUTF16(ss
.str()));
233 class InputMethodAuraLinuxTest
: public testing::Test
{
235 InputMethodAuraLinuxTest()
237 input_method_auralinux_(NULL
),
240 context_simple_(NULL
) {
241 factory_
= new LinuxInputMethodContextFactoryForTesting();
242 LinuxInputMethodContextFactory::SetInstance(factory_
);
243 test_result_
= TestResult::GetInstance();
245 ~InputMethodAuraLinuxTest() override
{
251 void SetUp() override
{
252 delegate_
= new InputMethodDelegateForTesting();
253 input_method_auralinux_
= new InputMethodAuraLinux(delegate_
);
254 input_method_auralinux_
->OnFocus();
255 context_
= static_cast<LinuxInputMethodContextForTesting
*>(
256 input_method_auralinux_
->GetContextForTesting(false));
257 context_simple_
= static_cast<LinuxInputMethodContextForTesting
*>(
258 input_method_auralinux_
->GetContextForTesting(true));
261 void TearDown() override
{
262 context_
->SetSyncMode(false);
263 context_
->SetEatKey(false);
265 context_simple_
->SetSyncMode(false);
266 context_simple_
->SetEatKey(false);
269 context_simple_
= NULL
;
271 delete input_method_auralinux_
;
272 input_method_auralinux_
= NULL
;
277 LinuxInputMethodContextFactoryForTesting
* factory_
;
278 InputMethodAuraLinux
* input_method_auralinux_
;
279 InputMethodDelegateForTesting
* delegate_
;
280 LinuxInputMethodContextForTesting
* context_
;
281 LinuxInputMethodContextForTesting
* context_simple_
;
282 TestResult
* test_result_
;
284 DISALLOW_COPY_AND_ASSIGN(InputMethodAuraLinuxTest
);
287 TEST_F(InputMethodAuraLinuxTest
, BasicSyncModeTest
) {
288 context_
->SetSyncMode(true);
289 context_
->SetEatKey(true);
290 context_
->AddCommitAction("a");
292 scoped_ptr
<TextInputClientForTesting
> client(
293 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
294 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
295 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
297 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
298 key_new
.set_character(L
'a');
300 KeyEvent key
= key_new
;
301 input_method_auralinux_
->DispatchKeyEvent(&key
);
303 test_result_
->ExpectAction("keydown:65");
304 test_result_
->ExpectAction("keypress:97");
305 test_result_
->Verify();
307 input_method_auralinux_
->DetachTextInputClient(client
.get());
308 client
.reset(new TextInputClientForTesting(TEXT_INPUT_TYPE_PASSWORD
));
309 context_simple_
->SetSyncMode(true);
310 context_simple_
->SetEatKey(false);
312 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
313 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
315 input_method_auralinux_
->DispatchKeyEvent(&key
);
317 test_result_
->ExpectAction("keydown:65");
318 test_result_
->ExpectAction("keypress:97");
319 test_result_
->Verify();
322 TEST_F(InputMethodAuraLinuxTest
, BasicAsyncModeTest
) {
323 context_
->SetSyncMode(false);
324 context_
->SetEatKey(true);
326 scoped_ptr
<TextInputClientForTesting
> client(
327 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
328 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
329 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
330 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
331 key_new
.set_character(L
'a');
332 KeyEvent key
= key_new
;
333 input_method_auralinux_
->DispatchKeyEvent(&key
);
334 input_method_auralinux_
->OnCommit(base::ASCIIToUTF16("a"));
336 test_result_
->ExpectAction("keydown:229");
337 test_result_
->ExpectAction("textinput:a");
338 test_result_
->Verify();
340 input_method_auralinux_
->DetachTextInputClient(client
.get());
341 client
.reset(new TextInputClientForTesting(TEXT_INPUT_TYPE_PASSWORD
));
342 context_simple_
->SetSyncMode(false);
343 context_simple_
->SetEatKey(false);
345 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
346 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
348 input_method_auralinux_
->DispatchKeyEvent(&key
);
350 test_result_
->ExpectAction("keydown:65");
351 test_result_
->ExpectAction("keypress:97");
352 test_result_
->Verify();
355 TEST_F(InputMethodAuraLinuxTest
, IBusUSTest
) {
356 context_
->SetSyncMode(false);
357 context_
->SetEatKey(true);
359 scoped_ptr
<TextInputClientForTesting
> client(
360 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
361 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
362 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
363 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
364 key_new
.set_character(L
'a');
365 KeyEvent key
= key_new
;
366 input_method_auralinux_
->DispatchKeyEvent(&key
);
368 // IBus mutes the key down.
369 test_result_
->Verify();
371 // IBus simulates a faked key down and handle it in sync mode.
372 context_
->SetSyncMode(true);
373 context_
->AddCommitAction("a");
375 input_method_auralinux_
->DispatchKeyEvent(&key
);
377 test_result_
->ExpectAction("keydown:65");
378 test_result_
->ExpectAction("keypress:97");
379 test_result_
->Verify();
381 // IBus does NOT handle the key up.
382 context_
->SetEatKey(false);
383 KeyEvent
key_up(ET_KEY_RELEASED
, VKEY_A
, 0);
384 input_method_auralinux_
->DispatchKeyEvent(&key_up
);
386 test_result_
->ExpectAction("keyup:65");
387 test_result_
->Verify();
390 TEST_F(InputMethodAuraLinuxTest
, IBusPinyinTest
) {
391 context_
->SetSyncMode(false);
392 context_
->SetEatKey(true);
394 scoped_ptr
<TextInputClientForTesting
> client(
395 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
396 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
397 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
398 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
399 key
.set_character(L
'a');
400 input_method_auralinux_
->DispatchKeyEvent(&key
);
402 // IBus issues a standalone set_composition action.
403 input_method_auralinux_
->OnPreeditStart();
404 CompositionText comp
;
405 comp
.text
= base::ASCIIToUTF16("a");
406 input_method_auralinux_
->OnPreeditChanged(comp
);
408 test_result_
->ExpectAction("keydown:229");
409 test_result_
->ExpectAction("compositionstart");
410 test_result_
->ExpectAction("compositionupdate:a");
411 test_result_
->Verify();
413 // IBus issues a commit text with composition after muting the space key down.
414 KeyEvent
key_up(ET_KEY_RELEASED
, VKEY_SPACE
, 0);
415 input_method_auralinux_
->DispatchKeyEvent(&key_up
);
417 input_method_auralinux_
->OnPreeditEnd();
418 input_method_auralinux_
->OnCommit(base::ASCIIToUTF16("A"));
420 test_result_
->ExpectAction("keydown:229");
421 test_result_
->ExpectAction("compositionend");
422 test_result_
->ExpectAction("keydown:229");
423 test_result_
->ExpectAction("textinput:A");
424 test_result_
->Verify();
428 TEST_F(InputMethodAuraLinuxTest
, DeadKeyTest
) {
429 context_simple_
->SetSyncMode(true);
430 context_simple_
->SetEatKey(true);
432 scoped_ptr
<TextInputClientForTesting
> client(
433 new TextInputClientForTesting(TEXT_INPUT_TYPE_NONE
));
434 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
435 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
437 KeyEvent
dead_key(ET_KEY_PRESSED
, VKEY_OEM_7
, 0);
438 dead_key
.set_character(L
'\'');
439 input_method_auralinux_
->DispatchKeyEvent(&dead_key
);
441 // The single quote key is muted.
442 test_result_
->ExpectAction("keydown:222");
443 test_result_
->Verify();
445 context_simple_
->AddCommitAction("X");
446 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
447 key
.set_character(L
'a');
448 input_method_auralinux_
->DispatchKeyEvent(&key
);
450 // The following A key generates the accent key: á.
451 test_result_
->ExpectAction("keydown:65");
452 test_result_
->ExpectAction("keypress:88");
453 test_result_
->Verify();
456 TEST_F(InputMethodAuraLinuxTest
, MultiCommitsTest
) {
457 context_
->SetSyncMode(true);
458 context_
->SetEatKey(true);
459 context_
->AddCommitAction("a");
460 context_
->AddCommitAction("b");
461 context_
->AddCommitAction("c");
463 scoped_ptr
<TextInputClientForTesting
> client(
464 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
465 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
466 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
468 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
469 key
.set_character(L
'a');
470 input_method_auralinux_
->DispatchKeyEvent(&key
);
472 test_result_
->ExpectAction("keydown:229");
473 test_result_
->ExpectAction("textinput:abc");
474 test_result_
->Verify();
477 TEST_F(InputMethodAuraLinuxTest
, MixedCompositionAndCommitTest
) {
478 context_
->SetSyncMode(true);
479 context_
->SetEatKey(true);
480 context_
->AddCommitAction("a");
481 context_
->AddCompositionStartAction();
482 context_
->AddCompositionUpdateAction("b");
483 context_
->AddCommitAction("c");
484 context_
->AddCompositionUpdateAction("d");
486 scoped_ptr
<TextInputClientForTesting
> client(
487 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
488 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
489 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
491 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
492 key_new
.set_character(L
'a');
493 KeyEvent key
= key_new
;
494 input_method_auralinux_
->DispatchKeyEvent(&key
);
496 test_result_
->ExpectAction("keydown:229");
497 test_result_
->ExpectAction("textinput:ac");
498 test_result_
->ExpectAction("compositionstart");
499 test_result_
->ExpectAction("compositionupdate:d");
500 test_result_
->Verify();
502 context_
->AddCommitAction("e");
504 input_method_auralinux_
->DispatchKeyEvent(&key
);
506 test_result_
->ExpectAction("keydown:229");
507 test_result_
->ExpectAction("compositionend");
508 test_result_
->ExpectAction("textinput:e");
509 test_result_
->Verify();
512 TEST_F(InputMethodAuraLinuxTest
, CompositionEndWithoutCommitTest
) {
513 context_
->SetSyncMode(true);
514 context_
->SetEatKey(true);
515 context_
->AddCompositionStartAction();
516 context_
->AddCompositionUpdateAction("a");
518 scoped_ptr
<TextInputClientForTesting
> client(
519 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
520 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
521 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
523 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
524 key_new
.set_character(L
'a');
525 KeyEvent key
= key_new
;
526 input_method_auralinux_
->DispatchKeyEvent(&key
);
528 test_result_
->ExpectAction("keydown:229");
529 test_result_
->ExpectAction("compositionstart");
530 test_result_
->ExpectAction("compositionupdate:a");
531 test_result_
->Verify();
533 context_
->AddCompositionEndAction();
535 input_method_auralinux_
->DispatchKeyEvent(&key
);
537 test_result_
->ExpectAction("keydown:229");
538 test_result_
->ExpectAction("compositionend");
539 test_result_
->Verify();
542 TEST_F(InputMethodAuraLinuxTest
, CompositionEndWithEmptyCommitTest
) {
543 context_
->SetSyncMode(true);
544 context_
->SetEatKey(true);
545 context_
->AddCompositionStartAction();
546 context_
->AddCompositionUpdateAction("a");
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());
553 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
554 key_new
.set_character(L
'a');
555 KeyEvent key
= key_new
;
556 input_method_auralinux_
->DispatchKeyEvent(&key
);
558 test_result_
->ExpectAction("keydown:229");
559 test_result_
->ExpectAction("compositionstart");
560 test_result_
->ExpectAction("compositionupdate:a");
561 test_result_
->Verify();
563 context_
->AddCompositionEndAction();
564 context_
->AddCommitAction("");
566 input_method_auralinux_
->DispatchKeyEvent(&key
);
568 test_result_
->ExpectAction("keydown:229");
569 test_result_
->ExpectAction("compositionend");
570 test_result_
->Verify();
573 TEST_F(InputMethodAuraLinuxTest
, CompositionEndWithCommitTest
) {
574 context_
->SetSyncMode(true);
575 context_
->SetEatKey(true);
576 context_
->AddCompositionStartAction();
577 context_
->AddCompositionUpdateAction("a");
579 scoped_ptr
<TextInputClientForTesting
> client(
580 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
581 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
582 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
584 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
585 key_new
.set_character(L
'a');
586 KeyEvent key
= key_new
;
587 input_method_auralinux_
->DispatchKeyEvent(&key
);
589 test_result_
->ExpectAction("keydown:229");
590 test_result_
->ExpectAction("compositionstart");
591 test_result_
->ExpectAction("compositionupdate:a");
592 test_result_
->Verify();
594 context_
->AddCompositionEndAction();
595 context_
->AddCommitAction("b");
597 input_method_auralinux_
->DispatchKeyEvent(&key
);
599 // Verifies single char commit under composition mode will call InsertText
600 // intead of InsertChar.
601 test_result_
->ExpectAction("keydown:229");
602 test_result_
->ExpectAction("compositionend");
603 test_result_
->ExpectAction("textinput:b");
604 test_result_
->Verify();
607 TEST_F(InputMethodAuraLinuxTest
, CompositionUpdateWithCommitTest
) {
608 context_
->SetSyncMode(true);
609 context_
->SetEatKey(true);
610 context_
->AddCompositionStartAction();
611 context_
->AddCompositionUpdateAction("a");
612 context_
->AddCommitAction("b");
614 scoped_ptr
<TextInputClientForTesting
> client(
615 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
616 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
617 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
619 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
620 key_new
.set_character(L
'a');
621 KeyEvent key
= key_new
;
622 input_method_auralinux_
->DispatchKeyEvent(&key
);
624 test_result_
->ExpectAction("keydown:229");
625 test_result_
->ExpectAction("textinput:b");
626 test_result_
->ExpectAction("compositionstart");
627 test_result_
->ExpectAction("compositionupdate:a");
628 test_result_
->Verify();
631 context_
->SetSyncMode(true);
632 context_
->SetEatKey(true);
633 context_
->AddCommitAction("c");
634 context_
->AddCompositionUpdateAction("");
636 input_method_auralinux_
->DispatchKeyEvent(&key
);
638 test_result_
->ExpectAction("keydown:229");
639 test_result_
->ExpectAction("compositionend");
640 test_result_
->ExpectAction("textinput:c");
641 test_result_
->Verify();
644 TEST_F(InputMethodAuraLinuxTest
, MixedAsyncAndSyncTest
) {
645 context_
->SetSyncMode(false);
646 context_
->SetEatKey(true);
648 scoped_ptr
<TextInputClientForTesting
> client(
649 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
650 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
651 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
653 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
654 key_new
.set_character(L
'a');
655 KeyEvent key
= key_new
;
656 input_method_auralinux_
->DispatchKeyEvent(&key
);
657 CompositionText comp
;
658 comp
.text
= base::ASCIIToUTF16("a");
659 input_method_auralinux_
->OnPreeditChanged(comp
);
661 test_result_
->ExpectAction("keydown:229");
662 test_result_
->ExpectAction("compositionstart");
663 test_result_
->ExpectAction("compositionupdate:a");
664 test_result_
->Verify();
666 context_
->SetSyncMode(true);
667 context_
->AddCompositionEndAction();
668 context_
->AddCommitAction("b");
671 input_method_auralinux_
->DispatchKeyEvent(&key
);
673 test_result_
->ExpectAction("keydown:229");
674 test_result_
->ExpectAction("compositionend");
675 test_result_
->ExpectAction("textinput:b");
676 test_result_
->Verify();
679 TEST_F(InputMethodAuraLinuxTest
, MixedSyncAndAsyncTest
) {
680 context_
->SetSyncMode(true);
681 context_
->SetEatKey(true);
682 context_
->AddCompositionStartAction();
683 context_
->AddCompositionUpdateAction("a");
685 scoped_ptr
<TextInputClientForTesting
> client(
686 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
687 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
688 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
690 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
691 key_new
.set_character(L
'a');
692 KeyEvent key
= key_new
;
693 input_method_auralinux_
->DispatchKeyEvent(&key
);
695 test_result_
->ExpectAction("keydown:229");
696 test_result_
->ExpectAction("compositionstart");
697 test_result_
->ExpectAction("compositionupdate:a");
698 test_result_
->Verify();
700 context_
->SetSyncMode(false);
703 input_method_auralinux_
->DispatchKeyEvent(&key
);
704 input_method_auralinux_
->OnCommit(base::ASCIIToUTF16("b"));
706 test_result_
->ExpectAction("keydown:229");
707 test_result_
->ExpectAction("compositionend");
708 test_result_
->ExpectAction("textinput:b");
709 test_result_
->Verify();
711 context_
->SetSyncMode(true);
712 context_
->AddCommitAction("c");
714 input_method_auralinux_
->DispatchKeyEvent(&key
);
716 test_result_
->ExpectAction("keydown:65");
717 test_result_
->ExpectAction("keypress:99");
718 test_result_
->Verify();
721 TEST_F(InputMethodAuraLinuxTest
, ReleaseKeyTest
) {
722 context_
->SetSyncMode(true);
723 context_
->SetEatKey(true);
724 context_
->AddCompositionUpdateAction("a");
726 scoped_ptr
<TextInputClientForTesting
> client(
727 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
728 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
729 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
731 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
732 key_new
.set_character(L
'A');
733 KeyEvent key
= key_new
;
734 input_method_auralinux_
->DispatchKeyEvent(&key
);
736 test_result_
->ExpectAction("keydown:229");
737 test_result_
->ExpectAction("compositionstart");
738 test_result_
->ExpectAction("compositionupdate:a");
739 test_result_
->Verify();
741 context_
->SetEatKey(false);
742 context_
->AddCommitAction("b");
744 input_method_auralinux_
->DispatchKeyEvent(&key
);
746 test_result_
->ExpectAction("compositionend");
747 test_result_
->ExpectAction("textinput:b");
748 test_result_
->ExpectAction("keydown:65");
749 test_result_
->ExpectAction("keypress:65");
750 test_result_
->Verify();
752 context_
->AddCommitAction("c");
754 input_method_auralinux_
->DispatchKeyEvent(&key
);
756 test_result_
->ExpectAction("textinput:c");
757 test_result_
->ExpectAction("keydown:65");
758 test_result_
->ExpectAction("keypress:65");
759 test_result_
->Verify();