| 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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| 11 #include "chrome/browser/chromeos/input_method/input_method_whitelist.h" | 12 #include "chrome/browser/chromeos/input_method/input_method_whitelist.h" |
| 12 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 15 | 16 |
| 16 #if defined(USE_VIRTUAL_KEYBOARD) | 17 #if defined(USE_VIRTUAL_KEYBOARD) |
| 17 // Since USE_VIRTUAL_KEYBOARD build only supports a few keyboard layouts, we | 18 // Since USE_VIRTUAL_KEYBOARD build only supports a few keyboard layouts, we |
| 18 // skip the tests for now. | 19 // skip the tests for now. |
| 19 #define TestGetFirstLoginInputMethodIds_Dvorak_And_Ja \ | 20 #define TestGetFirstLoginInputMethodIds_Dvorak_And_Ja \ |
| 20 DISABLED_TestGetFirstLoginInputMethodIds_Dvorak_And_Ja | 21 DISABLED_TestGetFirstLoginInputMethodIds_Dvorak_And_Ja |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 util_.GetInputMethodShortName(desc)); | 167 util_.GetInputMethodShortName(desc)); |
| 167 } | 168 } |
| 168 { | 169 { |
| 169 InputMethodDescriptor desc = | 170 InputMethodDescriptor desc = |
| 170 GetDesc(controller.get(), "m17n:zh:quick", "us", "zh-TW"); | 171 GetDesc(controller.get(), "m17n:zh:quick", "us", "zh-TW"); |
| 171 EXPECT_EQ(UTF8ToUTF16("\xe9\x80\x9f"), | 172 EXPECT_EQ(UTF8ToUTF16("\xe9\x80\x9f"), |
| 172 util_.GetInputMethodShortName(desc)); | 173 util_.GetInputMethodShortName(desc)); |
| 173 } | 174 } |
| 174 } | 175 } |
| 175 | 176 |
| 177 TEST_F(InputMethodUtilTest, GetInputMethodLongNameTest) { |
| 178 scoped_ptr<IBusController> controller(IBusController::Create()); |
| 179 |
| 180 // For most languages input method or keyboard layout name is returned. |
| 181 // See below for exceptions. |
| 182 { |
| 183 InputMethodDescriptor desc = |
| 184 GetDesc(controller.get(), "m17n:fa:isiri", "us", "fa"); |
| 185 EXPECT_EQ(ASCIIToUTF16("Persian input method (ISIRI 2901 layout)"), |
| 186 util_.GetInputMethodLongName(desc)); |
| 187 } |
| 188 { |
| 189 InputMethodDescriptor desc = |
| 190 GetDesc(controller.get(), "mozc-hangul", "us", "ko"); |
| 191 EXPECT_EQ(ASCIIToUTF16("Korean input method"), |
| 192 util_.GetInputMethodLongName(desc)); |
| 193 } |
| 194 { |
| 195 InputMethodDescriptor desc = |
| 196 GetDesc(controller.get(), "m17n:vi:tcvn", "us", "vi"); |
| 197 EXPECT_EQ(ASCIIToUTF16("Vietnamese input method (TCVN6064)"), |
| 198 util_.GetInputMethodLongName(desc)); |
| 199 } |
| 200 { |
| 201 InputMethodDescriptor desc = GetDesc(controller.get(), "mozc", "us", "ja"); |
| 202 #if !defined(GOOGLE_CHROME_BUILD) |
| 203 EXPECT_EQ(ASCIIToUTF16("Japanese input method (for US keyboard)"), |
| 204 #else |
| 205 EXPECT_EQ(ASCIIToUTF16("Google Japanese Input (for US keyboard)"), |
| 206 #endif // defined(GOOGLE_CHROME_BUILD) |
| 207 util_.GetInputMethodLongName(desc)); |
| 208 } |
| 209 { |
| 210 InputMethodDescriptor desc = |
| 211 GetDesc(controller.get(), "xkb:jp::jpn", "jp", "ja"); |
| 212 EXPECT_EQ(ASCIIToUTF16("Japanese keyboard"), |
| 213 util_.GetInputMethodLongName(desc)); |
| 214 } |
| 215 { |
| 216 InputMethodDescriptor desc = |
| 217 GetDesc(controller.get(), "xkb:us:dvorak:eng", "us(dvorak)", "en-US"); |
| 218 EXPECT_EQ(ASCIIToUTF16("US Dvorak keyboard"), |
| 219 util_.GetInputMethodLongName(desc)); |
| 220 } |
| 221 { |
| 222 InputMethodDescriptor desc = |
| 223 GetDesc(controller.get(), "xkb:gb:dvorak:eng", "gb(dvorak)", "en-US"); |
| 224 EXPECT_EQ(ASCIIToUTF16("UK Dvorak keyboard"), |
| 225 util_.GetInputMethodLongName(desc)); |
| 226 } |
| 227 |
| 228 // For Arabic, Dutch, French, German and Hindi, |
| 229 // "language - keyboard layout" pair is returned. |
| 230 { |
| 231 InputMethodDescriptor desc = |
| 232 GetDesc(controller.get(), "m17n:ar:kbd", "us", "ar"); |
| 233 EXPECT_EQ(ASCIIToUTF16("Arabic - Standard input method"), |
| 234 util_.GetInputMethodLongName(desc)); |
| 235 } |
| 236 { |
| 237 InputMethodDescriptor desc = |
| 238 GetDesc(controller.get(), "xkb:be::nld", "be", "nl"); |
| 239 EXPECT_EQ(ASCIIToUTF16("Dutch - Belgian keyboard"), |
| 240 util_.GetInputMethodLongName(desc)); |
| 241 } |
| 242 { |
| 243 InputMethodDescriptor desc = |
| 244 GetDesc(controller.get(), "xkb:fr::fra", "fr", "fr"); |
| 245 EXPECT_EQ(ASCIIToUTF16("French - French keyboard"), |
| 246 util_.GetInputMethodLongName(desc)); |
| 247 } |
| 248 { |
| 249 InputMethodDescriptor desc = |
| 250 GetDesc(controller.get(), "xkb:be::fra", "be", "fr"); |
| 251 EXPECT_EQ(ASCIIToUTF16("French - Belgian keyboard"), |
| 252 util_.GetInputMethodLongName(desc)); |
| 253 } |
| 254 { |
| 255 InputMethodDescriptor desc = |
| 256 GetDesc(controller.get(), "xkb:de::ger", "de", "de"); |
| 257 EXPECT_EQ(ASCIIToUTF16("German - German keyboard"), |
| 258 util_.GetInputMethodLongName(desc)); |
| 259 } |
| 260 { |
| 261 InputMethodDescriptor desc = |
| 262 GetDesc(controller.get(), "xkb:be::ger", "be", "de"); |
| 263 EXPECT_EQ(ASCIIToUTF16("German - Belgian keyboard"), |
| 264 util_.GetInputMethodLongName(desc)); |
| 265 } |
| 266 { |
| 267 InputMethodDescriptor desc = |
| 268 GetDesc(controller.get(), "m17n:hi:itrans", "us", "hi"); |
| 269 EXPECT_EQ(ASCIIToUTF16("Hindi - Standard input method"), |
| 270 util_.GetInputMethodLongName(desc)); |
| 271 } |
| 272 |
| 273 { |
| 274 InputMethodDescriptor desc = |
| 275 GetDesc(controller.get(), "invalid-id", "us", "xx"); |
| 276 // You can safely ignore the "Resouce ID is not found for: invalid-id" |
| 277 // error. |
| 278 EXPECT_EQ(ASCIIToUTF16("invalid-id"), |
| 279 util_.GetInputMethodLongName(desc)); |
| 280 } |
| 281 } |
| 282 |
| 176 TEST_F(InputMethodUtilTest, TestGetStringUTF8) { | 283 TEST_F(InputMethodUtilTest, TestGetStringUTF8) { |
| 177 EXPECT_EQ(UTF8ToUTF16("Pinyin input method"), | 284 EXPECT_EQ(UTF8ToUTF16("Pinyin input method"), |
| 178 util_.TranslateString("pinyin")); | 285 util_.TranslateString("pinyin")); |
| 179 #if !defined(GOOGLE_CHROME_BUILD) | 286 #if !defined(GOOGLE_CHROME_BUILD) |
| 180 EXPECT_EQ(UTF8ToUTF16("Japanese input method (for US Dvorak keyboard)"), | 287 EXPECT_EQ(UTF8ToUTF16("Japanese input method (for US Dvorak keyboard)"), |
| 181 util_.TranslateString("mozc-dv")); | 288 util_.TranslateString("mozc-dv")); |
| 182 #endif | 289 #endif |
| 183 } | 290 } |
| 184 | 291 |
| 185 TEST_F(InputMethodUtilTest, TestStringIsSupported) { | 292 TEST_F(InputMethodUtilTest, TestStringIsSupported) { |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 EXPECT_FALSE(display_name.empty()) | 560 EXPECT_FALSE(display_name.empty()) |
| 454 << "Invalid language code " << language_code; | 561 << "Invalid language code " << language_code; |
| 455 // On error, GetDisplayNameForLocale() returns the |language_code| as-is. | 562 // On error, GetDisplayNameForLocale() returns the |language_code| as-is. |
| 456 EXPECT_NE(language_code, UTF16ToUTF8(display_name)) | 563 EXPECT_NE(language_code, UTF16ToUTF8(display_name)) |
| 457 << "Invalid language code " << language_code; | 564 << "Invalid language code " << language_code; |
| 458 } | 565 } |
| 459 } | 566 } |
| 460 | 567 |
| 461 } // namespace input_method | 568 } // namespace input_method |
| 462 } // namespace chromeos | 569 } // namespace chromeos |
| OLD | NEW |