OLD | NEW |
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/fake_input_method_delegate.h" | 12 #include "chromeos/ime/fake_input_method_delegate.h" |
13 #include "chromeos/ime/input_method_manager.h" | 13 #include "chromeos/ime/input_method_manager.h" |
14 #include "chromeos/ime/input_method_whitelist.h" | 14 #include "chromeos/ime/input_method_whitelist.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
18 | 18 |
19 namespace chromeos { | 19 namespace chromeos { |
20 | 20 |
21 extern const char* kExtensionImePrefix; | 21 extern const char* kExtensionImePrefix; |
22 | 22 |
23 namespace input_method { | 23 namespace input_method { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
| 27 const char pinyin_ime_id[] = |
| 28 "_comp_ime_nmblnjkfdkabgdofidlkienfnnbjhnabzh-t-i0-pinyin"; |
| 29 const char zhuyin_ime_id[] = |
| 30 "_comp_ime_goedamlknlnjaengojinmfgpmdjmkooozh-hant-t-i0-und"; |
| 31 |
27 class TestableInputMethodUtil : public InputMethodUtil { | 32 class TestableInputMethodUtil : public InputMethodUtil { |
28 public: | 33 public: |
29 explicit TestableInputMethodUtil(InputMethodDelegate* delegate, | 34 explicit TestableInputMethodUtil(InputMethodDelegate* delegate, |
30 scoped_ptr<InputMethodDescriptors> methods) | 35 scoped_ptr<InputMethodDescriptors> methods) |
31 : InputMethodUtil(delegate, methods.Pass()) { | 36 : InputMethodUtil(delegate, methods.Pass()) { |
32 } | 37 } |
33 // Change access rights. | 38 // Change access rights. |
34 using InputMethodUtil::GetInputMethodIdsFromLanguageCodeInternal; | 39 using InputMethodUtil::GetInputMethodIdsFromLanguageCodeInternal; |
35 using InputMethodUtil::GetKeyboardLayoutName; | 40 using InputMethodUtil::GetKeyboardLayoutName; |
36 using InputMethodUtil::ReloadInternalMaps; | 41 using InputMethodUtil::ReloadInternalMaps; |
37 using InputMethodUtil::supported_input_methods_; | 42 using InputMethodUtil::supported_input_methods_; |
38 }; | 43 }; |
39 | 44 |
40 } // namespace | 45 } // namespace |
41 | 46 |
42 class InputMethodUtilTest : public testing::Test { | 47 class InputMethodUtilTest : public testing::Test { |
43 public: | 48 public: |
44 InputMethodUtilTest() | 49 InputMethodUtilTest() |
45 : util_(&delegate_, whitelist_.GetSupportedInputMethods()) { | 50 : util_(&delegate_, whitelist_.GetSupportedInputMethods()) { |
46 delegate_.set_get_localized_string_callback( | 51 delegate_.set_get_localized_string_callback( |
47 base::Bind(&l10n_util::GetStringUTF16)); | 52 base::Bind(&l10n_util::GetStringUTF16)); |
48 delegate_.set_get_display_language_name_callback( | 53 delegate_.set_get_display_language_name_callback( |
49 base::Bind(&InputMethodUtilTest::GetDisplayLanguageName)); | 54 base::Bind(&InputMethodUtilTest::GetDisplayLanguageName)); |
50 } | 55 } |
51 | 56 |
| 57 virtual void SetUp() OVERRIDE { |
| 58 InputMethodDescriptors input_methods; |
| 59 |
| 60 std::vector<std::string> layouts; |
| 61 std::vector<std::string> languages; |
| 62 layouts.push_back("us"); |
| 63 languages.push_back("zh-CN"); |
| 64 |
| 65 InputMethodDescriptor pinyin_ime(pinyin_ime_id, |
| 66 "Pinyin input for testing", |
| 67 layouts, |
| 68 languages, |
| 69 GURL("")); |
| 70 input_methods.push_back(pinyin_ime); |
| 71 |
| 72 languages.clear(); |
| 73 languages.push_back("zh-TW"); |
| 74 InputMethodDescriptor zhuyin_ime(zhuyin_ime_id, |
| 75 "Zhuyin input for testing", |
| 76 layouts, |
| 77 languages, |
| 78 GURL("")); |
| 79 input_methods.push_back(zhuyin_ime); |
| 80 |
| 81 util_.SetComponentExtensions(input_methods); |
| 82 } |
| 83 |
52 InputMethodDescriptor GetDesc(const std::string& id, | 84 InputMethodDescriptor GetDesc(const std::string& id, |
53 const std::string& raw_layout, | 85 const std::string& raw_layout, |
54 const std::string& language_code) { | 86 const std::string& language_code) { |
55 std::vector<std::string> layouts; | 87 std::vector<std::string> layouts; |
56 layouts.push_back(raw_layout); | 88 layouts.push_back(raw_layout); |
57 std::vector<std::string> languages; | 89 std::vector<std::string> languages; |
58 languages.push_back(language_code); | 90 languages.push_back(language_code); |
59 return InputMethodDescriptor(id, | 91 return InputMethodDescriptor(id, |
60 "", | 92 "", |
61 layouts, | 93 layouts, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } | 143 } |
112 { | 144 { |
113 InputMethodDescriptor desc = GetDesc("xkb:de:neo:ger", "de(neo)", "de"); | 145 InputMethodDescriptor desc = GetDesc("xkb:de:neo:ger", "de(neo)", "de"); |
114 EXPECT_EQ(ASCIIToUTF16("NEO"), util_.GetInputMethodShortName(desc)); | 146 EXPECT_EQ(ASCIIToUTF16("NEO"), util_.GetInputMethodShortName(desc)); |
115 } | 147 } |
116 { | 148 { |
117 InputMethodDescriptor desc = GetDesc("xkb:es:cat:cat", "es(cat)", "ca"); | 149 InputMethodDescriptor desc = GetDesc("xkb:es:cat:cat", "es(cat)", "ca"); |
118 EXPECT_EQ(ASCIIToUTF16("CAS"), util_.GetInputMethodShortName(desc)); | 150 EXPECT_EQ(ASCIIToUTF16("CAS"), util_.GetInputMethodShortName(desc)); |
119 } | 151 } |
120 { | 152 { |
121 InputMethodDescriptor desc = GetDesc("pinyin", "us", "zh-CN"); | 153 InputMethodDescriptor desc = GetDesc(pinyin_ime_id, "us", "zh-CN"); |
122 EXPECT_EQ(UTF8ToUTF16("\xe6\x8b\xbc"), | 154 EXPECT_EQ(UTF8ToUTF16("\xe6\x8b\xbc"), |
123 util_.GetInputMethodShortName(desc)); | 155 util_.GetInputMethodShortName(desc)); |
124 } | 156 } |
125 { | 157 { |
126 InputMethodDescriptor desc = GetDesc("pinyin-dv", "us(dvorak)", "zh-CN"); | 158 InputMethodDescriptor desc = GetDesc(zhuyin_ime_id, "us", "zh-TW"); |
127 EXPECT_EQ(UTF8ToUTF16("\xe6\x8b\xbc"), | |
128 util_.GetInputMethodShortName(desc)); | |
129 } | |
130 { | |
131 InputMethodDescriptor desc = GetDesc("mozc-chewing", "us", "zh-TW"); | |
132 EXPECT_EQ(UTF8ToUTF16("\xe9\x85\xb7"), | 159 EXPECT_EQ(UTF8ToUTF16("\xe9\x85\xb7"), |
133 util_.GetInputMethodShortName(desc)); | 160 util_.GetInputMethodShortName(desc)); |
134 } | 161 } |
135 { | 162 { |
136 InputMethodDescriptor desc = GetDesc("m17n:zh:cangjie", "us", "zh-TW"); | 163 InputMethodDescriptor desc = GetDesc("m17n:zh:cangjie", "us", "zh-TW"); |
137 EXPECT_EQ(UTF8ToUTF16("\xe5\x80\x89"), | 164 EXPECT_EQ(UTF8ToUTF16("\xe5\x80\x89"), |
138 util_.GetInputMethodShortName(desc)); | 165 util_.GetInputMethodShortName(desc)); |
139 } | 166 } |
140 { | 167 { |
141 InputMethodDescriptor desc = GetDesc("m17n:zh:quick", "us", "zh-TW"); | 168 InputMethodDescriptor desc = GetDesc("m17n:zh:quick", "us", "zh-TW"); |
(...skipping 21 matching lines...) Expand all Loading... |
163 string16 medium_name = util_.GetInputMethodMediumName(desc); | 190 string16 medium_name = util_.GetInputMethodMediumName(desc); |
164 string16 short_name = util_.GetInputMethodShortName(desc); | 191 string16 short_name = util_.GetInputMethodShortName(desc); |
165 EXPECT_EQ(medium_name,short_name); | 192 EXPECT_EQ(medium_name,short_name); |
166 } | 193 } |
167 } | 194 } |
168 { | 195 { |
169 // input methods with medium name not equal to short name | 196 // input methods with medium name not equal to short name |
170 const char * input_method_id[] = { | 197 const char * input_method_id[] = { |
171 "m17n:zh:cangjie", | 198 "m17n:zh:cangjie", |
172 "m17n:zh:quick", | 199 "m17n:zh:quick", |
173 "pinyin", | 200 pinyin_ime_id, |
174 "mozc-chewing", | 201 zhuyin_ime_id, |
175 "mozc-hangul", | 202 "mozc-hangul", |
176 "pinyin", | 203 pinyin_ime_id, |
177 "pinyin", | 204 pinyin_ime_id, |
178 "pinyin-dv", | |
179 }; | 205 }; |
180 const int len = ARRAYSIZE_UNSAFE(input_method_id); | 206 const int len = ARRAYSIZE_UNSAFE(input_method_id); |
181 for (int i=0; i<len; ++i) { | 207 for (int i=0; i<len; ++i) { |
182 InputMethodDescriptor desc = GetDesc(input_method_id[i], "", ""); | 208 InputMethodDescriptor desc = GetDesc(input_method_id[i], "", ""); |
183 string16 medium_name = util_.GetInputMethodMediumName(desc); | 209 string16 medium_name = util_.GetInputMethodMediumName(desc); |
184 string16 short_name = util_.GetInputMethodShortName(desc); | 210 string16 short_name = util_.GetInputMethodShortName(desc); |
185 EXPECT_NE(medium_name,short_name); | 211 EXPECT_NE(medium_name,short_name); |
186 } | 212 } |
187 } | 213 } |
188 } | 214 } |
(...skipping 10 matching lines...) Expand all Loading... |
199 InputMethodDescriptor desc = GetDesc("mozc-hangul", "us", "ko"); | 225 InputMethodDescriptor desc = GetDesc("mozc-hangul", "us", "ko"); |
200 EXPECT_EQ(ASCIIToUTF16("Korean input method"), | 226 EXPECT_EQ(ASCIIToUTF16("Korean input method"), |
201 util_.GetInputMethodLongName(desc)); | 227 util_.GetInputMethodLongName(desc)); |
202 } | 228 } |
203 { | 229 { |
204 InputMethodDescriptor desc = GetDesc("m17n:vi:tcvn", "us", "vi"); | 230 InputMethodDescriptor desc = GetDesc("m17n:vi:tcvn", "us", "vi"); |
205 EXPECT_EQ(ASCIIToUTF16("Vietnamese input method (TCVN6064)"), | 231 EXPECT_EQ(ASCIIToUTF16("Vietnamese input method (TCVN6064)"), |
206 util_.GetInputMethodLongName(desc)); | 232 util_.GetInputMethodLongName(desc)); |
207 } | 233 } |
208 { | 234 { |
209 InputMethodDescriptor desc = GetDesc("pinyin", "us", "ja"); | |
210 EXPECT_EQ(ASCIIToUTF16("Pinyin input method"), | |
211 util_.GetInputMethodLongName(desc)); | |
212 } | |
213 { | |
214 InputMethodDescriptor desc = GetDesc("xkb:jp::jpn", "jp", "ja"); | 235 InputMethodDescriptor desc = GetDesc("xkb:jp::jpn", "jp", "ja"); |
215 EXPECT_EQ(ASCIIToUTF16("Japanese keyboard"), | 236 EXPECT_EQ(ASCIIToUTF16("Japanese keyboard"), |
216 util_.GetInputMethodLongName(desc)); | 237 util_.GetInputMethodLongName(desc)); |
217 } | 238 } |
218 { | 239 { |
219 InputMethodDescriptor desc = | 240 InputMethodDescriptor desc = |
220 GetDesc("xkb:us:dvorak:eng", "us(dvorak)", "en-US"); | 241 GetDesc("xkb:us:dvorak:eng", "us(dvorak)", "en-US"); |
221 EXPECT_EQ(ASCIIToUTF16("US Dvorak keyboard"), | 242 EXPECT_EQ(ASCIIToUTF16("US Dvorak keyboard"), |
222 util_.GetInputMethodLongName(desc)); | 243 util_.GetInputMethodLongName(desc)); |
223 } | 244 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 289 |
269 { | 290 { |
270 InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx"); | 291 InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx"); |
271 // You can safely ignore the "Resouce ID is not found for: invalid-id" | 292 // You can safely ignore the "Resouce ID is not found for: invalid-id" |
272 // error. | 293 // error. |
273 EXPECT_EQ(ASCIIToUTF16("invalid-id"), | 294 EXPECT_EQ(ASCIIToUTF16("invalid-id"), |
274 util_.GetInputMethodLongName(desc)); | 295 util_.GetInputMethodLongName(desc)); |
275 } | 296 } |
276 } | 297 } |
277 | 298 |
278 TEST_F(InputMethodUtilTest, TestGetStringUTF8) { | |
279 EXPECT_EQ(UTF8ToUTF16("Pinyin input method"), | |
280 util_.TranslateString("pinyin")); | |
281 } | |
282 | |
283 TEST_F(InputMethodUtilTest, TestIsValidInputMethodId) { | 299 TEST_F(InputMethodUtilTest, TestIsValidInputMethodId) { |
284 EXPECT_TRUE(util_.IsValidInputMethodId("xkb:us:colemak:eng")); | 300 EXPECT_TRUE(util_.IsValidInputMethodId("xkb:us:colemak:eng")); |
285 EXPECT_TRUE(util_.IsValidInputMethodId("pinyin")); | 301 EXPECT_TRUE(util_.IsValidInputMethodId(pinyin_ime_id)); |
286 EXPECT_FALSE(util_.IsValidInputMethodId("unsupported-input-method")); | 302 EXPECT_FALSE(util_.IsValidInputMethodId("unsupported-input-method")); |
287 } | 303 } |
288 | 304 |
289 TEST_F(InputMethodUtilTest, TestIsKeyboardLayout) { | 305 TEST_F(InputMethodUtilTest, TestIsKeyboardLayout) { |
290 EXPECT_TRUE(InputMethodUtil::IsKeyboardLayout("xkb:us::eng")); | 306 EXPECT_TRUE(InputMethodUtil::IsKeyboardLayout("xkb:us::eng")); |
291 EXPECT_FALSE(InputMethodUtil::IsKeyboardLayout("pinyin")); | 307 EXPECT_FALSE(InputMethodUtil::IsKeyboardLayout(pinyin_ime_id)); |
292 } | 308 } |
293 | 309 |
294 TEST_F(InputMethodUtilTest, TestGetKeyboardLayoutName) { | 310 TEST_F(InputMethodUtilTest, TestGetKeyboardLayoutName) { |
295 // Unsupported case. | 311 // Unsupported case. |
296 EXPECT_EQ("", util_.GetKeyboardLayoutName("UNSUPPORTED_ID")); | 312 EXPECT_EQ("", util_.GetKeyboardLayoutName("UNSUPPORTED_ID")); |
297 | 313 |
298 // Supported cases (samples). | 314 // Supported cases (samples). |
299 EXPECT_EQ("us", util_.GetKeyboardLayoutName("pinyin")); | 315 EXPECT_EQ("us", util_.GetKeyboardLayoutName(pinyin_ime_id)); |
300 EXPECT_EQ("us(dvorak)", util_.GetKeyboardLayoutName("pinyin-dv")); | |
301 EXPECT_EQ("us", util_.GetKeyboardLayoutName("m17n:ar:kbd")); | 316 EXPECT_EQ("us", util_.GetKeyboardLayoutName("m17n:ar:kbd")); |
302 EXPECT_EQ("es", util_.GetKeyboardLayoutName("xkb:es::spa")); | 317 EXPECT_EQ("es", util_.GetKeyboardLayoutName("xkb:es::spa")); |
303 EXPECT_EQ("es(cat)", util_.GetKeyboardLayoutName("xkb:es:cat:cat")); | 318 EXPECT_EQ("es(cat)", util_.GetKeyboardLayoutName("xkb:es:cat:cat")); |
304 EXPECT_EQ("gb(extd)", util_.GetKeyboardLayoutName("xkb:gb:extd:eng")); | 319 EXPECT_EQ("gb(extd)", util_.GetKeyboardLayoutName("xkb:gb:extd:eng")); |
305 EXPECT_EQ("us", util_.GetKeyboardLayoutName("xkb:us::eng")); | 320 EXPECT_EQ("us", util_.GetKeyboardLayoutName("xkb:us::eng")); |
306 EXPECT_EQ("us(dvorak)", util_.GetKeyboardLayoutName("xkb:us:dvorak:eng")); | 321 EXPECT_EQ("us(dvorak)", util_.GetKeyboardLayoutName("xkb:us:dvorak:eng")); |
307 EXPECT_EQ("us(colemak)", util_.GetKeyboardLayoutName("xkb:us:colemak:eng")); | 322 EXPECT_EQ("us(colemak)", util_.GetKeyboardLayoutName("xkb:us:colemak:eng")); |
308 EXPECT_EQ("de(neo)", util_.GetKeyboardLayoutName("xkb:de:neo:ger")); | 323 EXPECT_EQ("de(neo)", util_.GetKeyboardLayoutName("xkb:de:neo:ger")); |
309 } | 324 } |
310 | 325 |
311 TEST_F(InputMethodUtilTest, TestGetLanguageCodeFromInputMethodId) { | 326 TEST_F(InputMethodUtilTest, TestGetLanguageCodeFromInputMethodId) { |
312 // Make sure that the -CN is added properly. | 327 // Make sure that the -CN is added properly. |
313 EXPECT_EQ("zh-CN", util_.GetLanguageCodeFromInputMethodId("pinyin")); | 328 EXPECT_EQ("zh-CN", util_.GetLanguageCodeFromInputMethodId(pinyin_ime_id)); |
314 } | 329 } |
315 | 330 |
316 TEST_F(InputMethodUtilTest, TestGetInputMethodDisplayNameFromId) { | 331 TEST_F(InputMethodUtilTest, TestGetInputMethodDisplayNameFromId) { |
317 EXPECT_EQ("Pinyin input method", | |
318 util_.GetInputMethodDisplayNameFromId("pinyin")); | |
319 EXPECT_EQ("US keyboard", | 332 EXPECT_EQ("US keyboard", |
320 util_.GetInputMethodDisplayNameFromId("xkb:us::eng")); | 333 util_.GetInputMethodDisplayNameFromId("xkb:us::eng")); |
321 EXPECT_EQ("", util_.GetInputMethodDisplayNameFromId("nonexistent")); | 334 EXPECT_EQ("", util_.GetInputMethodDisplayNameFromId("nonexistent")); |
322 } | 335 } |
323 | 336 |
324 TEST_F(InputMethodUtilTest, TestGetInputMethodDescriptorFromId) { | 337 TEST_F(InputMethodUtilTest, TestGetInputMethodDescriptorFromId) { |
325 EXPECT_EQ(NULL, util_.GetInputMethodDescriptorFromId("non_existent")); | 338 EXPECT_EQ(NULL, util_.GetInputMethodDescriptorFromId("non_existent")); |
326 | 339 |
327 const InputMethodDescriptor* descriptor = | 340 const InputMethodDescriptor* descriptor = |
328 util_.GetInputMethodDescriptorFromId("pinyin"); | 341 util_.GetInputMethodDescriptorFromId(pinyin_ime_id); |
329 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. | 342 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. |
330 EXPECT_EQ("pinyin", descriptor->id()); | 343 EXPECT_EQ(pinyin_ime_id, descriptor->id()); |
331 EXPECT_EQ("us", descriptor->GetPreferredKeyboardLayout()); | 344 EXPECT_EQ("us", descriptor->GetPreferredKeyboardLayout()); |
332 // This used to be "zh" but now we have "zh-CN" in input_methods.h, | 345 // This used to be "zh" but now we have "zh-CN" in input_methods.h, |
333 // hence this should be zh-CN now. | 346 // hence this should be zh-CN now. |
334 ASSERT_TRUE(!descriptor->language_codes().empty()); | 347 ASSERT_TRUE(!descriptor->language_codes().empty()); |
335 EXPECT_EQ("zh-CN", descriptor->language_codes().at(0)); | 348 EXPECT_EQ("zh-CN", descriptor->language_codes().at(0)); |
336 } | 349 } |
337 | 350 |
338 TEST_F(InputMethodUtilTest, TestGetInputMethodIdsForLanguageCode) { | 351 TEST_F(InputMethodUtilTest, TestGetInputMethodIdsForLanguageCode) { |
339 std::multimap<std::string, std::string> language_code_to_ids_map; | 352 std::multimap<std::string, std::string> language_code_to_ids_map; |
340 language_code_to_ids_map.insert(std::make_pair("ja", "pinyin")); | 353 language_code_to_ids_map.insert(std::make_pair("ja", pinyin_ime_id)); |
341 language_code_to_ids_map.insert(std::make_pair("ja", "pinyin")); | 354 language_code_to_ids_map.insert(std::make_pair("ja", pinyin_ime_id)); |
342 language_code_to_ids_map.insert(std::make_pair("ja", "xkb:jp:jpn")); | 355 language_code_to_ids_map.insert(std::make_pair("ja", "xkb:jp:jpn")); |
343 language_code_to_ids_map.insert(std::make_pair("fr", "xkb:fr:fra")); | 356 language_code_to_ids_map.insert(std::make_pair("fr", "xkb:fr:fra")); |
344 | 357 |
345 std::vector<std::string> result; | 358 std::vector<std::string> result; |
346 EXPECT_TRUE(util_.GetInputMethodIdsFromLanguageCodeInternal( | 359 EXPECT_TRUE(util_.GetInputMethodIdsFromLanguageCodeInternal( |
347 language_code_to_ids_map, "ja", kAllInputMethods, &result)); | 360 language_code_to_ids_map, "ja", kAllInputMethods, &result)); |
348 EXPECT_EQ(3U, result.size()); | 361 EXPECT_EQ(3U, result.size()); |
349 EXPECT_TRUE(util_.GetInputMethodIdsFromLanguageCodeInternal( | 362 EXPECT_TRUE(util_.GetInputMethodIdsFromLanguageCodeInternal( |
350 language_code_to_ids_map, "ja", kKeyboardLayoutsOnly, &result)); | 363 language_code_to_ids_map, "ja", kKeyboardLayoutsOnly, &result)); |
351 ASSERT_EQ(1U, result.size()); | 364 ASSERT_EQ(1U, result.size()); |
(...skipping 27 matching lines...) Expand all Loading... |
379 | 392 |
380 // US keyboard + Chinese UI = US keyboard + Pinyin IME. | 393 // US keyboard + Chinese UI = US keyboard + Pinyin IME. |
381 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_Zh) { | 394 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_Zh) { |
382 const InputMethodDescriptor* descriptor = | 395 const InputMethodDescriptor* descriptor = |
383 util_.GetInputMethodDescriptorFromId("xkb:us::eng"); // US keyboard. | 396 util_.GetInputMethodDescriptorFromId("xkb:us::eng"); // US keyboard. |
384 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. | 397 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. |
385 std::vector<std::string> input_method_ids; | 398 std::vector<std::string> input_method_ids; |
386 util_.GetFirstLoginInputMethodIds("zh-CN", *descriptor, &input_method_ids); | 399 util_.GetFirstLoginInputMethodIds("zh-CN", *descriptor, &input_method_ids); |
387 ASSERT_EQ(2U, input_method_ids.size()); | 400 ASSERT_EQ(2U, input_method_ids.size()); |
388 EXPECT_EQ("xkb:us::eng", input_method_ids[0]); | 401 EXPECT_EQ("xkb:us::eng", input_method_ids[0]); |
389 EXPECT_EQ("pinyin", input_method_ids[1]); // Pinyin for US keybaord. | 402 EXPECT_EQ(pinyin_ime_id, input_method_ids[1]); // Pinyin for US keybaord. |
390 } | 403 } |
391 | 404 |
392 // Korean keyboard + Korean UI = Korean keyboard + mozc-hangul. | 405 // Korean keyboard + Korean UI = Korean keyboard + mozc-hangul. |
393 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_KR_And_Ko) { | 406 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_KR_And_Ko) { |
394 // Korean keyboard | 407 // Korean keyboard |
395 const InputMethodDescriptor* descriptor = | 408 const InputMethodDescriptor* descriptor = |
396 util_.GetInputMethodDescriptorFromId("xkb:kr:kr104:kor"); | 409 util_.GetInputMethodDescriptorFromId("xkb:kr:kr104:kor"); |
397 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. | 410 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. |
398 std::vector<std::string> input_method_ids; | 411 std::vector<std::string> input_method_ids; |
399 util_.GetFirstLoginInputMethodIds("ko", *descriptor, &input_method_ids); | 412 util_.GetFirstLoginInputMethodIds("ko", *descriptor, &input_method_ids); |
(...skipping 16 matching lines...) Expand all Loading... |
416 | 429 |
417 // US keyboard + Traditional Chinese = US keyboard + chewing. | 430 // US keyboard + Traditional Chinese = US keyboard + chewing. |
418 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_ZhTw) { | 431 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_ZhTw) { |
419 const InputMethodDescriptor* descriptor = | 432 const InputMethodDescriptor* descriptor = |
420 util_.GetInputMethodDescriptorFromId("xkb:us::eng"); // US keyboard. | 433 util_.GetInputMethodDescriptorFromId("xkb:us::eng"); // US keyboard. |
421 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. | 434 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. |
422 std::vector<std::string> input_method_ids; | 435 std::vector<std::string> input_method_ids; |
423 util_.GetFirstLoginInputMethodIds("zh-TW", *descriptor, &input_method_ids); | 436 util_.GetFirstLoginInputMethodIds("zh-TW", *descriptor, &input_method_ids); |
424 ASSERT_EQ(2U, input_method_ids.size()); | 437 ASSERT_EQ(2U, input_method_ids.size()); |
425 EXPECT_EQ("xkb:us::eng", input_method_ids[0]); | 438 EXPECT_EQ("xkb:us::eng", input_method_ids[0]); |
426 EXPECT_EQ("mozc-chewing", input_method_ids[1]); // Chewing. | 439 EXPECT_EQ(zhuyin_ime_id, input_method_ids[1]); // Chewing. |
427 } | 440 } |
428 | 441 |
429 // US keyboard + Thai = US keyboard + kesmanee. | 442 // US keyboard + Thai = US keyboard + kesmanee. |
430 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_Th) { | 443 TEST_F(InputMethodUtilTest, TestGetFirstLoginInputMethodIds_Us_And_Th) { |
431 const InputMethodDescriptor* descriptor = | 444 const InputMethodDescriptor* descriptor = |
432 util_.GetInputMethodDescriptorFromId("xkb:us::eng"); // US keyboard. | 445 util_.GetInputMethodDescriptorFromId("xkb:us::eng"); // US keyboard. |
433 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. | 446 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. |
434 std::vector<std::string> input_method_ids; | 447 std::vector<std::string> input_method_ids; |
435 util_.GetFirstLoginInputMethodIds("th", *descriptor, &input_method_ids); | 448 util_.GetFirstLoginInputMethodIds("th", *descriptor, &input_method_ids); |
436 ASSERT_EQ(2U, input_method_ids.size()); | 449 ASSERT_EQ(2U, input_method_ids.size()); |
(...skipping 10 matching lines...) Expand all Loading... |
447 util_.GetFirstLoginInputMethodIds("vi", *descriptor, &input_method_ids); | 460 util_.GetFirstLoginInputMethodIds("vi", *descriptor, &input_method_ids); |
448 ASSERT_EQ(2U, input_method_ids.size()); | 461 ASSERT_EQ(2U, input_method_ids.size()); |
449 EXPECT_EQ("xkb:us::eng", input_method_ids[0]); | 462 EXPECT_EQ("xkb:us::eng", input_method_ids[0]); |
450 EXPECT_EQ("m17n:vi:tcvn", input_method_ids[1]); // TCVN6064. | 463 EXPECT_EQ("m17n:vi:tcvn", input_method_ids[1]); // TCVN6064. |
451 } | 464 } |
452 | 465 |
453 TEST_F(InputMethodUtilTest, TestGetLanguageCodesFromInputMethodIds) { | 466 TEST_F(InputMethodUtilTest, TestGetLanguageCodesFromInputMethodIds) { |
454 std::vector<std::string> input_method_ids; | 467 std::vector<std::string> input_method_ids; |
455 input_method_ids.push_back("xkb:us::eng"); // English US. | 468 input_method_ids.push_back("xkb:us::eng"); // English US. |
456 input_method_ids.push_back("xkb:us:dvorak:eng"); // English US Dvorak. | 469 input_method_ids.push_back("xkb:us:dvorak:eng"); // English US Dvorak. |
457 input_method_ids.push_back("pinyin"); // Pinyin | 470 input_method_ids.push_back(pinyin_ime_id); // Pinyin |
458 input_method_ids.push_back("xkb:fr::fra"); // French France. | 471 input_method_ids.push_back("xkb:fr::fra"); // French France. |
459 std::vector<std::string> language_codes; | 472 std::vector<std::string> language_codes; |
460 util_.GetLanguageCodesFromInputMethodIds(input_method_ids, &language_codes); | 473 util_.GetLanguageCodesFromInputMethodIds(input_method_ids, &language_codes); |
461 ASSERT_EQ(3U, language_codes.size()); | 474 ASSERT_EQ(3U, language_codes.size()); |
462 EXPECT_EQ("en-US", language_codes[0]); | 475 EXPECT_EQ("en-US", language_codes[0]); |
463 EXPECT_EQ("zh-CN", language_codes[1]); | 476 EXPECT_EQ("zh-CN", language_codes[1]); |
464 EXPECT_EQ("fr", language_codes[2]); | 477 EXPECT_EQ("fr", language_codes[2]); |
465 } | 478 } |
466 | 479 |
467 // Test all supported descriptors to detect a typo in ibus_input_methods.txt. | 480 // Test all supported descriptors to detect a typo in ibus_input_methods.txt. |
(...skipping 13 matching lines...) Expand all Loading... |
481 EXPECT_FALSE(display_name.empty()) | 494 EXPECT_FALSE(display_name.empty()) |
482 << "Invalid language code " << language_code; | 495 << "Invalid language code " << language_code; |
483 // On error, GetDisplayNameForLocale() returns the |language_code| as-is. | 496 // On error, GetDisplayNameForLocale() returns the |language_code| as-is. |
484 EXPECT_NE(language_code, UTF16ToUTF8(display_name)) | 497 EXPECT_NE(language_code, UTF16ToUTF8(display_name)) |
485 << "Invalid language code " << language_code; | 498 << "Invalid language code " << language_code; |
486 } | 499 } |
487 } | 500 } |
488 | 501 |
489 } // namespace input_method | 502 } // namespace input_method |
490 } // namespace chromeos | 503 } // namespace chromeos |
OLD | NEW |