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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 InputMethodDescriptor zhuyin_ime(zhuyin_ime_id, | 86 InputMethodDescriptor zhuyin_ime(zhuyin_ime_id, |
87 "Zhuyin input for testing", | 87 "Zhuyin input for testing", |
88 "TW", | 88 "TW", |
89 layouts, | 89 layouts, |
90 languages, | 90 languages, |
91 false, | 91 false, |
92 GURL(""), | 92 GURL(""), |
93 GURL("")); | 93 GURL("")); |
94 input_methods.push_back(zhuyin_ime); | 94 input_methods.push_back(zhuyin_ime); |
95 | 95 |
96 util_.SetComponentExtensions(input_methods); | 96 util_.InitXkbInputMethodsForTesting(); |
| 97 util_.AppendInputMethods(input_methods); |
97 } | 98 } |
98 | 99 |
99 std::string Id(const std::string& id) { | 100 std::string Id(const std::string& id) { |
100 return extension_ime_util::GetInputMethodIDByKeyboardLayout(id); | 101 return extension_ime_util::GetInputMethodIDByKeyboardLayout(id); |
101 } | 102 } |
102 | 103 |
103 InputMethodDescriptor GetDesc(const std::string& id, | 104 InputMethodDescriptor GetDesc(const std::string& id, |
104 const std::string& raw_layout, | 105 const std::string& raw_layout, |
105 const std::string& language_code, | 106 const std::string& language_code, |
106 const std::string& indicator) { | 107 const std::string& indicator) { |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 | 475 |
475 TEST_F(InputMethodUtilTest, TestGetLanguageCodesFromInputMethodIds) { | 476 TEST_F(InputMethodUtilTest, TestGetLanguageCodesFromInputMethodIds) { |
476 std::vector<std::string> input_method_ids; | 477 std::vector<std::string> input_method_ids; |
477 input_method_ids.push_back(Id("xkb:us::eng")); // English US. | 478 input_method_ids.push_back(Id("xkb:us::eng")); // English US. |
478 input_method_ids.push_back(Id("xkb:us:dvorak:eng")); // English US Dvorak. | 479 input_method_ids.push_back(Id("xkb:us:dvorak:eng")); // English US Dvorak. |
479 input_method_ids.push_back(pinyin_ime_id); // Pinyin | 480 input_method_ids.push_back(pinyin_ime_id); // Pinyin |
480 input_method_ids.push_back(Id("xkb:fr::fra")); // French France. | 481 input_method_ids.push_back(Id("xkb:fr::fra")); // French France. |
481 std::vector<std::string> language_codes; | 482 std::vector<std::string> language_codes; |
482 util_.GetLanguageCodesFromInputMethodIds(input_method_ids, &language_codes); | 483 util_.GetLanguageCodesFromInputMethodIds(input_method_ids, &language_codes); |
483 ASSERT_EQ(3U, language_codes.size()); | 484 ASSERT_EQ(3U, language_codes.size()); |
484 EXPECT_EQ("en-US", language_codes[0]); | 485 EXPECT_EQ("en", language_codes[0]); |
485 EXPECT_EQ("zh-CN", language_codes[1]); | 486 EXPECT_EQ("zh-CN", language_codes[1]); |
486 EXPECT_EQ("fr", language_codes[2]); | 487 EXPECT_EQ("fr", language_codes[2]); |
487 } | 488 } |
488 | 489 |
489 // Test all supported descriptors to detect a typo in input_methods.txt. | 490 // Test all supported descriptors to detect a typo in input_methods.txt. |
490 TEST_F(InputMethodUtilTest, TestIBusInputMethodText) { | 491 TEST_F(InputMethodUtilTest, TestIBusInputMethodText) { |
491 for (size_t i = 0; i < util_.supported_input_methods_->size(); ++i) { | 492 for (size_t i = 0; i < util_.supported_input_methods_->size(); ++i) { |
492 const std::string language_code = | 493 const std::string language_code = |
493 util_.supported_input_methods_->at(i).language_codes().at(0); | 494 util_.supported_input_methods_->at(i).language_codes().at(0); |
494 const base::string16 display_name = | 495 const base::string16 display_name = |
495 l10n_util::GetDisplayNameForLocale(language_code, "en", false); | 496 l10n_util::GetDisplayNameForLocale(language_code, "en", false); |
496 // Only two formats, like "fr" (lower case) and "en-US" (lower-upper), are | 497 // Only two formats, like "fr" (lower case) and "en-US" (lower-upper), are |
497 // allowed. See the text file for details. | 498 // allowed. See the text file for details. |
498 EXPECT_TRUE(language_code.length() == 2 || | 499 EXPECT_TRUE(language_code == "fil" || language_code.length() == 2 || |
499 (language_code.length() == 5 && language_code[2] == '-')) | 500 (language_code.length() == 5 && language_code[2] == '-')) |
500 << "Invalid language code " << language_code; | 501 << "Invalid language code " << language_code; |
501 EXPECT_TRUE(l10n_util::IsValidLocaleSyntax(language_code)) | 502 EXPECT_TRUE(l10n_util::IsValidLocaleSyntax(language_code)) |
502 << "Invalid language code " << language_code; | 503 << "Invalid language code " << language_code; |
503 EXPECT_FALSE(display_name.empty()) | 504 EXPECT_FALSE(display_name.empty()) |
504 << "Invalid language code " << language_code; | 505 << "Invalid language code " << language_code; |
505 // On error, GetDisplayNameForLocale() returns the |language_code| as-is. | 506 // On error, GetDisplayNameForLocale() returns the |language_code| as-is. |
506 EXPECT_NE(language_code, base::UTF16ToUTF8(display_name)) | 507 EXPECT_NE(language_code, base::UTF16ToUTF8(display_name)) |
507 << "Invalid language code " << language_code; | 508 << "Invalid language code " << language_code; |
508 } | 509 } |
509 } | 510 } |
510 | 511 |
511 } // namespace input_method | 512 } // namespace input_method |
512 } // namespace chromeos | 513 } // namespace chromeos |
OLD | NEW |