OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "services/ui/public/interfaces/ime/ime_struct_traits.h" | 5 #include "services/ui/public/interfaces/ime/ime_struct_traits.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "mojo/public/cpp/bindings/binding_set.h" | 9 #include "mojo/public/cpp/bindings/binding_set.h" |
10 #include "services/ui/public/interfaces/ime/ime_struct_traits_test.mojom.h" | 10 #include "services/ui/public/interfaces/ime/ime_struct_traits_test.mojom.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "ui/base/ime/composition_text.h" | 12 #include "ui/base/ime/composition_text.h" |
13 #include "ui/base/ime/composition_underline.h" | 13 #include "ui/base/ime/composition_underline.h" |
| 14 #include "ui/gfx/range/mojo/range_struct_traits.h" |
14 | 15 |
15 namespace ui { | 16 namespace ui { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 class IMEStructTraitsTest : public testing::Test, | 20 class IMEStructTraitsTest : public testing::Test, |
20 public mojom::IMEStructTraitsTest { | 21 public mojom::IMEStructTraitsTest { |
21 public: | 22 public: |
22 IMEStructTraitsTest() {} | 23 IMEStructTraitsTest() {} |
23 | 24 |
24 protected: | 25 protected: |
25 mojom::IMEStructTraitsTestPtr GetTraitsTestProxy() { | 26 mojom::IMEStructTraitsTestPtr GetTraitsTestProxy() { |
26 return traits_test_bindings_.CreateInterfacePtrAndBind(this); | 27 return traits_test_bindings_.CreateInterfacePtrAndBind(this); |
27 } | 28 } |
28 | 29 |
29 private: | 30 private: |
30 // mojom::IMEStructTraitsTest: | 31 // mojom::IMEStructTraitsTest: |
31 void EchoCompositionText( | |
32 const CompositionText& in, | |
33 const EchoCompositionTextCallback& callback) override { | |
34 callback.Run(in); | |
35 } | |
36 void EchoTextInputMode(TextInputMode in, | 32 void EchoTextInputMode(TextInputMode in, |
37 const EchoTextInputModeCallback& callback) override { | 33 const EchoTextInputModeCallback& callback) override { |
38 callback.Run(in); | 34 callback.Run(in); |
39 } | 35 } |
40 void EchoTextInputType(TextInputType in, | 36 void EchoTextInputType(TextInputType in, |
41 const EchoTextInputTypeCallback& callback) override { | 37 const EchoTextInputTypeCallback& callback) override { |
42 callback.Run(in); | 38 callback.Run(in); |
43 } | 39 } |
44 | 40 |
45 base::MessageLoop loop_; // A MessageLoop is needed for Mojo IPC to work. | 41 base::MessageLoop loop_; // A MessageLoop is needed for Mojo IPC to work. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 } | 104 } |
109 | 105 |
110 TEST_F(IMEStructTraitsTest, CompositionText) { | 106 TEST_F(IMEStructTraitsTest, CompositionText) { |
111 CompositionText input; | 107 CompositionText input; |
112 input.text = base::UTF8ToUTF16("abcdefghij"); | 108 input.text = base::UTF8ToUTF16("abcdefghij"); |
113 input.underlines.push_back(CompositionUnderline(0, 2, SK_ColorGRAY, false)); | 109 input.underlines.push_back(CompositionUnderline(0, 2, SK_ColorGRAY, false)); |
114 input.underlines.push_back( | 110 input.underlines.push_back( |
115 CompositionUnderline(3, 6, SK_ColorRED, true, SK_ColorGREEN)); | 111 CompositionUnderline(3, 6, SK_ColorRED, true, SK_ColorGREEN)); |
116 input.selection = gfx::Range(1, 7); | 112 input.selection = gfx::Range(1, 7); |
117 | 113 |
118 mojom::IMEStructTraitsTestPtr proxy = GetTraitsTestProxy(); | |
119 CompositionText output; | 114 CompositionText output; |
120 proxy->EchoCompositionText(input, &output); | 115 EXPECT_TRUE(mojom::CompositionText::Deserialize( |
| 116 mojom::CompositionText::Serialize(&input), &output)); |
121 | 117 |
122 EXPECT_EQ(input, output); | 118 EXPECT_EQ(input, output); |
123 } | 119 } |
124 | 120 |
125 TEST_F(IMEStructTraitsTest, TextInputMode) { | 121 TEST_F(IMEStructTraitsTest, TextInputMode) { |
126 const TextInputMode kTextInputModes[] = { | 122 const TextInputMode kTextInputModes[] = { |
127 TEXT_INPUT_MODE_DEFAULT, TEXT_INPUT_MODE_VERBATIM, | 123 TEXT_INPUT_MODE_DEFAULT, TEXT_INPUT_MODE_VERBATIM, |
128 TEXT_INPUT_MODE_LATIN, TEXT_INPUT_MODE_LATIN_NAME, | 124 TEXT_INPUT_MODE_LATIN, TEXT_INPUT_MODE_LATIN_NAME, |
129 TEXT_INPUT_MODE_LATIN_PROSE, TEXT_INPUT_MODE_FULL_WIDTH_LATIN, | 125 TEXT_INPUT_MODE_LATIN_PROSE, TEXT_INPUT_MODE_FULL_WIDTH_LATIN, |
130 TEXT_INPUT_MODE_KANA, TEXT_INPUT_MODE_KANA_NAME, | 126 TEXT_INPUT_MODE_KANA, TEXT_INPUT_MODE_KANA_NAME, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 160 |
165 mojom::IMEStructTraitsTestPtr proxy = GetTraitsTestProxy(); | 161 mojom::IMEStructTraitsTestPtr proxy = GetTraitsTestProxy(); |
166 for (size_t i = 0; i < arraysize(kTextInputTypes); i++) { | 162 for (size_t i = 0; i < arraysize(kTextInputTypes); i++) { |
167 ui::TextInputType type_out; | 163 ui::TextInputType type_out; |
168 ASSERT_TRUE(proxy->EchoTextInputType(kTextInputTypes[i], &type_out)); | 164 ASSERT_TRUE(proxy->EchoTextInputType(kTextInputTypes[i], &type_out)); |
169 EXPECT_EQ(kTextInputTypes[i], type_out); | 165 EXPECT_EQ(kTextInputTypes[i], type_out); |
170 } | 166 } |
171 } | 167 } |
172 | 168 |
173 } // namespace ui | 169 } // namespace ui |
OLD | NEW |