Add ICU message format support
[chromium-blink-merge.git] / ui / base / ime / input_method_auralinux_unittest.cc
blob5c4afc53535bfc6051e54c85d64a860bc40b7179
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"
18 namespace ui {
19 namespace {
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';
26 class TestResult {
27 public:
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));
38 void Verify() {
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();
48 private:
49 std::vector<base::string16> recorded_actions_;
50 std::vector<base::string16> expected_actions_;
53 class LinuxInputMethodContextForTesting : public LinuxInputMethodContext {
54 public:
55 LinuxInputMethodContextForTesting(LinuxInputMethodContextDelegate* delegate,
56 bool is_simple)
57 : delegate_(delegate),
58 is_simple_(is_simple),
59 is_sync_mode_(false),
60 eat_key_(false),
61 focused_(false) {}
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"));
82 protected:
83 bool DispatchKeyEvent(const ui::KeyEvent& key_event) override {
84 if (!is_sync_mode_) {
85 actions_.clear();
86 return eat_key_;
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];
93 base::string16 param;
94 if (parts.size() > 1)
95 param = parts[1];
96 if (id == kActionCommit) {
97 delegate_->OnCommit(param);
98 } else if (id == kActionCompositionStart) {
99 delegate_->OnPreeditStart();
100 } else if (id == kActionCompositionUpdate) {
101 CompositionText comp;
102 comp.text = param;
103 delegate_->OnPreeditChanged(comp);
104 } else if (id == kActionCompositionEnd) {
105 delegate_->OnPreeditEnd();
109 actions_.clear();
110 return eat_key_;
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;
123 private:
124 LinuxInputMethodContextDelegate* delegate_;
125 std::vector<base::string16> actions_;
126 bool is_simple_;
127 bool is_sync_mode_;
128 bool eat_key_;
129 bool focused_;
130 gfx::Rect cursor_position_;
132 DISALLOW_COPY_AND_ASSIGN(LinuxInputMethodContextForTesting);
135 class LinuxInputMethodContextFactoryForTesting
136 : public LinuxInputMethodContextFactory {
137 public:
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));
147 private:
148 DISALLOW_COPY_AND_ASSIGN(LinuxInputMethodContextFactoryForTesting);
151 class InputMethodDelegateForTesting : public internal::InputMethodDelegate {
152 public:
153 InputMethodDelegateForTesting(){};
154 ~InputMethodDelegateForTesting() override{};
156 ui::EventDispatchDetails DispatchKeyEventPostIME(
157 ui::KeyEvent* key_event) override {
158 std::string action;
159 switch (key_event->type()) {
160 case ET_KEY_PRESSED:
161 action = "keydown:";
162 break;
163 case ET_KEY_RELEASED:
164 action = "keyup:";
165 break;
166 default:
167 break;
169 std::stringstream ss;
170 ss << key_event->key_code();
171 action += std::string(ss.str());
172 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16(action));
173 return ui::EventDispatchDetails();
176 private:
177 DISALLOW_COPY_AND_ASSIGN(InputMethodDelegateForTesting);
180 class TextInputClientForTesting : public DummyTextInputClient {
181 public:
182 explicit TextInputClientForTesting(TextInputType text_input_type)
183 : DummyTextInputClient(text_input_type){};
185 base::string16 composition_text;
187 protected:
188 void SetCompositionText(const CompositionText& composition) override {
189 composition_text = composition.text;
190 TestResult::GetInstance()->RecordAction(
191 base::ASCIIToUTF16("compositionstart"));
192 TestResult::GetInstance()->RecordAction(
193 base::ASCIIToUTF16("compositionupdate:") + composition.text);
196 bool HasCompositionText() const override { return !composition_text.empty(); }
198 void ConfirmCompositionText() override {
199 TestResult::GetInstance()->RecordAction(
200 base::ASCIIToUTF16("compositionend"));
201 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16("textinput:") +
202 composition_text);
203 composition_text.clear();
206 void ClearCompositionText() override {
207 TestResult::GetInstance()->RecordAction(
208 base::ASCIIToUTF16("compositionend"));
209 composition_text.clear();
212 void InsertText(const base::string16& text) override {
213 if (HasCompositionText()) {
214 TestResult::GetInstance()->RecordAction(
215 base::ASCIIToUTF16("compositionend"));
217 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16("textinput:") +
218 text);
219 composition_text.clear();
222 void InsertChar(base::char16 ch, int flags) override {
223 std::stringstream ss;
224 ss << ch;
225 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16("keypress:") +
226 base::ASCIIToUTF16(ss.str()));
230 class InputMethodAuraLinuxTest : public testing::Test {
231 protected:
232 InputMethodAuraLinuxTest()
233 : factory_(NULL),
234 input_method_auralinux_(NULL),
235 delegate_(NULL),
236 context_(NULL),
237 context_simple_(NULL) {
238 factory_ = new LinuxInputMethodContextFactoryForTesting();
239 LinuxInputMethodContextFactory::SetInstance(factory_);
240 test_result_ = TestResult::GetInstance();
242 ~InputMethodAuraLinuxTest() override {
243 delete factory_;
244 factory_ = NULL;
245 test_result_ = NULL;
248 void SetUp() override {
249 delegate_ = new InputMethodDelegateForTesting();
250 input_method_auralinux_ = new InputMethodAuraLinux(delegate_);
251 input_method_auralinux_->OnFocus();
252 context_ = static_cast<LinuxInputMethodContextForTesting*>(
253 input_method_auralinux_->GetContextForTesting(false));
254 context_simple_ = static_cast<LinuxInputMethodContextForTesting*>(
255 input_method_auralinux_->GetContextForTesting(true));
258 void TearDown() override {
259 context_->SetSyncMode(false);
260 context_->SetEatKey(false);
262 context_simple_->SetSyncMode(false);
263 context_simple_->SetEatKey(false);
265 context_ = NULL;
266 context_simple_ = NULL;
268 delete input_method_auralinux_;
269 input_method_auralinux_ = NULL;
270 delete delegate_;
271 delegate_ = NULL;
274 LinuxInputMethodContextFactoryForTesting* factory_;
275 InputMethodAuraLinux* input_method_auralinux_;
276 InputMethodDelegateForTesting* delegate_;
277 LinuxInputMethodContextForTesting* context_;
278 LinuxInputMethodContextForTesting* context_simple_;
279 TestResult* test_result_;
281 DISALLOW_COPY_AND_ASSIGN(InputMethodAuraLinuxTest);
284 TEST_F(InputMethodAuraLinuxTest, BasicSyncModeTest) {
285 context_->SetSyncMode(true);
286 context_->SetEatKey(true);
287 context_->AddCommitAction("a");
289 scoped_ptr<TextInputClientForTesting> client(
290 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
291 input_method_auralinux_->SetFocusedTextInputClient(client.get());
292 input_method_auralinux_->OnTextInputTypeChanged(client.get());
294 KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0);
295 key_new.set_character(L'a');
297 KeyEvent key = key_new;
298 input_method_auralinux_->DispatchKeyEvent(&key);
300 test_result_->ExpectAction("keydown:65");
301 test_result_->ExpectAction("keypress:97");
302 test_result_->Verify();
304 input_method_auralinux_->DetachTextInputClient(client.get());
305 client.reset(new TextInputClientForTesting(TEXT_INPUT_TYPE_PASSWORD));
306 context_simple_->SetSyncMode(true);
307 context_simple_->SetEatKey(false);
309 input_method_auralinux_->SetFocusedTextInputClient(client.get());
310 input_method_auralinux_->OnTextInputTypeChanged(client.get());
311 key = key_new;
312 input_method_auralinux_->DispatchKeyEvent(&key);
314 test_result_->ExpectAction("keydown:65");
315 test_result_->ExpectAction("keypress:97");
316 test_result_->Verify();
319 TEST_F(InputMethodAuraLinuxTest, BasicAsyncModeTest) {
320 context_->SetSyncMode(false);
321 context_->SetEatKey(true);
323 scoped_ptr<TextInputClientForTesting> client(
324 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
325 input_method_auralinux_->SetFocusedTextInputClient(client.get());
326 input_method_auralinux_->OnTextInputTypeChanged(client.get());
327 KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0);
328 key_new.set_character(L'a');
329 KeyEvent key = key_new;
330 input_method_auralinux_->DispatchKeyEvent(&key);
331 input_method_auralinux_->OnCommit(base::ASCIIToUTF16("a"));
333 test_result_->ExpectAction("keydown:229");
334 test_result_->ExpectAction("textinput:a");
335 test_result_->Verify();
337 input_method_auralinux_->DetachTextInputClient(client.get());
338 client.reset(new TextInputClientForTesting(TEXT_INPUT_TYPE_PASSWORD));
339 context_simple_->SetSyncMode(false);
340 context_simple_->SetEatKey(false);
342 input_method_auralinux_->SetFocusedTextInputClient(client.get());
343 input_method_auralinux_->OnTextInputTypeChanged(client.get());
344 key = key_new;
345 input_method_auralinux_->DispatchKeyEvent(&key);
347 test_result_->ExpectAction("keydown:65");
348 test_result_->ExpectAction("keypress:97");
349 test_result_->Verify();
352 TEST_F(InputMethodAuraLinuxTest, IBusUSTest) {
353 context_->SetSyncMode(false);
354 context_->SetEatKey(true);
356 scoped_ptr<TextInputClientForTesting> client(
357 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
358 input_method_auralinux_->SetFocusedTextInputClient(client.get());
359 input_method_auralinux_->OnTextInputTypeChanged(client.get());
360 KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0);
361 key_new.set_character(L'a');
362 KeyEvent key = key_new;
363 input_method_auralinux_->DispatchKeyEvent(&key);
365 // IBus mutes the key down.
366 test_result_->Verify();
368 // IBus simulates a faked key down and handle it in sync mode.
369 context_->SetSyncMode(true);
370 context_->AddCommitAction("a");
371 key = key_new;
372 input_method_auralinux_->DispatchKeyEvent(&key);
374 test_result_->ExpectAction("keydown:65");
375 test_result_->ExpectAction("keypress:97");
376 test_result_->Verify();
378 // IBus does NOT handle the key up.
379 context_->SetEatKey(false);
380 KeyEvent key_up(ET_KEY_RELEASED, VKEY_A, 0);
381 input_method_auralinux_->DispatchKeyEvent(&key_up);
383 test_result_->ExpectAction("keyup:65");
384 test_result_->Verify();
387 TEST_F(InputMethodAuraLinuxTest, IBusPinyinTest) {
388 context_->SetSyncMode(false);
389 context_->SetEatKey(true);
391 scoped_ptr<TextInputClientForTesting> client(
392 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
393 input_method_auralinux_->SetFocusedTextInputClient(client.get());
394 input_method_auralinux_->OnTextInputTypeChanged(client.get());
395 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0);
396 key.set_character(L'a');
397 input_method_auralinux_->DispatchKeyEvent(&key);
399 // IBus issues a standalone set_composition action.
400 input_method_auralinux_->OnPreeditStart();
401 CompositionText comp;
402 comp.text = base::ASCIIToUTF16("a");
403 input_method_auralinux_->OnPreeditChanged(comp);
405 test_result_->ExpectAction("keydown:229");
406 test_result_->ExpectAction("compositionstart");
407 test_result_->ExpectAction("compositionupdate:a");
408 test_result_->Verify();
410 // IBus issues a commit text with composition after muting the space key down.
411 KeyEvent key_up(ET_KEY_RELEASED, VKEY_SPACE, 0);
412 input_method_auralinux_->DispatchKeyEvent(&key_up);
414 input_method_auralinux_->OnPreeditEnd();
415 input_method_auralinux_->OnCommit(base::ASCIIToUTF16("A"));
417 test_result_->ExpectAction("keydown:229");
418 test_result_->ExpectAction("compositionend");
419 test_result_->ExpectAction("keydown:229");
420 test_result_->ExpectAction("textinput:A");
421 test_result_->Verify();
424 // crbug.com/463491
425 TEST_F(InputMethodAuraLinuxTest, DeadKeyTest) {
426 context_simple_->SetSyncMode(true);
427 context_simple_->SetEatKey(true);
429 scoped_ptr<TextInputClientForTesting> client(
430 new TextInputClientForTesting(TEXT_INPUT_TYPE_NONE));
431 input_method_auralinux_->SetFocusedTextInputClient(client.get());
432 input_method_auralinux_->OnTextInputTypeChanged(client.get());
434 KeyEvent dead_key(ET_KEY_PRESSED, VKEY_OEM_7, 0);
435 dead_key.set_character(L'\'');
436 input_method_auralinux_->DispatchKeyEvent(&dead_key);
438 // The single quote key is muted.
439 test_result_->ExpectAction("keydown:222");
440 test_result_->Verify();
442 context_simple_->AddCommitAction("X");
443 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0);
444 key.set_character(L'a');
445 input_method_auralinux_->DispatchKeyEvent(&key);
447 // The following A key generates the accent key: á.
448 test_result_->ExpectAction("keydown:65");
449 test_result_->ExpectAction("keypress:88");
450 test_result_->Verify();
453 TEST_F(InputMethodAuraLinuxTest, MultiCommitsTest) {
454 context_->SetSyncMode(true);
455 context_->SetEatKey(true);
456 context_->AddCommitAction("a");
457 context_->AddCommitAction("b");
458 context_->AddCommitAction("c");
460 scoped_ptr<TextInputClientForTesting> client(
461 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
462 input_method_auralinux_->SetFocusedTextInputClient(client.get());
463 input_method_auralinux_->OnTextInputTypeChanged(client.get());
465 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0);
466 key.set_character(L'a');
467 input_method_auralinux_->DispatchKeyEvent(&key);
469 test_result_->ExpectAction("keydown:229");
470 test_result_->ExpectAction("textinput:abc");
471 test_result_->Verify();
474 TEST_F(InputMethodAuraLinuxTest, MixedCompositionAndCommitTest) {
475 context_->SetSyncMode(true);
476 context_->SetEatKey(true);
477 context_->AddCommitAction("a");
478 context_->AddCompositionStartAction();
479 context_->AddCompositionUpdateAction("b");
480 context_->AddCommitAction("c");
481 context_->AddCompositionUpdateAction("d");
483 scoped_ptr<TextInputClientForTesting> client(
484 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
485 input_method_auralinux_->SetFocusedTextInputClient(client.get());
486 input_method_auralinux_->OnTextInputTypeChanged(client.get());
488 KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0);
489 key_new.set_character(L'a');
490 KeyEvent key = key_new;
491 input_method_auralinux_->DispatchKeyEvent(&key);
493 test_result_->ExpectAction("keydown:229");
494 test_result_->ExpectAction("textinput:ac");
495 test_result_->ExpectAction("compositionstart");
496 test_result_->ExpectAction("compositionupdate:d");
497 test_result_->Verify();
499 context_->AddCommitAction("e");
500 key = key_new;
501 input_method_auralinux_->DispatchKeyEvent(&key);
503 test_result_->ExpectAction("keydown:229");
504 test_result_->ExpectAction("compositionend");
505 test_result_->ExpectAction("textinput:e");
506 test_result_->Verify();
509 TEST_F(InputMethodAuraLinuxTest, CompositionEndWithoutCommitTest) {
510 context_->SetSyncMode(true);
511 context_->SetEatKey(true);
512 context_->AddCompositionStartAction();
513 context_->AddCompositionUpdateAction("a");
515 scoped_ptr<TextInputClientForTesting> client(
516 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
517 input_method_auralinux_->SetFocusedTextInputClient(client.get());
518 input_method_auralinux_->OnTextInputTypeChanged(client.get());
520 KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0);
521 key_new.set_character(L'a');
522 KeyEvent key = key_new;
523 input_method_auralinux_->DispatchKeyEvent(&key);
525 test_result_->ExpectAction("keydown:229");
526 test_result_->ExpectAction("compositionstart");
527 test_result_->ExpectAction("compositionupdate:a");
528 test_result_->Verify();
530 context_->AddCompositionEndAction();
531 key = key_new;
532 input_method_auralinux_->DispatchKeyEvent(&key);
534 test_result_->ExpectAction("keydown:229");
535 test_result_->ExpectAction("compositionend");
536 test_result_->Verify();
539 TEST_F(InputMethodAuraLinuxTest, CompositionEndWithEmptyCommitTest) {
540 context_->SetSyncMode(true);
541 context_->SetEatKey(true);
542 context_->AddCompositionStartAction();
543 context_->AddCompositionUpdateAction("a");
545 scoped_ptr<TextInputClientForTesting> client(
546 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
547 input_method_auralinux_->SetFocusedTextInputClient(client.get());
548 input_method_auralinux_->OnTextInputTypeChanged(client.get());
550 KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0);
551 key_new.set_character(L'a');
552 KeyEvent key = key_new;
553 input_method_auralinux_->DispatchKeyEvent(&key);
555 test_result_->ExpectAction("keydown:229");
556 test_result_->ExpectAction("compositionstart");
557 test_result_->ExpectAction("compositionupdate:a");
558 test_result_->Verify();
560 context_->AddCompositionEndAction();
561 context_->AddCommitAction("");
562 key = key_new;
563 input_method_auralinux_->DispatchKeyEvent(&key);
565 test_result_->ExpectAction("keydown:229");
566 test_result_->ExpectAction("compositionend");
567 test_result_->Verify();
570 TEST_F(InputMethodAuraLinuxTest, CompositionEndWithCommitTest) {
571 context_->SetSyncMode(true);
572 context_->SetEatKey(true);
573 context_->AddCompositionStartAction();
574 context_->AddCompositionUpdateAction("a");
576 scoped_ptr<TextInputClientForTesting> client(
577 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
578 input_method_auralinux_->SetFocusedTextInputClient(client.get());
579 input_method_auralinux_->OnTextInputTypeChanged(client.get());
581 KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0);
582 key_new.set_character(L'a');
583 KeyEvent key = key_new;
584 input_method_auralinux_->DispatchKeyEvent(&key);
586 test_result_->ExpectAction("keydown:229");
587 test_result_->ExpectAction("compositionstart");
588 test_result_->ExpectAction("compositionupdate:a");
589 test_result_->Verify();
591 context_->AddCompositionEndAction();
592 context_->AddCommitAction("b");
593 key = key_new;
594 input_method_auralinux_->DispatchKeyEvent(&key);
596 // Verifies single char commit under composition mode will call InsertText
597 // intead of InsertChar.
598 test_result_->ExpectAction("keydown:229");
599 test_result_->ExpectAction("compositionend");
600 test_result_->ExpectAction("textinput:b");
601 test_result_->Verify();
604 TEST_F(InputMethodAuraLinuxTest, CompositionUpdateWithCommitTest) {
605 context_->SetSyncMode(true);
606 context_->SetEatKey(true);
607 context_->AddCompositionStartAction();
608 context_->AddCompositionUpdateAction("a");
609 context_->AddCommitAction("b");
611 scoped_ptr<TextInputClientForTesting> client(
612 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
613 input_method_auralinux_->SetFocusedTextInputClient(client.get());
614 input_method_auralinux_->OnTextInputTypeChanged(client.get());
616 KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0);
617 key_new.set_character(L'a');
618 KeyEvent key = key_new;
619 input_method_auralinux_->DispatchKeyEvent(&key);
621 test_result_->ExpectAction("keydown:229");
622 test_result_->ExpectAction("textinput:b");
623 test_result_->ExpectAction("compositionstart");
624 test_result_->ExpectAction("compositionupdate:a");
625 test_result_->Verify();
627 // crbug.com/513124.
628 context_->SetSyncMode(true);
629 context_->SetEatKey(true);
630 context_->AddCommitAction("c");
631 context_->AddCompositionUpdateAction("");
632 key = key_new;
633 input_method_auralinux_->DispatchKeyEvent(&key);
635 test_result_->ExpectAction("keydown:229");
636 test_result_->ExpectAction("compositionend");
637 test_result_->ExpectAction("textinput:c");
638 test_result_->Verify();
641 TEST_F(InputMethodAuraLinuxTest, MixedAsyncAndSyncTest) {
642 context_->SetSyncMode(false);
643 context_->SetEatKey(true);
645 scoped_ptr<TextInputClientForTesting> client(
646 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
647 input_method_auralinux_->SetFocusedTextInputClient(client.get());
648 input_method_auralinux_->OnTextInputTypeChanged(client.get());
650 KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0);
651 key_new.set_character(L'a');
652 KeyEvent key = key_new;
653 input_method_auralinux_->DispatchKeyEvent(&key);
654 CompositionText comp;
655 comp.text = base::ASCIIToUTF16("a");
656 input_method_auralinux_->OnPreeditChanged(comp);
658 test_result_->ExpectAction("keydown:229");
659 test_result_->ExpectAction("compositionstart");
660 test_result_->ExpectAction("compositionupdate:a");
661 test_result_->Verify();
663 context_->SetSyncMode(true);
664 context_->AddCompositionEndAction();
665 context_->AddCommitAction("b");
667 key = key_new;
668 input_method_auralinux_->DispatchKeyEvent(&key);
670 test_result_->ExpectAction("keydown:229");
671 test_result_->ExpectAction("compositionend");
672 test_result_->ExpectAction("textinput:b");
673 test_result_->Verify();
676 TEST_F(InputMethodAuraLinuxTest, MixedSyncAndAsyncTest) {
677 context_->SetSyncMode(true);
678 context_->SetEatKey(true);
679 context_->AddCompositionStartAction();
680 context_->AddCompositionUpdateAction("a");
682 scoped_ptr<TextInputClientForTesting> client(
683 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
684 input_method_auralinux_->SetFocusedTextInputClient(client.get());
685 input_method_auralinux_->OnTextInputTypeChanged(client.get());
687 KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0);
688 key_new.set_character(L'a');
689 KeyEvent key = key_new;
690 input_method_auralinux_->DispatchKeyEvent(&key);
692 test_result_->ExpectAction("keydown:229");
693 test_result_->ExpectAction("compositionstart");
694 test_result_->ExpectAction("compositionupdate:a");
695 test_result_->Verify();
697 context_->SetSyncMode(false);
699 key = key_new;
700 input_method_auralinux_->DispatchKeyEvent(&key);
701 input_method_auralinux_->OnCommit(base::ASCIIToUTF16("b"));
703 test_result_->ExpectAction("keydown:229");
704 test_result_->ExpectAction("compositionend");
705 test_result_->ExpectAction("textinput:b");
706 test_result_->Verify();
708 context_->SetSyncMode(true);
709 context_->AddCommitAction("c");
710 key = key_new;
711 input_method_auralinux_->DispatchKeyEvent(&key);
713 test_result_->ExpectAction("keydown:65");
714 test_result_->ExpectAction("keypress:99");
715 test_result_->Verify();
718 TEST_F(InputMethodAuraLinuxTest, ReleaseKeyTest) {
719 context_->SetSyncMode(true);
720 context_->SetEatKey(true);
721 context_->AddCompositionUpdateAction("a");
723 scoped_ptr<TextInputClientForTesting> client(
724 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT));
725 input_method_auralinux_->SetFocusedTextInputClient(client.get());
726 input_method_auralinux_->OnTextInputTypeChanged(client.get());
728 KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0);
729 key_new.set_character(L'A');
730 KeyEvent key = key_new;
731 input_method_auralinux_->DispatchKeyEvent(&key);
733 test_result_->ExpectAction("keydown:229");
734 test_result_->ExpectAction("compositionstart");
735 test_result_->ExpectAction("compositionupdate:a");
736 test_result_->Verify();
738 context_->SetEatKey(false);
739 context_->AddCommitAction("b");
740 key = key_new;
741 input_method_auralinux_->DispatchKeyEvent(&key);
743 test_result_->ExpectAction("compositionend");
744 test_result_->ExpectAction("textinput:b");
745 test_result_->ExpectAction("keydown:65");
746 test_result_->ExpectAction("keypress:65");
747 test_result_->Verify();
749 context_->AddCommitAction("c");
750 key = key_new;
751 input_method_auralinux_->DispatchKeyEvent(&key);
753 test_result_->ExpectAction("textinput:c");
754 test_result_->ExpectAction("keydown:65");
755 test_result_->ExpectAction("keypress:65");
756 test_result_->Verify();
759 } // namespace
760 } // namespace ui