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