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/mock_candidate_window_controller.
h" | 16 #include "chrome/browser/chromeos/input_method/mock_candidate_window_controller.
h" |
17 #include "chrome/browser/chromeos/input_method/mock_ibus_controller.h" | 17 #include "chrome/browser/chromeos/input_method/mock_ibus_controller.h" |
18 #include "chromeos/dbus/fake_dbus_thread_manager.h" | 18 #include "chromeos/dbus/fake_dbus_thread_manager.h" |
19 #include "chromeos/dbus/ibus/mock_ibus_client.h" | |
20 #include "chromeos/ime/extension_ime_util.h" | 19 #include "chromeos/ime/extension_ime_util.h" |
21 #include "chromeos/ime/fake_input_method_delegate.h" | 20 #include "chromeos/ime/fake_input_method_delegate.h" |
22 #include "chromeos/ime/mock_component_extension_ime_manager_delegate.h" | 21 #include "chromeos/ime/mock_component_extension_ime_manager_delegate.h" |
23 #include "chromeos/ime/mock_ibus_daemon_controller.h" | 22 #include "chromeos/ime/mock_ibus_daemon_controller.h" |
24 #include "chromeos/ime/mock_ime_engine_handler.h" | 23 #include "chromeos/ime/mock_ime_engine_handler.h" |
25 #include "chromeos/ime/mock_xkeyboard.h" | 24 #include "chromeos/ime/mock_xkeyboard.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "ui/base/accelerators/accelerator.h" | 26 #include "ui/base/accelerators/accelerator.h" |
28 #include "ui/events/keycodes/keyboard_codes.h" | 27 #include "ui/events/keycodes/keyboard_codes.h" |
29 | 28 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 void InitComponentExtension() { | 143 void InitComponentExtension() { |
145 mock_delegate_ = new MockComponentExtIMEManagerDelegate(); | 144 mock_delegate_ = new MockComponentExtIMEManagerDelegate(); |
146 mock_delegate_->set_ime_list(ime_list_); | 145 mock_delegate_->set_ime_list(ime_list_); |
147 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(mock_delegate_); | 146 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(mock_delegate_); |
148 manager_->InitializeComponentExtensionForTesting(delegate.Pass()); | 147 manager_->InitializeComponentExtensionForTesting(delegate.Pass()); |
149 } | 148 } |
150 | 149 |
151 // Helper function to initialize IBus bus connection for testing. Do not use | 150 // Helper function to initialize IBus bus connection for testing. Do not use |
152 // ibus related mocks before calling this function. | 151 // ibus related mocks before calling this function. |
153 void InitIBusBus() { | 152 void InitIBusBus() { |
154 mock_ibus_client_ = new MockIBusClient; | |
155 fake_dbus_thread_manager_->SetIBusClient( | |
156 scoped_ptr<IBusClient>(mock_ibus_client_)); | |
157 mock_ibus_daemon_controller_->EmulateConnect(); | 153 mock_ibus_daemon_controller_->EmulateConnect(); |
158 } | 154 } |
159 | 155 |
160 scoped_ptr<InputMethodManagerImpl> manager_; | 156 scoped_ptr<InputMethodManagerImpl> manager_; |
161 FakeInputMethodDelegate* delegate_; | 157 FakeInputMethodDelegate* delegate_; |
162 MockIBusController* controller_; | 158 MockIBusController* controller_; |
163 MockCandidateWindowController* candidate_window_controller_; | 159 MockCandidateWindowController* candidate_window_controller_; |
164 MockIBusDaemonController* mock_ibus_daemon_controller_; | 160 MockIBusDaemonController* mock_ibus_daemon_controller_; |
165 scoped_ptr<MockIMEEngineHandler> mock_engine_handler_; | 161 scoped_ptr<MockIMEEngineHandler> mock_engine_handler_; |
166 MockIBusClient* mock_ibus_client_; | |
167 FakeDBusThreadManager* fake_dbus_thread_manager_; | 162 FakeDBusThreadManager* fake_dbus_thread_manager_; |
168 MockXKeyboard* xkeyboard_; | 163 MockXKeyboard* xkeyboard_; |
169 base::MessageLoop message_loop_; | 164 base::MessageLoop message_loop_; |
170 MockComponentExtIMEManagerDelegate* mock_delegate_; | 165 MockComponentExtIMEManagerDelegate* mock_delegate_; |
171 std::vector<ComponentExtensionIME> ime_list_; | 166 std::vector<ComponentExtensionIME> ime_list_; |
172 | 167 |
173 private: | 168 private: |
174 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImplTest); | 169 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImplTest); |
175 }; | 170 }; |
176 | 171 |
(...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 InitComponentExtension(); | 1101 InitComponentExtension(); |
1107 InitIBusBus(); | 1102 InitIBusBus(); |
1108 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 1103 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); |
1109 std::vector<std::string> ids; | 1104 std::vector<std::string> ids; |
1110 ids.push_back("xkb:us::eng"); | 1105 ids.push_back("xkb:us::eng"); |
1111 ids.push_back(nacl_mozc_us_id); | 1106 ids.push_back(nacl_mozc_us_id); |
1112 EXPECT_TRUE(manager_->EnableInputMethods(ids)); | 1107 EXPECT_TRUE(manager_->EnableInputMethods(ids)); |
1113 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1108 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
1114 EXPECT_EQ(0, mock_engine_handler_->reset_call_count()); | 1109 EXPECT_EQ(0, mock_engine_handler_->reset_call_count()); |
1115 manager_->ChangeInputMethod(nacl_mozc_us_id); | 1110 manager_->ChangeInputMethod(nacl_mozc_us_id); |
1116 EXPECT_EQ(1, mock_ibus_client_->set_global_engine_call_count()); | 1111 EXPECT_EQ(nacl_mozc_us_id, manager_->GetCurrentInputMethod().id()); |
1117 EXPECT_EQ(nacl_mozc_us_id, mock_ibus_client_->latest_global_engine_name()); | |
1118 EXPECT_EQ(0, mock_engine_handler_->reset_call_count()); | 1112 EXPECT_EQ(0, mock_engine_handler_->reset_call_count()); |
1119 manager_->ChangeInputMethod("xkb:us::eng"); | 1113 manager_->ChangeInputMethod("xkb:us::eng"); |
1120 EXPECT_EQ(1, mock_ibus_client_->set_global_engine_call_count()); | 1114 EXPECT_EQ(nacl_mozc_us_id, manager_->GetCurrentInputMethod().id()); |
1121 EXPECT_EQ(nacl_mozc_us_id, mock_ibus_client_->latest_global_engine_name()); | |
1122 EXPECT_EQ(0, mock_engine_handler_->reset_call_count()); | 1115 EXPECT_EQ(0, mock_engine_handler_->reset_call_count()); |
1123 } | 1116 } |
1124 | 1117 |
1125 TEST_F(InputMethodManagerImplTest, | 1118 TEST_F(InputMethodManagerImplTest, |
1126 ChangeInputMethodBeforeComponentExtensionInitialization_OneIME) { | 1119 ChangeInputMethodBeforeComponentExtensionInitialization_OneIME) { |
1127 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 1120 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); |
1128 std::vector<std::string> ids; | 1121 std::vector<std::string> ids; |
1129 ids.push_back(nacl_mozc_us_id); | 1122 ids.push_back(nacl_mozc_us_id); |
1130 EXPECT_TRUE(manager_->EnableInputMethods(ids)); | 1123 EXPECT_TRUE(manager_->EnableInputMethods(ids)); |
1131 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1124 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |
1132 manager_->ChangeInputMethod(nacl_mozc_us_id); | 1125 manager_->ChangeInputMethod(nacl_mozc_us_id); |
1133 | 1126 |
1134 InitIBusBus(); | 1127 InitIBusBus(); |
1135 InitComponentExtension(); | 1128 InitComponentExtension(); |
1136 EXPECT_EQ(1, mock_ibus_client_->set_global_engine_call_count()); | 1129 EXPECT_EQ(nacl_mozc_us_id, manager_->GetCurrentInputMethod().id()); |
1137 EXPECT_EQ(nacl_mozc_us_id, mock_ibus_client_->latest_global_engine_name()); | |
1138 } | 1130 } |
1139 | 1131 |
1140 TEST_F(InputMethodManagerImplTest, | 1132 TEST_F(InputMethodManagerImplTest, |
1141 ChangeInputMethodBeforeComponentExtensionInitialization_TwoIME) { | 1133 ChangeInputMethodBeforeComponentExtensionInitialization_TwoIME) { |
1142 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 1134 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); |
1143 std::vector<std::string> ids; | 1135 std::vector<std::string> ids; |
1144 ids.push_back(nacl_mozc_us_id); | 1136 ids.push_back(nacl_mozc_us_id); |
1145 ids.push_back(nacl_mozc_jp_id); | 1137 ids.push_back(nacl_mozc_jp_id); |
1146 EXPECT_TRUE(manager_->EnableInputMethods(ids)); | 1138 EXPECT_TRUE(manager_->EnableInputMethods(ids)); |
1147 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1139 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
1148 manager_->ChangeInputMethod(nacl_mozc_us_id); | 1140 manager_->ChangeInputMethod(nacl_mozc_us_id); |
1149 manager_->ChangeInputMethod(nacl_mozc_jp_id); | 1141 manager_->ChangeInputMethod(nacl_mozc_jp_id); |
1150 | 1142 |
1151 InitComponentExtension(); | 1143 InitComponentExtension(); |
1152 InitIBusBus(); | 1144 InitIBusBus(); |
1153 EXPECT_EQ(1, mock_ibus_client_->set_global_engine_call_count()); | 1145 EXPECT_EQ(nacl_mozc_jp_id, manager_->GetCurrentInputMethod().id()); |
1154 EXPECT_EQ(nacl_mozc_jp_id, mock_ibus_client_->latest_global_engine_name()); | |
1155 } | 1146 } |
1156 | 1147 |
1157 TEST_F(InputMethodManagerImplTest, | 1148 TEST_F(InputMethodManagerImplTest, |
1158 ChangeInputMethodBeforeComponentExtensionInitialization_CompOneIME) { | 1149 ChangeInputMethodBeforeComponentExtensionInitialization_CompOneIME) { |
1159 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 1150 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); |
1160 const std::string ext_id = | 1151 const std::string ext_id = |
1161 TestableComponentExtensionIMEManager::GetComponentExtensionIMEId( | 1152 TestableComponentExtensionIMEManager::GetComponentExtensionIMEId( |
1162 ime_list_[0].id, | 1153 ime_list_[0].id, |
1163 ime_list_[0].engines[0].engine_id); | 1154 ime_list_[0].engines[0].engine_id); |
1164 std::vector<std::string> ids; | 1155 std::vector<std::string> ids; |
1165 ids.push_back(ext_id); | 1156 ids.push_back(ext_id); |
1166 EXPECT_TRUE(manager_->EnableInputMethods(ids)); | 1157 EXPECT_TRUE(manager_->EnableInputMethods(ids)); |
1167 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1158 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |
1168 manager_->ChangeInputMethod(ext_id); | 1159 manager_->ChangeInputMethod(ext_id); |
1169 | 1160 |
1170 InitComponentExtension(); | 1161 InitComponentExtension(); |
1171 InitIBusBus(); | 1162 InitIBusBus(); |
1172 EXPECT_EQ(1, mock_ibus_client_->set_global_engine_call_count()); | 1163 EXPECT_EQ(ext_id, manager_->GetCurrentInputMethod().id()); |
1173 EXPECT_EQ(ext_id, mock_ibus_client_->latest_global_engine_name()); | |
1174 } | 1164 } |
1175 | 1165 |
1176 TEST_F(InputMethodManagerImplTest, | 1166 TEST_F(InputMethodManagerImplTest, |
1177 ChangeInputMethodBeforeComponentExtensionInitialization_CompTwoIME) { | 1167 ChangeInputMethodBeforeComponentExtensionInitialization_CompTwoIME) { |
1178 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 1168 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); |
1179 const std::string ext_id1 = | 1169 const std::string ext_id1 = |
1180 TestableComponentExtensionIMEManager::GetComponentExtensionIMEId( | 1170 TestableComponentExtensionIMEManager::GetComponentExtensionIMEId( |
1181 ime_list_[0].id, | 1171 ime_list_[0].id, |
1182 ime_list_[0].engines[0].engine_id); | 1172 ime_list_[0].engines[0].engine_id); |
1183 const std::string ext_id2 = | 1173 const std::string ext_id2 = |
1184 TestableComponentExtensionIMEManager::GetComponentExtensionIMEId( | 1174 TestableComponentExtensionIMEManager::GetComponentExtensionIMEId( |
1185 ime_list_[1].id, | 1175 ime_list_[1].id, |
1186 ime_list_[1].engines[0].engine_id); | 1176 ime_list_[1].engines[0].engine_id); |
1187 std::vector<std::string> ids; | 1177 std::vector<std::string> ids; |
1188 ids.push_back(ext_id1); | 1178 ids.push_back(ext_id1); |
1189 ids.push_back(ext_id2); | 1179 ids.push_back(ext_id2); |
1190 EXPECT_TRUE(manager_->EnableInputMethods(ids)); | 1180 EXPECT_TRUE(manager_->EnableInputMethods(ids)); |
1191 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1181 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
1192 manager_->ChangeInputMethod(ext_id1); | 1182 manager_->ChangeInputMethod(ext_id1); |
1193 manager_->ChangeInputMethod(ext_id2); | 1183 manager_->ChangeInputMethod(ext_id2); |
1194 | 1184 |
1195 InitComponentExtension(); | 1185 InitComponentExtension(); |
1196 InitIBusBus(); | 1186 InitIBusBus(); |
1197 EXPECT_EQ(1, mock_ibus_client_->set_global_engine_call_count()); | 1187 EXPECT_EQ(ext_id2, manager_->GetCurrentInputMethod().id()); |
1198 EXPECT_EQ(ext_id2, mock_ibus_client_->latest_global_engine_name()); | |
1199 } | 1188 } |
1200 | 1189 |
1201 TEST_F(InputMethodManagerImplTest, | 1190 TEST_F(InputMethodManagerImplTest, |
1202 ChangeInputMethod_ComponenteExtensionOneIME) { | 1191 ChangeInputMethod_ComponenteExtensionOneIME) { |
1203 InitComponentExtension(); | 1192 InitComponentExtension(); |
1204 InitIBusBus(); | 1193 InitIBusBus(); |
1205 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 1194 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); |
1206 const std::string ext_id = | 1195 const std::string ext_id = |
1207 TestableComponentExtensionIMEManager::GetComponentExtensionIMEId( | 1196 TestableComponentExtensionIMEManager::GetComponentExtensionIMEId( |
1208 ime_list_[0].id, | 1197 ime_list_[0].id, |
1209 ime_list_[0].engines[0].engine_id); | 1198 ime_list_[0].engines[0].engine_id); |
1210 std::vector<std::string> ids; | 1199 std::vector<std::string> ids; |
1211 ids.push_back(ext_id); | 1200 ids.push_back(ext_id); |
1212 EXPECT_TRUE(manager_->EnableInputMethods(ids)); | 1201 EXPECT_TRUE(manager_->EnableInputMethods(ids)); |
1213 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1202 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |
1214 EXPECT_EQ(1, mock_ibus_client_->set_global_engine_call_count()); | 1203 EXPECT_EQ(ext_id, manager_->GetCurrentInputMethod().id()); |
1215 EXPECT_EQ(ext_id, mock_ibus_client_->latest_global_engine_name()); | |
1216 } | 1204 } |
1217 | 1205 |
1218 TEST_F(InputMethodManagerImplTest, | 1206 TEST_F(InputMethodManagerImplTest, |
1219 ChangeInputMethod_ComponenteExtensionTwoIME) { | 1207 ChangeInputMethod_ComponenteExtensionTwoIME) { |
1220 InitComponentExtension(); | 1208 InitComponentExtension(); |
1221 InitIBusBus(); | 1209 InitIBusBus(); |
1222 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 1210 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); |
1223 const std::string ext_id1 = | 1211 const std::string ext_id1 = |
1224 TestableComponentExtensionIMEManager::GetComponentExtensionIMEId( | 1212 TestableComponentExtensionIMEManager::GetComponentExtensionIMEId( |
1225 ime_list_[0].id, | 1213 ime_list_[0].id, |
1226 ime_list_[0].engines[0].engine_id); | 1214 ime_list_[0].engines[0].engine_id); |
1227 const std::string ext_id2 = | 1215 const std::string ext_id2 = |
1228 TestableComponentExtensionIMEManager::GetComponentExtensionIMEId( | 1216 TestableComponentExtensionIMEManager::GetComponentExtensionIMEId( |
1229 ime_list_[1].id, | 1217 ime_list_[1].id, |
1230 ime_list_[1].engines[0].engine_id); | 1218 ime_list_[1].engines[0].engine_id); |
1231 std::vector<std::string> ids; | 1219 std::vector<std::string> ids; |
1232 ids.push_back(ext_id1); | 1220 ids.push_back(ext_id1); |
1233 ids.push_back(ext_id2); | 1221 ids.push_back(ext_id2); |
1234 EXPECT_TRUE(manager_->EnableInputMethods(ids)); | 1222 EXPECT_TRUE(manager_->EnableInputMethods(ids)); |
1235 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1223 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
1236 EXPECT_EQ(1, mock_ibus_client_->set_global_engine_call_count()); | 1224 EXPECT_EQ(ext_id1, manager_->GetCurrentInputMethod().id()); |
1237 EXPECT_EQ(ext_id1, mock_ibus_client_->latest_global_engine_name()); | |
1238 manager_->ChangeInputMethod(ext_id2); | 1225 manager_->ChangeInputMethod(ext_id2); |
1239 EXPECT_EQ(2, mock_ibus_client_->set_global_engine_call_count()); | 1226 EXPECT_EQ(ext_id2, manager_->GetCurrentInputMethod().id()); |
1240 EXPECT_EQ(ext_id2, mock_ibus_client_->latest_global_engine_name()); | |
1241 } | 1227 } |
1242 | 1228 |
1243 TEST_F(InputMethodManagerImplTest, | 1229 TEST_F(InputMethodManagerImplTest, |
1244 AsyncComponentExtentionInitializeBeforeIBusDaemonConnection) { | 1230 AsyncComponentExtentionInitializeBeforeIBusDaemonConnection) { |
1245 const std::string xkb_id = "xkb:cz::cze"; | 1231 const std::string xkb_id = "xkb:cz::cze"; |
1246 const std::string ime_id = nacl_mozc_us_id; | 1232 const std::string ime_id = nacl_mozc_us_id; |
1247 const std::string fallback_id = "xkb:us::eng"; | 1233 const std::string fallback_id = "xkb:us::eng"; |
1248 std::vector<std::string> ids; | 1234 std::vector<std::string> ids; |
1249 ids.push_back(xkb_id); | 1235 ids.push_back(xkb_id); |
1250 ids.push_back(ime_id); | 1236 ids.push_back(ime_id); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 EXPECT_EQ(fallback_id, manager_->GetCurrentInputMethod().id()); | 1279 EXPECT_EQ(fallback_id, manager_->GetCurrentInputMethod().id()); |
1294 | 1280 |
1295 // After component extension IME is initialized, previous specified input | 1281 // After component extension IME is initialized, previous specified input |
1296 // method should be automatically enabled. | 1282 // method should be automatically enabled. |
1297 InitComponentExtension(); | 1283 InitComponentExtension(); |
1298 EXPECT_EQ(xkb_id, manager_->GetCurrentInputMethod().id()); | 1284 EXPECT_EQ(xkb_id, manager_->GetCurrentInputMethod().id()); |
1299 } | 1285 } |
1300 | 1286 |
1301 } // namespace input_method | 1287 } // namespace input_method |
1302 } // namespace chromeos | 1288 } // namespace chromeos |
OLD | NEW |