| 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/bind.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 : util_(&delegate_, whitelist_.GetSupportedInputMethods()) { | 45 : util_(&delegate_, whitelist_.GetSupportedInputMethods()) { |
| 46 delegate_.set_get_localized_string_callback( | 46 delegate_.set_get_localized_string_callback( |
| 47 base::Bind(&l10n_util::GetStringUTF16)); | 47 base::Bind(&l10n_util::GetStringUTF16)); |
| 48 delegate_.set_get_display_language_name_callback( | 48 delegate_.set_get_display_language_name_callback( |
| 49 base::Bind(&InputMethodUtilTest::GetDisplayLanguageName)); | 49 base::Bind(&InputMethodUtilTest::GetDisplayLanguageName)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 InputMethodDescriptor GetDesc(const std::string& id, | 52 InputMethodDescriptor GetDesc(const std::string& id, |
| 53 const std::string& raw_layout, | 53 const std::string& raw_layout, |
| 54 const std::string& language_code) { | 54 const std::string& language_code) { |
| 55 std::vector<std::string> layouts; |
| 56 layouts.push_back(raw_layout); |
| 55 return InputMethodDescriptor(id, | 57 return InputMethodDescriptor(id, |
| 56 "", | 58 "", |
| 57 raw_layout, | 59 layouts, |
| 58 language_code, | 60 language_code, |
| 59 ""); // options page url | 61 ""); // options page url |
| 60 } | 62 } |
| 61 | 63 |
| 62 static string16 GetDisplayLanguageName(const std::string& language_code) { | 64 static string16 GetDisplayLanguageName(const std::string& language_code) { |
| 63 return l10n_util::GetDisplayNameForLocale(language_code, "en", true); | 65 return l10n_util::GetDisplayNameForLocale(language_code, "en", true); |
| 64 } | 66 } |
| 65 | 67 |
| 66 FakeInputMethodDelegate delegate_; | 68 FakeInputMethodDelegate delegate_; |
| 67 InputMethodWhitelist whitelist_; | 69 InputMethodWhitelist whitelist_; |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 EXPECT_EQ("", util_.GetInputMethodDisplayNameFromId("nonexistent")); | 339 EXPECT_EQ("", util_.GetInputMethodDisplayNameFromId("nonexistent")); |
| 338 } | 340 } |
| 339 | 341 |
| 340 TEST_F(InputMethodUtilTest, TestGetInputMethodDescriptorFromId) { | 342 TEST_F(InputMethodUtilTest, TestGetInputMethodDescriptorFromId) { |
| 341 EXPECT_EQ(NULL, util_.GetInputMethodDescriptorFromId("non_existent")); | 343 EXPECT_EQ(NULL, util_.GetInputMethodDescriptorFromId("non_existent")); |
| 342 | 344 |
| 343 const InputMethodDescriptor* descriptor = | 345 const InputMethodDescriptor* descriptor = |
| 344 util_.GetInputMethodDescriptorFromId("pinyin"); | 346 util_.GetInputMethodDescriptorFromId("pinyin"); |
| 345 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. | 347 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. |
| 346 EXPECT_EQ("pinyin", descriptor->id()); | 348 EXPECT_EQ("pinyin", descriptor->id()); |
| 347 EXPECT_EQ("us", descriptor->keyboard_layout()); | 349 EXPECT_EQ("us", descriptor->GetPreferredKeyboardLayout()); |
| 348 // This used to be "zh" but now we have "zh-CN" in input_methods.h, | 350 // This used to be "zh" but now we have "zh-CN" in input_methods.h, |
| 349 // hence this should be zh-CN now. | 351 // hence this should be zh-CN now. |
| 350 EXPECT_EQ("zh-CN", descriptor->language_code()); | 352 EXPECT_EQ("zh-CN", descriptor->language_code()); |
| 351 } | 353 } |
| 352 | 354 |
| 353 TEST_F(InputMethodUtilTest, TestGetInputMethodIdsForLanguageCode) { | 355 TEST_F(InputMethodUtilTest, TestGetInputMethodIdsForLanguageCode) { |
| 354 std::multimap<std::string, std::string> language_code_to_ids_map; | 356 std::multimap<std::string, std::string> language_code_to_ids_map; |
| 355 language_code_to_ids_map.insert(std::make_pair("ja", "mozc")); | 357 language_code_to_ids_map.insert(std::make_pair("ja", "mozc")); |
| 356 language_code_to_ids_map.insert(std::make_pair("ja", "mozc-jp")); | 358 language_code_to_ids_map.insert(std::make_pair("ja", "mozc-jp")); |
| 357 language_code_to_ids_map.insert(std::make_pair("ja", "xkb:jp:jpn")); | 359 language_code_to_ids_map.insert(std::make_pair("ja", "xkb:jp:jpn")); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 EXPECT_FALSE(display_name.empty()) | 510 EXPECT_FALSE(display_name.empty()) |
| 509 << "Invalid language code " << language_code; | 511 << "Invalid language code " << language_code; |
| 510 // On error, GetDisplayNameForLocale() returns the |language_code| as-is. | 512 // On error, GetDisplayNameForLocale() returns the |language_code| as-is. |
| 511 EXPECT_NE(language_code, UTF16ToUTF8(display_name)) | 513 EXPECT_NE(language_code, UTF16ToUTF8(display_name)) |
| 512 << "Invalid language code " << language_code; | 514 << "Invalid language code " << language_code; |
| 513 } | 515 } |
| 514 } | 516 } |
| 515 | 517 |
| 516 } // namespace input_method | 518 } // namespace input_method |
| 517 } // namespace chromeos | 519 } // namespace chromeos |
| OLD | NEW |