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

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_util_unittest.cc

Issue 309623005: Remove the flag g_use_wrapped_extension_keyboard_layouts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/input_method/input_method_util.h" 5 #include "chrome/browser/chromeos/input_method/input_method_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chromeos/ime/extension_ime_util.h" 12 #include "chromeos/ime/extension_ime_util.h"
13 #include "chromeos/ime/fake_input_method_delegate.h" 13 #include "chromeos/ime/fake_input_method_delegate.h"
14 #include "chromeos/ime/input_method_manager.h" 14 #include "chromeos/ime/input_method_manager.h"
15 #include "chromeos/ime/input_method_whitelist.h" 15 #include "chromeos/ime/input_method_whitelist.h"
16 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
19 19
20 using base::ASCIIToUTF16; 20 using base::ASCIIToUTF16;
21 21
22 namespace chromeos { 22 namespace chromeos {
23 23
24 extern const char* kExtensionImePrefix; 24 extern const char* kExtensionImePrefix;
25 25
26 namespace input_method { 26 namespace input_method {
27 27
28 namespace { 28 namespace {
29 29
30 const char pinyin_ime_id[] = 30 const char pinyin_ime_id[] = "zh-t-i0-pinyin";
31 "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-t-i0-pinyin"; 31 const char zhuyin_ime_id[] = "zh-hant-t-i0-und";
32 const char zhuyin_ime_id[] =
33 "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-hant-t-i0-und";
34 const char kKeyboardExtId[] =
35 #if defined(OFFICIAL_BUILD)
36 "habcdindjejkmepknlhkkloncjcpcnbf";
37 #else
38 "jhffeifommiaekmbkkjlpmilogcfdohp";
39 #endif
40 32
41 class TestableInputMethodUtil : public InputMethodUtil { 33 class TestableInputMethodUtil : public InputMethodUtil {
42 public: 34 public:
43 explicit TestableInputMethodUtil(InputMethodDelegate* delegate, 35 explicit TestableInputMethodUtil(InputMethodDelegate* delegate,
44 scoped_ptr<InputMethodDescriptors> methods) 36 scoped_ptr<InputMethodDescriptors> methods)
45 : InputMethodUtil(delegate, methods.Pass()) { 37 : InputMethodUtil(delegate, methods.Pass()) {
46 } 38 }
47 // Change access rights. 39 // Change access rights.
48 using InputMethodUtil::GetInputMethodIdsFromLanguageCodeInternal; 40 using InputMethodUtil::GetInputMethodIdsFromLanguageCodeInternal;
49 using InputMethodUtil::GetKeyboardLayoutName; 41 using InputMethodUtil::GetKeyboardLayoutName;
(...skipping 14 matching lines...) Expand all
64 } 56 }
65 57
66 virtual void SetUp() OVERRIDE { 58 virtual void SetUp() OVERRIDE {
67 InputMethodDescriptors input_methods; 59 InputMethodDescriptors input_methods;
68 60
69 std::vector<std::string> layouts; 61 std::vector<std::string> layouts;
70 std::vector<std::string> languages; 62 std::vector<std::string> languages;
71 layouts.push_back("us"); 63 layouts.push_back("us");
72 languages.push_back("zh-CN"); 64 languages.push_back("zh-CN");
73 65
74 InputMethodDescriptor pinyin_ime(pinyin_ime_id, 66 InputMethodDescriptor pinyin_ime(Id(pinyin_ime_id),
75 "Pinyin input for testing", 67 "Pinyin input for testing",
76 "CN", 68 "CN",
77 layouts, 69 layouts,
78 languages, 70 languages,
79 false, 71 false,
80 GURL(""), 72 GURL(""),
81 GURL("")); 73 GURL(""));
82 input_methods.push_back(pinyin_ime); 74 input_methods.push_back(pinyin_ime);
83 75
84 languages.clear(); 76 languages.clear();
85 languages.push_back("zh-TW"); 77 languages.push_back("zh-TW");
86 InputMethodDescriptor zhuyin_ime(zhuyin_ime_id, 78 InputMethodDescriptor zhuyin_ime(zhuyin_ime_id,
87 "Zhuyin input for testing", 79 "Zhuyin input for testing",
88 "TW", 80 "TW",
89 layouts, 81 layouts,
90 languages, 82 languages,
91 false, 83 false,
92 GURL(""), 84 GURL(""),
93 GURL("")); 85 GURL(""));
94 input_methods.push_back(zhuyin_ime); 86 input_methods.push_back(zhuyin_ime);
95 87
96 util_.InitXkbInputMethodsForTesting(); 88 util_.InitXkbInputMethodsForTesting();
97 util_.AppendInputMethods(input_methods); 89 util_.AppendInputMethods(input_methods);
98 } 90 }
99 91
100 std::string Id(const std::string& id) { 92 std::string Id(const std::string& id) {
101 return extension_ime_util::GetInputMethodIDByKeyboardLayout(id); 93 return extension_ime_util::GetInputMethodIDByEngineID(id);
102 } 94 }
103 95
104 InputMethodDescriptor GetDesc(const std::string& id, 96 InputMethodDescriptor GetDesc(const std::string& id,
105 const std::string& raw_layout, 97 const std::string& raw_layout,
106 const std::string& language_code, 98 const std::string& language_code,
107 const std::string& indicator) { 99 const std::string& indicator) {
108 std::vector<std::string> layouts; 100 std::vector<std::string> layouts;
109 layouts.push_back(raw_layout); 101 layouts.push_back(raw_layout);
110 std::vector<std::string> languages; 102 std::vector<std::string> languages;
111 languages.push_back(language_code); 103 languages.push_back(language_code);
(...skipping 12 matching lines...) Expand all
124 } 116 }
125 117
126 FakeInputMethodDelegate delegate_; 118 FakeInputMethodDelegate delegate_;
127 InputMethodWhitelist whitelist_; 119 InputMethodWhitelist whitelist_;
128 TestableInputMethodUtil util_; 120 TestableInputMethodUtil util_;
129 }; 121 };
130 122
131 TEST_F(InputMethodUtilTest, GetInputMethodShortNameTest) { 123 TEST_F(InputMethodUtilTest, GetInputMethodShortNameTest) {
132 // Test normal cases. Two-letter language code should be returned. 124 // Test normal cases. Two-letter language code should be returned.
133 { 125 {
134 InputMethodDescriptor desc = GetDesc("m17n:fa:isiri", // input method id 126 InputMethodDescriptor desc = GetDesc("vkd_fa", // input method id
135 "us", // keyboard layout name 127 "us", // keyboard layout name
136 "fa", // language name 128 "fa", // language name
137 ""); // indicator 129 ""); // indicator
138 EXPECT_EQ(ASCIIToUTF16("FA"), util_.GetInputMethodShortName(desc)); 130 EXPECT_EQ(ASCIIToUTF16("FA"), util_.GetInputMethodShortName(desc));
139 } 131 }
140 { 132 {
141 InputMethodDescriptor desc = GetDesc("mozc-hangul", "us", "ko", ""); 133 InputMethodDescriptor desc = GetDesc("hangul_2set", "us", "ko", "");
142 EXPECT_EQ(base::UTF8ToUTF16("\xed\x95\x9c"), 134 EXPECT_EQ(base::UTF8ToUTF16("\xed\x95\x9c"),
143 util_.GetInputMethodShortName(desc)); 135 util_.GetInputMethodShortName(desc));
144 } 136 }
145 { 137 {
146 InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", ""); 138 InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", "");
147 // Upper-case string of the unknown language code, "xx", should be returned. 139 // Upper-case string of the unknown language code, "xx", should be returned.
148 EXPECT_EQ(ASCIIToUTF16("XX"), util_.GetInputMethodShortName(desc)); 140 EXPECT_EQ(ASCIIToUTF16("XX"), util_.GetInputMethodShortName(desc));
149 } 141 }
150 142
151 // Test special cases. 143 // Test special cases.
(...skipping 27 matching lines...) Expand all
179 GetDesc("xkb:es:cat:cat", "es(cat)", "ca", "CAS"); 171 GetDesc("xkb:es:cat:cat", "es(cat)", "ca", "CAS");
180 EXPECT_EQ(ASCIIToUTF16("CAS"), util_.GetInputMethodShortName(desc)); 172 EXPECT_EQ(ASCIIToUTF16("CAS"), util_.GetInputMethodShortName(desc));
181 } 173 }
182 { 174 {
183 InputMethodDescriptor desc = 175 InputMethodDescriptor desc =
184 GetDesc(pinyin_ime_id, "us", "zh-CN", ""); 176 GetDesc(pinyin_ime_id, "us", "zh-CN", "");
185 EXPECT_EQ(base::UTF8ToUTF16("\xe6\x8b\xbc"), 177 EXPECT_EQ(base::UTF8ToUTF16("\xe6\x8b\xbc"),
186 util_.GetInputMethodShortName(desc)); 178 util_.GetInputMethodShortName(desc));
187 } 179 }
188 { 180 {
189 InputMethodDescriptor desc = 181 InputMethodDescriptor desc = GetDesc(zhuyin_ime_id, "us", "zh-TW", "");
190 GetDesc(zhuyin_ime_id, "us", "zh-TW", "");
191 EXPECT_EQ(base::UTF8ToUTF16("\xE6\xB3\xA8"), 182 EXPECT_EQ(base::UTF8ToUTF16("\xE6\xB3\xA8"),
192 util_.GetInputMethodShortName(desc)); 183 util_.GetInputMethodShortName(desc));
193 } 184 }
194 } 185 }
195 186
196 TEST_F(InputMethodUtilTest, GetInputMethodMediumNameTest) { 187 TEST_F(InputMethodUtilTest, GetInputMethodMediumNameTest) {
197 { 188 {
198 // input methods with medium name equal to short name 189 // input methods with medium name equal to short name
199 const char * input_method_id[] = { 190 const char * input_method_id[] = {
200 "xkb:us:altgr-intl:eng", 191 "xkb:us:altgr-intl:eng",
201 "xkb:us:dvorak:eng", 192 "xkb:us:dvorak:eng",
202 "xkb:us:intl:eng", 193 "xkb:us:intl:eng",
203 "xkb:us:colemak:eng", 194 "xkb:us:colemak:eng",
204 "xkb:de:neo:ger", 195 "xkb:de:neo:ger",
205 "xkb:es:cat:cat", 196 "xkb:es:cat:cat",
206 "xkb:gb:dvorak:eng", 197 "xkb:gb:dvorak:eng",
207 }; 198 };
208 const int len = ARRAYSIZE_UNSAFE(input_method_id); 199 const int len = ARRAYSIZE_UNSAFE(input_method_id);
209 for (int i=0; i<len; ++i) { 200 for (int i=0; i<len; ++i) {
210 InputMethodDescriptor desc = GetDesc(input_method_id[i], "", "", ""); 201 InputMethodDescriptor desc = GetDesc(input_method_id[i], "", "", "");
211 base::string16 medium_name = util_.GetInputMethodMediumName(desc); 202 base::string16 medium_name = util_.GetInputMethodMediumName(desc);
212 base::string16 short_name = util_.GetInputMethodShortName(desc); 203 base::string16 short_name = util_.GetInputMethodShortName(desc);
213 EXPECT_EQ(medium_name,short_name); 204 EXPECT_EQ(medium_name,short_name);
214 } 205 }
215 } 206 }
216 { 207 {
217 // input methods with medium name not equal to short name 208 // input methods with medium name not equal to short name
218 const char * input_method_id[] = { 209 const char * input_method_id[] = {
219 "m17n:zh:cangjie",
220 "m17n:zh:quick",
221 pinyin_ime_id, 210 pinyin_ime_id,
222 zhuyin_ime_id, 211 zhuyin_ime_id,
223 "mozc-hangul",
224 pinyin_ime_id,
225 pinyin_ime_id,
226 }; 212 };
227 const int len = ARRAYSIZE_UNSAFE(input_method_id); 213 const int len = ARRAYSIZE_UNSAFE(input_method_id);
228 for (int i=0; i<len; ++i) { 214 for (int i=0; i<len; ++i) {
229 InputMethodDescriptor desc = GetDesc(input_method_id[i], "", "", ""); 215 InputMethodDescriptor desc = GetDesc(input_method_id[i], "", "", "");
230 base::string16 medium_name = util_.GetInputMethodMediumName(desc); 216 base::string16 medium_name = util_.GetInputMethodMediumName(desc);
231 base::string16 short_name = util_.GetInputMethodShortName(desc); 217 base::string16 short_name = util_.GetInputMethodShortName(desc);
232 EXPECT_NE(medium_name,short_name); 218 EXPECT_NE(medium_name,short_name);
233 } 219 }
234 } 220 }
235 } 221 }
236 222
237 TEST_F(InputMethodUtilTest, GetInputMethodLongNameTest) { 223 TEST_F(InputMethodUtilTest, GetInputMethodLongNameTest) {
238 // For most languages input method or keyboard layout name is returned. 224 // For most languages input method or keyboard layout name is returned.
239 // See below for exceptions. 225 // See below for exceptions.
240 { 226 {
241 InputMethodDescriptor desc = GetDesc("m17n:fa:isiri", "us", "fa", "");
242 EXPECT_EQ(ASCIIToUTF16("Persian input method (ISIRI 2901 layout)"),
243 util_.GetInputMethodLongName(desc));
244 }
245 {
246 InputMethodDescriptor desc = GetDesc("mozc-hangul", "us", "ko", "");
247 EXPECT_EQ(ASCIIToUTF16("Korean input method"),
248 util_.GetInputMethodLongName(desc));
249 }
250 {
251 InputMethodDescriptor desc = GetDesc("m17n:vi:tcvn", "us", "vi", "");
252 EXPECT_EQ(ASCIIToUTF16("Vietnamese input method (TCVN6064)"),
253 util_.GetInputMethodLongName(desc));
254 }
255 {
256 InputMethodDescriptor desc = GetDesc("xkb:jp::jpn", "jp", "ja", ""); 227 InputMethodDescriptor desc = GetDesc("xkb:jp::jpn", "jp", "ja", "");
257 EXPECT_EQ(ASCIIToUTF16("Japanese"), 228 EXPECT_EQ(ASCIIToUTF16("Japanese"),
258 util_.GetInputMethodLongName(desc)); 229 util_.GetInputMethodLongName(desc));
259 } 230 }
260 { 231 {
261 InputMethodDescriptor desc = 232 InputMethodDescriptor desc =
262 GetDesc("xkb:us:dvorak:eng", "us(dvorak)", "en-US", ""); 233 GetDesc("xkb:us:dvorak:eng", "us(dvorak)", "en-US", "");
263 EXPECT_EQ(ASCIIToUTF16("US Dvorak"), 234 EXPECT_EQ(ASCIIToUTF16("US Dvorak"),
264 util_.GetInputMethodLongName(desc)); 235 util_.GetInputMethodLongName(desc));
265 } 236 }
266 { 237 {
267 InputMethodDescriptor desc = 238 InputMethodDescriptor desc =
268 GetDesc("xkb:gb:dvorak:eng", "gb(dvorak)", "en-US", ""); 239 GetDesc("xkb:gb:dvorak:eng", "gb(dvorak)", "en-US", "");
269 EXPECT_EQ(ASCIIToUTF16("UK Dvorak"), 240 EXPECT_EQ(ASCIIToUTF16("UK Dvorak"),
270 util_.GetInputMethodLongName(desc)); 241 util_.GetInputMethodLongName(desc));
271 } 242 }
272 243
273 // For Arabic, Dutch, French, German and Hindi, 244 // For Dutch, French, German and Hindi,
274 // "language - keyboard layout" pair is returned. 245 // "language - keyboard layout" pair is returned.
275 { 246 {
276 InputMethodDescriptor desc = GetDesc("m17n:ar:kbd", "us", "ar", "");
277 EXPECT_EQ(ASCIIToUTF16("Arabic - Standard input method"),
278 util_.GetInputMethodLongName(desc));
279 }
280 {
281 InputMethodDescriptor desc = GetDesc("xkb:be::nld", "be", "nl", ""); 247 InputMethodDescriptor desc = GetDesc("xkb:be::nld", "be", "nl", "");
282 EXPECT_EQ(ASCIIToUTF16("Dutch - Belgian"), 248 EXPECT_EQ(ASCIIToUTF16("Dutch - Belgian"),
283 util_.GetInputMethodLongName(desc)); 249 util_.GetInputMethodLongName(desc));
284 } 250 }
285 { 251 {
286 InputMethodDescriptor desc = GetDesc("xkb:fr::fra", "fr", "fr", ""); 252 InputMethodDescriptor desc = GetDesc("xkb:fr::fra", "fr", "fr", "");
287 EXPECT_EQ(ASCIIToUTF16("French - French"), 253 EXPECT_EQ(ASCIIToUTF16("French - French"),
288 util_.GetInputMethodLongName(desc)); 254 util_.GetInputMethodLongName(desc));
289 } 255 }
290 { 256 {
291 InputMethodDescriptor desc = GetDesc("xkb:be::fra", "be", "fr", ""); 257 InputMethodDescriptor desc = GetDesc("xkb:be::fra", "be", "fr", "");
292 EXPECT_EQ(ASCIIToUTF16("French - Belgian"), 258 EXPECT_EQ(ASCIIToUTF16("French - Belgian"),
293 util_.GetInputMethodLongName(desc)); 259 util_.GetInputMethodLongName(desc));
294 } 260 }
295 { 261 {
296 InputMethodDescriptor desc = GetDesc("xkb:de::ger", "de", "de", ""); 262 InputMethodDescriptor desc = GetDesc("xkb:de::ger", "de", "de", "");
297 EXPECT_EQ(ASCIIToUTF16("German - German"), 263 EXPECT_EQ(ASCIIToUTF16("German - German"),
298 util_.GetInputMethodLongName(desc)); 264 util_.GetInputMethodLongName(desc));
299 } 265 }
300 { 266 {
301 InputMethodDescriptor desc = GetDesc("xkb:be::ger", "be", "de", ""); 267 InputMethodDescriptor desc = GetDesc("xkb:be::ger", "be", "de", "");
302 EXPECT_EQ(ASCIIToUTF16("German - Belgian"), 268 EXPECT_EQ(ASCIIToUTF16("German - Belgian"),
303 util_.GetInputMethodLongName(desc)); 269 util_.GetInputMethodLongName(desc));
304 } 270 }
305 {
306 InputMethodDescriptor desc = GetDesc("m17n:hi:itrans", "us", "hi", "");
307 EXPECT_EQ(ASCIIToUTF16("Hindi - Standard input method"),
308 util_.GetInputMethodLongName(desc));
309 }
310 271
311 { 272 {
312 InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", ""); 273 InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", "");
313 // You can safely ignore the "Resouce ID is not found for: invalid-id" 274 // You can safely ignore the "Resouce ID is not found for: invalid-id"
314 // error. 275 // error.
315 EXPECT_EQ(ASCIIToUTF16("invalid-id"), 276 EXPECT_EQ(ASCIIToUTF16("invalid-id"),
316 util_.GetInputMethodLongName(desc)); 277 util_.GetInputMethodLongName(desc));
317 } 278 }
318 } 279 }
319 280
320 TEST_F(InputMethodUtilTest, TestIsValidInputMethodId) { 281 TEST_F(InputMethodUtilTest, TestIsValidInputMethodId) {
321 EXPECT_TRUE(util_.IsValidInputMethodId(Id("xkb:us:colemak:eng"))); 282 EXPECT_TRUE(util_.IsValidInputMethodId(Id("xkb:us:colemak:eng")));
322 EXPECT_TRUE(util_.IsValidInputMethodId(pinyin_ime_id)); 283 EXPECT_TRUE(util_.IsValidInputMethodId(Id(pinyin_ime_id)));
323 EXPECT_FALSE(util_.IsValidInputMethodId("unsupported-input-method")); 284 EXPECT_FALSE(util_.IsValidInputMethodId("unsupported-input-method"));
324 } 285 }
325 286
326 TEST_F(InputMethodUtilTest, TestIsKeyboardLayout) { 287 TEST_F(InputMethodUtilTest, TestIsKeyboardLayout) {
327 EXPECT_TRUE(InputMethodUtil::IsKeyboardLayout("xkb:us::eng")); 288 EXPECT_TRUE(InputMethodUtil::IsKeyboardLayout("xkb:us::eng"));
328 EXPECT_FALSE(InputMethodUtil::IsKeyboardLayout(pinyin_ime_id)); 289 EXPECT_FALSE(InputMethodUtil::IsKeyboardLayout(Id(pinyin_ime_id)));
329 } 290 }
330 291
331 TEST_F(InputMethodUtilTest, TestGetKeyboardLayoutName) { 292 TEST_F(InputMethodUtilTest, TestGetKeyboardLayoutName) {
332 // Unsupported case. 293 // Unsupported case.
333 EXPECT_EQ("", util_.GetKeyboardLayoutName("UNSUPPORTED_ID")); 294 EXPECT_EQ("", util_.GetKeyboardLayoutName("UNSUPPORTED_ID"));
334 295
335 // Supported cases (samples). 296 // Supported cases (samples).
336 EXPECT_EQ("us", util_.GetKeyboardLayoutName(pinyin_ime_id)); 297 EXPECT_EQ("us", util_.GetKeyboardLayoutName(Id(pinyin_ime_id)));
337 EXPECT_EQ("es", util_.GetKeyboardLayoutName(Id("xkb:es::spa"))); 298 EXPECT_EQ("es", util_.GetKeyboardLayoutName(Id("xkb:es::spa")));
338 EXPECT_EQ("es(cat)", util_.GetKeyboardLayoutName(Id("xkb:es:cat:cat"))); 299 EXPECT_EQ("es(cat)", util_.GetKeyboardLayoutName(Id("xkb:es:cat:cat")));
339 EXPECT_EQ("gb(extd)", util_.GetKeyboardLayoutName(Id("xkb:gb:extd:eng"))); 300 EXPECT_EQ("gb(extd)", util_.GetKeyboardLayoutName(Id("xkb:gb:extd:eng")));
340 EXPECT_EQ("us", util_.GetKeyboardLayoutName(Id("xkb:us::eng"))); 301 EXPECT_EQ("us", util_.GetKeyboardLayoutName(Id("xkb:us::eng")));
341 EXPECT_EQ("us(dvorak)", util_.GetKeyboardLayoutName(Id("xkb:us:dvorak:eng"))); 302 EXPECT_EQ("us(dvorak)", util_.GetKeyboardLayoutName(Id("xkb:us:dvorak:eng")));
342 EXPECT_EQ("us(colemak)", 303 EXPECT_EQ("us(colemak)",
343 util_.GetKeyboardLayoutName(Id("xkb:us:colemak:eng"))); 304 util_.GetKeyboardLayoutName(Id("xkb:us:colemak:eng")));
344 EXPECT_EQ("de(neo)", util_.GetKeyboardLayoutName(Id("xkb:de:neo:ger"))); 305 EXPECT_EQ("de(neo)", util_.GetKeyboardLayoutName(Id("xkb:de:neo:ger")));
345 } 306 }
346 307
347 TEST_F(InputMethodUtilTest, TestGetLanguageCodeFromInputMethodId) { 308 TEST_F(InputMethodUtilTest, TestGetLanguageCodeFromInputMethodId) {
348 // Make sure that the -CN is added properly. 309 // Make sure that the -CN is added properly.
349 EXPECT_EQ("zh-CN", util_.GetLanguageCodeFromInputMethodId(pinyin_ime_id)); 310 EXPECT_EQ("zh-CN", util_.GetLanguageCodeFromInputMethodId(Id(pinyin_ime_id)));
350 } 311 }
351 312
352 TEST_F(InputMethodUtilTest, TestGetInputMethodDisplayNameFromId) { 313 TEST_F(InputMethodUtilTest, TestGetInputMethodDisplayNameFromId) {
353 EXPECT_EQ("US", 314 EXPECT_EQ("US",
354 util_.GetInputMethodDisplayNameFromId("xkb:us::eng")); 315 util_.GetInputMethodDisplayNameFromId("xkb:us::eng"));
355 EXPECT_EQ("", util_.GetInputMethodDisplayNameFromId("nonexistent")); 316 EXPECT_EQ("", util_.GetInputMethodDisplayNameFromId("nonexistent"));
356 } 317 }
357 318
358 TEST_F(InputMethodUtilTest, TestGetInputMethodDescriptorFromId) { 319 TEST_F(InputMethodUtilTest, TestGetInputMethodDescriptorFromId) {
359 EXPECT_EQ(NULL, util_.GetInputMethodDescriptorFromId("non_existent")); 320 EXPECT_EQ(NULL, util_.GetInputMethodDescriptorFromId("non_existent"));
360 321
361 const InputMethodDescriptor* descriptor = 322 const InputMethodDescriptor* descriptor =
362 util_.GetInputMethodDescriptorFromId(pinyin_ime_id); 323 util_.GetInputMethodDescriptorFromId(Id(pinyin_ime_id));
363 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. 324 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile.
364 EXPECT_EQ(pinyin_ime_id, descriptor->id()); 325 EXPECT_EQ(Id(pinyin_ime_id), descriptor->id());
365 EXPECT_EQ("us", descriptor->GetPreferredKeyboardLayout()); 326 EXPECT_EQ("us", descriptor->GetPreferredKeyboardLayout());
366 // This used to be "zh" but now we have "zh-CN" in input_methods.h, 327 // This used to be "zh" but now we have "zh-CN" in input_methods.h,
367 // hence this should be zh-CN now. 328 // hence this should be zh-CN now.
368 ASSERT_TRUE(!descriptor->language_codes().empty()); 329 ASSERT_TRUE(!descriptor->language_codes().empty());
369 EXPECT_EQ("zh-CN", descriptor->language_codes().at(0)); 330 EXPECT_EQ("zh-CN", descriptor->language_codes().at(0));
370 } 331 }
371 332
372 TEST_F(InputMethodUtilTest, TestGetInputMethodIdsForLanguageCode) { 333 TEST_F(InputMethodUtilTest, TestGetInputMethodIdsForLanguageCode) {
373 std::multimap<std::string, std::string> language_code_to_ids_map; 334 std::multimap<std::string, std::string> language_code_to_ids_map;
374 language_code_to_ids_map.insert(std::make_pair("ja", pinyin_ime_id)); 335 language_code_to_ids_map.insert(std::make_pair("ja", pinyin_ime_id));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 374
414 // US keyboard + Chinese UI = US keyboard + Pinyin IME. 375 // US keyboard + Chinese UI = US keyboard + Pinyin IME.
415 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_Zh) { 376 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_Zh) {
416 const InputMethodDescriptor* descriptor = 377 const InputMethodDescriptor* descriptor =
417 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard. 378 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard.
418 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. 379 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile.
419 std::vector<std::string> input_method_ids; 380 std::vector<std::string> input_method_ids;
420 util_.GetFirstLoginInputMethodIds("zh-CN", *descriptor, &input_method_ids); 381 util_.GetFirstLoginInputMethodIds("zh-CN", *descriptor, &input_method_ids);
421 ASSERT_EQ(2U, input_method_ids.size()); 382 ASSERT_EQ(2U, input_method_ids.size());
422 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]); 383 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]);
423 EXPECT_EQ(pinyin_ime_id, input_method_ids[1]); // Pinyin for US keybaord. 384 EXPECT_EQ(Id(pinyin_ime_id), input_method_ids[1]); // Pinyin for US keybaord.
424 } 385 }
425 386
426 // US keyboard + Russian UI = US keyboard + Russsian keyboard 387 // US keyboard + Russian UI = US keyboard + Russsian keyboard
427 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_Ru) { 388 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_Ru) {
428 const InputMethodDescriptor* descriptor = 389 const InputMethodDescriptor* descriptor =
429 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard. 390 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard.
430 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. 391 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile.
431 std::vector<std::string> input_method_ids; 392 std::vector<std::string> input_method_ids;
432 util_.GetFirstLoginInputMethodIds("ru", *descriptor, &input_method_ids); 393 util_.GetFirstLoginInputMethodIds("ru", *descriptor, &input_method_ids);
433 ASSERT_EQ(2U, input_method_ids.size()); 394 ASSERT_EQ(2U, input_method_ids.size());
434 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]); 395 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]);
435 EXPECT_EQ(Id("xkb:ru::rus"), input_method_ids[1]); // Russian keyboard. 396 EXPECT_EQ(Id("xkb:ru::rus"), input_method_ids[1]); // Russian keyboard.
436 } 397 }
437 398
438 // US keyboard + Traditional Chinese = US keyboard + chewing. 399 // US keyboard + Traditional Chinese = US keyboard + chewing.
439 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_ZhTw) { 400 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_ZhTw) {
440 const InputMethodDescriptor* descriptor = 401 const InputMethodDescriptor* descriptor =
441 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard. 402 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard.
442 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. 403 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile.
443 std::vector<std::string> input_method_ids; 404 std::vector<std::string> input_method_ids;
444 util_.GetFirstLoginInputMethodIds("zh-TW", *descriptor, &input_method_ids); 405 util_.GetFirstLoginInputMethodIds("zh-TW", *descriptor, &input_method_ids);
445 ASSERT_EQ(2U, input_method_ids.size()); 406 ASSERT_EQ(2U, input_method_ids.size());
446 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]); 407 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]);
447 EXPECT_EQ(zhuyin_ime_id, input_method_ids[1]); // Chewing. 408 EXPECT_EQ(Id(zhuyin_ime_id), input_method_ids[1]); // Chewing.
448 } 409 }
449 410
450 // US keyboard + Thai = US keyboard + kesmanee. 411 // US keyboard + Thai = US keyboard + kesmanee.
451 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_Th) { 412 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_Th) {
452 const InputMethodDescriptor* descriptor = 413 const InputMethodDescriptor* descriptor =
453 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard. 414 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard.
454 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. 415 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile.
455 std::vector<std::string> input_method_ids; 416 std::vector<std::string> input_method_ids;
456 util_.GetFirstLoginInputMethodIds("th", *descriptor, &input_method_ids); 417 util_.GetFirstLoginInputMethodIds("th", *descriptor, &input_method_ids);
457 ASSERT_EQ(2U, input_method_ids.size()); 418 ASSERT_EQ(2U, input_method_ids.size());
458 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]); 419 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]);
459 EXPECT_EQ(std::string("_comp_ime_") + kKeyboardExtId + "vkd_th", 420 EXPECT_EQ(Id("vkd_th"), input_method_ids[1]); // Kesmanee.
460 input_method_ids[1]); // Kesmanee.
461 } 421 }
462 422
463 // US keyboard + Vietnamese = US keyboard + TCVN6064. 423 // US keyboard + Vietnamese = US keyboard + TCVN6064.
464 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_Vi) { 424 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_Vi) {
465 const InputMethodDescriptor* descriptor = 425 const InputMethodDescriptor* descriptor =
466 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard. 426 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard.
467 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. 427 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile.
468 std::vector<std::string> input_method_ids; 428 std::vector<std::string> input_method_ids;
469 util_.GetFirstLoginInputMethodIds("vi", *descriptor, &input_method_ids); 429 util_.GetFirstLoginInputMethodIds("vi", *descriptor, &input_method_ids);
470 ASSERT_EQ(2U, input_method_ids.size()); 430 ASSERT_EQ(2U, input_method_ids.size());
471 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]); 431 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]);
472 EXPECT_EQ(std::string("_comp_ime_") + kKeyboardExtId + "vkd_vi_tcvn", 432 EXPECT_EQ(Id("vkd_vi_tcvn"), input_method_ids[1]); // TCVN6064.
473 input_method_ids[1]); // TCVN6064.
474 } 433 }
475 434
476 TEST_F(InputMethodUtilTest, TestGetLanguageCodesFromInputMethodIds) { 435 TEST_F(InputMethodUtilTest, TestGetLanguageCodesFromInputMethodIds) {
477 std::vector<std::string> input_method_ids; 436 std::vector<std::string> input_method_ids;
478 input_method_ids.push_back(Id("xkb:us::eng")); // English US. 437 input_method_ids.push_back(Id("xkb:us::eng")); // English US.
479 input_method_ids.push_back(Id("xkb:us:dvorak:eng")); // English US Dvorak. 438 input_method_ids.push_back(Id("xkb:us:dvorak:eng")); // English US Dvorak.
480 input_method_ids.push_back(pinyin_ime_id); // Pinyin 439 input_method_ids.push_back(Id(pinyin_ime_id)); // Pinyin
481 input_method_ids.push_back(Id("xkb:fr::fra")); // French France. 440 input_method_ids.push_back(Id("xkb:fr::fra")); // French France.
482 std::vector<std::string> language_codes; 441 std::vector<std::string> language_codes;
483 util_.GetLanguageCodesFromInputMethodIds(input_method_ids, &language_codes); 442 util_.GetLanguageCodesFromInputMethodIds(input_method_ids, &language_codes);
484 ASSERT_EQ(3U, language_codes.size()); 443 ASSERT_EQ(3U, language_codes.size());
485 EXPECT_EQ("en", language_codes[0]); 444 EXPECT_EQ("en", language_codes[0]);
486 EXPECT_EQ("zh-CN", language_codes[1]); 445 EXPECT_EQ("zh-CN", language_codes[1]);
487 EXPECT_EQ("fr", language_codes[2]); 446 EXPECT_EQ("fr", language_codes[2]);
488 } 447 }
489 448
490 // Test all supported descriptors to detect a typo in input_methods.txt. 449 // Test all supported descriptors to detect a typo in input_methods.txt.
(...skipping 13 matching lines...) Expand all
504 EXPECT_FALSE(display_name.empty()) 463 EXPECT_FALSE(display_name.empty())
505 << "Invalid language code " << language_code; 464 << "Invalid language code " << language_code;
506 // On error, GetDisplayNameForLocale() returns the |language_code| as-is. 465 // On error, GetDisplayNameForLocale() returns the |language_code| as-is.
507 EXPECT_NE(language_code, base::UTF16ToUTF8(display_name)) 466 EXPECT_NE(language_code, base::UTF16ToUTF8(display_name))
508 << "Invalid language code " << language_code; 467 << "Invalid language code " << language_code;
509 } 468 }
510 } 469 }
511 470
512 } // namespace input_method 471 } // namespace input_method
513 } // namespace chromeos 472 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698