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 <stddef.h> | 7 #include <stddef.h> |
| 8 |
8 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> |
9 #include <utility> | 11 #include <utility> |
10 | 12 |
11 #include "base/bind.h" | 13 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
13 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
14 #include "base/logging.h" | 16 #include "base/logging.h" |
15 #include "base/macros.h" | 17 #include "base/macros.h" |
16 #include "base/memory/scoped_ptr.h" | |
17 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
18 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
19 #include "chrome/browser/chromeos/input_method/mock_candidate_window_controller.
h" | 20 #include "chrome/browser/chromeos/input_method/mock_candidate_window_controller.
h" |
20 #include "chrome/browser/chromeos/input_method/mock_input_method_engine.h" | 21 #include "chrome/browser/chromeos/input_method/mock_input_method_engine.h" |
21 #include "chrome/browser/profiles/profile_manager.h" | 22 #include "chrome/browser/profiles/profile_manager.h" |
22 #include "chrome/test/base/browser_with_test_window_test.h" | 23 #include "chrome/test/base/browser_with_test_window_test.h" |
23 #include "chrome/test/base/testing_browser_process.h" | 24 #include "chrome/test/base/testing_browser_process.h" |
24 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
25 #include "chrome/test/base/testing_profile_manager.h" | 26 #include "chrome/test/base/testing_profile_manager.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 ~InputMethodManagerImplTest() override {} | 128 ~InputMethodManagerImplTest() override {} |
128 | 129 |
129 void SetUp() override { | 130 void SetUp() override { |
130 profile_manager_.reset(new TestingProfileManager(GetBrowserProcess())); | 131 profile_manager_.reset(new TestingProfileManager(GetBrowserProcess())); |
131 ASSERT_TRUE(profile_manager_->SetUp()); | 132 ASSERT_TRUE(profile_manager_->SetUp()); |
132 | 133 |
133 ui::InitializeInputMethodForTesting(); | 134 ui::InitializeInputMethodForTesting(); |
134 | 135 |
135 delegate_ = new FakeInputMethodDelegate(); | 136 delegate_ = new FakeInputMethodDelegate(); |
136 manager_.reset(new InputMethodManagerImpl( | 137 manager_.reset(new InputMethodManagerImpl( |
137 scoped_ptr<InputMethodDelegate>(delegate_), false)); | 138 std::unique_ptr<InputMethodDelegate>(delegate_), false)); |
138 manager_->GetInputMethodUtil()->UpdateHardwareLayoutCache(); | 139 manager_->GetInputMethodUtil()->UpdateHardwareLayoutCache(); |
139 candidate_window_controller_ = new MockCandidateWindowController; | 140 candidate_window_controller_ = new MockCandidateWindowController; |
140 manager_->SetCandidateWindowControllerForTesting( | 141 manager_->SetCandidateWindowControllerForTesting( |
141 candidate_window_controller_); | 142 candidate_window_controller_); |
142 keyboard_ = new FakeImeKeyboard; | 143 keyboard_ = new FakeImeKeyboard; |
143 manager_->SetImeKeyboardForTesting(keyboard_); | 144 manager_->SetImeKeyboardForTesting(keyboard_); |
144 mock_engine_handler_.reset(new MockInputMethodEngine()); | 145 mock_engine_handler_.reset(new MockInputMethodEngine()); |
145 ui::IMEBridge::Initialize(); | 146 ui::IMEBridge::Initialize(); |
146 ui::IMEBridge::Get()->SetCurrentEngineHandler(mock_engine_handler_.get()); | 147 ui::IMEBridge::Get()->SetCurrentEngineHandler(mock_engine_handler_.get()); |
147 | 148 |
(...skipping 15 matching lines...) Expand all Loading... |
163 manager_.reset(); | 164 manager_.reset(); |
164 | 165 |
165 profile_manager_.reset(); | 166 profile_manager_.reset(); |
166 } | 167 } |
167 | 168 |
168 protected: | 169 protected: |
169 // Helper function to initialize component extension stuff for testing. | 170 // Helper function to initialize component extension stuff for testing. |
170 void InitComponentExtension() { | 171 void InitComponentExtension() { |
171 mock_delegate_ = new MockComponentExtIMEManagerDelegate(); | 172 mock_delegate_ = new MockComponentExtIMEManagerDelegate(); |
172 mock_delegate_->set_ime_list(ime_list_); | 173 mock_delegate_->set_ime_list(ime_list_); |
173 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(mock_delegate_); | 174 std::unique_ptr<ComponentExtensionIMEManagerDelegate> delegate( |
| 175 mock_delegate_); |
174 | 176 |
175 // CreateNewState(NULL) returns state with non-empty current_input_method. | 177 // CreateNewState(NULL) returns state with non-empty current_input_method. |
176 // So SetState() triggers ChangeInputMethod(). | 178 // So SetState() triggers ChangeInputMethod(). |
177 manager_->SetState( | 179 manager_->SetState( |
178 manager_->CreateNewState(ProfileManager::GetActiveUserProfile())); | 180 manager_->CreateNewState(ProfileManager::GetActiveUserProfile())); |
179 | 181 |
180 std::vector<std::string> layouts; | 182 std::vector<std::string> layouts; |
181 layouts.push_back("us"); | 183 layouts.push_back("us"); |
182 std::vector<std::string> languages; | 184 std::vector<std::string> languages; |
183 languages.push_back("en-US"); | 185 languages.push_back("en-US"); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 ext2_engine2.layouts.push_back("us(dvorak)"); | 340 ext2_engine2.layouts.push_back("us(dvorak)"); |
339 ext2.engines.push_back(ext2_engine2); | 341 ext2.engines.push_back(ext2_engine2); |
340 | 342 |
341 ime_list_.push_back(ext2); | 343 ime_list_.push_back(ext2); |
342 } | 344 } |
343 | 345 |
344 TestingBrowserProcess* GetBrowserProcess() { | 346 TestingBrowserProcess* GetBrowserProcess() { |
345 return TestingBrowserProcess::GetGlobal(); | 347 return TestingBrowserProcess::GetGlobal(); |
346 } | 348 } |
347 | 349 |
348 scoped_ptr<TestingProfileManager> profile_manager_; | 350 std::unique_ptr<TestingProfileManager> profile_manager_; |
349 scoped_ptr<InputMethodManagerImpl> manager_; | 351 std::unique_ptr<InputMethodManagerImpl> manager_; |
350 FakeInputMethodDelegate* delegate_; | 352 FakeInputMethodDelegate* delegate_; |
351 MockCandidateWindowController* candidate_window_controller_; | 353 MockCandidateWindowController* candidate_window_controller_; |
352 scoped_ptr<MockInputMethodEngine> mock_engine_handler_; | 354 std::unique_ptr<MockInputMethodEngine> mock_engine_handler_; |
353 FakeImeKeyboard* keyboard_; | 355 FakeImeKeyboard* keyboard_; |
354 MockComponentExtIMEManagerDelegate* mock_delegate_; | 356 MockComponentExtIMEManagerDelegate* mock_delegate_; |
355 std::vector<ComponentExtensionIME> ime_list_; | 357 std::vector<ComponentExtensionIME> ime_list_; |
356 ui::ime::InputMethodMenuManager* menu_manager_; | 358 ui::ime::InputMethodMenuManager* menu_manager_; |
357 | 359 |
358 private: | 360 private: |
359 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImplTest); | 361 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImplTest); |
360 }; | 362 }; |
361 | 363 |
362 TEST_F(InputMethodManagerImplTest, TestGetImeKeyboard) { | 364 TEST_F(InputMethodManagerImplTest, TestGetImeKeyboard) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 // xkb:us:eng | 522 // xkb:us:eng |
521 EXPECT_EQ(1U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); | 523 EXPECT_EQ(1U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
522 } | 524 } |
523 | 525 |
524 TEST_F(InputMethodManagerImplTest, TestActiveInputMethods) { | 526 TEST_F(InputMethodManagerImplTest, TestActiveInputMethods) { |
525 InitComponentExtension(); | 527 InitComponentExtension(); |
526 std::vector<std::string> keyboard_layouts; | 528 std::vector<std::string> keyboard_layouts; |
527 manager_->GetActiveIMEState()->EnableLoginLayouts( | 529 manager_->GetActiveIMEState()->EnableLoginLayouts( |
528 "ja", keyboard_layouts); // Japanese | 530 "ja", keyboard_layouts); // Japanese |
529 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); | 531 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
530 scoped_ptr<InputMethodDescriptors> methods( | 532 std::unique_ptr<InputMethodDescriptors> methods( |
531 manager_->GetActiveIMEState()->GetActiveInputMethods()); | 533 manager_->GetActiveIMEState()->GetActiveInputMethods()); |
532 ASSERT_TRUE(methods.get()); | 534 ASSERT_TRUE(methods.get()); |
533 EXPECT_EQ(2U, methods->size()); | 535 EXPECT_EQ(2U, methods->size()); |
534 const InputMethodDescriptor* id_to_find = | 536 const InputMethodDescriptor* id_to_find = |
535 manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( | 537 manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( |
536 ImeIdFromEngineId("xkb:us::eng")); | 538 ImeIdFromEngineId("xkb:us::eng")); |
537 EXPECT_TRUE(id_to_find && Contain(*methods.get(), *id_to_find)); | 539 EXPECT_TRUE(id_to_find && Contain(*methods.get(), *id_to_find)); |
538 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( | 540 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( |
539 ImeIdFromEngineId("xkb:jp::jpn")); | 541 ImeIdFromEngineId("xkb:jp::jpn")); |
540 EXPECT_TRUE(id_to_find && Contain(*methods.get(), *id_to_find)); | 542 EXPECT_TRUE(id_to_find && Contain(*methods.get(), *id_to_find)); |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 | 1218 |
1217 // Extension IMEs are not enabled by default. | 1219 // Extension IMEs are not enabled by default. |
1218 EXPECT_EQ(1U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); | 1220 EXPECT_EQ(1U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
1219 | 1221 |
1220 std::vector<std::string> extension_ime_ids; | 1222 std::vector<std::string> extension_ime_ids; |
1221 extension_ime_ids.push_back(ext1_id); | 1223 extension_ime_ids.push_back(ext1_id); |
1222 manager_->GetActiveIMEState()->SetEnabledExtensionImes(&extension_ime_ids); | 1224 manager_->GetActiveIMEState()->SetEnabledExtensionImes(&extension_ime_ids); |
1223 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); | 1225 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
1224 | 1226 |
1225 { | 1227 { |
1226 scoped_ptr<InputMethodDescriptors> methods( | 1228 std::unique_ptr<InputMethodDescriptors> methods( |
1227 manager_->GetActiveIMEState()->GetActiveInputMethods()); | 1229 manager_->GetActiveIMEState()->GetActiveInputMethods()); |
1228 ASSERT_EQ(2U, methods->size()); | 1230 ASSERT_EQ(2U, methods->size()); |
1229 // Ext IMEs should be at the end of the list. | 1231 // Ext IMEs should be at the end of the list. |
1230 EXPECT_EQ(ext1_id, methods->at(1).id()); | 1232 EXPECT_EQ(ext1_id, methods->at(1).id()); |
1231 } | 1233 } |
1232 | 1234 |
1233 const std::string ext2_id = | 1235 const std::string ext2_id = |
1234 extension_ime_util::GetInputMethodID(kExtensionId2, "engine_id"); | 1236 extension_ime_util::GetInputMethodID(kExtensionId2, "engine_id"); |
1235 const InputMethodDescriptor descriptor2(ext2_id, | 1237 const InputMethodDescriptor descriptor2(ext2_id, |
1236 "cafebabe input method", | 1238 "cafebabe input method", |
1237 "CB", | 1239 "CB", |
1238 layouts, | 1240 layouts, |
1239 languages, | 1241 languages, |
1240 false, // is_login_keyboard | 1242 false, // is_login_keyboard |
1241 GURL(), | 1243 GURL(), |
1242 GURL()); | 1244 GURL()); |
1243 descriptors.clear(); | 1245 descriptors.clear(); |
1244 descriptors.push_back(descriptor2); | 1246 descriptors.push_back(descriptor2); |
1245 MockInputMethodEngine engine2; | 1247 MockInputMethodEngine engine2; |
1246 manager_->GetActiveIMEState()->AddInputMethodExtension( | 1248 manager_->GetActiveIMEState()->AddInputMethodExtension( |
1247 kExtensionId2, descriptors, &engine2); | 1249 kExtensionId2, descriptors, &engine2); |
1248 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); | 1250 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
1249 | 1251 |
1250 extension_ime_ids.push_back(ext2_id); | 1252 extension_ime_ids.push_back(ext2_id); |
1251 manager_->GetActiveIMEState()->SetEnabledExtensionImes(&extension_ime_ids); | 1253 manager_->GetActiveIMEState()->SetEnabledExtensionImes(&extension_ime_ids); |
1252 EXPECT_EQ(3U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); | 1254 EXPECT_EQ(3U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
1253 { | 1255 { |
1254 scoped_ptr<InputMethodDescriptors> methods( | 1256 std::unique_ptr<InputMethodDescriptors> methods( |
1255 manager_->GetActiveIMEState()->GetActiveInputMethods()); | 1257 manager_->GetActiveIMEState()->GetActiveInputMethods()); |
1256 ASSERT_EQ(3U, methods->size()); | 1258 ASSERT_EQ(3U, methods->size()); |
1257 // Ext IMEs should be at the end of the list. | 1259 // Ext IMEs should be at the end of the list. |
1258 EXPECT_EQ(ext1_id, methods->at(1).id()); | 1260 EXPECT_EQ(ext1_id, methods->at(1).id()); |
1259 EXPECT_EQ(ext2_id, methods->at(2).id()); | 1261 EXPECT_EQ(ext2_id, methods->at(2).id()); |
1260 } | 1262 } |
1261 | 1263 |
1262 // Remove them. | 1264 // Remove them. |
1263 manager_->GetActiveIMEState()->RemoveInputMethodExtension(kExtensionId1); | 1265 manager_->GetActiveIMEState()->RemoveInputMethodExtension(kExtensionId1); |
1264 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); | 1266 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 | 1335 |
1334 // Unlock the screen. | 1336 // Unlock the screen. |
1335 manager_->SetState(saved_ime_state); | 1337 manager_->SetState(saved_ime_state); |
1336 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); | 1338 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
1337 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); | 1339 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
1338 EXPECT_EQ(ext_id, | 1340 EXPECT_EQ(ext_id, |
1339 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); | 1341 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
1340 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 1342 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
1341 { | 1343 { |
1342 // This is for crosbug.com/27052. | 1344 // This is for crosbug.com/27052. |
1343 scoped_ptr<InputMethodDescriptors> methods( | 1345 std::unique_ptr<InputMethodDescriptors> methods( |
1344 manager_->GetActiveIMEState()->GetActiveInputMethods()); | 1346 manager_->GetActiveIMEState()->GetActiveInputMethods()); |
1345 ASSERT_EQ(2U, methods->size()); | 1347 ASSERT_EQ(2U, methods->size()); |
1346 // Ext. IMEs should be at the end of the list. | 1348 // Ext. IMEs should be at the end of the list. |
1347 EXPECT_EQ(ext_id, methods->at(1).id()); | 1349 EXPECT_EQ(ext_id, methods->at(1).id()); |
1348 } | 1350 } |
1349 manager_->RemoveObserver(&observer); | 1351 manager_->RemoveObserver(&observer); |
1350 } | 1352 } |
1351 | 1353 |
1352 TEST_F(InputMethodManagerImplTest, | 1354 TEST_F(InputMethodManagerImplTest, |
1353 ChangeInputMethod_ComponenteExtensionOneIME) { | 1355 ChangeInputMethod_ComponenteExtensionOneIME) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1402 ASSERT_EQ(4U, input_method_ids.size()); | 1404 ASSERT_EQ(4U, input_method_ids.size()); |
1403 | 1405 |
1404 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), input_method_ids[0]); | 1406 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), input_method_ids[0]); |
1405 EXPECT_EQ(ImeIdFromEngineId("xkb:fr::fra"), input_method_ids[1]); | 1407 EXPECT_EQ(ImeIdFromEngineId("xkb:fr::fra"), input_method_ids[1]); |
1406 EXPECT_EQ("_comp_ime_asdf_pinyin", input_method_ids[2]); | 1408 EXPECT_EQ("_comp_ime_asdf_pinyin", input_method_ids[2]); |
1407 EXPECT_EQ(ImeIdFromEngineId("zh-t-i0-pinyin"), input_method_ids[3]); | 1409 EXPECT_EQ(ImeIdFromEngineId("zh-t-i0-pinyin"), input_method_ids[3]); |
1408 } | 1410 } |
1409 | 1411 |
1410 } // namespace input_method | 1412 } // namespace input_method |
1411 } // namespace chromeos | 1413 } // namespace chromeos |
OLD | NEW |