BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / chromeos / input_method / input_method_util_unittest.cc
blobc53a7c17ea688023e8dbd97c59acf9c3680a94cc
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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/input_method/input_method_util.h"
7 #include <string>
9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/base/ime/chromeos/extension_ime_util.h"
14 #include "ui/base/ime/chromeos/fake_input_method_delegate.h"
15 #include "ui/base/ime/chromeos/input_method_manager.h"
16 #include "ui/base/ime/chromeos/input_method_whitelist.h"
17 #include "ui/base/l10n/l10n_util.h"
19 using base::ASCIIToUTF16;
21 namespace chromeos {
23 namespace input_method {
25 namespace {
27 const char pinyin_ime_id[] = "zh-t-i0-pinyin";
28 const char zhuyin_ime_id[] = "zh-hant-t-i0-und";
30 class TestableInputMethodUtil : public InputMethodUtil {
31 public:
32 explicit TestableInputMethodUtil(InputMethodDelegate* delegate,
33 scoped_ptr<InputMethodDescriptors> methods)
34 : InputMethodUtil(delegate) {
35 ResetInputMethods(*methods);
37 // Change access rights.
38 using InputMethodUtil::GetInputMethodIdsFromLanguageCodeInternal;
39 using InputMethodUtil::GetKeyboardLayoutName;
42 } // namespace
44 class InputMethodUtilTest : public testing::Test {
45 public:
46 InputMethodUtilTest()
47 : util_(&delegate_, whitelist_.GetSupportedInputMethods()) {
48 delegate_.set_get_localized_string_callback(
49 base::Bind(&l10n_util::GetStringUTF16));
50 delegate_.set_get_display_language_name_callback(
51 base::Bind(&InputMethodUtilTest::GetDisplayLanguageName));
54 void SetUp() override {
55 InputMethodDescriptors input_methods;
57 std::vector<std::string> layouts;
58 std::vector<std::string> languages;
59 layouts.push_back("us");
60 languages.push_back("zh-CN");
62 InputMethodDescriptor pinyin_ime(Id(pinyin_ime_id),
63 "Pinyin input for testing",
64 "CN",
65 layouts,
66 languages,
67 false,
68 GURL(""),
69 GURL(""));
70 input_methods.push_back(pinyin_ime);
72 languages.clear();
73 languages.push_back("zh-TW");
74 InputMethodDescriptor zhuyin_ime(zhuyin_ime_id,
75 "Zhuyin input for testing",
76 "TW",
77 layouts,
78 languages,
79 false,
80 GURL(""),
81 GURL(""));
82 input_methods.push_back(zhuyin_ime);
84 util_.InitXkbInputMethodsForTesting();
85 util_.AppendInputMethods(input_methods);
88 std::string Id(const std::string& id) {
89 return extension_ime_util::GetInputMethodIDByEngineID(id);
92 InputMethodDescriptor GetDesc(const std::string& id,
93 const std::string& raw_layout,
94 const std::string& language_code,
95 const std::string& indicator) {
96 std::vector<std::string> layouts;
97 layouts.push_back(raw_layout);
98 std::vector<std::string> languages;
99 languages.push_back(language_code);
100 return InputMethodDescriptor(Id(id),
101 "", // Description.
102 indicator, // Short name used for indicator.
103 layouts,
104 languages,
105 true,
106 GURL(), // options page url
107 GURL()); // input view page url
110 static base::string16 GetDisplayLanguageName(
111 const std::string& language_code) {
112 return l10n_util::GetDisplayNameForLocale(language_code, "en", true);
115 FakeInputMethodDelegate delegate_;
116 InputMethodWhitelist whitelist_;
117 TestableInputMethodUtil util_;
120 TEST_F(InputMethodUtilTest, GetInputMethodShortNameTest) {
121 // Test invalid cases. Two-letter language code should be returned.
123 InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", "");
124 // Upper-case string of the unknown language code, "xx", should be returned.
125 EXPECT_EQ(ASCIIToUTF16("XX"), util_.GetInputMethodShortName(desc));
128 // Test special cases.
130 InputMethodDescriptor desc =
131 GetDesc("xkb:us:dvorak:eng", "us", "en-US", "DV");
132 EXPECT_EQ(ASCIIToUTF16("DV"), util_.GetInputMethodShortName(desc));
135 InputMethodDescriptor desc =
136 GetDesc("xkb:us:colemak:eng", "us", "en-US", "CO");
137 EXPECT_EQ(ASCIIToUTF16("CO"), util_.GetInputMethodShortName(desc));
140 InputMethodDescriptor desc =
141 GetDesc("xkb:us:altgr-intl:eng", "us", "en-US", "EXTD");
142 EXPECT_EQ(ASCIIToUTF16("EXTD"), util_.GetInputMethodShortName(desc));
145 InputMethodDescriptor desc =
146 GetDesc("xkb:us:intl:eng", "us", "en-US", "INTL");
147 EXPECT_EQ(ASCIIToUTF16("INTL"), util_.GetInputMethodShortName(desc));
150 InputMethodDescriptor desc =
151 GetDesc("xkb:de:neo:ger", "de(neo)", "de", "NEO");
152 EXPECT_EQ(ASCIIToUTF16("NEO"), util_.GetInputMethodShortName(desc));
155 InputMethodDescriptor desc =
156 GetDesc("xkb:es:cat:cat", "es(cat)", "ca", "CAS");
157 EXPECT_EQ(ASCIIToUTF16("CAS"), util_.GetInputMethodShortName(desc));
160 InputMethodDescriptor desc =
161 GetDesc(pinyin_ime_id, "us", "zh-CN", "\xe6\x8b\xbc");
162 EXPECT_EQ(base::UTF8ToUTF16("\xe6\x8b\xbc"),
163 util_.GetInputMethodShortName(desc));
166 InputMethodDescriptor desc =
167 GetDesc(zhuyin_ime_id, "us", "zh-TW", "\xE6\xB3\xA8");
168 EXPECT_EQ(base::UTF8ToUTF16("\xE6\xB3\xA8"),
169 util_.GetInputMethodShortName(desc));
173 TEST_F(InputMethodUtilTest, GetInputMethodMediumNameTest) {
175 // input methods with medium name equal to short name
176 const char* const input_method_id[] = {
177 "xkb:us:altgr-intl:eng", "xkb:us:dvorak:eng", "xkb:us:intl:eng",
178 "xkb:us:colemak:eng", "xkb:de:neo:ger", "xkb:es:cat:cat",
179 "xkb:gb:dvorak:eng",
181 const int len = arraysize(input_method_id);
182 for (int i = 0; i < len; ++i) {
183 InputMethodDescriptor desc = GetDesc(input_method_id[i], "", "", "");
184 base::string16 medium_name = util_.GetInputMethodMediumName(desc);
185 base::string16 short_name = util_.GetInputMethodShortName(desc);
186 EXPECT_EQ(medium_name, short_name);
190 // input methods with medium name not equal to short name
191 const char* const input_method_id[] = {
192 pinyin_ime_id, zhuyin_ime_id,
194 const int len = arraysize(input_method_id);
195 for (int i = 0; i < len; ++i) {
196 InputMethodDescriptor desc = GetDesc(input_method_id[i], "", "", "");
197 base::string16 medium_name = util_.GetInputMethodMediumName(desc);
198 base::string16 short_name = util_.GetInputMethodShortName(desc);
199 EXPECT_NE(medium_name, short_name);
204 TEST_F(InputMethodUtilTest, GetInputMethodLongNameTest) {
205 // For most languages input method or keyboard layout name is returned.
206 // See below for exceptions.
208 InputMethodDescriptor desc = GetDesc("xkb:jp::jpn", "jp", "ja", "");
209 EXPECT_EQ(ASCIIToUTF16("Japanese"),
210 util_.GetInputMethodLongName(desc));
213 InputMethodDescriptor desc =
214 GetDesc("xkb:us:dvorak:eng", "us(dvorak)", "en-US", "");
215 EXPECT_EQ(ASCIIToUTF16("US Dvorak"),
216 util_.GetInputMethodLongName(desc));
219 InputMethodDescriptor desc =
220 GetDesc("xkb:gb:dvorak:eng", "gb(dvorak)", "en-US", "");
221 EXPECT_EQ(ASCIIToUTF16("UK Dvorak"),
222 util_.GetInputMethodLongName(desc));
225 // For Dutch, French, German and Hindi,
226 // "language - keyboard layout" pair is returned.
228 InputMethodDescriptor desc = GetDesc("xkb:be::nld", "be", "nl", "");
229 EXPECT_EQ(ASCIIToUTF16("Dutch - Belgian"),
230 util_.GetInputMethodLongName(desc));
233 InputMethodDescriptor desc = GetDesc("xkb:fr::fra", "fr", "fr", "");
234 EXPECT_EQ(ASCIIToUTF16("French - French"),
235 util_.GetInputMethodLongName(desc));
238 InputMethodDescriptor desc = GetDesc("xkb:be::fra", "be", "fr", "");
239 EXPECT_EQ(ASCIIToUTF16("French - Belgian"),
240 util_.GetInputMethodLongName(desc));
243 InputMethodDescriptor desc = GetDesc("xkb:de::ger", "de", "de", "");
244 EXPECT_EQ(ASCIIToUTF16("German - German"),
245 util_.GetInputMethodLongName(desc));
248 InputMethodDescriptor desc = GetDesc("xkb:be::ger", "be", "de", "");
249 EXPECT_EQ(ASCIIToUTF16("German - Belgian"),
250 util_.GetInputMethodLongName(desc));
254 InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", "");
255 // You can safely ignore the "Resouce ID is not found for: invalid-id"
256 // error.
257 EXPECT_EQ(ASCIIToUTF16("invalid-id"),
258 util_.GetInputMethodLongName(desc));
262 TEST_F(InputMethodUtilTest, TestIsValidInputMethodId) {
263 EXPECT_TRUE(util_.IsValidInputMethodId(Id("xkb:us:colemak:eng")));
264 EXPECT_TRUE(util_.IsValidInputMethodId(Id(pinyin_ime_id)));
265 EXPECT_FALSE(util_.IsValidInputMethodId("unsupported-input-method"));
268 TEST_F(InputMethodUtilTest, TestIsKeyboardLayout) {
269 EXPECT_TRUE(InputMethodUtil::IsKeyboardLayout("xkb:us::eng"));
270 EXPECT_FALSE(InputMethodUtil::IsKeyboardLayout(Id(pinyin_ime_id)));
273 TEST_F(InputMethodUtilTest, TestGetKeyboardLayoutName) {
274 // Unsupported case.
275 EXPECT_EQ("", util_.GetKeyboardLayoutName("UNSUPPORTED_ID"));
277 // Supported cases (samples).
278 EXPECT_EQ("us", util_.GetKeyboardLayoutName(Id(pinyin_ime_id)));
279 EXPECT_EQ("es", util_.GetKeyboardLayoutName(Id("xkb:es::spa")));
280 EXPECT_EQ("es(cat)", util_.GetKeyboardLayoutName(Id("xkb:es:cat:cat")));
281 EXPECT_EQ("gb(extd)", util_.GetKeyboardLayoutName(Id("xkb:gb:extd:eng")));
282 EXPECT_EQ("us", util_.GetKeyboardLayoutName(Id("xkb:us::eng")));
283 EXPECT_EQ("us(dvorak)", util_.GetKeyboardLayoutName(Id("xkb:us:dvorak:eng")));
284 EXPECT_EQ("us(colemak)",
285 util_.GetKeyboardLayoutName(Id("xkb:us:colemak:eng")));
286 EXPECT_EQ("de(neo)", util_.GetKeyboardLayoutName(Id("xkb:de:neo:ger")));
289 TEST_F(InputMethodUtilTest, TestGetInputMethodDisplayNameFromId) {
290 EXPECT_EQ("US",
291 util_.GetInputMethodDisplayNameFromId("xkb:us::eng"));
292 EXPECT_EQ("", util_.GetInputMethodDisplayNameFromId("nonexistent"));
295 TEST_F(InputMethodUtilTest, TestGetInputMethodDescriptorFromId) {
296 EXPECT_EQ(NULL, util_.GetInputMethodDescriptorFromId("non_existent"));
298 const InputMethodDescriptor* descriptor =
299 util_.GetInputMethodDescriptorFromId(Id(pinyin_ime_id));
300 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile.
301 EXPECT_EQ(Id(pinyin_ime_id), descriptor->id());
302 EXPECT_EQ("us", descriptor->GetPreferredKeyboardLayout());
303 // This used to be "zh" but now we have "zh-CN" in input_methods.h,
304 // hence this should be zh-CN now.
305 ASSERT_TRUE(!descriptor->language_codes().empty());
306 EXPECT_EQ("zh-CN", descriptor->language_codes().at(0));
309 TEST_F(InputMethodUtilTest, TestGetInputMethodIdsForLanguageCode) {
310 std::multimap<std::string, std::string> language_code_to_ids_map;
311 language_code_to_ids_map.insert(std::make_pair("ja", pinyin_ime_id));
312 language_code_to_ids_map.insert(std::make_pair("ja", pinyin_ime_id));
313 language_code_to_ids_map.insert(std::make_pair("ja", "xkb:jp:jpn"));
314 language_code_to_ids_map.insert(std::make_pair("fr", "xkb:fr:fra"));
316 std::vector<std::string> result;
317 EXPECT_TRUE(util_.GetInputMethodIdsFromLanguageCodeInternal(
318 language_code_to_ids_map, "ja", kAllInputMethods, &result));
319 EXPECT_EQ(3U, result.size());
320 EXPECT_TRUE(util_.GetInputMethodIdsFromLanguageCodeInternal(
321 language_code_to_ids_map, "ja", kKeyboardLayoutsOnly, &result));
322 ASSERT_EQ(1U, result.size());
323 EXPECT_EQ("xkb:jp:jpn", result[0]);
325 EXPECT_TRUE(util_.GetInputMethodIdsFromLanguageCodeInternal(
326 language_code_to_ids_map, "fr", kAllInputMethods, &result));
327 ASSERT_EQ(1U, result.size());
328 EXPECT_EQ("xkb:fr:fra", result[0]);
329 EXPECT_TRUE(util_.GetInputMethodIdsFromLanguageCodeInternal(
330 language_code_to_ids_map, "fr", kKeyboardLayoutsOnly, &result));
331 ASSERT_EQ(1U, result.size());
332 EXPECT_EQ("xkb:fr:fra", result[0]);
334 EXPECT_FALSE(util_.GetInputMethodIdsFromLanguageCodeInternal(
335 language_code_to_ids_map, "invalid_lang", kAllInputMethods, &result));
336 EXPECT_FALSE(util_.GetInputMethodIdsFromLanguageCodeInternal(
337 language_code_to_ids_map, "invalid_lang", kKeyboardLayoutsOnly, &result));
340 // US keyboard + English US UI = US keyboard only.
341 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_EnUs) {
342 const InputMethodDescriptor* descriptor =
343 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard.
344 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile.
345 std::vector<std::string> input_method_ids;
346 util_.GetFirstLoginInputMethodIds("en-US", *descriptor, &input_method_ids);
347 ASSERT_EQ(1U, input_method_ids.size());
348 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]);
351 // US keyboard + Chinese UI = US keyboard + Pinyin IME.
352 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_Zh) {
353 const InputMethodDescriptor* descriptor =
354 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard.
355 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile.
356 std::vector<std::string> input_method_ids;
357 util_.GetFirstLoginInputMethodIds("zh-CN", *descriptor, &input_method_ids);
358 ASSERT_EQ(2U, input_method_ids.size());
359 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]);
360 EXPECT_EQ(Id(pinyin_ime_id), input_method_ids[1]); // Pinyin for US keybaord.
363 // US keyboard + Russian UI = US keyboard + Russsian keyboard
364 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_Ru) {
365 const InputMethodDescriptor* descriptor =
366 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard.
367 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile.
368 std::vector<std::string> input_method_ids;
369 util_.GetFirstLoginInputMethodIds("ru", *descriptor, &input_method_ids);
370 ASSERT_EQ(2U, input_method_ids.size());
371 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]);
372 EXPECT_EQ(Id("xkb:ru::rus"), input_method_ids[1]); // Russian keyboard.
375 // US keyboard + Traditional Chinese = US keyboard + chewing.
376 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_ZhTw) {
377 const InputMethodDescriptor* descriptor =
378 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard.
379 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile.
380 std::vector<std::string> input_method_ids;
381 util_.GetFirstLoginInputMethodIds("zh-TW", *descriptor, &input_method_ids);
382 ASSERT_EQ(2U, input_method_ids.size());
383 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]);
384 EXPECT_EQ(Id(zhuyin_ime_id), input_method_ids[1]); // Chewing.
387 // US keyboard + Thai = US keyboard + kesmanee.
388 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_Th) {
389 const InputMethodDescriptor* descriptor =
390 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard.
391 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile.
392 std::vector<std::string> input_method_ids;
393 util_.GetFirstLoginInputMethodIds("th", *descriptor, &input_method_ids);
394 ASSERT_EQ(2U, input_method_ids.size());
395 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]);
396 EXPECT_EQ(Id("vkd_th"), input_method_ids[1]); // Kesmanee.
399 // US keyboard + Vietnamese = US keyboard + TCVN6064.
400 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_Vi) {
401 const InputMethodDescriptor* descriptor =
402 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard.
403 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile.
404 std::vector<std::string> input_method_ids;
405 util_.GetFirstLoginInputMethodIds("vi", *descriptor, &input_method_ids);
406 ASSERT_EQ(2U, input_method_ids.size());
407 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]);
408 EXPECT_EQ(Id("vkd_vi_tcvn"), input_method_ids[1]); // TCVN6064.
411 // US keyboard + Japanese = US keyboard + mozc(us).
412 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_Jp) {
413 const InputMethodDescriptor* descriptor =
414 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard.
415 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile.
416 std::vector<std::string> input_method_ids;
417 util_.GetFirstLoginInputMethodIds("ja", *descriptor, &input_method_ids);
418 ASSERT_EQ(2U, input_method_ids.size());
419 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]);
420 EXPECT_EQ(Id("nacl_mozc_us"), input_method_ids[1]);
423 // JP keyboard + Japanese = JP keyboard + mozc(jp).
424 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Jp_And_Jp) {
425 const InputMethodDescriptor* descriptor =
426 util_.GetInputMethodDescriptorFromId(Id("xkb:jp::jpn")); // JP keyboard.
427 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile.
428 std::vector<std::string> input_method_ids;
429 util_.GetFirstLoginInputMethodIds("ja", *descriptor, &input_method_ids);
430 ASSERT_EQ(2U, input_method_ids.size());
431 EXPECT_EQ(Id("xkb:jp::jpn"), input_method_ids[0]);
432 EXPECT_EQ(Id("nacl_mozc_jp"), input_method_ids[1]);
435 // US keyboard + Hebrew = US keyboard + Hebrew keyboard.
436 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_He) {
437 const InputMethodDescriptor* descriptor =
438 util_.GetInputMethodDescriptorFromId(Id("xkb:us::eng")); // US keyboard.
439 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile.
440 std::vector<std::string> input_method_ids;
441 util_.GetFirstLoginInputMethodIds("he", *descriptor, &input_method_ids);
442 ASSERT_EQ(2U, input_method_ids.size());
443 EXPECT_EQ(Id("xkb:us::eng"), input_method_ids[0]);
444 EXPECT_EQ(Id("xkb:il::heb"), input_method_ids[1]);
447 TEST_F(InputMethodUtilTest, TestGetLanguageCodesFromInputMethodIds) {
448 std::vector<std::string> input_method_ids;
449 input_method_ids.push_back(Id("xkb:us::eng")); // English US.
450 input_method_ids.push_back(Id("xkb:us:dvorak:eng")); // English US Dvorak.
451 input_method_ids.push_back(Id(pinyin_ime_id)); // Pinyin
452 input_method_ids.push_back(Id("xkb:fr::fra")); // French France.
453 std::vector<std::string> language_codes;
454 util_.GetLanguageCodesFromInputMethodIds(input_method_ids, &language_codes);
455 ASSERT_EQ(3U, language_codes.size());
456 EXPECT_EQ("en", language_codes[0]);
457 EXPECT_EQ("zh-CN", language_codes[1]);
458 EXPECT_EQ("fr", language_codes[2]);
461 // Test all supported descriptors to detect a typo in input_methods.txt.
462 TEST_F(InputMethodUtilTest, TestIBusInputMethodText) {
463 const std::map<std::string, InputMethodDescriptor>& id_to_descriptor =
464 util_.GetIdToDesciptorMapForTesting();
465 for (std::map<std::string, InputMethodDescriptor>::const_iterator it =
466 id_to_descriptor.begin(); it != id_to_descriptor.end(); ++it) {
467 const std::string language_code = it->second.language_codes().at(0);
468 const base::string16 display_name =
469 l10n_util::GetDisplayNameForLocale(language_code, "en", false);
470 // Only two formats, like "fr" (lower case) and "en-US" (lower-upper), are
471 // allowed. See the text file for details.
472 EXPECT_TRUE(language_code == "fil" || language_code.length() == 2 ||
473 (language_code.length() == 5 && language_code[2] == '-'))
474 << "Invalid language code " << language_code;
475 EXPECT_TRUE(l10n_util::IsValidLocaleSyntax(language_code))
476 << "Invalid language code " << language_code;
477 EXPECT_FALSE(display_name.empty())
478 << "Invalid language code " << language_code;
479 // On error, GetDisplayNameForLocale() returns the |language_code| as-is.
480 EXPECT_NE(language_code, base::UTF16ToUTF8(display_name))
481 << "Invalid language code " << language_code;
485 // Test the input method ID migration.
486 TEST_F(InputMethodUtilTest, TestInputMethodIDMigration) {
487 const char* const migration_cases[][2] = {
488 {"ime:zh:pinyin", "zh-t-i0-pinyin"},
489 {"ime:zh-t:zhuyin", "zh-hant-t-i0-und"},
490 {"ime:zh-t:quick", "zh-hant-t-i0-cangjie-1987-x-m0-simplified"},
491 {"ime:jp:mozc_us", "nacl_mozc_us"},
492 {"ime:ko:hangul", "hangul_2set"},
493 {"m17n:deva_phone", "vkd_deva_phone"},
494 {"m17n:ar", "vkd_ar"},
495 {"t13n:hi", "hi-t-i0-und"},
496 {"unknown", "unknown"},
498 std::vector<std::string> input_method_ids;
499 for (size_t i = 0; i < arraysize(migration_cases); ++i)
500 input_method_ids.push_back(migration_cases[i][0]);
501 // Duplicated hangul_2set.
502 input_method_ids.push_back("ime:ko:hangul_2set");
504 util_.MigrateInputMethods(&input_method_ids);
506 EXPECT_EQ(arraysize(migration_cases), input_method_ids.size());
507 for (size_t i = 0; i < arraysize(migration_cases); ++i) {
508 EXPECT_EQ(
509 extension_ime_util::GetInputMethodIDByEngineID(migration_cases[i][1]),
510 input_method_ids[i]);
514 // Test getting hardware input method IDs.
515 TEST_F(InputMethodUtilTest, TestHardwareInputMethodIDs) {
516 util_.SetHardwareKeyboardLayoutForTesting("xkb:ru::rus");
517 std::vector<std::string> input_method_ids = util_.GetHardwareInputMethodIds();
518 std::vector<std::string> login_input_method_ids =
519 util_.GetHardwareLoginInputMethodIds();
521 EXPECT_EQ(2U, input_method_ids.size());
522 EXPECT_EQ(1U, login_input_method_ids.size());
524 EXPECT_EQ("xkb:us::eng", extension_ime_util::GetComponentIDByInputMethodID(
525 input_method_ids[0]));
526 EXPECT_EQ("xkb:ru::rus", extension_ime_util::GetComponentIDByInputMethodID(
527 input_method_ids[1]));
528 EXPECT_EQ("xkb:us::eng", extension_ime_util::GetComponentIDByInputMethodID(
529 login_input_method_ids[0]));
532 } // namespace input_method
533 } // namespace chromeos