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" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 languages.push_back(language_code); | 94 languages.push_back(language_code); |
95 return InputMethodDescriptor(id, | 95 return InputMethodDescriptor(id, |
96 "", | 96 "", |
97 layouts, | 97 layouts, |
98 languages, | 98 languages, |
99 true, | 99 true, |
100 GURL(), // options page url | 100 GURL(), // options page url |
101 GURL()); // input view page url | 101 GURL()); // input view page url |
102 } | 102 } |
103 | 103 |
104 static string16 GetDisplayLanguageName(const std::string& language_code) { | 104 static base::string16 GetDisplayLanguageName(const std::string& language_code)
{ |
105 return l10n_util::GetDisplayNameForLocale(language_code, "en", true); | 105 return l10n_util::GetDisplayNameForLocale(language_code, "en", true); |
106 } | 106 } |
107 | 107 |
108 FakeInputMethodDelegate delegate_; | 108 FakeInputMethodDelegate delegate_; |
109 InputMethodWhitelist whitelist_; | 109 InputMethodWhitelist whitelist_; |
110 TestableInputMethodUtil util_; | 110 TestableInputMethodUtil util_; |
111 }; | 111 }; |
112 | 112 |
113 TEST_F(InputMethodUtilTest, GetInputMethodShortNameTest) { | 113 TEST_F(InputMethodUtilTest, GetInputMethodShortNameTest) { |
114 // Test normal cases. Two-letter language code should be returned. | 114 // Test normal cases. Two-letter language code should be returned. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 "xkb:us:intl:eng", | 176 "xkb:us:intl:eng", |
177 "xkb:us:colemak:eng", | 177 "xkb:us:colemak:eng", |
178 "english-m", | 178 "english-m", |
179 "xkb:de:neo:ger", | 179 "xkb:de:neo:ger", |
180 "xkb:es:cat:cat", | 180 "xkb:es:cat:cat", |
181 "xkb:gb:dvorak:eng", | 181 "xkb:gb:dvorak:eng", |
182 }; | 182 }; |
183 const int len = ARRAYSIZE_UNSAFE(input_method_id); | 183 const int len = ARRAYSIZE_UNSAFE(input_method_id); |
184 for (int i=0; i<len; ++i) { | 184 for (int i=0; i<len; ++i) { |
185 InputMethodDescriptor desc = GetDesc(input_method_id[i], "", ""); | 185 InputMethodDescriptor desc = GetDesc(input_method_id[i], "", ""); |
186 string16 medium_name = util_.GetInputMethodMediumName(desc); | 186 base::string16 medium_name = util_.GetInputMethodMediumName(desc); |
187 string16 short_name = util_.GetInputMethodShortName(desc); | 187 base::string16 short_name = util_.GetInputMethodShortName(desc); |
188 EXPECT_EQ(medium_name,short_name); | 188 EXPECT_EQ(medium_name,short_name); |
189 } | 189 } |
190 } | 190 } |
191 { | 191 { |
192 // input methods with medium name not equal to short name | 192 // input methods with medium name not equal to short name |
193 const char * input_method_id[] = { | 193 const char * input_method_id[] = { |
194 "m17n:zh:cangjie", | 194 "m17n:zh:cangjie", |
195 "m17n:zh:quick", | 195 "m17n:zh:quick", |
196 pinyin_ime_id, | 196 pinyin_ime_id, |
197 zhuyin_ime_id, | 197 zhuyin_ime_id, |
198 "mozc-hangul", | 198 "mozc-hangul", |
199 pinyin_ime_id, | 199 pinyin_ime_id, |
200 pinyin_ime_id, | 200 pinyin_ime_id, |
201 }; | 201 }; |
202 const int len = ARRAYSIZE_UNSAFE(input_method_id); | 202 const int len = ARRAYSIZE_UNSAFE(input_method_id); |
203 for (int i=0; i<len; ++i) { | 203 for (int i=0; i<len; ++i) { |
204 InputMethodDescriptor desc = GetDesc(input_method_id[i], "", ""); | 204 InputMethodDescriptor desc = GetDesc(input_method_id[i], "", ""); |
205 string16 medium_name = util_.GetInputMethodMediumName(desc); | 205 base::string16 medium_name = util_.GetInputMethodMediumName(desc); |
206 string16 short_name = util_.GetInputMethodShortName(desc); | 206 base::string16 short_name = util_.GetInputMethodShortName(desc); |
207 EXPECT_NE(medium_name,short_name); | 207 EXPECT_NE(medium_name,short_name); |
208 } | 208 } |
209 } | 209 } |
210 } | 210 } |
211 | 211 |
212 TEST_F(InputMethodUtilTest, GetInputMethodLongNameTest) { | 212 TEST_F(InputMethodUtilTest, GetInputMethodLongNameTest) { |
213 // For most languages input method or keyboard layout name is returned. | 213 // For most languages input method or keyboard layout name is returned. |
214 // See below for exceptions. | 214 // See below for exceptions. |
215 { | 215 { |
216 InputMethodDescriptor desc = GetDesc("m17n:fa:isiri", "us", "fa"); | 216 InputMethodDescriptor desc = GetDesc("m17n:fa:isiri", "us", "fa"); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 EXPECT_EQ("en-US", language_codes[0]); | 459 EXPECT_EQ("en-US", language_codes[0]); |
460 EXPECT_EQ("zh-CN", language_codes[1]); | 460 EXPECT_EQ("zh-CN", language_codes[1]); |
461 EXPECT_EQ("fr", language_codes[2]); | 461 EXPECT_EQ("fr", language_codes[2]); |
462 } | 462 } |
463 | 463 |
464 // Test all supported descriptors to detect a typo in ibus_input_methods.txt. | 464 // Test all supported descriptors to detect a typo in ibus_input_methods.txt. |
465 TEST_F(InputMethodUtilTest, TestIBusInputMethodText) { | 465 TEST_F(InputMethodUtilTest, TestIBusInputMethodText) { |
466 for (size_t i = 0; i < util_.supported_input_methods_->size(); ++i) { | 466 for (size_t i = 0; i < util_.supported_input_methods_->size(); ++i) { |
467 const std::string language_code = | 467 const std::string language_code = |
468 util_.supported_input_methods_->at(i).language_codes().at(0); | 468 util_.supported_input_methods_->at(i).language_codes().at(0); |
469 const string16 display_name = | 469 const base::string16 display_name = |
470 l10n_util::GetDisplayNameForLocale(language_code, "en", false); | 470 l10n_util::GetDisplayNameForLocale(language_code, "en", false); |
471 // Only two formats, like "fr" (lower case) and "en-US" (lower-upper), are | 471 // Only two formats, like "fr" (lower case) and "en-US" (lower-upper), are |
472 // allowed. See the text file for details. | 472 // allowed. See the text file for details. |
473 EXPECT_TRUE(language_code.length() == 2 || | 473 EXPECT_TRUE(language_code.length() == 2 || |
474 (language_code.length() == 5 && language_code[2] == '-')) | 474 (language_code.length() == 5 && language_code[2] == '-')) |
475 << "Invalid language code " << language_code; | 475 << "Invalid language code " << language_code; |
476 EXPECT_TRUE(l10n_util::IsValidLocaleSyntax(language_code)) | 476 EXPECT_TRUE(l10n_util::IsValidLocaleSyntax(language_code)) |
477 << "Invalid language code " << language_code; | 477 << "Invalid language code " << language_code; |
478 EXPECT_FALSE(display_name.empty()) | 478 EXPECT_FALSE(display_name.empty()) |
479 << "Invalid language code " << language_code; | 479 << "Invalid language code " << language_code; |
480 // On error, GetDisplayNameForLocale() returns the |language_code| as-is. | 480 // On error, GetDisplayNameForLocale() returns the |language_code| as-is. |
481 EXPECT_NE(language_code, UTF16ToUTF8(display_name)) | 481 EXPECT_NE(language_code, UTF16ToUTF8(display_name)) |
482 << "Invalid language code " << language_code; | 482 << "Invalid language code " << language_code; |
483 } | 483 } |
484 } | 484 } |
485 | 485 |
486 } // namespace input_method | 486 } // namespace input_method |
487 } // namespace chromeos | 487 } // namespace chromeos |
OLD | NEW |