diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-08 07:17:04 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-08 07:17:04 +0000 |
commit | 257493d2371e714358e1294ec390fda22a1b77c7 (patch) | |
tree | 6fd61e1a2b597bc5ae8307992d03cd184eb2b16c /chrome/browser/chromeos/input_method | |
parent | bc50a69fff79438452df572735a6273e99140144 (diff) | |
download | chromium_src-257493d2371e714358e1294ec390fda22a1b77c7.zip chromium_src-257493d2371e714358e1294ec390fda22a1b77c7.tar.gz chromium_src-257493d2371e714358e1294ec390fda22a1b77c7.tar.bz2 |
More clean-up for InputMethodLibrary and related code.
- Use GetSupportedInputMethodDescriptors() instead of GetSupportedInputMethods().
- Call EnsureLoadedAndStarted() where we use input_method_status_connection_.
- Introduce InputMethodUtilTest to make input_method_util_unittest more stable.
BUG=chromium-os:11528
TEST=manually on the netbook
Review URL: http://codereview.chromium.org/6368124
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74099 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/input_method')
3 files changed, 37 insertions, 18 deletions
diff --git a/chrome/browser/chromeos/input_method/input_method_util.cc b/chrome/browser/chromeos/input_method/input_method_util.cc index ffe76e7..ed64023 100644 --- a/chrome/browser/chromeos/input_method/input_method_util.cc +++ b/chrome/browser/chromeos/input_method/input_method_util.cc @@ -607,9 +607,13 @@ InputMethodDescriptor GetFallbackInputMethodDescriptor() { return InputMethodDescriptor("xkb:us::eng", "USA", "us", "eng"); } -void OnLocaleChanged() { +void ReloadInternalMaps() { IdMaps::GetInstance()->ReloadMaps(); } +void OnLocaleChanged() { + ReloadInternalMaps(); +} + } // namespace input_method } // namespace chromeos diff --git a/chrome/browser/chromeos/input_method/input_method_util.h b/chrome/browser/chromeos/input_method/input_method_util.h index 7b6b6da..338d93d 100644 --- a/chrome/browser/chromeos/input_method/input_method_util.h +++ b/chrome/browser/chromeos/input_method/input_method_util.h @@ -164,6 +164,10 @@ InputMethodDescriptor GetHardwareInputMethodDescriptor(); // as the fallback, when there is no other choice. InputMethodDescriptor GetFallbackInputMethodDescriptor(); +// This function should be called when Chrome's application locale is +// changed, so that the internal maps of this library is reloaded. +void OnLocaleChanged(); + // DO NOT USE Functions below. These are only exported for unit tests. void SortInputMethodIdsByNamesInternal( const std::map<std::string, std::string>& id_to_language_code_map, @@ -175,7 +179,7 @@ bool GetInputMethodIdsFromLanguageCodeInternal( InputMethodType type, std::vector<std::string>* out_input_method_ids); -void OnLocaleChanged(); +void ReloadInternalMaps(); } // namespace input_method } // namespace chromeos diff --git a/chrome/browser/chromeos/input_method/input_method_util_unittest.cc b/chrome/browser/chromeos/input_method/input_method_util_unittest.cc index 6cad62e..0a4d7be 100644 --- a/chrome/browser/chromeos/input_method/input_method_util_unittest.cc +++ b/chrome/browser/chromeos/input_method/input_method_util_unittest.cc @@ -15,7 +15,21 @@ namespace chromeos { namespace input_method { -TEST(InputMethodUtilTest, GetStringUTF8) { +class InputMethodUtilTest : public testing::Test { + public: + static void SetUpTestCase() { + // Reload the internal maps before running tests, with the stub + // libcros enabled, so that test data is loaded properly. + ScopedStubCrosEnabler stub_cros_enabler; + ReloadInternalMaps(); + } + + private: + // Ensure we always use the stub libcros in each test. + ScopedStubCrosEnabler stub_cros_enabler_; +}; + +TEST_F(InputMethodUtilTest, GetStringUTF8) { EXPECT_EQ("Pinyin input method", GetStringUTF8("Pinyin")); EXPECT_EQ("Japanese input method (for US Dvorak keyboard)", @@ -24,14 +38,14 @@ TEST(InputMethodUtilTest, GetStringUTF8) { GetStringUTF8("Google Japanese Input (US Dvorak keyboard layout)")); } -TEST(InputMethodUtilTest, StringIsSupported) { +TEST_F(InputMethodUtilTest, StringIsSupported) { EXPECT_TRUE(StringIsSupported("Hiragana")); EXPECT_TRUE(StringIsSupported("Latin")); EXPECT_TRUE(StringIsSupported("Direct input")); EXPECT_FALSE(StringIsSupported("####THIS_STRING_IS_NOT_SUPPORTED####")); } -TEST(InputMethodUtilTest, NormalizeLanguageCode) { +TEST_F(InputMethodUtilTest, NormalizeLanguageCode) { // TODO(yusukes): test all language codes that IBus provides. EXPECT_EQ("ja", NormalizeLanguageCode("ja")); EXPECT_EQ("ja", NormalizeLanguageCode("jpn")); @@ -54,12 +68,12 @@ TEST(InputMethodUtilTest, NormalizeLanguageCode) { EXPECT_EQ("sk", NormalizeLanguageCode("slo")); } -TEST(InputMethodUtilTest, IsKeyboardLayout) { +TEST_F(InputMethodUtilTest, IsKeyboardLayout) { EXPECT_TRUE(IsKeyboardLayout("xkb:us::eng")); EXPECT_FALSE(IsKeyboardLayout("anthy")); } -TEST(InputMethodUtilTest, GetLanguageCodeFromDescriptor) { +TEST_F(InputMethodUtilTest, GetLanguageCodeFromDescriptor) { EXPECT_EQ("ja", GetLanguageCodeFromDescriptor( InputMethodDescriptor("anthy", "Anthy", "us", "ja"))); EXPECT_EQ("zh-TW", GetLanguageCodeFromDescriptor( @@ -78,8 +92,7 @@ TEST(InputMethodUtilTest, GetLanguageCodeFromDescriptor) { InputMethodDescriptor("xkb:uk::eng", "United Kingdom", "us", "eng"))); } -TEST(InputMethodUtilTest, GetKeyboardLayoutName) { - ScopedStubCrosEnabler stub_cros_enabler; +TEST_F(InputMethodUtilTest, GetKeyboardLayoutName) { // Unsupported case. EXPECT_EQ("", GetKeyboardLayoutName("UNSUPPORTED_ID")); @@ -95,21 +108,19 @@ TEST(InputMethodUtilTest, GetKeyboardLayoutName) { EXPECT_EQ("us(colemak)", GetKeyboardLayoutName("xkb:us:colemak:eng")); } -TEST(InputMethodUtilTest, GetLanguageCodeFromInputMethodId) { - ScopedStubCrosEnabler stub_cros_enabler; +TEST_F(InputMethodUtilTest, GetLanguageCodeFromInputMethodId) { // Make sure that the -CN is added properly. EXPECT_EQ("zh-CN", GetLanguageCodeFromInputMethodId("pinyin")); } -TEST(InputMethodUtilTest, GetInputMethodDisplayNameFromId) { +TEST_F(InputMethodUtilTest, GetInputMethodDisplayNameFromId) { EXPECT_EQ("Pinyin input method", GetInputMethodDisplayNameFromId("pinyin")); EXPECT_EQ("English (United States)", GetInputMethodDisplayNameFromId("xkb:us::eng")); EXPECT_EQ("", GetInputMethodDisplayNameFromId("nonexistent")); } -TEST(InputMethodUtilTest, GetInputMethodDescriptorFromId) { - ScopedStubCrosEnabler stub_cros_enabler; +TEST_F(InputMethodUtilTest, GetInputMethodDescriptorFromId) { EXPECT_EQ(NULL, GetInputMethodDescriptorFromId("non_existent")); const InputMethodDescriptor* descriptor = @@ -124,11 +135,11 @@ TEST(InputMethodUtilTest, GetInputMethodDescriptorFromId) { EXPECT_EQ("zh", descriptor->language_code); } -TEST(InputMethodUtilTest, GetLanguageNativeDisplayNameFromCode) { +TEST_F(InputMethodUtilTest, GetLanguageNativeDisplayNameFromCode) { EXPECT_EQ(UTF8ToUTF16("suomi"), GetLanguageNativeDisplayNameFromCode("fi")); } -TEST(InputMethodUtilTest, SortLanguageCodesByNames) { +TEST_F(InputMethodUtilTest, SortLanguageCodesByNames) { std::vector<std::string> language_codes; // Check if this function can handle an empty list. SortLanguageCodesByNames(&language_codes); @@ -153,7 +164,7 @@ TEST(InputMethodUtilTest, SortLanguageCodesByNames) { ASSERT_EQ("t", language_codes[3]); // Others } -TEST(LanguageConfigModelTest, SortInputMethodIdsByNamesInternal) { +TEST_F(InputMethodUtilTest, SortInputMethodIdsByNamesInternal) { std::map<std::string, std::string> id_to_language_code_map; id_to_language_code_map.insert(std::make_pair("mozc", "ja")); id_to_language_code_map.insert(std::make_pair("mozc-jp", "ja")); @@ -193,7 +204,7 @@ TEST(LanguageConfigModelTest, SortInputMethodIdsByNamesInternal) { ASSERT_EQ("mozc-jp", input_method_ids[3]); // Japanese } -TEST(LanguageConfigModelTest, GetInputMethodIdsForLanguageCode) { +TEST_F(InputMethodUtilTest, GetInputMethodIdsForLanguageCode) { std::multimap<std::string, std::string> language_code_to_ids_map; language_code_to_ids_map.insert(std::make_pair("ja", "mozc")); language_code_to_ids_map.insert(std::make_pair("ja", "mozc-jp")); |