OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/views/mus/input_method_mus.h" | |
6 | |
7 #include "base/message_loop/message_loop.h" | |
8 #include "base/run_loop.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 #include "ui/base/ime/dummy_text_input_client.h" | |
11 #include "ui/base/ime/input_method_delegate.h" | |
12 #include "ui/events/event.h" | |
13 #include "ui/views/mus/window_manager_connection.h" | |
14 #include "ui/views/test/scoped_views_test_helper.h" | |
15 | |
16 namespace views { | |
17 namespace { | |
18 | |
19 class TestInputMethodDelegate : public ui::internal::InputMethodDelegate { | |
20 public: | |
21 TestInputMethodDelegate() {} | |
22 ~TestInputMethodDelegate() override {} | |
23 | |
24 // ui::internal::InputMethodDelegate: | |
25 ui::EventDispatchDetails DispatchKeyEventPostIME( | |
26 ui::KeyEvent* key_event) override { | |
27 return ui::EventDispatchDetails(); | |
28 } | |
29 | |
30 private: | |
31 DISALLOW_COPY_AND_ASSIGN(TestInputMethodDelegate); | |
32 }; | |
33 | |
34 class TestTextInputClient : public ui::DummyTextInputClient { | |
35 public: | |
36 TestTextInputClient() {} | |
37 ~TestTextInputClient() override {} | |
38 | |
39 ui::KeyEvent* ReceieveKeyEvent() { | |
sadrul
2016/08/16 20:01:51
WaitUntilInputReceived()?
Hadi
2016/08/16 20:18:25
Done.
| |
40 run_loop_.reset(new base::RunLoop); | |
41 run_loop_->Run(); | |
42 run_loop_.reset(); | |
43 | |
44 return received_event_->AsKeyEvent(); | |
45 } | |
46 | |
47 // ui::DummyTextInputClient: | |
48 void InsertChar(const ui::KeyEvent& event) override { | |
49 received_event_ = ui::Event::Clone(event); | |
50 run_loop_->Quit(); | |
51 } | |
52 | |
53 private: | |
54 std::unique_ptr<base::RunLoop> run_loop_; | |
55 std::unique_ptr<ui::Event> received_event_; | |
56 | |
57 DISALLOW_COPY_AND_ASSIGN(TestTextInputClient); | |
58 }; | |
59 | |
60 } // namespace | |
61 | |
62 class InputMethodMusTest : public testing::Test { | |
63 public: | |
64 InputMethodMusTest() : message_loop_(base::MessageLoop::TYPE_UI) {} | |
65 ~InputMethodMusTest() override {} | |
66 | |
67 shell::Connector* connector() { | |
68 return WindowManagerConnection::Get()->connector(); | |
69 } | |
70 | |
71 private: | |
72 base::MessageLoop message_loop_; | |
73 ScopedViewsTestHelper helper_; | |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(InputMethodMusTest); | |
76 }; | |
77 | |
78 TEST_F(InputMethodMusTest, DispatchKeyEvent) { | |
79 // test_ime_driver will register itself as the current IMEDriver. It echoes | |
80 // back the key events it receives. | |
81 ASSERT_TRUE(connector()->Connect("mojo:test_ime_driver")); | |
82 | |
83 TestInputMethodDelegate input_method_delegate; | |
84 InputMethodMus input_method(&input_method_delegate, nullptr); | |
85 input_method.Init(connector()); | |
86 | |
87 TestTextInputClient text_input_client; | |
88 input_method.SetFocusedTextInputClient(&text_input_client); | |
89 | |
90 ui::KeyEvent key_event('A', ui::VKEY_A, 0); | |
91 input_method.DispatchKeyEvent(&key_event); | |
92 | |
93 ui::KeyEvent* received_event = text_input_client.ReceieveKeyEvent(); | |
94 ASSERT_EQ(ui::ET_KEY_PRESSED, received_event->type()); | |
sadrul
2016/08/16 20:01:51
EXPECT_EQ
Hadi
2016/08/16 20:18:25
Done.
| |
95 ASSERT_EQ(key_event.GetCharacter(), received_event->GetCharacter()); | |
sadrul
2016/08/16 20:01:51
ditto
Also check EXPECT_TRUE(received_event->is_c
Hadi
2016/08/16 20:18:25
Done.
| |
96 } | |
97 | |
98 } // namespace views | |
OLD | NEW |