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

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: 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 21 matching lines...) Expand all
32 32
33 class TestableInputMethodUtil : public InputMethodUtil { 33 class TestableInputMethodUtil : public InputMethodUtil {
34 public: 34 public:
35 explicit TestableInputMethodUtil(InputMethodDelegate* delegate, 35 explicit TestableInputMethodUtil(InputMethodDelegate* delegate,
36 scoped_ptr<InputMethodDescriptors> methods) 36 scoped_ptr<InputMethodDescriptors> methods)
37 : InputMethodUtil(delegate, methods.Pass()) { 37 : InputMethodUtil(delegate, methods.Pass()) {
38 } 38 }
39 // Change access rights. 39 // Change access rights.
40 using InputMethodUtil::GetInputMethodIdsFromLanguageCodeInternal; 40 using InputMethodUtil::GetInputMethodIdsFromLanguageCodeInternal;
41 using InputMethodUtil::GetKeyboardLayoutName; 41 using InputMethodUtil::GetKeyboardLayoutName;
42 using InputMethodUtil::ReloadInternalMaps;
43 using InputMethodUtil::supported_input_methods_;
44 }; 42 };
45 43
46 } // namespace 44 } // namespace
47 45
48 class InputMethodUtilTest : public testing::Test { 46 class InputMethodUtilTest : public testing::Test {
49 public: 47 public:
50 InputMethodUtilTest() 48 InputMethodUtilTest()
51 : util_(&delegate_, whitelist_.GetSupportedInputMethods()) { 49 : util_(&delegate_, whitelist_.GetSupportedInputMethods()) {
52 delegate_.set_get_localized_string_callback( 50 delegate_.set_get_localized_string_callback(
53 base::Bind(&l10n_util::GetStringUTF16)); 51 base::Bind(&l10n_util::GetStringUTF16));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 static base::string16 GetDisplayLanguageName(const std::string& language_code) { 112 static base::string16 GetDisplayLanguageName(const std::string& language_code) {
115 return l10n_util::GetDisplayNameForLocale(language_code, "en", true); 113 return l10n_util::GetDisplayNameForLocale(language_code, "en", true);
116 } 114 }
117 115
118 FakeInputMethodDelegate delegate_; 116 FakeInputMethodDelegate delegate_;
119 InputMethodWhitelist whitelist_; 117 InputMethodWhitelist whitelist_;
120 TestableInputMethodUtil util_; 118 TestableInputMethodUtil util_;
121 }; 119 };
122 120
123 TEST_F(InputMethodUtilTest, GetInputMethodShortNameTest) { 121 TEST_F(InputMethodUtilTest, GetInputMethodShortNameTest) {
124 // Test normal cases. Two-letter language code should be returned. 122 // Test invalid cases. Two-letter language code should be returned.
125 {
126 InputMethodDescriptor desc = GetDesc("vkd_fa", // input method id
127 "us", // keyboard layout name
128 "fa", // language name
129 ""); // indicator
130 EXPECT_EQ(ASCIIToUTF16("FA"), util_.GetInputMethodShortName(desc));
131 }
132 {
133 InputMethodDescriptor desc = GetDesc("hangul_2set", "us", "ko", "");
134 EXPECT_EQ(base::UTF8ToUTF16("\xed\x95\x9c"),
135 util_.GetInputMethodShortName(desc));
136 }
137 { 123 {
138 InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", ""); 124 InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", "");
139 // Upper-case string of the unknown language code, "xx", should be returned. 125 // Upper-case string of the unknown language code, "xx", should be returned.
140 EXPECT_EQ(ASCIIToUTF16("XX"), util_.GetInputMethodShortName(desc)); 126 EXPECT_EQ(ASCIIToUTF16("XX"), util_.GetInputMethodShortName(desc));
141 } 127 }
142 128
143 // Test special cases. 129 // Test special cases.
144 { 130 {
145 InputMethodDescriptor desc = 131 InputMethodDescriptor desc =
146 GetDesc("xkb:us:dvorak:eng", "us", "en-US", "DV"); 132 GetDesc("xkb:us:dvorak:eng", "us", "en-US", "DV");
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 EXPECT_EQ("es", util_.GetKeyboardLayoutName(Id("xkb:es::spa"))); 284 EXPECT_EQ("es", util_.GetKeyboardLayoutName(Id("xkb:es::spa")));
299 EXPECT_EQ("es(cat)", util_.GetKeyboardLayoutName(Id("xkb:es:cat:cat"))); 285 EXPECT_EQ("es(cat)", util_.GetKeyboardLayoutName(Id("xkb:es:cat:cat")));
300 EXPECT_EQ("gb(extd)", util_.GetKeyboardLayoutName(Id("xkb:gb:extd:eng"))); 286 EXPECT_EQ("gb(extd)", util_.GetKeyboardLayoutName(Id("xkb:gb:extd:eng")));
301 EXPECT_EQ("us", util_.GetKeyboardLayoutName(Id("xkb:us::eng"))); 287 EXPECT_EQ("us", util_.GetKeyboardLayoutName(Id("xkb:us::eng")));
302 EXPECT_EQ("us(dvorak)", util_.GetKeyboardLayoutName(Id("xkb:us:dvorak:eng"))); 288 EXPECT_EQ("us(dvorak)", util_.GetKeyboardLayoutName(Id("xkb:us:dvorak:eng")));
303 EXPECT_EQ("us(colemak)", 289 EXPECT_EQ("us(colemak)",
304 util_.GetKeyboardLayoutName(Id("xkb:us:colemak:eng"))); 290 util_.GetKeyboardLayoutName(Id("xkb:us:colemak:eng")));
305 EXPECT_EQ("de(neo)", util_.GetKeyboardLayoutName(Id("xkb:de:neo:ger"))); 291 EXPECT_EQ("de(neo)", util_.GetKeyboardLayoutName(Id("xkb:de:neo:ger")));
306 } 292 }
307 293
308 TEST_F(InputMethodUtilTest, TestGetLanguageCodeFromInputMethodId) {
309 // Make sure that the -CN is added properly.
310 EXPECT_EQ("zh-CN", util_.GetLanguageCodeFromInputMethodId(Id(pinyin_ime_id)));
311 }
312
313 TEST_F(InputMethodUtilTest, TestGetInputMethodDisplayNameFromId) { 294 TEST_F(InputMethodUtilTest, TestGetInputMethodDisplayNameFromId) {
314 EXPECT_EQ("US", 295 EXPECT_EQ("US",
315 util_.GetInputMethodDisplayNameFromId("xkb:us::eng")); 296 util_.GetInputMethodDisplayNameFromId("xkb:us::eng"));
316 EXPECT_EQ("", util_.GetInputMethodDisplayNameFromId("nonexistent")); 297 EXPECT_EQ("", util_.GetInputMethodDisplayNameFromId("nonexistent"));
317 } 298 }
318 299
319 TEST_F(InputMethodUtilTest, TestGetInputMethodDescriptorFromId) { 300 TEST_F(InputMethodUtilTest, TestGetInputMethodDescriptorFromId) {
320 EXPECT_EQ(NULL, util_.GetInputMethodDescriptorFromId("non_existent")); 301 EXPECT_EQ(NULL, util_.GetInputMethodDescriptorFromId("non_existent"));
321 302
322 const InputMethodDescriptor* descriptor = 303 const InputMethodDescriptor* descriptor =
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 std::vector<std::string> language_codes; 422 std::vector<std::string> language_codes;
442 util_.GetLanguageCodesFromInputMethodIds(input_method_ids, &language_codes); 423 util_.GetLanguageCodesFromInputMethodIds(input_method_ids, &language_codes);
443 ASSERT_EQ(3U, language_codes.size()); 424 ASSERT_EQ(3U, language_codes.size());
444 EXPECT_EQ("en", language_codes[0]); 425 EXPECT_EQ("en", language_codes[0]);
445 EXPECT_EQ("zh-CN", language_codes[1]); 426 EXPECT_EQ("zh-CN", language_codes[1]);
446 EXPECT_EQ("fr", language_codes[2]); 427 EXPECT_EQ("fr", language_codes[2]);
447 } 428 }
448 429
449 // Test all supported descriptors to detect a typo in input_methods.txt. 430 // Test all supported descriptors to detect a typo in input_methods.txt.
450 TEST_F(InputMethodUtilTest, TestIBusInputMethodText) { 431 TEST_F(InputMethodUtilTest, TestIBusInputMethodText) {
451 for (size_t i = 0; i < util_.supported_input_methods_->size(); ++i) { 432 const std::map<std::string, InputMethodDescriptor>& id_to_descriptor =
452 const std::string language_code = 433 util_.GetIdToDesciptorMapForTesting();
453 util_.supported_input_methods_->at(i).language_codes().at(0); 434 for (std::map<std::string, InputMethodDescriptor>::const_iterator it =
435 id_to_descriptor.begin(); it != id_to_descriptor.end(); ++it) {
436 const std::string language_code = it->second.language_codes().at(0);
454 const base::string16 display_name = 437 const base::string16 display_name =
455 l10n_util::GetDisplayNameForLocale(language_code, "en", false); 438 l10n_util::GetDisplayNameForLocale(language_code, "en", false);
456 // Only two formats, like "fr" (lower case) and "en-US" (lower-upper), are 439 // Only two formats, like "fr" (lower case) and "en-US" (lower-upper), are
457 // allowed. See the text file for details. 440 // allowed. See the text file for details.
458 EXPECT_TRUE(language_code == "fil" || language_code.length() == 2 || 441 EXPECT_TRUE(language_code == "fil" || language_code.length() == 2 ||
459 (language_code.length() == 5 && language_code[2] == '-')) 442 (language_code.length() == 5 && language_code[2] == '-'))
460 << "Invalid language code " << language_code; 443 << "Invalid language code " << language_code;
461 EXPECT_TRUE(l10n_util::IsValidLocaleSyntax(language_code)) 444 EXPECT_TRUE(l10n_util::IsValidLocaleSyntax(language_code))
462 << "Invalid language code " << language_code; 445 << "Invalid language code " << language_code;
463 EXPECT_FALSE(display_name.empty()) 446 EXPECT_FALSE(display_name.empty())
464 << "Invalid language code " << language_code; 447 << "Invalid language code " << language_code;
465 // On error, GetDisplayNameForLocale() returns the |language_code| as-is. 448 // On error, GetDisplayNameForLocale() returns the |language_code| as-is.
466 EXPECT_NE(language_code, base::UTF16ToUTF8(display_name)) 449 EXPECT_NE(language_code, base::UTF16ToUTF8(display_name))
467 << "Invalid language code " << language_code; 450 << "Invalid language code " << language_code;
468 } 451 }
469 } 452 }
470 453
471 } // namespace input_method 454 } // namespace input_method
472 } // namespace chromeos 455 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/input_method/input_method_util.cc ('k') | chromeos/ime/input_method_whitelist.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698