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() { return Singleton
<TestResult
>::get(); }
30 void RecordAction(const base::string16
& action
) {
31 recorded_actions_
.push_back(action
);
34 void ExpectAction(const std::string
& action
) {
35 expected_actions_
.push_back(base::ASCIIToUTF16(action
));
39 size_t len
= recorded_actions_
.size();
40 size_t len_exp
= expected_actions_
.size();
41 EXPECT_EQ(len_exp
, len
);
42 for (size_t i
= 0; i
< len
; i
++)
43 EXPECT_EQ(expected_actions_
[i
], recorded_actions_
[i
]);
44 recorded_actions_
.clear();
45 expected_actions_
.clear();
49 std::vector
<base::string16
> recorded_actions_
;
50 std::vector
<base::string16
> expected_actions_
;
53 class LinuxInputMethodContextForTesting
: public LinuxInputMethodContext
{
55 LinuxInputMethodContextForTesting(LinuxInputMethodContextDelegate
* delegate
,
57 : delegate_(delegate
),
58 is_simple_(is_simple
),
63 void SetSyncMode(bool is_sync_mode
) { is_sync_mode_
= is_sync_mode
; }
64 void SetEatKey(bool eat_key
) { eat_key_
= eat_key
; }
66 void AddCommitAction(const std::string
& text
) {
67 actions_
.push_back(base::ASCIIToUTF16("C:" + text
));
70 void AddCompositionUpdateAction(const std::string
& text
) {
71 actions_
.push_back(base::ASCIIToUTF16("U:" + text
));
74 void AddCompositionStartAction() {
75 actions_
.push_back(base::ASCIIToUTF16("S"));
78 void AddCompositionEndAction() {
79 actions_
.push_back(base::ASCIIToUTF16("E"));
83 bool DispatchKeyEvent(const ui::KeyEvent
& key_event
) override
{
89 for (const auto& action
: actions_
) {
90 std::vector
<base::string16
> parts
= base::SplitString(
91 action
, base::string16(1, ':'), base::TRIM_WHITESPACE
,
92 base::SPLIT_WANT_ALL
);
93 base::char16 id
= parts
[0][0];
97 if (id
== kActionCommit
) {
98 delegate_
->OnCommit(param
);
99 } else if (id
== kActionCompositionStart
) {
100 delegate_
->OnPreeditStart();
101 } else if (id
== kActionCompositionUpdate
) {
102 CompositionText comp
;
104 delegate_
->OnPreeditChanged(comp
);
105 } else if (id
== kActionCompositionEnd
) {
106 delegate_
->OnPreeditEnd();
114 void Reset() override
{}
116 void Focus() override
{ focused_
= true; }
118 void Blur() override
{ focused_
= false; }
120 void SetCursorLocation(const gfx::Rect
& rect
) override
{
121 cursor_position_
= rect
;
125 LinuxInputMethodContextDelegate
* delegate_
;
126 std::vector
<base::string16
> actions_
;
131 gfx::Rect cursor_position_
;
133 DISALLOW_COPY_AND_ASSIGN(LinuxInputMethodContextForTesting
);
136 class LinuxInputMethodContextFactoryForTesting
137 : public LinuxInputMethodContextFactory
{
139 LinuxInputMethodContextFactoryForTesting(){};
141 scoped_ptr
<LinuxInputMethodContext
> CreateInputMethodContext(
142 LinuxInputMethodContextDelegate
* delegate
,
143 bool is_simple
) const override
{
144 return scoped_ptr
<ui::LinuxInputMethodContext
>(
145 new LinuxInputMethodContextForTesting(delegate
, is_simple
));
149 DISALLOW_COPY_AND_ASSIGN(LinuxInputMethodContextFactoryForTesting
);
152 class InputMethodDelegateForTesting
: public internal::InputMethodDelegate
{
154 InputMethodDelegateForTesting(){};
155 ~InputMethodDelegateForTesting() override
{};
157 ui::EventDispatchDetails
DispatchKeyEventPostIME(
158 ui::KeyEvent
* key_event
) override
{
160 switch (key_event
->type()) {
164 case ET_KEY_RELEASED
:
170 std::stringstream ss
;
171 ss
<< key_event
->key_code();
172 action
+= std::string(ss
.str());
173 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16(action
));
174 return ui::EventDispatchDetails();
178 DISALLOW_COPY_AND_ASSIGN(InputMethodDelegateForTesting
);
181 class TextInputClientForTesting
: public DummyTextInputClient
{
183 explicit TextInputClientForTesting(TextInputType text_input_type
)
184 : DummyTextInputClient(text_input_type
){};
186 base::string16 composition_text
;
189 void SetCompositionText(const CompositionText
& composition
) override
{
190 composition_text
= composition
.text
;
191 TestResult::GetInstance()->RecordAction(
192 base::ASCIIToUTF16("compositionstart"));
193 TestResult::GetInstance()->RecordAction(
194 base::ASCIIToUTF16("compositionupdate:") + composition
.text
);
197 bool HasCompositionText() const override
{ return !composition_text
.empty(); }
199 void ConfirmCompositionText() override
{
200 TestResult::GetInstance()->RecordAction(
201 base::ASCIIToUTF16("compositionend"));
202 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16("textinput:") +
204 composition_text
.clear();
207 void ClearCompositionText() override
{
208 TestResult::GetInstance()->RecordAction(
209 base::ASCIIToUTF16("compositionend"));
210 composition_text
.clear();
213 void InsertText(const base::string16
& text
) override
{
214 if (HasCompositionText()) {
215 TestResult::GetInstance()->RecordAction(
216 base::ASCIIToUTF16("compositionend"));
218 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16("textinput:") +
220 composition_text
.clear();
223 void InsertChar(base::char16 ch
, int flags
) override
{
224 std::stringstream ss
;
226 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16("keypress:") +
227 base::ASCIIToUTF16(ss
.str()));
231 class InputMethodAuraLinuxTest
: public testing::Test
{
233 InputMethodAuraLinuxTest()
235 input_method_auralinux_(NULL
),
238 context_simple_(NULL
) {
239 factory_
= new LinuxInputMethodContextFactoryForTesting();
240 LinuxInputMethodContextFactory::SetInstance(factory_
);
241 test_result_
= TestResult::GetInstance();
243 ~InputMethodAuraLinuxTest() override
{
249 void SetUp() override
{
250 delegate_
= new InputMethodDelegateForTesting();
251 input_method_auralinux_
= new InputMethodAuraLinux(delegate_
);
252 input_method_auralinux_
->OnFocus();
253 context_
= static_cast<LinuxInputMethodContextForTesting
*>(
254 input_method_auralinux_
->GetContextForTesting(false));
255 context_simple_
= static_cast<LinuxInputMethodContextForTesting
*>(
256 input_method_auralinux_
->GetContextForTesting(true));
259 void TearDown() override
{
260 context_
->SetSyncMode(false);
261 context_
->SetEatKey(false);
263 context_simple_
->SetSyncMode(false);
264 context_simple_
->SetEatKey(false);
267 context_simple_
= NULL
;
269 delete input_method_auralinux_
;
270 input_method_auralinux_
= NULL
;
275 LinuxInputMethodContextFactoryForTesting
* factory_
;
276 InputMethodAuraLinux
* input_method_auralinux_
;
277 InputMethodDelegateForTesting
* delegate_
;
278 LinuxInputMethodContextForTesting
* context_
;
279 LinuxInputMethodContextForTesting
* context_simple_
;
280 TestResult
* test_result_
;
282 DISALLOW_COPY_AND_ASSIGN(InputMethodAuraLinuxTest
);
285 TEST_F(InputMethodAuraLinuxTest
, BasicSyncModeTest
) {
286 context_
->SetSyncMode(true);
287 context_
->SetEatKey(true);
288 context_
->AddCommitAction("a");
290 scoped_ptr
<TextInputClientForTesting
> client(
291 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
292 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
293 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
295 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
296 key_new
.set_character(L
'a');
298 KeyEvent key
= key_new
;
299 input_method_auralinux_
->DispatchKeyEvent(&key
);
301 test_result_
->ExpectAction("keydown:65");
302 test_result_
->ExpectAction("keypress:97");
303 test_result_
->Verify();
305 input_method_auralinux_
->DetachTextInputClient(client
.get());
306 client
.reset(new TextInputClientForTesting(TEXT_INPUT_TYPE_PASSWORD
));
307 context_simple_
->SetSyncMode(true);
308 context_simple_
->SetEatKey(false);
310 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
311 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
313 input_method_auralinux_
->DispatchKeyEvent(&key
);
315 test_result_
->ExpectAction("keydown:65");
316 test_result_
->ExpectAction("keypress:97");
317 test_result_
->Verify();
320 TEST_F(InputMethodAuraLinuxTest
, BasicAsyncModeTest
) {
321 context_
->SetSyncMode(false);
322 context_
->SetEatKey(true);
324 scoped_ptr
<TextInputClientForTesting
> client(
325 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
326 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
327 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
328 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
329 key_new
.set_character(L
'a');
330 KeyEvent key
= key_new
;
331 input_method_auralinux_
->DispatchKeyEvent(&key
);
332 input_method_auralinux_
->OnCommit(base::ASCIIToUTF16("a"));
334 test_result_
->ExpectAction("keydown:229");
335 test_result_
->ExpectAction("textinput:a");
336 test_result_
->Verify();
338 input_method_auralinux_
->DetachTextInputClient(client
.get());
339 client
.reset(new TextInputClientForTesting(TEXT_INPUT_TYPE_PASSWORD
));
340 context_simple_
->SetSyncMode(false);
341 context_simple_
->SetEatKey(false);
343 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
344 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
346 input_method_auralinux_
->DispatchKeyEvent(&key
);
348 test_result_
->ExpectAction("keydown:65");
349 test_result_
->ExpectAction("keypress:97");
350 test_result_
->Verify();
353 TEST_F(InputMethodAuraLinuxTest
, IBusUSTest
) {
354 context_
->SetSyncMode(false);
355 context_
->SetEatKey(true);
357 scoped_ptr
<TextInputClientForTesting
> client(
358 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
359 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
360 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
361 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
362 key_new
.set_character(L
'a');
363 KeyEvent key
= key_new
;
364 input_method_auralinux_
->DispatchKeyEvent(&key
);
366 // IBus mutes the key down.
367 test_result_
->Verify();
369 // IBus simulates a faked key down and handle it in sync mode.
370 context_
->SetSyncMode(true);
371 context_
->AddCommitAction("a");
373 input_method_auralinux_
->DispatchKeyEvent(&key
);
375 test_result_
->ExpectAction("keydown:65");
376 test_result_
->ExpectAction("keypress:97");
377 test_result_
->Verify();
379 // IBus does NOT handle the key up.
380 context_
->SetEatKey(false);
381 KeyEvent
key_up(ET_KEY_RELEASED
, VKEY_A
, 0);
382 input_method_auralinux_
->DispatchKeyEvent(&key_up
);
384 test_result_
->ExpectAction("keyup:65");
385 test_result_
->Verify();
388 TEST_F(InputMethodAuraLinuxTest
, IBusPinyinTest
) {
389 context_
->SetSyncMode(false);
390 context_
->SetEatKey(true);
392 scoped_ptr
<TextInputClientForTesting
> client(
393 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
394 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
395 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
396 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
397 key
.set_character(L
'a');
398 input_method_auralinux_
->DispatchKeyEvent(&key
);
400 // IBus issues a standalone set_composition action.
401 input_method_auralinux_
->OnPreeditStart();
402 CompositionText comp
;
403 comp
.text
= base::ASCIIToUTF16("a");
404 input_method_auralinux_
->OnPreeditChanged(comp
);
406 test_result_
->ExpectAction("keydown:229");
407 test_result_
->ExpectAction("compositionstart");
408 test_result_
->ExpectAction("compositionupdate:a");
409 test_result_
->Verify();
411 // IBus issues a commit text with composition after muting the space key down.
412 KeyEvent
key_up(ET_KEY_RELEASED
, VKEY_SPACE
, 0);
413 input_method_auralinux_
->DispatchKeyEvent(&key_up
);
415 input_method_auralinux_
->OnPreeditEnd();
416 input_method_auralinux_
->OnCommit(base::ASCIIToUTF16("A"));
418 test_result_
->ExpectAction("keydown:229");
419 test_result_
->ExpectAction("compositionend");
420 test_result_
->ExpectAction("keydown:229");
421 test_result_
->ExpectAction("textinput:A");
422 test_result_
->Verify();
426 TEST_F(InputMethodAuraLinuxTest
, DeadKeyTest
) {
427 context_simple_
->SetSyncMode(true);
428 context_simple_
->SetEatKey(true);
430 scoped_ptr
<TextInputClientForTesting
> client(
431 new TextInputClientForTesting(TEXT_INPUT_TYPE_NONE
));
432 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
433 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
);
439 // The single quote key is muted.
440 test_result_
->ExpectAction("keydown:222");
441 test_result_
->Verify();
443 context_simple_
->AddCommitAction("X");
444 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
445 key
.set_character(L
'a');
446 input_method_auralinux_
->DispatchKeyEvent(&key
);
448 // The following A key generates the accent key: á.
449 test_result_
->ExpectAction("keydown:65");
450 test_result_
->ExpectAction("keypress:88");
451 test_result_
->Verify();
454 TEST_F(InputMethodAuraLinuxTest
, MultiCommitsTest
) {
455 context_
->SetSyncMode(true);
456 context_
->SetEatKey(true);
457 context_
->AddCommitAction("a");
458 context_
->AddCommitAction("b");
459 context_
->AddCommitAction("c");
461 scoped_ptr
<TextInputClientForTesting
> client(
462 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
463 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
464 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
466 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
467 key
.set_character(L
'a');
468 input_method_auralinux_
->DispatchKeyEvent(&key
);
470 test_result_
->ExpectAction("keydown:229");
471 test_result_
->ExpectAction("textinput:abc");
472 test_result_
->Verify();
475 TEST_F(InputMethodAuraLinuxTest
, MixedCompositionAndCommitTest
) {
476 context_
->SetSyncMode(true);
477 context_
->SetEatKey(true);
478 context_
->AddCommitAction("a");
479 context_
->AddCompositionStartAction();
480 context_
->AddCompositionUpdateAction("b");
481 context_
->AddCommitAction("c");
482 context_
->AddCompositionUpdateAction("d");
484 scoped_ptr
<TextInputClientForTesting
> client(
485 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
486 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
487 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
489 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
490 key_new
.set_character(L
'a');
491 KeyEvent key
= key_new
;
492 input_method_auralinux_
->DispatchKeyEvent(&key
);
494 test_result_
->ExpectAction("keydown:229");
495 test_result_
->ExpectAction("textinput:ac");
496 test_result_
->ExpectAction("compositionstart");
497 test_result_
->ExpectAction("compositionupdate:d");
498 test_result_
->Verify();
500 context_
->AddCommitAction("e");
502 input_method_auralinux_
->DispatchKeyEvent(&key
);
504 test_result_
->ExpectAction("keydown:229");
505 test_result_
->ExpectAction("compositionend");
506 test_result_
->ExpectAction("textinput:e");
507 test_result_
->Verify();
510 TEST_F(InputMethodAuraLinuxTest
, CompositionEndWithoutCommitTest
) {
511 context_
->SetSyncMode(true);
512 context_
->SetEatKey(true);
513 context_
->AddCompositionStartAction();
514 context_
->AddCompositionUpdateAction("a");
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());
521 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
522 key_new
.set_character(L
'a');
523 KeyEvent key
= key_new
;
524 input_method_auralinux_
->DispatchKeyEvent(&key
);
526 test_result_
->ExpectAction("keydown:229");
527 test_result_
->ExpectAction("compositionstart");
528 test_result_
->ExpectAction("compositionupdate:a");
529 test_result_
->Verify();
531 context_
->AddCompositionEndAction();
533 input_method_auralinux_
->DispatchKeyEvent(&key
);
535 test_result_
->ExpectAction("keydown:229");
536 test_result_
->ExpectAction("compositionend");
537 test_result_
->Verify();
540 TEST_F(InputMethodAuraLinuxTest
, CompositionEndWithEmptyCommitTest
) {
541 context_
->SetSyncMode(true);
542 context_
->SetEatKey(true);
543 context_
->AddCompositionStartAction();
544 context_
->AddCompositionUpdateAction("a");
546 scoped_ptr
<TextInputClientForTesting
> client(
547 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
548 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
549 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
551 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
552 key_new
.set_character(L
'a');
553 KeyEvent key
= key_new
;
554 input_method_auralinux_
->DispatchKeyEvent(&key
);
556 test_result_
->ExpectAction("keydown:229");
557 test_result_
->ExpectAction("compositionstart");
558 test_result_
->ExpectAction("compositionupdate:a");
559 test_result_
->Verify();
561 context_
->AddCompositionEndAction();
562 context_
->AddCommitAction("");
564 input_method_auralinux_
->DispatchKeyEvent(&key
);
566 test_result_
->ExpectAction("keydown:229");
567 test_result_
->ExpectAction("compositionend");
568 test_result_
->Verify();
571 TEST_F(InputMethodAuraLinuxTest
, CompositionEndWithCommitTest
) {
572 context_
->SetSyncMode(true);
573 context_
->SetEatKey(true);
574 context_
->AddCompositionStartAction();
575 context_
->AddCompositionUpdateAction("a");
577 scoped_ptr
<TextInputClientForTesting
> client(
578 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
579 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
580 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
582 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
583 key_new
.set_character(L
'a');
584 KeyEvent key
= key_new
;
585 input_method_auralinux_
->DispatchKeyEvent(&key
);
587 test_result_
->ExpectAction("keydown:229");
588 test_result_
->ExpectAction("compositionstart");
589 test_result_
->ExpectAction("compositionupdate:a");
590 test_result_
->Verify();
592 context_
->AddCompositionEndAction();
593 context_
->AddCommitAction("b");
595 input_method_auralinux_
->DispatchKeyEvent(&key
);
597 // Verifies single char commit under composition mode will call InsertText
598 // intead of InsertChar.
599 test_result_
->ExpectAction("keydown:229");
600 test_result_
->ExpectAction("compositionend");
601 test_result_
->ExpectAction("textinput:b");
602 test_result_
->Verify();
605 TEST_F(InputMethodAuraLinuxTest
, CompositionUpdateWithCommitTest
) {
606 context_
->SetSyncMode(true);
607 context_
->SetEatKey(true);
608 context_
->AddCompositionStartAction();
609 context_
->AddCompositionUpdateAction("a");
610 context_
->AddCommitAction("b");
612 scoped_ptr
<TextInputClientForTesting
> client(
613 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
614 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
615 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
617 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
618 key_new
.set_character(L
'a');
619 KeyEvent key
= key_new
;
620 input_method_auralinux_
->DispatchKeyEvent(&key
);
622 test_result_
->ExpectAction("keydown:229");
623 test_result_
->ExpectAction("textinput:b");
624 test_result_
->ExpectAction("compositionstart");
625 test_result_
->ExpectAction("compositionupdate:a");
626 test_result_
->Verify();
629 context_
->SetSyncMode(true);
630 context_
->SetEatKey(true);
631 context_
->AddCommitAction("c");
632 context_
->AddCompositionUpdateAction("");
634 input_method_auralinux_
->DispatchKeyEvent(&key
);
636 test_result_
->ExpectAction("keydown:229");
637 test_result_
->ExpectAction("compositionend");
638 test_result_
->ExpectAction("textinput:c");
639 test_result_
->Verify();
642 TEST_F(InputMethodAuraLinuxTest
, MixedAsyncAndSyncTest
) {
643 context_
->SetSyncMode(false);
644 context_
->SetEatKey(true);
646 scoped_ptr
<TextInputClientForTesting
> client(
647 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
648 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
649 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
651 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
652 key_new
.set_character(L
'a');
653 KeyEvent key
= key_new
;
654 input_method_auralinux_
->DispatchKeyEvent(&key
);
655 CompositionText comp
;
656 comp
.text
= base::ASCIIToUTF16("a");
657 input_method_auralinux_
->OnPreeditChanged(comp
);
659 test_result_
->ExpectAction("keydown:229");
660 test_result_
->ExpectAction("compositionstart");
661 test_result_
->ExpectAction("compositionupdate:a");
662 test_result_
->Verify();
664 context_
->SetSyncMode(true);
665 context_
->AddCompositionEndAction();
666 context_
->AddCommitAction("b");
669 input_method_auralinux_
->DispatchKeyEvent(&key
);
671 test_result_
->ExpectAction("keydown:229");
672 test_result_
->ExpectAction("compositionend");
673 test_result_
->ExpectAction("textinput:b");
674 test_result_
->Verify();
677 TEST_F(InputMethodAuraLinuxTest
, MixedSyncAndAsyncTest
) {
678 context_
->SetSyncMode(true);
679 context_
->SetEatKey(true);
680 context_
->AddCompositionStartAction();
681 context_
->AddCompositionUpdateAction("a");
683 scoped_ptr
<TextInputClientForTesting
> client(
684 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
685 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
686 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
688 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
689 key_new
.set_character(L
'a');
690 KeyEvent key
= key_new
;
691 input_method_auralinux_
->DispatchKeyEvent(&key
);
693 test_result_
->ExpectAction("keydown:229");
694 test_result_
->ExpectAction("compositionstart");
695 test_result_
->ExpectAction("compositionupdate:a");
696 test_result_
->Verify();
698 context_
->SetSyncMode(false);
701 input_method_auralinux_
->DispatchKeyEvent(&key
);
702 input_method_auralinux_
->OnCommit(base::ASCIIToUTF16("b"));
704 test_result_
->ExpectAction("keydown:229");
705 test_result_
->ExpectAction("compositionend");
706 test_result_
->ExpectAction("textinput:b");
707 test_result_
->Verify();
709 context_
->SetSyncMode(true);
710 context_
->AddCommitAction("c");
712 input_method_auralinux_
->DispatchKeyEvent(&key
);
714 test_result_
->ExpectAction("keydown:65");
715 test_result_
->ExpectAction("keypress:99");
716 test_result_
->Verify();
719 TEST_F(InputMethodAuraLinuxTest
, ReleaseKeyTest
) {
720 context_
->SetSyncMode(true);
721 context_
->SetEatKey(true);
722 context_
->AddCompositionUpdateAction("a");
724 scoped_ptr
<TextInputClientForTesting
> client(
725 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
726 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
727 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
729 KeyEvent
key_new(ET_KEY_PRESSED
, VKEY_A
, 0);
730 key_new
.set_character(L
'A');
731 KeyEvent key
= key_new
;
732 input_method_auralinux_
->DispatchKeyEvent(&key
);
734 test_result_
->ExpectAction("keydown:229");
735 test_result_
->ExpectAction("compositionstart");
736 test_result_
->ExpectAction("compositionupdate:a");
737 test_result_
->Verify();
739 context_
->SetEatKey(false);
740 context_
->AddCommitAction("b");
742 input_method_auralinux_
->DispatchKeyEvent(&key
);
744 test_result_
->ExpectAction("compositionend");
745 test_result_
->ExpectAction("textinput:b");
746 test_result_
->ExpectAction("keydown:65");
747 test_result_
->ExpectAction("keypress:65");
748 test_result_
->Verify();
750 context_
->AddCommitAction("c");
752 input_method_auralinux_
->DispatchKeyEvent(&key
);
754 test_result_
->ExpectAction("textinput:c");
755 test_result_
->ExpectAction("keydown:65");
756 test_result_
->ExpectAction("keypress:65");
757 test_result_
->Verify();