• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 "chrome/browser/chromeos/status/input_method_menu.h"
6 
7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/chromeos/cros/cros_library.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 
11 namespace chromeos {
12 
TEST(InputMethodMenuTest,GetTextForIndicatorTest)13 TEST(InputMethodMenuTest, GetTextForIndicatorTest) {
14   ScopedStubCrosEnabler enabler;
15   // Test normal cases. Two-letter language code should be returned.
16   {
17     InputMethodDescriptor desc("m17n:fa:isiri",  // input method engine id
18                                "isiri (m17n)",  // input method name
19                                "us",  // keyboard layout name
20                                "fa");  // language name
21     EXPECT_EQ(L"FA", InputMethodMenu::GetTextForIndicator(desc));
22   }
23   {
24     InputMethodDescriptor desc("hangul", "Korean", "us", "ko");
25     EXPECT_EQ(UTF8ToWide("\xed\x95\x9c"),
26               InputMethodMenu::GetTextForIndicator(desc));
27   }
28   {
29     InputMethodDescriptor desc("invalid-id", "unregistered string", "us", "xx");
30     // Upper-case string of the unknown language code, "xx", should be returned.
31     EXPECT_EQ(L"XX", InputMethodMenu::GetTextForIndicator(desc));
32   }
33 
34   // Test special cases.
35   {
36     InputMethodDescriptor desc("xkb:us:dvorak:eng", "Dvorak", "us", "eng");
37     EXPECT_EQ(L"DV", InputMethodMenu::GetTextForIndicator(desc));
38   }
39   {
40     InputMethodDescriptor desc("xkb:us:colemak:eng", "Colemak", "us", "eng");
41     EXPECT_EQ(L"CO", InputMethodMenu::GetTextForIndicator(desc));
42   }
43   {
44     InputMethodDescriptor desc("xkb:us:altgr-intl:eng", "US extd", "us", "eng");
45     EXPECT_EQ(L"EXTD", InputMethodMenu::GetTextForIndicator(desc));
46   }
47   {
48     InputMethodDescriptor desc("xkb:us:intl:eng", "US intl", "us", "eng");
49     EXPECT_EQ(L"INTL", InputMethodMenu::GetTextForIndicator(desc));
50   }
51   {
52     InputMethodDescriptor desc("xkb:de:neo:ger", "Germany - Neo 2", "de(neo)",
53                                "ger");
54     EXPECT_EQ(L"NEO", InputMethodMenu::GetTextForIndicator(desc));
55   }
56   {
57     InputMethodDescriptor desc("mozc", "Mozc", "us", "ja");
58     EXPECT_EQ(UTF8ToWide("\xe3\x81\x82"),
59               InputMethodMenu::GetTextForIndicator(desc));
60   }
61   {
62     InputMethodDescriptor desc("mozc-jp", "Mozc", "jp", "ja");
63     EXPECT_EQ(UTF8ToWide("\xe3\x81\x82"),
64               InputMethodMenu::GetTextForIndicator(desc));
65   }
66   {
67     InputMethodDescriptor desc("pinyin", "Pinyin", "us", "zh-CN");
68     EXPECT_EQ(UTF8ToWide("\xe6\x8b\xbc"),
69               InputMethodMenu::GetTextForIndicator(desc));
70   }
71   {
72     InputMethodDescriptor desc("mozc-chewing", "Chewing", "us", "zh-TW");
73     EXPECT_EQ(UTF8ToWide("\xe9\x85\xb7"),
74               InputMethodMenu::GetTextForIndicator(desc));
75   }
76   {
77     InputMethodDescriptor desc("m17n:zh:cangjie", "Cangjie", "us", "zh-TW");
78     EXPECT_EQ(UTF8ToWide("\xe5\x80\x89"),
79               InputMethodMenu::GetTextForIndicator(desc));
80   }
81   {
82     InputMethodDescriptor desc("m17n:zh:quick", "Quick", "us", "zh-TW");
83     EXPECT_EQ(UTF8ToWide("\xe9\x80\x9f"),
84               InputMethodMenu::GetTextForIndicator(desc));
85   }
86 }
87 
88 
89 // Test whether the function returns language name for non-ambiguous languages.
TEST(InputMethodMenuTest,GetTextForMenuTest)90 TEST(InputMethodMenuTest, GetTextForMenuTest) {
91   // For most languages input method or keyboard layout name is returned.
92   // See below for exceptions.
93   {
94     InputMethodDescriptor desc("m17n:fa:isiri", "isiri (m17n)", "us", "fa");
95     EXPECT_EQ(L"Persian input method (ISIRI 2901 layout)",
96               InputMethodMenu::GetTextForMenu(desc));
97   }
98   {
99     InputMethodDescriptor desc("hangul", "Korean", "us", "ko");
100     EXPECT_EQ(L"Korean input method",
101               InputMethodMenu::GetTextForMenu(desc));
102   }
103   {
104     InputMethodDescriptor desc("m17n:vi:tcvn", "tcvn (m17n)", "us", "vi");
105     EXPECT_EQ(L"Vietnamese input method (TCVN6064)",
106               InputMethodMenu::GetTextForMenu(desc));
107   }
108   {
109     InputMethodDescriptor desc("mozc", "Mozc (US keyboard layout)", "us", "ja");
110     EXPECT_EQ(L"Japanese input method (for US keyboard)",
111               InputMethodMenu::GetTextForMenu(desc));
112   }
113   {
114     InputMethodDescriptor desc("xkb:jp::jpn", "Japan", "jp", "jpn");
115     EXPECT_EQ(L"Japanese keyboard",
116               InputMethodMenu::GetTextForMenu(desc));
117   }
118   {
119     InputMethodDescriptor desc("xkb:us:dvorak:eng", "USA - Dvorak",
120                                "us(dvorak)", "eng");
121     EXPECT_EQ(L"US Dvorak keyboard",
122               InputMethodMenu::GetTextForMenu(desc));
123   }
124   {
125     InputMethodDescriptor desc("xkb:gb:dvorak:eng", "United Kingdom - Dvorak",
126                                "gb(dvorak)", "eng");
127     EXPECT_EQ(L"UK Dvorak keyboard",
128               InputMethodMenu::GetTextForMenu(desc));
129   }
130 
131   // For Arabic, Dutch, French, German and Hindi,
132   // "language - keyboard layout" pair is returned.
133   {
134     InputMethodDescriptor desc("m17n:ar:kbd", "kbd (m17n)", "us", "ar");
135     EXPECT_EQ(L"Arabic - Standard input method",
136               InputMethodMenu::GetTextForMenu(desc));
137   }
138   {
139     InputMethodDescriptor desc("xkb:nl::nld", "Netherlands", "nl", "nld");
140     EXPECT_EQ(L"Dutch - Dutch keyboard",
141               InputMethodMenu::GetTextForMenu(desc));
142   }
143   {
144     InputMethodDescriptor desc("xkb:be::nld", "Belgium", "be", "nld");
145     EXPECT_EQ(L"Dutch - Belgian keyboard",
146               InputMethodMenu::GetTextForMenu(desc));
147   }
148   {
149     InputMethodDescriptor desc("xkb:fr::fra", "France", "fr", "fra");
150     EXPECT_EQ(L"French - French keyboard",
151               InputMethodMenu::GetTextForMenu(desc));
152   }
153   {
154     InputMethodDescriptor desc("xkb:be::fra", "Belgium", "be", "fra");
155     EXPECT_EQ(L"French - Belgian keyboard",
156               InputMethodMenu::GetTextForMenu(desc));
157   }
158   {
159     InputMethodDescriptor desc("xkb:de::ger", "Germany", "de", "ger");
160     EXPECT_EQ(L"German - German keyboard",
161               InputMethodMenu::GetTextForMenu(desc));
162   }
163   {
164     InputMethodDescriptor desc("xkb:be::ger", "Belgium", "be", "ger");
165     EXPECT_EQ(L"German - Belgian keyboard",
166               InputMethodMenu::GetTextForMenu(desc));
167   }
168   {
169     InputMethodDescriptor desc("m17n:hi:itrans", "itrans (m17n)", "us", "hi");
170     EXPECT_EQ(L"Hindi - Standard input method",
171               InputMethodMenu::GetTextForMenu(desc));
172   }
173 
174   {
175     InputMethodDescriptor desc("invalid-id", "unregistered string", "us", "xx");
176     // You can safely ignore the "Resouce ID is not found for: unregistered
177     // string" error.
178     EXPECT_EQ(L"unregistered string",
179               InputMethodMenu::GetTextForMenu(desc));
180   }
181 }
182 
183 }  // namespace chromeos
184