Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: services/ui/public/interfaces/ime/ime_struct_traits_unittest.cc

Issue 2839243002: IME for Mus: Structs and StructTraits for IME Candidate Window. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "mojo/public/cpp/bindings/binding_set.h" 7 #include "mojo/public/cpp/bindings/binding_set.h"
8 #include "services/ui/public/interfaces/ime/ime_struct_traits_test.mojom.h" 8 #include "services/ui/public/interfaces/ime/ime_struct_traits_test.mojom.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/base/ime/composition_text.h" 10 #include "ui/base/ime/composition_text.h"
11 #include "ui/base/ime/composition_underline.h" 11 #include "ui/base/ime/composition_underline.h"
12 12
13 namespace ui { 13 namespace ui {
14 14
15 namespace { 15 namespace {
16 16
17 class IMEStructTraitsTest : public testing::Test, 17 class IMEStructTraitsTest : public testing::Test,
18 public mojom::IMEStructTraitsTest { 18 public mojom::IMEStructTraitsTest {
19 public: 19 public:
20 IMEStructTraitsTest() {} 20 IMEStructTraitsTest() {}
21 21
22 protected: 22 protected:
23 mojom::IMEStructTraitsTestPtr GetTraitsTestProxy() { 23 mojom::IMEStructTraitsTestPtr GetTraitsTestProxy() {
24 return traits_test_bindings_.CreateInterfacePtrAndBind(this); 24 return traits_test_bindings_.CreateInterfacePtrAndBind(this);
25 } 25 }
26 26
27 private: 27 private:
28 // mojom::IMEStructTraitsTest: 28 // mojom::IMEStructTraitsTest:
29 void EchoCandidateWindowProperties(
30 const CandidateWindow::CandidateWindowProperty& in,
31 const EchoCandidateWindowPropertiesCallback& callback) override {
32 callback.Run(in);
33 }
34 void EchoCandidateWindowEntry(
35 const CandidateWindow::Entry& in,
36 const EchoCandidateWindowEntryCallback& callback) override {
37 callback.Run(in);
38 }
29 void EchoCompositionText( 39 void EchoCompositionText(
30 const CompositionText& in, 40 const CompositionText& in,
31 const EchoCompositionTextCallback& callback) override { 41 const EchoCompositionTextCallback& callback) override {
32 callback.Run(in); 42 callback.Run(in);
33 } 43 }
34 void EchoTextInputMode(TextInputMode in, 44 void EchoTextInputMode(TextInputMode in,
35 const EchoTextInputModeCallback& callback) override { 45 const EchoTextInputModeCallback& callback) override {
36 callback.Run(in); 46 callback.Run(in);
37 } 47 }
38 void EchoTextInputType(TextInputType in, 48 void EchoTextInputType(TextInputType in,
39 const EchoTextInputTypeCallback& callback) override { 49 const EchoTextInputTypeCallback& callback) override {
40 callback.Run(in); 50 callback.Run(in);
41 } 51 }
42 52
43 base::MessageLoop loop_; // A MessageLoop is needed for Mojo IPC to work. 53 base::MessageLoop loop_; // A MessageLoop is needed for Mojo IPC to work.
44 mojo::BindingSet<mojom::IMEStructTraitsTest> traits_test_bindings_; 54 mojo::BindingSet<mojom::IMEStructTraitsTest> traits_test_bindings_;
45 55
46 DISALLOW_COPY_AND_ASSIGN(IMEStructTraitsTest); 56 DISALLOW_COPY_AND_ASSIGN(IMEStructTraitsTest);
47 }; 57 };
48 58
49 } // namespace 59 } // namespace
50 60
61 TEST_F(IMEStructTraitsTest, CandidateWindowProperties) {
62 CandidateWindow::CandidateWindowProperty input;
63 input.page_size = 7;
64 input.cursor_position = 3;
65 input.is_cursor_visible = true;
66 input.is_vertical = false;
67 input.show_window_at_composition = true;
68 input.auxiliary_text = "abcdefghij";
69 input.is_auxiliary_text_visible = false;
70
71 mojom::IMEStructTraitsTestPtr proxy = GetTraitsTestProxy();
72 CandidateWindow::CandidateWindowProperty output;
73 proxy->EchoCandidateWindowProperties(input, &output);
74
75 EXPECT_EQ(input.page_size, output.page_size);
76 EXPECT_EQ(input.cursor_position, output.cursor_position);
77 EXPECT_EQ(input.is_cursor_visible, output.is_cursor_visible);
78 EXPECT_EQ(input.is_vertical, output.is_vertical);
79 EXPECT_EQ(input.show_window_at_composition,
80 output.show_window_at_composition);
81 EXPECT_EQ(input.auxiliary_text, output.auxiliary_text);
82 EXPECT_EQ(input.is_auxiliary_text_visible, output.is_auxiliary_text_visible);
83
84 // Reverse boolean fields and check we still serialize/deserialize correctly.
85 input.is_cursor_visible = !input.is_cursor_visible;
86 input.is_vertical = !input.is_vertical;
87 input.show_window_at_composition = !input.show_window_at_composition;
88 input.is_auxiliary_text_visible = !input.is_auxiliary_text_visible;
89 proxy->EchoCandidateWindowProperties(input, &output);
90
91 EXPECT_EQ(input.is_cursor_visible, output.is_cursor_visible);
92 EXPECT_EQ(input.is_vertical, output.is_vertical);
93 EXPECT_EQ(input.show_window_at_composition,
94 output.show_window_at_composition);
95 EXPECT_EQ(input.is_auxiliary_text_visible, output.is_auxiliary_text_visible);
96 }
97
98 TEST_F(IMEStructTraitsTest, CandidateWindowEntry) {
99 CandidateWindow::Entry input;
100 input.value = base::UTF8ToUTF16("entry_value");
101 input.label = base::UTF8ToUTF16("entry_label");
102 input.annotation = base::UTF8ToUTF16("entry_annotation");
103 input.description_title = base::UTF8ToUTF16("entry_description_title");
104 input.description_body = base::UTF8ToUTF16("entry_description_body");
105
106 mojom::IMEStructTraitsTestPtr proxy = GetTraitsTestProxy();
107 CandidateWindow::Entry output;
108 proxy->EchoCandidateWindowEntry(input, &output);
109
110 EXPECT_EQ(input.value, output.value);
111 EXPECT_EQ(input.label, output.label);
112 EXPECT_EQ(input.annotation, output.annotation);
113 EXPECT_EQ(input.description_title, output.description_title);
114 EXPECT_EQ(input.description_body, output.description_body);
115 }
116
51 TEST_F(IMEStructTraitsTest, CompositionText) { 117 TEST_F(IMEStructTraitsTest, CompositionText) {
52 CompositionText input; 118 CompositionText input;
53 input.text = base::UTF8ToUTF16("abcdefghij"); 119 input.text = base::UTF8ToUTF16("abcdefghij");
54 input.underlines.push_back(CompositionUnderline(0, 2, SK_ColorGRAY, false)); 120 input.underlines.push_back(CompositionUnderline(0, 2, SK_ColorGRAY, false));
55 input.underlines.push_back( 121 input.underlines.push_back(
56 CompositionUnderline(3, 6, SK_ColorRED, true, SK_ColorGREEN)); 122 CompositionUnderline(3, 6, SK_ColorRED, true, SK_ColorGREEN));
57 input.selection = gfx::Range(1, 7); 123 input.selection = gfx::Range(1, 7);
58 124
59 mojom::IMEStructTraitsTestPtr proxy = GetTraitsTestProxy(); 125 mojom::IMEStructTraitsTestPtr proxy = GetTraitsTestProxy();
60 CompositionText output; 126 CompositionText output;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 171
106 mojom::IMEStructTraitsTestPtr proxy = GetTraitsTestProxy(); 172 mojom::IMEStructTraitsTestPtr proxy = GetTraitsTestProxy();
107 for (size_t i = 0; i < arraysize(kTextInputTypes); i++) { 173 for (size_t i = 0; i < arraysize(kTextInputTypes); i++) {
108 ui::TextInputType type_out; 174 ui::TextInputType type_out;
109 ASSERT_TRUE(proxy->EchoTextInputType(kTextInputTypes[i], &type_out)); 175 ASSERT_TRUE(proxy->EchoTextInputType(kTextInputTypes[i], &type_out));
110 EXPECT_EQ(kTextInputTypes[i], type_out); 176 EXPECT_EQ(kTextInputTypes[i], type_out);
111 } 177 }
112 } 178 }
113 179
114 } // namespace ui 180 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698