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

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_util_unittest.cc

Issue 306053005: Adds whitelisted non-extension-based input methods if no component extensions are at present (e.g. … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed test failures. 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"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 static base::string16 GetDisplayLanguageName(const std::string& language_code) { 121 static base::string16 GetDisplayLanguageName(const std::string& language_code) {
122 return l10n_util::GetDisplayNameForLocale(language_code, "en", true); 122 return l10n_util::GetDisplayNameForLocale(language_code, "en", true);
123 } 123 }
124 124
125 FakeInputMethodDelegate delegate_; 125 FakeInputMethodDelegate delegate_;
126 InputMethodWhitelist whitelist_; 126 InputMethodWhitelist whitelist_;
127 TestableInputMethodUtil util_; 127 TestableInputMethodUtil util_;
128 }; 128 };
129 129
130 TEST_F(InputMethodUtilTest, GetInputMethodShortNameTest) { 130 TEST_F(InputMethodUtilTest, GetInputMethodShortNameTest) {
131 // Test normal cases. Two-letter language code should be returned. 131 // Test invalid cases. Two-letter language code should be returned.
132 {
133 InputMethodDescriptor desc = GetDesc("m17n:fa:isiri", // input method id
134 "us", // keyboard layout name
135 "fa", // language name
136 ""); // indicator
137 EXPECT_EQ(ASCIIToUTF16("FA"), util_.GetInputMethodShortName(desc));
138 }
139 {
140 InputMethodDescriptor desc = GetDesc("mozc-hangul", "us", "ko", "");
141 EXPECT_EQ(base::UTF8ToUTF16("\xed\x95\x9c"),
142 util_.GetInputMethodShortName(desc));
143 }
144 { 132 {
145 InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", ""); 133 InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", "");
146 // Upper-case string of the unknown language code, "xx", should be returned. 134 // Upper-case string of the unknown language code, "xx", should be returned.
147 EXPECT_EQ(ASCIIToUTF16("XX"), util_.GetInputMethodShortName(desc)); 135 EXPECT_EQ(ASCIIToUTF16("XX"), util_.GetInputMethodShortName(desc));
148 } 136 }
149 137
150 // Test special cases. 138 // Test special cases.
151 { 139 {
152 InputMethodDescriptor desc = 140 InputMethodDescriptor desc =
153 GetDesc("xkb:us:dvorak:eng", "us", "en-US", "DV"); 141 GetDesc("xkb:us:dvorak:eng", "us", "en-US", "DV");
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 for (int i=0; i<len; ++i) { 196 for (int i=0; i<len; ++i) {
209 InputMethodDescriptor desc = GetDesc(input_method_id[i], "", "", ""); 197 InputMethodDescriptor desc = GetDesc(input_method_id[i], "", "", "");
210 base::string16 medium_name = util_.GetInputMethodMediumName(desc); 198 base::string16 medium_name = util_.GetInputMethodMediumName(desc);
211 base::string16 short_name = util_.GetInputMethodShortName(desc); 199 base::string16 short_name = util_.GetInputMethodShortName(desc);
212 EXPECT_EQ(medium_name,short_name); 200 EXPECT_EQ(medium_name,short_name);
213 } 201 }
214 } 202 }
215 { 203 {
216 // input methods with medium name not equal to short name 204 // input methods with medium name not equal to short name
217 const char * input_method_id[] = { 205 const char * input_method_id[] = {
218 "m17n:zh:cangjie",
219 "m17n:zh:quick",
220 pinyin_ime_id, 206 pinyin_ime_id,
221 zhuyin_ime_id, 207 zhuyin_ime_id,
222 "mozc-hangul",
223 pinyin_ime_id, 208 pinyin_ime_id,
224 pinyin_ime_id, 209 pinyin_ime_id,
225 }; 210 };
226 const int len = ARRAYSIZE_UNSAFE(input_method_id); 211 const int len = ARRAYSIZE_UNSAFE(input_method_id);
227 for (int i=0; i<len; ++i) { 212 for (int i=0; i<len; ++i) {
228 InputMethodDescriptor desc = GetDesc(input_method_id[i], "", "", ""); 213 InputMethodDescriptor desc = GetDesc(input_method_id[i], "", "", "");
229 base::string16 medium_name = util_.GetInputMethodMediumName(desc); 214 base::string16 medium_name = util_.GetInputMethodMediumName(desc);
230 base::string16 short_name = util_.GetInputMethodShortName(desc); 215 base::string16 short_name = util_.GetInputMethodShortName(desc);
231 EXPECT_NE(medium_name,short_name); 216 EXPECT_NE(medium_name,short_name);
232 } 217 }
233 } 218 }
234 } 219 }
235 220
236 TEST_F(InputMethodUtilTest, GetInputMethodLongNameTest) { 221 TEST_F(InputMethodUtilTest, GetInputMethodLongNameTest) {
237 // For most languages input method or keyboard layout name is returned. 222 // For most languages input method or keyboard layout name is returned.
238 // See below for exceptions. 223 // See below for exceptions.
239 { 224 {
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", ""); 225 InputMethodDescriptor desc = GetDesc("xkb:jp::jpn", "jp", "ja", "");
256 EXPECT_EQ(ASCIIToUTF16("Japanese"), 226 EXPECT_EQ(ASCIIToUTF16("Japanese"),
257 util_.GetInputMethodLongName(desc)); 227 util_.GetInputMethodLongName(desc));
258 } 228 }
259 { 229 {
260 InputMethodDescriptor desc = 230 InputMethodDescriptor desc =
261 GetDesc("xkb:us:dvorak:eng", "us(dvorak)", "en-US", ""); 231 GetDesc("xkb:us:dvorak:eng", "us(dvorak)", "en-US", "");
262 EXPECT_EQ(ASCIIToUTF16("US Dvorak"), 232 EXPECT_EQ(ASCIIToUTF16("US Dvorak"),
263 util_.GetInputMethodLongName(desc)); 233 util_.GetInputMethodLongName(desc));
264 } 234 }
265 { 235 {
266 InputMethodDescriptor desc = 236 InputMethodDescriptor desc =
267 GetDesc("xkb:gb:dvorak:eng", "gb(dvorak)", "en-US", ""); 237 GetDesc("xkb:gb:dvorak:eng", "gb(dvorak)", "en-US", "");
268 EXPECT_EQ(ASCIIToUTF16("UK Dvorak"), 238 EXPECT_EQ(ASCIIToUTF16("UK Dvorak"),
269 util_.GetInputMethodLongName(desc)); 239 util_.GetInputMethodLongName(desc));
270 } 240 }
271 241
272 // For Arabic, Dutch, French, German and Hindi, 242 // For Dutch, French, German and Hindi,
273 // "language - keyboard layout" pair is returned. 243 // "language - keyboard layout" pair is returned.
274 { 244 {
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", ""); 245 InputMethodDescriptor desc = GetDesc("xkb:be::nld", "be", "nl", "");
281 EXPECT_EQ(ASCIIToUTF16("Dutch - Belgian"), 246 EXPECT_EQ(ASCIIToUTF16("Dutch - Belgian"),
282 util_.GetInputMethodLongName(desc)); 247 util_.GetInputMethodLongName(desc));
283 } 248 }
284 { 249 {
285 InputMethodDescriptor desc = GetDesc("xkb:fr::fra", "fr", "fr", ""); 250 InputMethodDescriptor desc = GetDesc("xkb:fr::fra", "fr", "fr", "");
286 EXPECT_EQ(ASCIIToUTF16("French - French"), 251 EXPECT_EQ(ASCIIToUTF16("French - French"),
287 util_.GetInputMethodLongName(desc)); 252 util_.GetInputMethodLongName(desc));
288 } 253 }
289 { 254 {
290 InputMethodDescriptor desc = GetDesc("xkb:be::fra", "be", "fr", ""); 255 InputMethodDescriptor desc = GetDesc("xkb:be::fra", "be", "fr", "");
291 EXPECT_EQ(ASCIIToUTF16("French - Belgian"), 256 EXPECT_EQ(ASCIIToUTF16("French - Belgian"),
292 util_.GetInputMethodLongName(desc)); 257 util_.GetInputMethodLongName(desc));
293 } 258 }
294 { 259 {
295 InputMethodDescriptor desc = GetDesc("xkb:de::ger", "de", "de", ""); 260 InputMethodDescriptor desc = GetDesc("xkb:de::ger", "de", "de", "");
296 EXPECT_EQ(ASCIIToUTF16("German - German"), 261 EXPECT_EQ(ASCIIToUTF16("German - German"),
297 util_.GetInputMethodLongName(desc)); 262 util_.GetInputMethodLongName(desc));
298 } 263 }
299 { 264 {
300 InputMethodDescriptor desc = GetDesc("xkb:be::ger", "be", "de", ""); 265 InputMethodDescriptor desc = GetDesc("xkb:be::ger", "be", "de", "");
301 EXPECT_EQ(ASCIIToUTF16("German - Belgian"), 266 EXPECT_EQ(ASCIIToUTF16("German - Belgian"),
302 util_.GetInputMethodLongName(desc)); 267 util_.GetInputMethodLongName(desc));
303 } 268 }
304 {
305 InputMethodDescriptor desc = GetDesc("m17n:hi:itrans", "us", "hi", "");
306 EXPECT_EQ(ASCIIToUTF16("Hindi - Standard input method"),
307 util_.GetInputMethodLongName(desc));
308 }
309 269
310 { 270 {
311 InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", ""); 271 InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", "");
312 // You can safely ignore the "Resouce ID is not found for: invalid-id" 272 // You can safely ignore the "Resouce ID is not found for: invalid-id"
313 // error. 273 // error.
314 EXPECT_EQ(ASCIIToUTF16("invalid-id"), 274 EXPECT_EQ(ASCIIToUTF16("invalid-id"),
315 util_.GetInputMethodLongName(desc)); 275 util_.GetInputMethodLongName(desc));
316 } 276 }
317 } 277 }
318 278
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 EXPECT_FALSE(display_name.empty()) 463 EXPECT_FALSE(display_name.empty())
504 << "Invalid language code " << language_code; 464 << "Invalid language code " << language_code;
505 // On error, GetDisplayNameForLocale() returns the |language_code| as-is. 465 // On error, GetDisplayNameForLocale() returns the |language_code| as-is.
506 EXPECT_NE(language_code, base::UTF16ToUTF8(display_name)) 466 EXPECT_NE(language_code, base::UTF16ToUTF8(display_name))
507 << "Invalid language code " << language_code; 467 << "Invalid language code " << language_code;
508 } 468 }
509 } 469 }
510 470
511 } // namespace input_method 471 } // namespace input_method
512 } // namespace chromeos 472 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698