OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium OS 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 // How to run the test: |
| 6 // $ FEATURES="test" emerge-x86-generic -a libcros |
| 7 |
| 8 #include "chromeos_input_method.h" |
| 9 |
| 10 #include <gtest/gtest.h> |
| 11 |
| 12 #include "base/logging.h" |
| 13 |
| 14 namespace chromeos { |
| 15 namespace { |
| 16 InputMethodDescriptor GetDesc(const std::string& raw_layout) { |
| 17 return CreateInputMethodDescriptor( |
| 18 "id", "display_name", raw_layout, "language_code"); |
| 19 } |
| 20 } // namespace |
| 21 |
| 22 // Tests InputMethodIdIsWhitelisted function. |
| 23 TEST(ChromeOSInputMethodTest, TestInputMethodIdIsWhitelisted) { |
| 24 EXPECT_TRUE(InputMethodIdIsWhitelisted("mozc")); |
| 25 EXPECT_TRUE(InputMethodIdIsWhitelisted("xkb:us:dvorak:eng")); |
| 26 EXPECT_FALSE(InputMethodIdIsWhitelisted("mozc,")); |
| 27 EXPECT_FALSE(InputMethodIdIsWhitelisted("mozc,xkb:us:dvorak:eng")); |
| 28 EXPECT_FALSE(InputMethodIdIsWhitelisted("not-supported-id")); |
| 29 EXPECT_FALSE(InputMethodIdIsWhitelisted(",")); |
| 30 EXPECT_FALSE(InputMethodIdIsWhitelisted("")); |
| 31 } |
| 32 |
| 33 // Tests XkbLayoutIsSupported function. |
| 34 TEST(ChromeOSInputMethodTest, TestXkbLayoutIsSupported) { |
| 35 EXPECT_TRUE(XkbLayoutIsSupported("us")); |
| 36 EXPECT_TRUE(XkbLayoutIsSupported("us(dvorak)")); |
| 37 EXPECT_TRUE(XkbLayoutIsSupported("fr")); |
| 38 EXPECT_FALSE(XkbLayoutIsSupported("us,")); |
| 39 EXPECT_FALSE(XkbLayoutIsSupported("us,fr")); |
| 40 EXPECT_FALSE(XkbLayoutIsSupported("xkb:us:dvorak:eng")); |
| 41 EXPECT_FALSE(XkbLayoutIsSupported("mozc")); |
| 42 EXPECT_FALSE(XkbLayoutIsSupported(",")); |
| 43 EXPECT_FALSE(XkbLayoutIsSupported("")); |
| 44 } |
| 45 |
| 46 // Tests CreateInputMethodDescriptor function. |
| 47 TEST(ChromeOSInputMethodTest, TestCreateInputMethodDescriptor) { |
| 48 EXPECT_EQ(GetDesc("us").keyboard_layout, "us"); |
| 49 EXPECT_EQ(GetDesc("us,us(dvorak)").keyboard_layout, "us"); |
| 50 EXPECT_EQ(GetDesc("us(dvorak),us").keyboard_layout, "us(dvorak)"); |
| 51 |
| 52 EXPECT_EQ(GetDesc("fr").keyboard_layout, "fr"); |
| 53 EXPECT_EQ(GetDesc("fr,us(dvorak)").keyboard_layout, "fr"); |
| 54 EXPECT_EQ(GetDesc("us(dvorak),fr").keyboard_layout, "us(dvorak)"); |
| 55 |
| 56 EXPECT_EQ(GetDesc("not-supported,fr").keyboard_layout, "fr"); |
| 57 EXPECT_EQ(GetDesc("fr,not-supported").keyboard_layout, "fr"); |
| 58 |
| 59 static const char kFallbackLayout[] = "us"; |
| 60 EXPECT_EQ(GetDesc("not-supported").keyboard_layout, kFallbackLayout); |
| 61 EXPECT_EQ(GetDesc(",").keyboard_layout, kFallbackLayout); |
| 62 EXPECT_EQ(GetDesc("").keyboard_layout, kFallbackLayout); |
| 63 |
| 64 // TODO(yusukes): Add tests for |virtual_keyboard_layout| member. |
| 65 } |
| 66 |
| 67 } |
OLD | NEW |