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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 12 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| 13 #include "chromeos/ime/fake_input_method_delegate.h" |
12 #include "chromeos/ime/input_method_whitelist.h" | 14 #include "chromeos/ime/input_method_whitelist.h" |
13 #include "chromeos/ime/mock_input_method_delegate.h" | |
14 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
17 | 18 |
18 namespace chromeos { | 19 namespace chromeos { |
19 | 20 |
20 extern const char* kExtensionImePrefix; | 21 extern const char* kExtensionImePrefix; |
21 | 22 |
22 namespace input_method { | 23 namespace input_method { |
23 | 24 |
(...skipping 11 matching lines...) Expand all Loading... |
35 using InputMethodUtil::ReloadInternalMaps; | 36 using InputMethodUtil::ReloadInternalMaps; |
36 using InputMethodUtil::supported_input_methods_; | 37 using InputMethodUtil::supported_input_methods_; |
37 }; | 38 }; |
38 | 39 |
39 } // namespace | 40 } // namespace |
40 | 41 |
41 class InputMethodUtilTest : public testing::Test { | 42 class InputMethodUtilTest : public testing::Test { |
42 public: | 43 public: |
43 InputMethodUtilTest() | 44 InputMethodUtilTest() |
44 : util_(&delegate_, whitelist_.GetSupportedInputMethods()) { | 45 : util_(&delegate_, whitelist_.GetSupportedInputMethods()) { |
| 46 delegate_.set_get_localized_string_callback( |
| 47 base::Bind(&l10n_util::GetStringUTF16)); |
| 48 delegate_.set_get_display_language_name_callback( |
| 49 base::Bind(&InputMethodUtilTest::GetDisplayLanguageName)); |
45 } | 50 } |
46 | 51 |
47 InputMethodDescriptor GetDesc(const std::string& id, | 52 InputMethodDescriptor GetDesc(const std::string& id, |
48 const std::string& raw_layout, | 53 const std::string& raw_layout, |
49 const std::string& language_code) { | 54 const std::string& language_code) { |
50 return InputMethodDescriptor(id, | 55 return InputMethodDescriptor(id, |
51 "", | 56 "", |
52 raw_layout, | 57 raw_layout, |
53 language_code, | 58 language_code, |
54 "", // options page url | 59 "", // options page url |
55 false); | 60 false); |
56 } | 61 } |
57 | 62 |
58 MockInputMethodDelegate delegate_; | 63 static string16 GetDisplayLanguageName(const std::string& language_code) { |
| 64 return l10n_util::GetDisplayNameForLocale(language_code, "en", true); |
| 65 } |
| 66 |
| 67 FakeInputMethodDelegate delegate_; |
59 InputMethodWhitelist whitelist_; | 68 InputMethodWhitelist whitelist_; |
60 TestableInputMethodUtil util_; | 69 TestableInputMethodUtil util_; |
61 }; | 70 }; |
62 | 71 |
63 TEST_F(InputMethodUtilTest, GetInputMethodShortNameTest) { | 72 TEST_F(InputMethodUtilTest, GetInputMethodShortNameTest) { |
64 // Test normal cases. Two-letter language code should be returned. | 73 // Test normal cases. Two-letter language code should be returned. |
65 { | 74 { |
66 InputMethodDescriptor desc = GetDesc("m17n:fa:isiri", // input method id | 75 InputMethodDescriptor desc = GetDesc("m17n:fa:isiri", // input method id |
67 "us", // keyboard layout name | 76 "us", // keyboard layout name |
68 "fa"); // language name | 77 "fa"); // language name |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 const InputMethodDescriptor* descriptor = | 344 const InputMethodDescriptor* descriptor = |
336 util_.GetInputMethodDescriptorFromId("pinyin"); | 345 util_.GetInputMethodDescriptorFromId("pinyin"); |
337 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. | 346 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. |
338 EXPECT_EQ("pinyin", descriptor->id()); | 347 EXPECT_EQ("pinyin", descriptor->id()); |
339 EXPECT_EQ("us", descriptor->keyboard_layout()); | 348 EXPECT_EQ("us", descriptor->keyboard_layout()); |
340 // This used to be "zh" but now we have "zh-CN" in input_methods.h, | 349 // This used to be "zh" but now we have "zh-CN" in input_methods.h, |
341 // hence this should be zh-CN now. | 350 // hence this should be zh-CN now. |
342 EXPECT_EQ("zh-CN", descriptor->language_code()); | 351 EXPECT_EQ("zh-CN", descriptor->language_code()); |
343 } | 352 } |
344 | 353 |
345 TEST_F(InputMethodUtilTest, TestGetLanguageNativeDisplayNameFromCode) { | |
346 EXPECT_EQ(UTF8ToUTF16("suomi"), | |
347 InputMethodUtil::GetLanguageNativeDisplayNameFromCode("fi")); | |
348 } | |
349 | |
350 TEST_F(InputMethodUtilTest, TestGetInputMethodIdsForLanguageCode) { | 354 TEST_F(InputMethodUtilTest, TestGetInputMethodIdsForLanguageCode) { |
351 std::multimap<std::string, std::string> language_code_to_ids_map; | 355 std::multimap<std::string, std::string> language_code_to_ids_map; |
352 language_code_to_ids_map.insert(std::make_pair("ja", "mozc")); | 356 language_code_to_ids_map.insert(std::make_pair("ja", "mozc")); |
353 language_code_to_ids_map.insert(std::make_pair("ja", "mozc-jp")); | 357 language_code_to_ids_map.insert(std::make_pair("ja", "mozc-jp")); |
354 language_code_to_ids_map.insert(std::make_pair("ja", "xkb:jp:jpn")); | 358 language_code_to_ids_map.insert(std::make_pair("ja", "xkb:jp:jpn")); |
355 language_code_to_ids_map.insert(std::make_pair("fr", "xkb:fr:fra")); | 359 language_code_to_ids_map.insert(std::make_pair("fr", "xkb:fr:fra")); |
356 | 360 |
357 std::vector<std::string> result; | 361 std::vector<std::string> result; |
358 EXPECT_TRUE(util_.GetInputMethodIdsFromLanguageCodeInternal( | 362 EXPECT_TRUE(util_.GetInputMethodIdsFromLanguageCodeInternal( |
359 language_code_to_ids_map, "ja", kAllInputMethods, &result)); | 363 language_code_to_ids_map, "ja", kAllInputMethods, &result)); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 EXPECT_FALSE(display_name.empty()) | 509 EXPECT_FALSE(display_name.empty()) |
506 << "Invalid language code " << language_code; | 510 << "Invalid language code " << language_code; |
507 // On error, GetDisplayNameForLocale() returns the |language_code| as-is. | 511 // On error, GetDisplayNameForLocale() returns the |language_code| as-is. |
508 EXPECT_NE(language_code, UTF16ToUTF8(display_name)) | 512 EXPECT_NE(language_code, UTF16ToUTF8(display_name)) |
509 << "Invalid language code " << language_code; | 513 << "Invalid language code " << language_code; |
510 } | 514 } |
511 } | 515 } |
512 | 516 |
513 } // namespace input_method | 517 } // namespace input_method |
514 } // namespace chromeos | 518 } // namespace chromeos |
OLD | NEW |