| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/status/input_method_menu.h" | |
| 6 | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "chrome/browser/chromeos/input_method/ibus_controller.h" | |
| 10 #include "chrome/test/base/testing_browser_process.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 namespace chromeos { | |
| 14 | |
| 15 using input_method::IBusController; | |
| 16 using input_method::InputMethodDescriptor; | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 InputMethodDescriptor GetDesc(IBusController* controller, | |
| 21 const std::string& id, | |
| 22 const std::string& raw_layout, | |
| 23 const std::string& language_code) { | |
| 24 return controller->CreateInputMethodDescriptor(id, "", raw_layout, | |
| 25 language_code); | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 // Test whether the function returns language name for non-ambiguous languages. | |
| 31 TEST(InputMethodMenuTest, GetTextForMenuTest) { | |
| 32 scoped_ptr<IBusController> controller(IBusController::Create()); | |
| 33 | |
| 34 // For most languages input method or keyboard layout name is returned. | |
| 35 // See below for exceptions. | |
| 36 { | |
| 37 InputMethodDescriptor desc = | |
| 38 GetDesc(controller.get(), "m17n:fa:isiri", "us", "fa"); | |
| 39 EXPECT_EQ(ASCIIToUTF16("Persian input method (ISIRI 2901 layout)"), | |
| 40 InputMethodMenu::GetTextForMenu(desc)); | |
| 41 } | |
| 42 { | |
| 43 InputMethodDescriptor desc = | |
| 44 GetDesc(controller.get(), "mozc-hangul", "us", "ko"); | |
| 45 EXPECT_EQ(ASCIIToUTF16("Korean input method"), | |
| 46 InputMethodMenu::GetTextForMenu(desc)); | |
| 47 } | |
| 48 { | |
| 49 InputMethodDescriptor desc = | |
| 50 GetDesc(controller.get(), "m17n:vi:tcvn", "us", "vi"); | |
| 51 EXPECT_EQ(ASCIIToUTF16("Vietnamese input method (TCVN6064)"), | |
| 52 InputMethodMenu::GetTextForMenu(desc)); | |
| 53 } | |
| 54 { | |
| 55 InputMethodDescriptor desc = GetDesc(controller.get(), "mozc", "us", "ja"); | |
| 56 #if !defined(GOOGLE_CHROME_BUILD) | |
| 57 EXPECT_EQ(ASCIIToUTF16("Japanese input method (for US keyboard)"), | |
| 58 #else | |
| 59 EXPECT_EQ(ASCIIToUTF16("Google Japanese Input (for US keyboard)"), | |
| 60 #endif // defined(GOOGLE_CHROME_BUILD) | |
| 61 InputMethodMenu::GetTextForMenu(desc)); | |
| 62 } | |
| 63 { | |
| 64 InputMethodDescriptor desc = | |
| 65 GetDesc(controller.get(), "xkb:jp::jpn", "jp", "ja"); | |
| 66 EXPECT_EQ(ASCIIToUTF16("Japanese keyboard"), | |
| 67 InputMethodMenu::GetTextForMenu(desc)); | |
| 68 } | |
| 69 { | |
| 70 InputMethodDescriptor desc = | |
| 71 GetDesc(controller.get(), "xkb:us:dvorak:eng", "us(dvorak)", "en-US"); | |
| 72 EXPECT_EQ(ASCIIToUTF16("US Dvorak keyboard"), | |
| 73 InputMethodMenu::GetTextForMenu(desc)); | |
| 74 } | |
| 75 { | |
| 76 InputMethodDescriptor desc = | |
| 77 GetDesc(controller.get(), "xkb:gb:dvorak:eng", "gb(dvorak)", "en-US"); | |
| 78 EXPECT_EQ(ASCIIToUTF16("UK Dvorak keyboard"), | |
| 79 InputMethodMenu::GetTextForMenu(desc)); | |
| 80 } | |
| 81 | |
| 82 // For Arabic, Dutch, French, German and Hindi, | |
| 83 // "language - keyboard layout" pair is returned. | |
| 84 { | |
| 85 InputMethodDescriptor desc = | |
| 86 GetDesc(controller.get(), "m17n:ar:kbd", "us", "ar"); | |
| 87 EXPECT_EQ(ASCIIToUTF16("Arabic - Standard input method"), | |
| 88 InputMethodMenu::GetTextForMenu(desc)); | |
| 89 } | |
| 90 { | |
| 91 InputMethodDescriptor desc = | |
| 92 GetDesc(controller.get(), "xkb:be::nld", "be", "nl"); | |
| 93 EXPECT_EQ(ASCIIToUTF16("Dutch - Belgian keyboard"), | |
| 94 InputMethodMenu::GetTextForMenu(desc)); | |
| 95 } | |
| 96 { | |
| 97 InputMethodDescriptor desc = | |
| 98 GetDesc(controller.get(), "xkb:fr::fra", "fr", "fr"); | |
| 99 EXPECT_EQ(ASCIIToUTF16("French - French keyboard"), | |
| 100 InputMethodMenu::GetTextForMenu(desc)); | |
| 101 } | |
| 102 { | |
| 103 InputMethodDescriptor desc = | |
| 104 GetDesc(controller.get(), "xkb:be::fra", "be", "fr"); | |
| 105 EXPECT_EQ(ASCIIToUTF16("French - Belgian keyboard"), | |
| 106 InputMethodMenu::GetTextForMenu(desc)); | |
| 107 } | |
| 108 { | |
| 109 InputMethodDescriptor desc = | |
| 110 GetDesc(controller.get(), "xkb:de::ger", "de", "de"); | |
| 111 EXPECT_EQ(ASCIIToUTF16("German - German keyboard"), | |
| 112 InputMethodMenu::GetTextForMenu(desc)); | |
| 113 } | |
| 114 { | |
| 115 InputMethodDescriptor desc = | |
| 116 GetDesc(controller.get(), "xkb:be::ger", "be", "de"); | |
| 117 EXPECT_EQ(ASCIIToUTF16("German - Belgian keyboard"), | |
| 118 InputMethodMenu::GetTextForMenu(desc)); | |
| 119 } | |
| 120 { | |
| 121 InputMethodDescriptor desc = | |
| 122 GetDesc(controller.get(), "m17n:hi:itrans", "us", "hi"); | |
| 123 EXPECT_EQ(ASCIIToUTF16("Hindi - Standard input method"), | |
| 124 InputMethodMenu::GetTextForMenu(desc)); | |
| 125 } | |
| 126 | |
| 127 { | |
| 128 InputMethodDescriptor desc = | |
| 129 GetDesc(controller.get(), "invalid-id", "us", "xx"); | |
| 130 // You can safely ignore the "Resouce ID is not found for: invalid-id" | |
| 131 // error. | |
| 132 EXPECT_EQ(ASCIIToUTF16("invalid-id"), | |
| 133 InputMethodMenu::GetTextForMenu(desc)); | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 } // namespace chromeos | |
| OLD | NEW |