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_manager_impl.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "chrome/browser/chromeos/input_method/input_method_engine_interface.h" |
16 #include "chrome/browser/chromeos/input_method/mock_candidate_window_controller.
h" | 17 #include "chrome/browser/chromeos/input_method/mock_candidate_window_controller.
h" |
| 18 #include "chrome/browser/chromeos/input_method/mock_input_method_engine.h" |
17 #include "chromeos/ime/extension_ime_util.h" | 19 #include "chromeos/ime/extension_ime_util.h" |
18 #include "chromeos/ime/fake_input_method_delegate.h" | 20 #include "chromeos/ime/fake_input_method_delegate.h" |
19 #include "chromeos/ime/mock_component_extension_ime_manager_delegate.h" | 21 #include "chromeos/ime/mock_component_extension_ime_manager_delegate.h" |
20 #include "chromeos/ime/mock_xkeyboard.h" | 22 #include "chromeos/ime/mock_xkeyboard.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "ui/base/accelerators/accelerator.h" | 24 #include "ui/base/accelerators/accelerator.h" |
23 #include "ui/base/ime/chromeos/mock_ime_engine_handler.h" | 25 #include "ui/base/ime/chromeos/mock_ime_engine_handler.h" |
24 #include "ui/events/keycodes/keyboard_codes.h" | 26 #include "ui/events/keycodes/keyboard_codes.h" |
25 | 27 |
26 namespace chromeos { | 28 namespace chromeos { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 virtual void CandidateWindowClosed(InputMethodManager* manager) OVERRIDE { | 200 virtual void CandidateWindowClosed(InputMethodManager* manager) OVERRIDE { |
199 ++candidate_window_closed_count_; | 201 ++candidate_window_closed_count_; |
200 } | 202 } |
201 | 203 |
202 int candidate_window_opened_count_; | 204 int candidate_window_opened_count_; |
203 int candidate_window_closed_count_; | 205 int candidate_window_closed_count_; |
204 | 206 |
205 private: | 207 private: |
206 DISALLOW_COPY_AND_ASSIGN(TestCandidateWindowObserver); | 208 DISALLOW_COPY_AND_ASSIGN(TestCandidateWindowObserver); |
207 }; | 209 }; |
208 | |
209 } // namespace | 210 } // namespace |
210 | 211 |
211 TEST_F(InputMethodManagerImplTest, TestGetXKeyboard) { | 212 TEST_F(InputMethodManagerImplTest, TestGetXKeyboard) { |
212 EXPECT_TRUE(manager_->GetXKeyboard()); | 213 EXPECT_TRUE(manager_->GetXKeyboard()); |
213 EXPECT_EQ(xkeyboard_, manager_->GetXKeyboard()); | 214 EXPECT_EQ(xkeyboard_, manager_->GetXKeyboard()); |
214 } | 215 } |
215 | 216 |
216 TEST_F(InputMethodManagerImplTest, TestCandidateWindowObserver) { | 217 TEST_F(InputMethodManagerImplTest, TestCandidateWindowObserver) { |
217 TestCandidateWindowObserver observer; | 218 TestCandidateWindowObserver observer; |
218 candidate_window_controller_->NotifyCandidateWindowOpened(); // nop | 219 candidate_window_controller_->NotifyCandidateWindowOpened(); // nop |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 EXPECT_EQ(1, observer.input_method_changed_count_); | 905 EXPECT_EQ(1, observer.input_method_changed_count_); |
905 EXPECT_EQ(ids[0], | 906 EXPECT_EQ(ids[0], |
906 manager_->GetCurrentInputMethod().id()); | 907 manager_->GetCurrentInputMethod().id()); |
907 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); | 908 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); |
908 | 909 |
909 // Add two Extension IMEs. | 910 // Add two Extension IMEs. |
910 std::vector<std::string> layouts; | 911 std::vector<std::string> layouts; |
911 layouts.push_back("us"); | 912 layouts.push_back("us"); |
912 std::vector<std::string> languages; | 913 std::vector<std::string> languages; |
913 languages.push_back("en-US"); | 914 languages.push_back("en-US"); |
| 915 |
914 const std::string ext1_id = | 916 const std::string ext1_id = |
915 extension_ime_util::GetInputMethodID("deadbeef", "engine_id"); | 917 extension_ime_util::GetInputMethodID("deadbeef", "engine_id"); |
916 manager_->AddInputMethodExtension( | 918 const InputMethodDescriptor descriptor1(ext1_id, |
917 ext1_id, | 919 "deadbeef input method", |
918 "deadbeef input method", | 920 layouts, |
919 layouts, | 921 languages, |
920 languages, | 922 false, // is_login_keyboard |
921 GURL(), | 923 GURL(), |
922 GURL(), | 924 GURL()); |
923 NULL); | 925 MockInputMethodEngine engine(descriptor1); |
924 IBusBridge::Get()->SetEngineHandler(ext1_id, mock_engine_handler_.get()); | 926 manager_->AddInputMethodExtension(ext1_id, &engine); |
925 | 927 |
926 // Extension IMEs are not enabled by default. | 928 // Extension IMEs are not enabled by default. |
927 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 929 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |
928 | 930 |
929 std::vector<std::string> extension_ime_ids; | 931 std::vector<std::string> extension_ime_ids; |
930 extension_ime_ids.push_back( | 932 extension_ime_ids.push_back(ext1_id); |
931 extension_ime_util::GetInputMethodID("deadbeef", "engine_id")); | |
932 manager_->SetEnabledExtensionImes(&extension_ime_ids); | 933 manager_->SetEnabledExtensionImes(&extension_ime_ids); |
933 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 934 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
934 | 935 |
935 { | 936 { |
936 scoped_ptr<InputMethodDescriptors> methods( | 937 scoped_ptr<InputMethodDescriptors> methods( |
937 manager_->GetActiveInputMethods()); | 938 manager_->GetActiveInputMethods()); |
938 ASSERT_EQ(2U, methods->size()); | 939 ASSERT_EQ(2U, methods->size()); |
939 EXPECT_EQ(extension_ime_util::GetInputMethodID("deadbeef", "engine_id"), | 940 // Ext IMEs should be at the end of the list. |
940 // Ext IMEs should be at the end of the list. | 941 EXPECT_EQ(ext1_id, methods->at(1).id()); |
941 methods->at(1).id()); | |
942 } | 942 } |
| 943 |
943 const std::string ext2_id = | 944 const std::string ext2_id = |
944 extension_ime_util::GetInputMethodID("cafebabe", "engine_id"); | 945 extension_ime_util::GetInputMethodID("cafebabe", "engine_id"); |
945 manager_->AddInputMethodExtension( | 946 const InputMethodDescriptor descriptor2(ext2_id, |
946 ext2_id, | 947 "cafebabe input method", |
947 "cafebabe input method", | 948 layouts, |
948 layouts, | 949 languages, |
949 languages, | 950 false, // is_login_keyboard |
950 GURL(), | 951 GURL(), |
951 GURL(), | 952 GURL()); |
952 NULL); | 953 MockInputMethodEngine engine2(descriptor2); |
953 IBusBridge::Get()->SetEngineHandler(ext2_id, mock_engine_handler_.get()); | 954 manager_->AddInputMethodExtension(ext2_id, &engine2); |
954 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 955 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
955 | 956 |
956 extension_ime_ids.push_back( | 957 extension_ime_ids.push_back(ext2_id); |
957 extension_ime_util::GetInputMethodID("cafebabe", "engine_id")); | |
958 manager_->SetEnabledExtensionImes(&extension_ime_ids); | 958 manager_->SetEnabledExtensionImes(&extension_ime_ids); |
959 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); | 959 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); |
960 { | 960 { |
961 scoped_ptr<InputMethodDescriptors> methods( | 961 scoped_ptr<InputMethodDescriptors> methods( |
962 manager_->GetActiveInputMethods()); | 962 manager_->GetActiveInputMethods()); |
963 ASSERT_EQ(3U, methods->size()); | 963 ASSERT_EQ(3U, methods->size()); |
964 EXPECT_EQ(extension_ime_util::GetInputMethodID("deadbeef", "engine_id"), | 964 // Ext IMEs should be at the end of the list. |
965 // Ext IMEs should be at the end of the list. | 965 EXPECT_EQ(ext1_id, methods->at(1).id()); |
966 methods->at(1).id()); | 966 EXPECT_EQ(ext2_id, methods->at(2).id()); |
967 } | 967 } |
968 | 968 |
969 // Remove them. | 969 // Remove them. |
970 manager_->RemoveInputMethodExtension( | 970 manager_->RemoveInputMethodExtension(ext1_id); |
971 extension_ime_util::GetInputMethodID("deadbeef", "engine_id")); | |
972 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 971 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
973 manager_->RemoveInputMethodExtension( | 972 manager_->RemoveInputMethodExtension(ext2_id); |
974 extension_ime_util::GetInputMethodID("cafebabe", "engine_id")); | |
975 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 973 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |
976 } | 974 } |
977 | 975 |
978 TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) { | 976 TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) { |
979 TestObserver observer; | 977 TestObserver observer; |
980 InitComponentExtension(); | 978 InitComponentExtension(); |
981 manager_->AddObserver(&observer); | 979 manager_->AddObserver(&observer); |
982 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 980 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); |
983 std::vector<std::string> ids; | 981 std::vector<std::string> ids; |
984 ids.push_back("xkb:us::eng"); | 982 ids.push_back("xkb:us::eng"); |
985 EXPECT_TRUE(manager_->EnableInputMethods(ids)); | 983 EXPECT_TRUE(manager_->EnableInputMethods(ids)); |
986 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 984 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |
987 EXPECT_EQ(1, observer.input_method_changed_count_); | 985 EXPECT_EQ(1, observer.input_method_changed_count_); |
988 EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); | 986 EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); |
989 EXPECT_EQ("us", xkeyboard_->last_layout_); | 987 EXPECT_EQ("us", xkeyboard_->last_layout_); |
990 | 988 |
991 // Add an Extension IME. | 989 // Add an Extension IME. |
992 std::vector<std::string> layouts; | 990 std::vector<std::string> layouts; |
993 layouts.push_back("us(dvorak)"); | 991 layouts.push_back("us(dvorak)"); |
994 std::vector<std::string> languages; | 992 std::vector<std::string> languages; |
995 languages.push_back("en-US"); | 993 languages.push_back("en-US"); |
| 994 |
996 const std::string ext_id = | 995 const std::string ext_id = |
997 extension_ime_util::GetInputMethodID("deadbeef", "engine_id"); | 996 extension_ime_util::GetInputMethodID("deadbeef", "engine_id"); |
998 manager_->AddInputMethodExtension( | 997 const InputMethodDescriptor descriptor(ext_id, |
999 ext_id, | 998 "deadbeef input method", |
1000 "deadbeef input method", | 999 layouts, |
1001 layouts, | 1000 languages, |
1002 languages, | 1001 false, // is_login_keyboard |
1003 GURL(), | 1002 GURL(), |
1004 GURL(), | 1003 GURL()); |
1005 NULL); | 1004 MockInputMethodEngine engine(descriptor); |
1006 IBusBridge::Get()->SetEngineHandler(ext_id, mock_engine_handler_.get()); | 1005 manager_->AddInputMethodExtension(ext_id, &engine); |
1007 | 1006 |
1008 // Extension IME is not enabled by default. | 1007 // Extension IME is not enabled by default. |
1009 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1008 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |
1010 EXPECT_EQ(1, observer.input_method_changed_count_); | 1009 EXPECT_EQ(1, observer.input_method_changed_count_); |
1011 | 1010 |
1012 std::vector<std::string> extension_ime_ids; | 1011 std::vector<std::string> extension_ime_ids; |
1013 extension_ime_ids.push_back( | 1012 extension_ime_ids.push_back(ext_id); |
1014 extension_ime_util::GetInputMethodID("deadbeef", "engine_id")); | |
1015 manager_->SetEnabledExtensionImes(&extension_ime_ids); | 1013 manager_->SetEnabledExtensionImes(&extension_ime_ids); |
1016 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1014 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
1017 | 1015 |
1018 // Switch to the IME. | 1016 // Switch to the IME. |
1019 manager_->SwitchToNextInputMethod(); | 1017 manager_->SwitchToNextInputMethod(); |
1020 EXPECT_EQ(3, observer.input_method_changed_count_); | 1018 EXPECT_EQ(3, observer.input_method_changed_count_); |
1021 EXPECT_EQ(extension_ime_util::GetInputMethodID("deadbeef", "engine_id"), | 1019 EXPECT_EQ(ext_id, manager_->GetCurrentInputMethod().id()); |
1022 manager_->GetCurrentInputMethod().id()); | |
1023 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); | 1020 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); |
1024 | 1021 |
1025 // Lock the screen. This is for crosbug.com/27049. | 1022 // Lock the screen. This is for crosbug.com/27049. |
1026 manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN); | 1023 manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN); |
1027 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); // Qwerty. No Ext. IME | 1024 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); // Qwerty. No Ext. IME |
1028 EXPECT_EQ("xkb:us::eng", | 1025 EXPECT_EQ("xkb:us::eng", |
1029 manager_->GetCurrentInputMethod().id()); | 1026 manager_->GetCurrentInputMethod().id()); |
1030 EXPECT_EQ("us", xkeyboard_->last_layout_); | 1027 EXPECT_EQ("us", xkeyboard_->last_layout_); |
1031 | 1028 |
1032 // Unlock the screen. | 1029 // Unlock the screen. |
1033 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 1030 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); |
1034 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1031 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
1035 EXPECT_EQ(extension_ime_util::GetInputMethodID("deadbeef", "engine_id"), | 1032 EXPECT_EQ(ext_id, manager_->GetCurrentInputMethod().id()); |
1036 manager_->GetCurrentInputMethod().id()); | |
1037 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); | 1033 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); |
1038 { | 1034 { |
1039 // This is for crosbug.com/27052. | 1035 // This is for crosbug.com/27052. |
1040 scoped_ptr<InputMethodDescriptors> methods( | 1036 scoped_ptr<InputMethodDescriptors> methods( |
1041 manager_->GetActiveInputMethods()); | 1037 manager_->GetActiveInputMethods()); |
1042 ASSERT_EQ(2U, methods->size()); | 1038 ASSERT_EQ(2U, methods->size()); |
1043 EXPECT_EQ(extension_ime_util::GetInputMethodID("deadbeef", "engine_id"), | 1039 // Ext. IMEs should be at the end of the list. |
1044 // Ext. IMEs should be at the end of the list. | 1040 EXPECT_EQ(ext_id, methods->at(1).id()); |
1045 methods->at(1).id()); | |
1046 } | 1041 } |
1047 manager_->RemoveObserver(&observer); | 1042 manager_->RemoveObserver(&observer); |
1048 } | 1043 } |
1049 | 1044 |
1050 TEST_F(InputMethodManagerImplTest, | 1045 TEST_F(InputMethodManagerImplTest, |
1051 ChangeInputMethodBeforeComponentExtensionInitialization_OneIME) { | 1046 ChangeInputMethodBeforeComponentExtensionInitialization_OneIME) { |
1052 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 1047 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); |
1053 std::vector<std::string> ids; | 1048 std::vector<std::string> ids; |
1054 ids.push_back(kNaclMozcUsId); | 1049 ids.push_back(kNaclMozcUsId); |
1055 EXPECT_TRUE(manager_->EnableInputMethods(ids)); | 1050 EXPECT_TRUE(manager_->EnableInputMethods(ids)); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 ids.push_back(ext_id2); | 1136 ids.push_back(ext_id2); |
1142 EXPECT_TRUE(manager_->EnableInputMethods(ids)); | 1137 EXPECT_TRUE(manager_->EnableInputMethods(ids)); |
1143 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1138 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
1144 EXPECT_EQ(ext_id1, manager_->GetCurrentInputMethod().id()); | 1139 EXPECT_EQ(ext_id1, manager_->GetCurrentInputMethod().id()); |
1145 manager_->ChangeInputMethod(ext_id2); | 1140 manager_->ChangeInputMethod(ext_id2); |
1146 EXPECT_EQ(ext_id2, manager_->GetCurrentInputMethod().id()); | 1141 EXPECT_EQ(ext_id2, manager_->GetCurrentInputMethod().id()); |
1147 } | 1142 } |
1148 | 1143 |
1149 } // namespace input_method | 1144 } // namespace input_method |
1150 } // namespace chromeos | 1145 } // namespace chromeos |
OLD | NEW |