| 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 "ash/ime/input_method_menu_item.h" | 9 #include "ash/ime/input_method_menu_item.h" |
| 10 #include "ash/ime/input_method_menu_manager.h" | 10 #include "ash/ime/input_method_menu_manager.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 if (descriptors[i].id() == target.id()) | 51 if (descriptors[i].id() == target.id()) |
| 52 return true; | 52 return true; |
| 53 } | 53 } |
| 54 return false; | 54 return false; |
| 55 } | 55 } |
| 56 | 56 |
| 57 std::string ImeIdFromEngineId(const std::string& id) { | 57 std::string ImeIdFromEngineId(const std::string& id) { |
| 58 return extension_ime_util::GetInputMethodIDByEngineID(id); | 58 return extension_ime_util::GetInputMethodIDByEngineID(id); |
| 59 } | 59 } |
| 60 | 60 |
| 61 class TestObserver : public InputMethodManager::Observer, |
| 62 public ash::ime::InputMethodMenuManager::Observer { |
| 63 public: |
| 64 TestObserver() |
| 65 : input_method_changed_count_(0), |
| 66 input_method_menu_item_changed_count_(0), |
| 67 last_show_message_(false) { |
| 68 } |
| 69 virtual ~TestObserver() {} |
| 70 |
| 71 virtual void InputMethodChanged(InputMethodManager* manager, |
| 72 bool show_message) OVERRIDE { |
| 73 ++input_method_changed_count_; |
| 74 last_show_message_ = show_message; |
| 75 } |
| 76 virtual void InputMethodMenuItemChanged( |
| 77 ash::ime::InputMethodMenuManager* manager) OVERRIDE { |
| 78 ++input_method_menu_item_changed_count_; |
| 79 } |
| 80 |
| 81 int input_method_changed_count_; |
| 82 int input_method_menu_item_changed_count_; |
| 83 bool last_show_message_; |
| 84 |
| 85 private: |
| 86 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
| 87 }; |
| 88 |
| 89 class TestCandidateWindowObserver |
| 90 : public InputMethodManager::CandidateWindowObserver { |
| 91 public: |
| 92 TestCandidateWindowObserver() |
| 93 : candidate_window_opened_count_(0), |
| 94 candidate_window_closed_count_(0) { |
| 95 } |
| 96 |
| 97 virtual ~TestCandidateWindowObserver() {} |
| 98 |
| 99 virtual void CandidateWindowOpened(InputMethodManager* manager) OVERRIDE { |
| 100 ++candidate_window_opened_count_; |
| 101 } |
| 102 virtual void CandidateWindowClosed(InputMethodManager* manager) OVERRIDE { |
| 103 ++candidate_window_closed_count_; |
| 104 } |
| 105 |
| 106 int candidate_window_opened_count_; |
| 107 int candidate_window_closed_count_; |
| 108 |
| 109 private: |
| 110 DISALLOW_COPY_AND_ASSIGN(TestCandidateWindowObserver); |
| 111 }; |
| 112 } // namespace |
| 113 |
| 61 class InputMethodManagerImplTest : public BrowserWithTestWindowTest { | 114 class InputMethodManagerImplTest : public BrowserWithTestWindowTest { |
| 62 public: | 115 public: |
| 63 InputMethodManagerImplTest() | 116 InputMethodManagerImplTest() |
| 64 : delegate_(NULL), | 117 : delegate_(NULL), |
| 65 candidate_window_controller_(NULL), | 118 candidate_window_controller_(NULL), |
| 66 keyboard_(NULL) { | 119 keyboard_(NULL) { |
| 67 } | 120 } |
| 68 virtual ~InputMethodManagerImplTest() {} | 121 virtual ~InputMethodManagerImplTest() {} |
| 69 | 122 |
| 70 virtual void SetUp() OVERRIDE { | 123 virtual void SetUp() OVERRIDE { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 101 | 154 |
| 102 delegate_ = NULL; | 155 delegate_ = NULL; |
| 103 candidate_window_controller_ = NULL; | 156 candidate_window_controller_ = NULL; |
| 104 keyboard_ = NULL; | 157 keyboard_ = NULL; |
| 105 manager_.reset(); | 158 manager_.reset(); |
| 106 | 159 |
| 107 profile_manager_.reset(); | 160 profile_manager_.reset(); |
| 108 } | 161 } |
| 109 | 162 |
| 110 protected: | 163 protected: |
| 164 Profile* GetProfile() { return manager_->GetProfile(); } |
| 111 // Helper function to initialize component extension stuff for testing. | 165 // Helper function to initialize component extension stuff for testing. |
| 112 void InitComponentExtension() { | 166 void InitComponentExtension() { |
| 113 mock_delegate_ = new MockComponentExtIMEManagerDelegate(); | 167 mock_delegate_ = new MockComponentExtIMEManagerDelegate(); |
| 114 mock_delegate_->set_ime_list(ime_list_); | 168 mock_delegate_->set_ime_list(ime_list_); |
| 115 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(mock_delegate_); | 169 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(mock_delegate_); |
| 116 | 170 |
| 117 // Note, for production, these SetEngineHandler are called when | 171 // Note, for production, these SetEngineHandler are called when |
| 118 // IMEEngineHandlerInterface is initialized via | 172 // IMEEngineHandlerInterface is initialized via |
| 119 // InitializeComponentextension. | 173 // InitializeComponentextension. |
| 120 manager_->AddInputMethodExtension(ImeIdFromEngineId(kNaclMozcUsId), | 174 manager_->AddInputMethodExtension(GetProfile(), |
| 175 ImeIdFromEngineId(kNaclMozcUsId), |
| 121 mock_engine_handler_.get()); | 176 mock_engine_handler_.get()); |
| 122 manager_->AddInputMethodExtension(ImeIdFromEngineId(kNaclMozcJpId), | 177 manager_->AddInputMethodExtension(GetProfile(), |
| 178 ImeIdFromEngineId(kNaclMozcJpId), |
| 123 mock_engine_handler_.get()); | 179 mock_engine_handler_.get()); |
| 124 manager_->AddInputMethodExtension(ImeIdFromEngineId(kExt2Engine1Id), | 180 manager_->AddInputMethodExtension(GetProfile(), |
| 181 ImeIdFromEngineId(kExt2Engine1Id), |
| 125 mock_engine_handler_.get()); | 182 mock_engine_handler_.get()); |
| 126 manager_->AddInputMethodExtension(ImeIdFromEngineId(kExt2Engine2Id), | 183 manager_->AddInputMethodExtension(GetProfile(), |
| 184 ImeIdFromEngineId(kExt2Engine2Id), |
| 127 mock_engine_handler_.get()); | 185 mock_engine_handler_.get()); |
| 128 manager_->InitializeComponentExtensionForTesting(delegate.Pass()); | 186 manager_->InitializeComponentExtensionForTesting(delegate.Pass()); |
| 129 } | 187 } |
| 130 | 188 |
| 131 void InitImeList() { | 189 void InitImeList() { |
| 132 ime_list_.clear(); | 190 ime_list_.clear(); |
| 133 | 191 |
| 134 ComponentExtensionIME ext_xkb; | 192 ComponentExtensionIME ext_xkb; |
| 135 ext_xkb.id = extension_ime_util::kXkbExtensionId; | 193 ext_xkb.id = extension_ime_util::kXkbExtensionId; |
| 136 ext_xkb.description = "ext_xkb_description"; | 194 ext_xkb.description = "ext_xkb_description"; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 scoped_ptr<MockInputMethodEngine> mock_engine_handler_; | 320 scoped_ptr<MockInputMethodEngine> mock_engine_handler_; |
| 263 FakeImeKeyboard* keyboard_; | 321 FakeImeKeyboard* keyboard_; |
| 264 MockComponentExtIMEManagerDelegate* mock_delegate_; | 322 MockComponentExtIMEManagerDelegate* mock_delegate_; |
| 265 std::vector<ComponentExtensionIME> ime_list_; | 323 std::vector<ComponentExtensionIME> ime_list_; |
| 266 ash::ime::InputMethodMenuManager* menu_manager_; | 324 ash::ime::InputMethodMenuManager* menu_manager_; |
| 267 | 325 |
| 268 private: | 326 private: |
| 269 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImplTest); | 327 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImplTest); |
| 270 }; | 328 }; |
| 271 | 329 |
| 272 class TestObserver : public InputMethodManager::Observer, | |
| 273 public ash::ime::InputMethodMenuManager::Observer{ | |
| 274 public: | |
| 275 TestObserver() | |
| 276 : input_method_changed_count_(0), | |
| 277 input_method_menu_item_changed_count_(0), | |
| 278 last_show_message_(false) { | |
| 279 } | |
| 280 virtual ~TestObserver() {} | |
| 281 | |
| 282 virtual void InputMethodChanged(InputMethodManager* manager, | |
| 283 bool show_message) OVERRIDE { | |
| 284 ++input_method_changed_count_; | |
| 285 last_show_message_ = show_message; | |
| 286 } | |
| 287 virtual void InputMethodMenuItemChanged( | |
| 288 ash::ime::InputMethodMenuManager* manager) OVERRIDE { | |
| 289 ++input_method_menu_item_changed_count_; | |
| 290 } | |
| 291 | |
| 292 int input_method_changed_count_; | |
| 293 int input_method_menu_item_changed_count_; | |
| 294 bool last_show_message_; | |
| 295 | |
| 296 private: | |
| 297 DISALLOW_COPY_AND_ASSIGN(TestObserver); | |
| 298 }; | |
| 299 | |
| 300 class TestCandidateWindowObserver | |
| 301 : public InputMethodManager::CandidateWindowObserver { | |
| 302 public: | |
| 303 TestCandidateWindowObserver() | |
| 304 : candidate_window_opened_count_(0), | |
| 305 candidate_window_closed_count_(0) { | |
| 306 } | |
| 307 virtual ~TestCandidateWindowObserver() {} | |
| 308 | |
| 309 virtual void CandidateWindowOpened(InputMethodManager* manager) OVERRIDE { | |
| 310 ++candidate_window_opened_count_; | |
| 311 } | |
| 312 virtual void CandidateWindowClosed(InputMethodManager* manager) OVERRIDE { | |
| 313 ++candidate_window_closed_count_; | |
| 314 } | |
| 315 | |
| 316 int candidate_window_opened_count_; | |
| 317 int candidate_window_closed_count_; | |
| 318 | |
| 319 private: | |
| 320 DISALLOW_COPY_AND_ASSIGN(TestCandidateWindowObserver); | |
| 321 }; | |
| 322 } // namespace | |
| 323 | |
| 324 TEST_F(InputMethodManagerImplTest, TestGetImeKeyboard) { | 330 TEST_F(InputMethodManagerImplTest, TestGetImeKeyboard) { |
| 325 EXPECT_TRUE(manager_->GetImeKeyboard()); | 331 EXPECT_TRUE(manager_->GetImeKeyboard()); |
| 326 EXPECT_EQ(keyboard_, manager_->GetImeKeyboard()); | 332 EXPECT_EQ(keyboard_, manager_->GetImeKeyboard()); |
| 327 } | 333 } |
| 328 | 334 |
| 329 TEST_F(InputMethodManagerImplTest, TestCandidateWindowObserver) { | 335 TEST_F(InputMethodManagerImplTest, TestCandidateWindowObserver) { |
| 330 TestCandidateWindowObserver observer; | 336 TestCandidateWindowObserver observer; |
| 331 candidate_window_controller_->NotifyCandidateWindowOpened(); // nop | 337 candidate_window_controller_->NotifyCandidateWindowOpened(); // nop |
| 332 candidate_window_controller_->NotifyCandidateWindowClosed(); // nop | 338 candidate_window_controller_->NotifyCandidateWindowClosed(); // nop |
| 333 manager_->AddCandidateWindowObserver(&observer); | 339 manager_->AddCandidateWindowObserver(&observer); |
| (...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 extension_ime_util::GetInputMethodID("deadbeef", "engine_id"); | 1128 extension_ime_util::GetInputMethodID("deadbeef", "engine_id"); |
| 1123 const InputMethodDescriptor descriptor1(ext1_id, | 1129 const InputMethodDescriptor descriptor1(ext1_id, |
| 1124 "deadbeef input method", | 1130 "deadbeef input method", |
| 1125 "DB", | 1131 "DB", |
| 1126 layouts, | 1132 layouts, |
| 1127 languages, | 1133 languages, |
| 1128 false, // is_login_keyboard | 1134 false, // is_login_keyboard |
| 1129 GURL(), | 1135 GURL(), |
| 1130 GURL()); | 1136 GURL()); |
| 1131 MockInputMethodEngine engine(descriptor1); | 1137 MockInputMethodEngine engine(descriptor1); |
| 1132 manager_->AddInputMethodExtension(ext1_id, &engine); | 1138 manager_->AddInputMethodExtension(GetProfile(), ext1_id, &engine); |
| 1133 | 1139 |
| 1134 // Extension IMEs are not enabled by default. | 1140 // Extension IMEs are not enabled by default. |
| 1135 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1141 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |
| 1136 | 1142 |
| 1137 std::vector<std::string> extension_ime_ids; | 1143 std::vector<std::string> extension_ime_ids; |
| 1138 extension_ime_ids.push_back(ext1_id); | 1144 extension_ime_ids.push_back(ext1_id); |
| 1139 manager_->SetEnabledExtensionImes(&extension_ime_ids); | 1145 manager_->SetEnabledExtensionImes(&extension_ime_ids); |
| 1140 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1146 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
| 1141 | 1147 |
| 1142 { | 1148 { |
| 1143 scoped_ptr<InputMethodDescriptors> methods( | 1149 scoped_ptr<InputMethodDescriptors> methods( |
| 1144 manager_->GetActiveInputMethods()); | 1150 manager_->GetActiveInputMethods()); |
| 1145 ASSERT_EQ(2U, methods->size()); | 1151 ASSERT_EQ(2U, methods->size()); |
| 1146 // Ext IMEs should be at the end of the list. | 1152 // Ext IMEs should be at the end of the list. |
| 1147 EXPECT_EQ(ext1_id, methods->at(1).id()); | 1153 EXPECT_EQ(ext1_id, methods->at(1).id()); |
| 1148 } | 1154 } |
| 1149 | 1155 |
| 1150 const std::string ext2_id = | 1156 const std::string ext2_id = |
| 1151 extension_ime_util::GetInputMethodID("cafebabe", "engine_id"); | 1157 extension_ime_util::GetInputMethodID("cafebabe", "engine_id"); |
| 1152 const InputMethodDescriptor descriptor2(ext2_id, | 1158 const InputMethodDescriptor descriptor2(ext2_id, |
| 1153 "cafebabe input method", | 1159 "cafebabe input method", |
| 1154 "CB", | 1160 "CB", |
| 1155 layouts, | 1161 layouts, |
| 1156 languages, | 1162 languages, |
| 1157 false, // is_login_keyboard | 1163 false, // is_login_keyboard |
| 1158 GURL(), | 1164 GURL(), |
| 1159 GURL()); | 1165 GURL()); |
| 1160 MockInputMethodEngine engine2(descriptor2); | 1166 MockInputMethodEngine engine2(descriptor2); |
| 1161 manager_->AddInputMethodExtension(ext2_id, &engine2); | 1167 manager_->AddInputMethodExtension(GetProfile(), ext2_id, &engine2); |
| 1162 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1168 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
| 1163 | 1169 |
| 1164 extension_ime_ids.push_back(ext2_id); | 1170 extension_ime_ids.push_back(ext2_id); |
| 1165 manager_->SetEnabledExtensionImes(&extension_ime_ids); | 1171 manager_->SetEnabledExtensionImes(&extension_ime_ids); |
| 1166 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); | 1172 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); |
| 1167 { | 1173 { |
| 1168 scoped_ptr<InputMethodDescriptors> methods( | 1174 scoped_ptr<InputMethodDescriptors> methods( |
| 1169 manager_->GetActiveInputMethods()); | 1175 manager_->GetActiveInputMethods()); |
| 1170 ASSERT_EQ(3U, methods->size()); | 1176 ASSERT_EQ(3U, methods->size()); |
| 1171 // Ext IMEs should be at the end of the list. | 1177 // Ext IMEs should be at the end of the list. |
| 1172 EXPECT_EQ(ext1_id, methods->at(1).id()); | 1178 EXPECT_EQ(ext1_id, methods->at(1).id()); |
| 1173 EXPECT_EQ(ext2_id, methods->at(2).id()); | 1179 EXPECT_EQ(ext2_id, methods->at(2).id()); |
| 1174 } | 1180 } |
| 1175 | 1181 |
| 1176 // Remove them. | 1182 // Remove them. |
| 1177 manager_->RemoveInputMethodExtension(ext1_id); | 1183 manager_->RemoveInputMethodExtension(GetProfile(), ext1_id); |
| 1178 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1184 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
| 1179 manager_->RemoveInputMethodExtension(ext2_id); | 1185 manager_->RemoveInputMethodExtension(GetProfile(), ext2_id); |
| 1180 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1186 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |
| 1181 } | 1187 } |
| 1182 | 1188 |
| 1183 TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) { | 1189 TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) { |
| 1184 TestObserver observer; | 1190 TestObserver observer; |
| 1185 InitComponentExtension(); | 1191 InitComponentExtension(); |
| 1186 manager_->AddObserver(&observer); | 1192 manager_->AddObserver(&observer); |
| 1187 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 1193 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 1188 std::vector<std::string> ids; | 1194 std::vector<std::string> ids; |
| 1189 ids.push_back(ImeIdFromEngineId("xkb:us::eng")); | 1195 ids.push_back(ImeIdFromEngineId("xkb:us::eng")); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1203 extension_ime_util::GetInputMethodID("deadbeef", "engine_id"); | 1209 extension_ime_util::GetInputMethodID("deadbeef", "engine_id"); |
| 1204 const InputMethodDescriptor descriptor(ext_id, | 1210 const InputMethodDescriptor descriptor(ext_id, |
| 1205 "deadbeef input method", | 1211 "deadbeef input method", |
| 1206 "DB", | 1212 "DB", |
| 1207 layouts, | 1213 layouts, |
| 1208 languages, | 1214 languages, |
| 1209 false, // is_login_keyboard | 1215 false, // is_login_keyboard |
| 1210 GURL(), | 1216 GURL(), |
| 1211 GURL()); | 1217 GURL()); |
| 1212 MockInputMethodEngine engine(descriptor); | 1218 MockInputMethodEngine engine(descriptor); |
| 1213 manager_->AddInputMethodExtension(ext_id, &engine); | 1219 manager_->AddInputMethodExtension(GetProfile(), ext_id, &engine); |
| 1214 | 1220 |
| 1215 // Extension IME is not enabled by default. | 1221 // Extension IME is not enabled by default. |
| 1216 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1222 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |
| 1217 EXPECT_EQ(1, observer.input_method_changed_count_); | 1223 EXPECT_EQ(1, observer.input_method_changed_count_); |
| 1218 | 1224 |
| 1219 std::vector<std::string> extension_ime_ids; | 1225 std::vector<std::string> extension_ime_ids; |
| 1220 extension_ime_ids.push_back(ext_id); | 1226 extension_ime_ids.push_back(ext_id); |
| 1221 manager_->SetEnabledExtensionImes(&extension_ime_ids); | 1227 manager_->SetEnabledExtensionImes(&extension_ime_ids); |
| 1222 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1228 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
| 1223 | 1229 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1299 ASSERT_EQ(4U, input_method_ids.size()); | 1305 ASSERT_EQ(4U, input_method_ids.size()); |
| 1300 | 1306 |
| 1301 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), input_method_ids[0]); | 1307 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), input_method_ids[0]); |
| 1302 EXPECT_EQ(ImeIdFromEngineId("xkb:fr::fra"), input_method_ids[1]); | 1308 EXPECT_EQ(ImeIdFromEngineId("xkb:fr::fra"), input_method_ids[1]); |
| 1303 EXPECT_EQ("_comp_ime_asdf_pinyin", input_method_ids[2]); | 1309 EXPECT_EQ("_comp_ime_asdf_pinyin", input_method_ids[2]); |
| 1304 EXPECT_EQ(ImeIdFromEngineId("zh-t-i0-pinyin"), input_method_ids[3]); | 1310 EXPECT_EQ(ImeIdFromEngineId("zh-t-i0-pinyin"), input_method_ids[3]); |
| 1305 } | 1311 } |
| 1306 | 1312 |
| 1307 } // namespace input_method | 1313 } // namespace input_method |
| 1308 } // namespace chromeos | 1314 } // namespace chromeos |
| OLD | NEW |