| 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 "ui/base/ime/chromeos/input_method_util.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 EXPECT_NE(medium_name, short_name); | 203 EXPECT_NE(medium_name, short_name); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 TEST_F(InputMethodUtilTest, GetInputMethodLongNameTest) { | 208 TEST_F(InputMethodUtilTest, GetInputMethodLongNameTest) { |
| 209 // For most languages input method or keyboard layout name is returned. | 209 // For most languages input method or keyboard layout name is returned. |
| 210 // See below for exceptions. | 210 // See below for exceptions. |
| 211 { | 211 { |
| 212 InputMethodDescriptor desc = GetDesc("xkb:jp::jpn", "jp", "ja", ""); | 212 InputMethodDescriptor desc = GetDesc("xkb:jp::jpn", "jp", "ja", ""); |
| 213 EXPECT_EQ(ASCIIToUTF16("Japanese"), | 213 EXPECT_EQ(ASCIIToUTF16("Japanese"), util_.GetInputMethodLongName(desc)); |
| 214 util_.GetInputMethodLongName(desc)); | |
| 215 } | 214 } |
| 216 { | 215 { |
| 217 InputMethodDescriptor desc = | 216 InputMethodDescriptor desc = |
| 218 GetDesc("xkb:us:dvorak:eng", "us(dvorak)", "en-US", ""); | 217 GetDesc("xkb:us:dvorak:eng", "us(dvorak)", "en-US", ""); |
| 219 EXPECT_EQ(ASCIIToUTF16("US Dvorak"), | 218 EXPECT_EQ(ASCIIToUTF16("US Dvorak"), util_.GetInputMethodLongName(desc)); |
| 220 util_.GetInputMethodLongName(desc)); | |
| 221 } | 219 } |
| 222 { | 220 { |
| 223 InputMethodDescriptor desc = | 221 InputMethodDescriptor desc = |
| 224 GetDesc("xkb:gb:dvorak:eng", "gb(dvorak)", "en-US", ""); | 222 GetDesc("xkb:gb:dvorak:eng", "gb(dvorak)", "en-US", ""); |
| 225 EXPECT_EQ(ASCIIToUTF16("UK Dvorak"), | 223 EXPECT_EQ(ASCIIToUTF16("UK Dvorak"), util_.GetInputMethodLongName(desc)); |
| 226 util_.GetInputMethodLongName(desc)); | |
| 227 } | 224 } |
| 228 | 225 |
| 229 // For Dutch, French, German and Hindi, | 226 // For Dutch, French, German and Hindi, |
| 230 // "language - keyboard layout" pair is returned. | 227 // "language - keyboard layout" pair is returned. |
| 231 { | 228 { |
| 232 InputMethodDescriptor desc = GetDesc("xkb:be::nld", "be", "nl", ""); | 229 InputMethodDescriptor desc = GetDesc("xkb:be::nld", "be", "nl", ""); |
| 233 EXPECT_EQ(ASCIIToUTF16("Dutch - Belgian"), | 230 EXPECT_EQ(ASCIIToUTF16("Dutch - Belgian"), |
| 234 util_.GetInputMethodLongName(desc)); | 231 util_.GetInputMethodLongName(desc)); |
| 235 } | 232 } |
| 236 { | 233 { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 251 { | 248 { |
| 252 InputMethodDescriptor desc = GetDesc("xkb:be::ger", "be", "de", ""); | 249 InputMethodDescriptor desc = GetDesc("xkb:be::ger", "be", "de", ""); |
| 253 EXPECT_EQ(ASCIIToUTF16("German - Belgian"), | 250 EXPECT_EQ(ASCIIToUTF16("German - Belgian"), |
| 254 util_.GetInputMethodLongName(desc)); | 251 util_.GetInputMethodLongName(desc)); |
| 255 } | 252 } |
| 256 | 253 |
| 257 { | 254 { |
| 258 InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", ""); | 255 InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", ""); |
| 259 // You can safely ignore the "Resouce ID is not found for: invalid-id" | 256 // You can safely ignore the "Resouce ID is not found for: invalid-id" |
| 260 // error. | 257 // error. |
| 261 EXPECT_EQ(ASCIIToUTF16("invalid-id"), | 258 EXPECT_EQ(ASCIIToUTF16("invalid-id"), util_.GetInputMethodLongName(desc)); |
| 262 util_.GetInputMethodLongName(desc)); | |
| 263 } | 259 } |
| 264 } | 260 } |
| 265 | 261 |
| 266 TEST_F(InputMethodUtilTest, TestIsValidInputMethodId) { | 262 TEST_F(InputMethodUtilTest, TestIsValidInputMethodId) { |
| 267 EXPECT_TRUE(util_.IsValidInputMethodId(Id("xkb:us:colemak:eng"))); | 263 EXPECT_TRUE(util_.IsValidInputMethodId(Id("xkb:us:colemak:eng"))); |
| 268 EXPECT_TRUE(util_.IsValidInputMethodId(Id(pinyin_ime_id))); | 264 EXPECT_TRUE(util_.IsValidInputMethodId(Id(pinyin_ime_id))); |
| 269 EXPECT_FALSE(util_.IsValidInputMethodId("unsupported-input-method")); | 265 EXPECT_FALSE(util_.IsValidInputMethodId("unsupported-input-method")); |
| 270 } | 266 } |
| 271 | 267 |
| 272 TEST_F(InputMethodUtilTest, TestIsKeyboardLayout) { | 268 TEST_F(InputMethodUtilTest, TestIsKeyboardLayout) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 284 EXPECT_EQ("es(cat)", util_.GetKeyboardLayoutName(Id("xkb:es:cat:cat"))); | 280 EXPECT_EQ("es(cat)", util_.GetKeyboardLayoutName(Id("xkb:es:cat:cat"))); |
| 285 EXPECT_EQ("gb(extd)", util_.GetKeyboardLayoutName(Id("xkb:gb:extd:eng"))); | 281 EXPECT_EQ("gb(extd)", util_.GetKeyboardLayoutName(Id("xkb:gb:extd:eng"))); |
| 286 EXPECT_EQ("us", util_.GetKeyboardLayoutName(Id("xkb:us::eng"))); | 282 EXPECT_EQ("us", util_.GetKeyboardLayoutName(Id("xkb:us::eng"))); |
| 287 EXPECT_EQ("us(dvorak)", util_.GetKeyboardLayoutName(Id("xkb:us:dvorak:eng"))); | 283 EXPECT_EQ("us(dvorak)", util_.GetKeyboardLayoutName(Id("xkb:us:dvorak:eng"))); |
| 288 EXPECT_EQ("us(colemak)", | 284 EXPECT_EQ("us(colemak)", |
| 289 util_.GetKeyboardLayoutName(Id("xkb:us:colemak:eng"))); | 285 util_.GetKeyboardLayoutName(Id("xkb:us:colemak:eng"))); |
| 290 EXPECT_EQ("de(neo)", util_.GetKeyboardLayoutName(Id("xkb:de:neo:ger"))); | 286 EXPECT_EQ("de(neo)", util_.GetKeyboardLayoutName(Id("xkb:de:neo:ger"))); |
| 291 } | 287 } |
| 292 | 288 |
| 293 TEST_F(InputMethodUtilTest, TestGetInputMethodDisplayNameFromId) { | 289 TEST_F(InputMethodUtilTest, TestGetInputMethodDisplayNameFromId) { |
| 294 EXPECT_EQ("US", | 290 EXPECT_EQ("US", util_.GetInputMethodDisplayNameFromId("xkb:us::eng")); |
| 295 util_.GetInputMethodDisplayNameFromId("xkb:us::eng")); | |
| 296 EXPECT_EQ("", util_.GetInputMethodDisplayNameFromId("nonexistent")); | 291 EXPECT_EQ("", util_.GetInputMethodDisplayNameFromId("nonexistent")); |
| 297 } | 292 } |
| 298 | 293 |
| 299 TEST_F(InputMethodUtilTest, TestGetInputMethodDescriptorFromId) { | 294 TEST_F(InputMethodUtilTest, TestGetInputMethodDescriptorFromId) { |
| 300 EXPECT_EQ(NULL, util_.GetInputMethodDescriptorFromId("non_existent")); | 295 EXPECT_EQ(NULL, util_.GetInputMethodDescriptorFromId("non_existent")); |
| 301 | 296 |
| 302 const InputMethodDescriptor* descriptor = | 297 const InputMethodDescriptor* descriptor = |
| 303 util_.GetInputMethodDescriptorFromId(Id(pinyin_ime_id)); | 298 util_.GetInputMethodDescriptorFromId(Id(pinyin_ime_id)); |
| 304 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. | 299 ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. |
| 305 EXPECT_EQ(Id(pinyin_ime_id), descriptor->id()); | 300 EXPECT_EQ(Id(pinyin_ime_id), descriptor->id()); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 TEST_F(InputMethodUtilTest, TestHardwareInputMethodIDs) { | 514 TEST_F(InputMethodUtilTest, TestHardwareInputMethodIDs) { |
| 520 util_.SetHardwareKeyboardLayoutForTesting("xkb:ru::rus"); | 515 util_.SetHardwareKeyboardLayoutForTesting("xkb:ru::rus"); |
| 521 std::vector<std::string> input_method_ids = util_.GetHardwareInputMethodIds(); | 516 std::vector<std::string> input_method_ids = util_.GetHardwareInputMethodIds(); |
| 522 std::vector<std::string> login_input_method_ids = | 517 std::vector<std::string> login_input_method_ids = |
| 523 util_.GetHardwareLoginInputMethodIds(); | 518 util_.GetHardwareLoginInputMethodIds(); |
| 524 | 519 |
| 525 EXPECT_EQ(2U, input_method_ids.size()); | 520 EXPECT_EQ(2U, input_method_ids.size()); |
| 526 EXPECT_EQ(1U, login_input_method_ids.size()); | 521 EXPECT_EQ(1U, login_input_method_ids.size()); |
| 527 | 522 |
| 528 EXPECT_EQ("xkb:us::eng", extension_ime_util::GetComponentIDByInputMethodID( | 523 EXPECT_EQ("xkb:us::eng", extension_ime_util::GetComponentIDByInputMethodID( |
| 529 input_method_ids[0])); | 524 input_method_ids[0])); |
| 530 EXPECT_EQ("xkb:ru::rus", extension_ime_util::GetComponentIDByInputMethodID( | 525 EXPECT_EQ("xkb:ru::rus", extension_ime_util::GetComponentIDByInputMethodID( |
| 531 input_method_ids[1])); | 526 input_method_ids[1])); |
| 532 EXPECT_EQ("xkb:us::eng", extension_ime_util::GetComponentIDByInputMethodID( | 527 EXPECT_EQ("xkb:us::eng", extension_ime_util::GetComponentIDByInputMethodID( |
| 533 login_input_method_ids[0])); | 528 login_input_method_ids[0])); |
| 534 } | 529 } |
| 535 | 530 |
| 536 } // namespace input_method | 531 } // namespace input_method |
| 537 } // namespace chromeos | 532 } // namespace chromeos |
| OLD | NEW |