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" |
| 6 |
5 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
6 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
7 #include "mojo/public/cpp/bindings/binding_set.h" | 9 #include "mojo/public/cpp/bindings/binding_set.h" |
8 #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" |
9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/base/ime/composition_text.h" | 12 #include "ui/base/ime/composition_text.h" |
11 #include "ui/base/ime/composition_underline.h" | 13 #include "ui/base/ime/composition_underline.h" |
12 | 14 |
13 namespace ui { | 15 namespace ui { |
14 | 16 |
(...skipping 26 matching lines...) Expand all Loading... |
41 } | 43 } |
42 | 44 |
43 base::MessageLoop loop_; // A MessageLoop is needed for Mojo IPC to work. | 45 base::MessageLoop loop_; // A MessageLoop is needed for Mojo IPC to work. |
44 mojo::BindingSet<mojom::IMEStructTraitsTest> traits_test_bindings_; | 46 mojo::BindingSet<mojom::IMEStructTraitsTest> traits_test_bindings_; |
45 | 47 |
46 DISALLOW_COPY_AND_ASSIGN(IMEStructTraitsTest); | 48 DISALLOW_COPY_AND_ASSIGN(IMEStructTraitsTest); |
47 }; | 49 }; |
48 | 50 |
49 } // namespace | 51 } // namespace |
50 | 52 |
| 53 TEST_F(IMEStructTraitsTest, CandidateWindowProperties) { |
| 54 CandidateWindow::CandidateWindowProperty input; |
| 55 input.page_size = 7; |
| 56 input.cursor_position = 3; |
| 57 input.is_cursor_visible = true; |
| 58 input.is_vertical = false; |
| 59 input.show_window_at_composition = true; |
| 60 input.auxiliary_text = "abcdefghij"; |
| 61 input.is_auxiliary_text_visible = false; |
| 62 |
| 63 CandidateWindow::CandidateWindowProperty output; |
| 64 EXPECT_TRUE(mojom::CandidateWindowProperties::Deserialize( |
| 65 mojom::CandidateWindowProperties::Serialize(&input), &output)); |
| 66 |
| 67 EXPECT_EQ(input.page_size, output.page_size); |
| 68 EXPECT_EQ(input.cursor_position, output.cursor_position); |
| 69 EXPECT_EQ(input.is_cursor_visible, output.is_cursor_visible); |
| 70 EXPECT_EQ(input.is_vertical, output.is_vertical); |
| 71 EXPECT_EQ(input.show_window_at_composition, |
| 72 output.show_window_at_composition); |
| 73 EXPECT_EQ(input.auxiliary_text, output.auxiliary_text); |
| 74 EXPECT_EQ(input.is_auxiliary_text_visible, output.is_auxiliary_text_visible); |
| 75 |
| 76 // Reverse boolean fields and check we still serialize/deserialize correctly. |
| 77 input.is_cursor_visible = !input.is_cursor_visible; |
| 78 input.is_vertical = !input.is_vertical; |
| 79 input.show_window_at_composition = !input.show_window_at_composition; |
| 80 input.is_auxiliary_text_visible = !input.is_auxiliary_text_visible; |
| 81 EXPECT_TRUE(mojom::CandidateWindowProperties::Deserialize( |
| 82 mojom::CandidateWindowProperties::Serialize(&input), &output)); |
| 83 |
| 84 EXPECT_EQ(input.is_cursor_visible, output.is_cursor_visible); |
| 85 EXPECT_EQ(input.is_vertical, output.is_vertical); |
| 86 EXPECT_EQ(input.show_window_at_composition, |
| 87 output.show_window_at_composition); |
| 88 EXPECT_EQ(input.is_auxiliary_text_visible, output.is_auxiliary_text_visible); |
| 89 } |
| 90 |
| 91 TEST_F(IMEStructTraitsTest, CandidateWindowEntry) { |
| 92 CandidateWindow::Entry input; |
| 93 input.value = base::UTF8ToUTF16("entry_value"); |
| 94 input.label = base::UTF8ToUTF16("entry_label"); |
| 95 input.annotation = base::UTF8ToUTF16("entry_annotation"); |
| 96 input.description_title = base::UTF8ToUTF16("entry_description_title"); |
| 97 input.description_body = base::UTF8ToUTF16("entry_description_body"); |
| 98 |
| 99 CandidateWindow::Entry output; |
| 100 EXPECT_TRUE(mojom::CandidateWindowEntry::Deserialize( |
| 101 mojom::CandidateWindowEntry::Serialize(&input), &output)); |
| 102 |
| 103 EXPECT_EQ(input.value, output.value); |
| 104 EXPECT_EQ(input.label, output.label); |
| 105 EXPECT_EQ(input.annotation, output.annotation); |
| 106 EXPECT_EQ(input.description_title, output.description_title); |
| 107 EXPECT_EQ(input.description_body, output.description_body); |
| 108 } |
| 109 |
51 TEST_F(IMEStructTraitsTest, CompositionText) { | 110 TEST_F(IMEStructTraitsTest, CompositionText) { |
52 CompositionText input; | 111 CompositionText input; |
53 input.text = base::UTF8ToUTF16("abcdefghij"); | 112 input.text = base::UTF8ToUTF16("abcdefghij"); |
54 input.underlines.push_back(CompositionUnderline(0, 2, SK_ColorGRAY, false)); | 113 input.underlines.push_back(CompositionUnderline(0, 2, SK_ColorGRAY, false)); |
55 input.underlines.push_back( | 114 input.underlines.push_back( |
56 CompositionUnderline(3, 6, SK_ColorRED, true, SK_ColorGREEN)); | 115 CompositionUnderline(3, 6, SK_ColorRED, true, SK_ColorGREEN)); |
57 input.selection = gfx::Range(1, 7); | 116 input.selection = gfx::Range(1, 7); |
58 | 117 |
59 mojom::IMEStructTraitsTestPtr proxy = GetTraitsTestProxy(); | 118 mojom::IMEStructTraitsTestPtr proxy = GetTraitsTestProxy(); |
60 CompositionText output; | 119 CompositionText output; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 164 |
106 mojom::IMEStructTraitsTestPtr proxy = GetTraitsTestProxy(); | 165 mojom::IMEStructTraitsTestPtr proxy = GetTraitsTestProxy(); |
107 for (size_t i = 0; i < arraysize(kTextInputTypes); i++) { | 166 for (size_t i = 0; i < arraysize(kTextInputTypes); i++) { |
108 ui::TextInputType type_out; | 167 ui::TextInputType type_out; |
109 ASSERT_TRUE(proxy->EchoTextInputType(kTextInputTypes[i], &type_out)); | 168 ASSERT_TRUE(proxy->EchoTextInputType(kTextInputTypes[i], &type_out)); |
110 EXPECT_EQ(kTextInputTypes[i], type_out); | 169 EXPECT_EQ(kTextInputTypes[i], type_out); |
111 } | 170 } |
112 } | 171 } |
113 | 172 |
114 } // namespace ui | 173 } // namespace ui |
OLD | NEW |