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

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

Powered by Google App Engine
This is Rietveld 408576698