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
;
91 base::SplitString(action
, L
':', &parts
);
92 base::char16 id
= parts
[0][0];
96 if (id
== kActionCommit
) {
97 delegate_
->OnCommit(param
);
98 } else if (id
== kActionCompositionStart
) {
99 delegate_
->OnPreeditStart();
100 } else if (id
== kActionCompositionUpdate
) {
101 CompositionText comp
;
103 delegate_
->OnPreeditChanged(comp
);
104 } else if (id
== kActionCompositionEnd
) {
105 delegate_
->OnPreeditEnd();
113 void Reset() override
{}
115 void Focus() override
{ focused_
= true; }
117 void Blur() override
{ focused_
= false; }
119 void SetCursorLocation(const gfx::Rect
& rect
) override
{
120 cursor_position_
= rect
;
124 LinuxInputMethodContextDelegate
* delegate_
;
125 std::vector
<base::string16
> actions_
;
130 gfx::Rect cursor_position_
;
132 DISALLOW_COPY_AND_ASSIGN(LinuxInputMethodContextForTesting
);
135 class LinuxInputMethodContextFactoryForTesting
136 : public LinuxInputMethodContextFactory
{
138 LinuxInputMethodContextFactoryForTesting(){};
140 scoped_ptr
<LinuxInputMethodContext
> CreateInputMethodContext(
141 LinuxInputMethodContextDelegate
* delegate
,
142 bool is_simple
) const override
{
143 return scoped_ptr
<ui::LinuxInputMethodContext
>(
144 new LinuxInputMethodContextForTesting(delegate
, is_simple
));
148 DISALLOW_COPY_AND_ASSIGN(LinuxInputMethodContextFactoryForTesting
);
151 class InputMethodDelegateForTesting
: public internal::InputMethodDelegate
{
153 InputMethodDelegateForTesting(){};
154 ~InputMethodDelegateForTesting() override
{};
156 bool DispatchKeyEventPostIME(const ui::KeyEvent
& key_event
) override
{
158 switch (key_event
.type()) {
162 case ET_KEY_RELEASED
:
168 std::stringstream ss
;
169 ss
<< key_event
.key_code();
170 action
+= std::string(ss
.str());
171 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16(action
));
176 DISALLOW_COPY_AND_ASSIGN(InputMethodDelegateForTesting
);
179 class TextInputClientForTesting
: public DummyTextInputClient
{
181 explicit TextInputClientForTesting(TextInputType text_input_type
)
182 : DummyTextInputClient(text_input_type
){};
184 base::string16 composition_text
;
187 void SetCompositionText(const CompositionText
& composition
) override
{
188 composition_text
= composition
.text
;
189 TestResult::GetInstance()->RecordAction(
190 base::ASCIIToUTF16("compositionstart"));
191 TestResult::GetInstance()->RecordAction(
192 base::ASCIIToUTF16("compositionupdate:") + composition
.text
);
195 bool HasCompositionText() const override
{ return !composition_text
.empty(); }
197 void ConfirmCompositionText() override
{
198 TestResult::GetInstance()->RecordAction(
199 base::ASCIIToUTF16("compositionend"));
200 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16("textinput:") +
202 composition_text
.clear();
205 void ClearCompositionText() override
{
206 TestResult::GetInstance()->RecordAction(
207 base::ASCIIToUTF16("compositionend"));
208 composition_text
.clear();
211 void InsertText(const base::string16
& text
) override
{
212 if (HasCompositionText()) {
213 TestResult::GetInstance()->RecordAction(
214 base::ASCIIToUTF16("compositionend"));
216 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16("textinput:") +
218 composition_text
.clear();
221 void InsertChar(base::char16 ch
, int flags
) override
{
222 std::stringstream ss
;
224 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16("keypress:") +
225 base::ASCIIToUTF16(ss
.str()));
229 class InputMethodAuraLinuxTest
: public testing::Test
{
231 InputMethodAuraLinuxTest()
233 input_method_auralinux_(NULL
),
236 context_simple_(NULL
) {
237 factory_
= new LinuxInputMethodContextFactoryForTesting();
238 LinuxInputMethodContextFactory::SetInstance(factory_
);
239 test_result_
= TestResult::GetInstance();
241 ~InputMethodAuraLinuxTest() override
{
247 void SetUp() override
{
248 delegate_
= new InputMethodDelegateForTesting();
249 input_method_auralinux_
= new InputMethodAuraLinux(delegate_
);
250 input_method_auralinux_
->OnFocus();
251 context_
= static_cast<LinuxInputMethodContextForTesting
*>(
252 input_method_auralinux_
->GetContextForTesting(false));
253 context_simple_
= static_cast<LinuxInputMethodContextForTesting
*>(
254 input_method_auralinux_
->GetContextForTesting(true));
257 void TearDown() override
{
258 context_
->SetSyncMode(false);
259 context_
->SetEatKey(false);
261 context_simple_
->SetSyncMode(false);
262 context_simple_
->SetEatKey(false);
265 context_simple_
= NULL
;
267 delete input_method_auralinux_
;
268 input_method_auralinux_
= NULL
;
273 LinuxInputMethodContextFactoryForTesting
* factory_
;
274 InputMethodAuraLinux
* input_method_auralinux_
;
275 InputMethodDelegateForTesting
* delegate_
;
276 LinuxInputMethodContextForTesting
* context_
;
277 LinuxInputMethodContextForTesting
* context_simple_
;
278 TestResult
* test_result_
;
280 DISALLOW_COPY_AND_ASSIGN(InputMethodAuraLinuxTest
);
283 TEST_F(InputMethodAuraLinuxTest
, BasicSyncModeTest
) {
284 context_
->SetSyncMode(true);
285 context_
->SetEatKey(true);
286 context_
->AddCommitAction("a");
288 scoped_ptr
<TextInputClientForTesting
> client(
289 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
290 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
291 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
293 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
294 key
.set_character(L
'a');
295 input_method_auralinux_
->DispatchKeyEvent(key
);
297 test_result_
->ExpectAction("keydown:65");
298 test_result_
->ExpectAction("keypress:97");
299 test_result_
->Verify();
301 input_method_auralinux_
->DetachTextInputClient(client
.get());
302 client
.reset(new TextInputClientForTesting(TEXT_INPUT_TYPE_PASSWORD
));
303 context_simple_
->SetSyncMode(true);
304 context_simple_
->SetEatKey(false);
306 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
307 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
308 input_method_auralinux_
->DispatchKeyEvent(key
);
310 test_result_
->ExpectAction("keydown:65");
311 test_result_
->ExpectAction("keypress:97");
312 test_result_
->Verify();
315 TEST_F(InputMethodAuraLinuxTest
, BasicAsyncModeTest
) {
316 context_
->SetSyncMode(false);
317 context_
->SetEatKey(true);
319 scoped_ptr
<TextInputClientForTesting
> client(
320 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
321 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
322 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
323 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
324 key
.set_character(L
'a');
325 input_method_auralinux_
->DispatchKeyEvent(key
);
326 input_method_auralinux_
->OnCommit(base::ASCIIToUTF16("a"));
328 test_result_
->ExpectAction("keydown:229");
329 test_result_
->ExpectAction("textinput:a");
330 test_result_
->Verify();
332 input_method_auralinux_
->DetachTextInputClient(client
.get());
333 client
.reset(new TextInputClientForTesting(TEXT_INPUT_TYPE_PASSWORD
));
334 context_simple_
->SetSyncMode(false);
335 context_simple_
->SetEatKey(false);
337 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
338 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
339 input_method_auralinux_
->DispatchKeyEvent(key
);
341 test_result_
->ExpectAction("keydown:65");
342 test_result_
->ExpectAction("keypress:97");
343 test_result_
->Verify();
346 TEST_F(InputMethodAuraLinuxTest
, IBusUSTest
) {
347 context_
->SetSyncMode(false);
348 context_
->SetEatKey(true);
350 scoped_ptr
<TextInputClientForTesting
> client(
351 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
352 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
353 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
354 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
355 key
.set_character(L
'a');
356 input_method_auralinux_
->DispatchKeyEvent(key
);
358 // IBus mutes the key down.
359 test_result_
->Verify();
361 // IBus simulates a faked key down and handle it in sync mode.
362 context_
->SetSyncMode(true);
363 context_
->AddCommitAction("a");
364 input_method_auralinux_
->DispatchKeyEvent(key
);
366 test_result_
->ExpectAction("keydown:65");
367 test_result_
->ExpectAction("keypress:97");
368 test_result_
->Verify();
370 // IBus does NOT handle the key up.
371 context_
->SetEatKey(false);
372 input_method_auralinux_
->DispatchKeyEvent(
373 KeyEvent(ET_KEY_RELEASED
, VKEY_A
, 0));
375 test_result_
->ExpectAction("keyup:65");
376 test_result_
->Verify();
379 TEST_F(InputMethodAuraLinuxTest
, IBusPinyinTest
) {
380 context_
->SetSyncMode(false);
381 context_
->SetEatKey(true);
383 scoped_ptr
<TextInputClientForTesting
> client(
384 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
385 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
386 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
387 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
388 key
.set_character(L
'a');
389 input_method_auralinux_
->DispatchKeyEvent(key
);
391 // IBus issues a standalone set_composition action.
392 input_method_auralinux_
->OnPreeditStart();
393 CompositionText comp
;
394 comp
.text
= base::ASCIIToUTF16("a");
395 input_method_auralinux_
->OnPreeditChanged(comp
);
397 test_result_
->ExpectAction("keydown:229");
398 test_result_
->ExpectAction("compositionstart");
399 test_result_
->ExpectAction("compositionupdate:a");
400 test_result_
->Verify();
402 // IBus issues a commit text with composition after muting the space key down.
403 input_method_auralinux_
->DispatchKeyEvent(
404 KeyEvent(ET_KEY_PRESSED
, VKEY_SPACE
, 0));
406 input_method_auralinux_
->OnPreeditEnd();
407 input_method_auralinux_
->OnCommit(base::ASCIIToUTF16("A"));
409 test_result_
->ExpectAction("keydown:229");
410 test_result_
->ExpectAction("compositionend");
411 test_result_
->ExpectAction("keydown:229");
412 test_result_
->ExpectAction("textinput:A");
413 test_result_
->Verify();
417 TEST_F(InputMethodAuraLinuxTest
, DeadKeyTest
) {
418 context_simple_
->SetSyncMode(true);
419 context_simple_
->SetEatKey(true);
421 scoped_ptr
<TextInputClientForTesting
> client(
422 new TextInputClientForTesting(TEXT_INPUT_TYPE_NONE
));
423 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
424 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
426 KeyEvent
dead_key(ET_KEY_PRESSED
, VKEY_OEM_7
, 0);
427 dead_key
.set_character(L
'\'');
428 input_method_auralinux_
->DispatchKeyEvent(dead_key
);
430 // The single quote key is muted.
431 test_result_
->ExpectAction("keydown:222");
432 test_result_
->Verify();
434 context_simple_
->AddCommitAction("X");
435 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
436 key
.set_character(L
'a');
437 input_method_auralinux_
->DispatchKeyEvent(key
);
439 // The following A key generates the accent key: á.
440 test_result_
->ExpectAction("keydown:65");
441 test_result_
->ExpectAction("keypress:88");
442 test_result_
->Verify();
445 TEST_F(InputMethodAuraLinuxTest
, MultiCommitsTest
) {
446 context_
->SetSyncMode(true);
447 context_
->SetEatKey(true);
448 context_
->AddCommitAction("a");
449 context_
->AddCommitAction("b");
450 context_
->AddCommitAction("c");
452 scoped_ptr
<TextInputClientForTesting
> client(
453 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
454 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
455 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
457 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
458 key
.set_character(L
'a');
459 input_method_auralinux_
->DispatchKeyEvent(key
);
461 test_result_
->ExpectAction("keydown:229");
462 test_result_
->ExpectAction("textinput:abc");
463 test_result_
->Verify();
466 TEST_F(InputMethodAuraLinuxTest
, MixedCompositionAndCommitTest
) {
467 context_
->SetSyncMode(true);
468 context_
->SetEatKey(true);
469 context_
->AddCommitAction("a");
470 context_
->AddCompositionStartAction();
471 context_
->AddCompositionUpdateAction("b");
472 context_
->AddCommitAction("c");
473 context_
->AddCompositionUpdateAction("d");
475 scoped_ptr
<TextInputClientForTesting
> client(
476 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
477 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
478 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
480 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
481 key
.set_character(L
'a');
482 input_method_auralinux_
->DispatchKeyEvent(key
);
484 test_result_
->ExpectAction("keydown:229");
485 test_result_
->ExpectAction("textinput:ac");
486 test_result_
->ExpectAction("compositionstart");
487 test_result_
->ExpectAction("compositionupdate:d");
488 test_result_
->Verify();
490 context_
->AddCommitAction("e");
491 input_method_auralinux_
->DispatchKeyEvent(key
);
493 test_result_
->ExpectAction("keydown:229");
494 test_result_
->ExpectAction("compositionend");
495 test_result_
->ExpectAction("textinput:e");
496 test_result_
->Verify();
499 TEST_F(InputMethodAuraLinuxTest
, CompositionEndWithoutCommitTest
) {
500 context_
->SetSyncMode(true);
501 context_
->SetEatKey(true);
502 context_
->AddCompositionStartAction();
503 context_
->AddCompositionUpdateAction("a");
505 scoped_ptr
<TextInputClientForTesting
> client(
506 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
507 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
508 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
510 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
511 key
.set_character(L
'a');
512 input_method_auralinux_
->DispatchKeyEvent(key
);
514 test_result_
->ExpectAction("keydown:229");
515 test_result_
->ExpectAction("compositionstart");
516 test_result_
->ExpectAction("compositionupdate:a");
517 test_result_
->Verify();
519 context_
->AddCompositionEndAction();
520 input_method_auralinux_
->DispatchKeyEvent(key
);
522 test_result_
->ExpectAction("keydown:229");
523 test_result_
->ExpectAction("compositionend");
524 test_result_
->Verify();
527 TEST_F(InputMethodAuraLinuxTest
, CompositionEndWithEmptyCommitTest
) {
528 context_
->SetSyncMode(true);
529 context_
->SetEatKey(true);
530 context_
->AddCompositionStartAction();
531 context_
->AddCompositionUpdateAction("a");
533 scoped_ptr
<TextInputClientForTesting
> client(
534 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
535 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
536 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
538 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
539 key
.set_character(L
'a');
540 input_method_auralinux_
->DispatchKeyEvent(key
);
542 test_result_
->ExpectAction("keydown:229");
543 test_result_
->ExpectAction("compositionstart");
544 test_result_
->ExpectAction("compositionupdate:a");
545 test_result_
->Verify();
547 context_
->AddCompositionEndAction();
548 context_
->AddCommitAction("");
549 input_method_auralinux_
->DispatchKeyEvent(key
);
551 test_result_
->ExpectAction("keydown:229");
552 test_result_
->ExpectAction("compositionend");
553 test_result_
->Verify();
556 TEST_F(InputMethodAuraLinuxTest
, CompositionEndWithCommitTest
) {
557 context_
->SetSyncMode(true);
558 context_
->SetEatKey(true);
559 context_
->AddCompositionStartAction();
560 context_
->AddCompositionUpdateAction("a");
562 scoped_ptr
<TextInputClientForTesting
> client(
563 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
564 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
565 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
567 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
568 key
.set_character(L
'a');
569 input_method_auralinux_
->DispatchKeyEvent(key
);
571 test_result_
->ExpectAction("keydown:229");
572 test_result_
->ExpectAction("compositionstart");
573 test_result_
->ExpectAction("compositionupdate:a");
574 test_result_
->Verify();
576 context_
->AddCompositionEndAction();
577 context_
->AddCommitAction("b");
578 input_method_auralinux_
->DispatchKeyEvent(key
);
580 // Verifies single char commit under composition mode will call InsertText
581 // intead of InsertChar.
582 test_result_
->ExpectAction("keydown:229");
583 test_result_
->ExpectAction("compositionend");
584 test_result_
->ExpectAction("textinput:b");
585 test_result_
->Verify();
588 TEST_F(InputMethodAuraLinuxTest
, CompositionUpdateWithCommitTest
) {
589 context_
->SetSyncMode(true);
590 context_
->SetEatKey(true);
591 context_
->AddCompositionStartAction();
592 context_
->AddCompositionUpdateAction("a");
593 context_
->AddCommitAction("b");
595 scoped_ptr
<TextInputClientForTesting
> client(
596 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
597 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
598 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
600 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
601 key
.set_character(L
'a');
602 input_method_auralinux_
->DispatchKeyEvent(key
);
604 test_result_
->ExpectAction("keydown:229");
605 test_result_
->ExpectAction("textinput:b");
606 test_result_
->ExpectAction("compositionstart");
607 test_result_
->ExpectAction("compositionupdate:a");
608 test_result_
->Verify();
611 context_
->SetSyncMode(true);
612 context_
->SetEatKey(true);
613 context_
->AddCommitAction("c");
614 context_
->AddCompositionUpdateAction("");
615 input_method_auralinux_
->DispatchKeyEvent(key
);
617 test_result_
->ExpectAction("keydown:229");
618 test_result_
->ExpectAction("compositionend");
619 test_result_
->ExpectAction("textinput:c");
620 test_result_
->Verify();
623 TEST_F(InputMethodAuraLinuxTest
, MixedAsyncAndSyncTest
) {
624 context_
->SetSyncMode(false);
625 context_
->SetEatKey(true);
627 scoped_ptr
<TextInputClientForTesting
> client(
628 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
629 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
630 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
632 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
633 key
.set_character(L
'a');
634 input_method_auralinux_
->DispatchKeyEvent(key
);
635 CompositionText comp
;
636 comp
.text
= base::ASCIIToUTF16("a");
637 input_method_auralinux_
->OnPreeditChanged(comp
);
639 test_result_
->ExpectAction("keydown:229");
640 test_result_
->ExpectAction("compositionstart");
641 test_result_
->ExpectAction("compositionupdate:a");
642 test_result_
->Verify();
644 context_
->SetSyncMode(true);
645 context_
->AddCompositionEndAction();
646 context_
->AddCommitAction("b");
648 input_method_auralinux_
->DispatchKeyEvent(key
);
650 test_result_
->ExpectAction("keydown:229");
651 test_result_
->ExpectAction("compositionend");
652 test_result_
->ExpectAction("textinput:b");
653 test_result_
->Verify();
656 TEST_F(InputMethodAuraLinuxTest
, MixedSyncAndAsyncTest
) {
657 context_
->SetSyncMode(true);
658 context_
->SetEatKey(true);
659 context_
->AddCompositionStartAction();
660 context_
->AddCompositionUpdateAction("a");
662 scoped_ptr
<TextInputClientForTesting
> client(
663 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
664 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
665 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
667 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
668 key
.set_character(L
'a');
669 input_method_auralinux_
->DispatchKeyEvent(key
);
671 test_result_
->ExpectAction("keydown:229");
672 test_result_
->ExpectAction("compositionstart");
673 test_result_
->ExpectAction("compositionupdate:a");
674 test_result_
->Verify();
676 context_
->SetSyncMode(false);
678 input_method_auralinux_
->DispatchKeyEvent(key
);
679 input_method_auralinux_
->OnCommit(base::ASCIIToUTF16("b"));
681 test_result_
->ExpectAction("keydown:229");
682 test_result_
->ExpectAction("compositionend");
683 test_result_
->ExpectAction("textinput:b");
684 test_result_
->Verify();
686 context_
->SetSyncMode(true);
687 context_
->AddCommitAction("c");
688 input_method_auralinux_
->DispatchKeyEvent(key
);
690 test_result_
->ExpectAction("keydown:65");
691 test_result_
->ExpectAction("keypress:99");
692 test_result_
->Verify();
695 TEST_F(InputMethodAuraLinuxTest
, ReleaseKeyTest
) {
696 context_
->SetSyncMode(true);
697 context_
->SetEatKey(true);
698 context_
->AddCompositionUpdateAction("a");
700 scoped_ptr
<TextInputClientForTesting
> client(
701 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT
));
702 input_method_auralinux_
->SetFocusedTextInputClient(client
.get());
703 input_method_auralinux_
->OnTextInputTypeChanged(client
.get());
705 KeyEvent
key(ET_KEY_PRESSED
, VKEY_A
, 0);
706 key
.set_character(L
'A');
707 input_method_auralinux_
->DispatchKeyEvent(key
);
709 test_result_
->ExpectAction("keydown:229");
710 test_result_
->ExpectAction("compositionstart");
711 test_result_
->ExpectAction("compositionupdate:a");
712 test_result_
->Verify();
714 context_
->SetEatKey(false);
715 context_
->AddCommitAction("b");
716 input_method_auralinux_
->DispatchKeyEvent(key
);
718 test_result_
->ExpectAction("compositionend");
719 test_result_
->ExpectAction("textinput:b");
720 test_result_
->ExpectAction("keydown:65");
721 test_result_
->ExpectAction("keypress:65");
722 test_result_
->Verify();
724 context_
->AddCommitAction("c");
725 input_method_auralinux_
->DispatchKeyEvent(key
);
727 test_result_
->ExpectAction("textinput:c");
728 test_result_
->ExpectAction("keydown:65");
729 test_result_
->ExpectAction("keypress:65");
730 test_result_
->Verify();