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 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 } | 129 } |
130 ~InputMethodManagerImplTest() override {} | 130 ~InputMethodManagerImplTest() override {} |
131 | 131 |
132 void SetUp() override { | 132 void SetUp() override { |
133 profile_manager_.reset(new TestingProfileManager(GetBrowserProcess())); | 133 profile_manager_.reset(new TestingProfileManager(GetBrowserProcess())); |
134 ASSERT_TRUE(profile_manager_->SetUp()); | 134 ASSERT_TRUE(profile_manager_->SetUp()); |
135 | 135 |
136 ui::InitializeInputMethodForTesting(); | 136 ui::InitializeInputMethodForTesting(); |
137 | 137 |
138 delegate_ = new FakeInputMethodDelegate(); | 138 delegate_ = new FakeInputMethodDelegate(); |
139 manager_.reset(new InputMethodManagerImpl( | 139 manager_ = new InputMethodManagerImpl( |
140 std::unique_ptr<InputMethodDelegate>(delegate_), false)); | 140 std::unique_ptr<InputMethodDelegate>(delegate_), false); |
| 141 InputMethodManager::Initialize(manager_); // Takes ownership. |
141 manager_->GetInputMethodUtil()->UpdateHardwareLayoutCache(); | 142 manager_->GetInputMethodUtil()->UpdateHardwareLayoutCache(); |
142 candidate_window_controller_ = new MockCandidateWindowController; | 143 candidate_window_controller_ = new MockCandidateWindowController; |
143 manager_->SetCandidateWindowControllerForTesting( | 144 manager_->SetCandidateWindowControllerForTesting( |
144 candidate_window_controller_); | 145 candidate_window_controller_); |
145 keyboard_ = new FakeImeKeyboard; | 146 keyboard_ = new FakeImeKeyboard; |
146 manager_->SetImeKeyboardForTesting(keyboard_); | 147 manager_->SetImeKeyboardForTesting(keyboard_); |
147 mock_engine_handler_.reset(new MockInputMethodEngine()); | 148 mock_engine_handler_.reset(new MockInputMethodEngine()); |
148 ui::IMEBridge::Initialize(); | 149 ui::IMEBridge::Initialize(); |
149 ui::IMEBridge::Get()->SetCurrentEngineHandler(mock_engine_handler_.get()); | 150 ui::IMEBridge::Get()->SetCurrentEngineHandler(mock_engine_handler_.get()); |
150 | 151 |
151 menu_manager_ = ui::ime::InputMethodMenuManager::GetInstance(); | 152 menu_manager_ = ui::ime::InputMethodMenuManager::GetInstance(); |
152 | 153 |
153 InitImeList(); | 154 InitImeList(); |
154 | 155 |
155 BrowserWithTestWindowTest::SetUp(); | 156 BrowserWithTestWindowTest::SetUp(); |
156 } | 157 } |
157 | 158 |
158 void TearDown() override { | 159 void TearDown() override { |
159 BrowserWithTestWindowTest::TearDown(); | 160 BrowserWithTestWindowTest::TearDown(); |
160 | 161 |
161 ui::ShutdownInputMethodForTesting(); | 162 ui::ShutdownInputMethodForTesting(); |
162 | 163 |
163 delegate_ = NULL; | 164 delegate_ = NULL; |
164 candidate_window_controller_ = NULL; | 165 candidate_window_controller_ = NULL; |
165 keyboard_ = NULL; | 166 keyboard_ = NULL; |
166 manager_.reset(); | 167 InputMethodManager::Shutdown(); |
| 168 manager_ = nullptr; |
167 | 169 |
168 profile_manager_.reset(); | 170 profile_manager_.reset(); |
169 } | 171 } |
170 | 172 |
171 protected: | 173 protected: |
172 // Helper function to initialize component extension stuff for testing. | 174 // Helper function to initialize component extension stuff for testing. |
173 void InitComponentExtension() { | 175 void InitComponentExtension() { |
174 mock_delegate_ = new MockComponentExtIMEManagerDelegate(); | 176 mock_delegate_ = new MockComponentExtIMEManagerDelegate(); |
175 mock_delegate_->set_ime_list(ime_list_); | 177 mock_delegate_->set_ime_list(ime_list_); |
176 std::unique_ptr<ComponentExtensionIMEManagerDelegate> delegate( | 178 std::unique_ptr<ComponentExtensionIMEManagerDelegate> delegate( |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 ext2.engines.push_back(ext2_engine2); | 345 ext2.engines.push_back(ext2_engine2); |
344 | 346 |
345 ime_list_.push_back(ext2); | 347 ime_list_.push_back(ext2); |
346 } | 348 } |
347 | 349 |
348 TestingBrowserProcess* GetBrowserProcess() { | 350 TestingBrowserProcess* GetBrowserProcess() { |
349 return TestingBrowserProcess::GetGlobal(); | 351 return TestingBrowserProcess::GetGlobal(); |
350 } | 352 } |
351 | 353 |
352 std::unique_ptr<TestingProfileManager> profile_manager_; | 354 std::unique_ptr<TestingProfileManager> profile_manager_; |
353 std::unique_ptr<InputMethodManagerImpl> manager_; | 355 InputMethodManagerImpl* manager_; // Owned by InputMethodManager. |
354 FakeInputMethodDelegate* delegate_; | 356 FakeInputMethodDelegate* delegate_; |
355 MockCandidateWindowController* candidate_window_controller_; | 357 MockCandidateWindowController* candidate_window_controller_; |
356 std::unique_ptr<MockInputMethodEngine> mock_engine_handler_; | 358 std::unique_ptr<MockInputMethodEngine> mock_engine_handler_; |
357 FakeImeKeyboard* keyboard_; | 359 FakeImeKeyboard* keyboard_; |
358 MockComponentExtIMEManagerDelegate* mock_delegate_; | 360 MockComponentExtIMEManagerDelegate* mock_delegate_; |
359 std::vector<ComponentExtensionIME> ime_list_; | 361 std::vector<ComponentExtensionIME> ime_list_; |
360 ui::ime::InputMethodMenuManager* menu_manager_; | 362 ui::ime::InputMethodMenuManager* menu_manager_; |
361 | 363 |
362 private: | 364 private: |
363 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImplTest); | 365 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImplTest); |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 828 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
827 // Disable Dvorak. | 829 // Disable Dvorak. |
828 ids.erase(ids.begin()); | 830 ids.erase(ids.begin()); |
829 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); | 831 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
830 EXPECT_EQ(3U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); | 832 EXPECT_EQ(3U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
831 EXPECT_EQ(7, keyboard_->set_current_keyboard_layout_by_name_count_); | 833 EXPECT_EQ(7, keyboard_->set_current_keyboard_layout_by_name_count_); |
832 EXPECT_EQ("us(colemak)", keyboard_->last_layout_); | 834 EXPECT_EQ("us(colemak)", keyboard_->last_layout_); |
833 } | 835 } |
834 | 836 |
835 TEST_F(InputMethodManagerImplTest, TestActivateInputMethodMenuItem) { | 837 TEST_F(InputMethodManagerImplTest, TestActivateInputMethodMenuItem) { |
| 838 // Activating a menu item triggers observers in ash that assume |
| 839 // GetActiveIMEState() is not null. |
| 840 manager_->SetState(manager_->CreateNewState(nullptr)); |
| 841 ui::IMEBridge::Get()->SetCurrentEngineHandler(mock_engine_handler_.get()); |
| 842 |
836 const std::string kKey = "key"; | 843 const std::string kKey = "key"; |
837 ui::ime::InputMethodMenuItemList menu_list; | 844 ui::ime::InputMethodMenuItemList menu_list; |
838 menu_list.push_back(ui::ime::InputMethodMenuItem( | 845 menu_list.push_back(ui::ime::InputMethodMenuItem( |
839 kKey, "label", false, false)); | 846 kKey, "label", false, false)); |
840 menu_manager_->SetCurrentInputMethodMenuItemList(menu_list); | 847 menu_manager_->SetCurrentInputMethodMenuItemList(menu_list); |
841 | 848 |
842 manager_->ActivateInputMethodMenuItem(kKey); | 849 manager_->ActivateInputMethodMenuItem(kKey); |
843 EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property()); | 850 EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property()); |
844 | 851 |
845 // Key2 is not registered, so activated property should not be changed. | 852 // Key2 is not registered, so activated property should not be changed. |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1555 EXPECT_TRUE(manager_->GetActiveIMEState()->SetAllowedInputMethods(allowed)); | 1562 EXPECT_TRUE(manager_->GetActiveIMEState()->SetAllowedInputMethods(allowed)); |
1556 manager_->GetActiveIMEState()->SetInputMethodLoginDefault(); | 1563 manager_->GetActiveIMEState()->SetInputMethodLoginDefault(); |
1557 EXPECT_THAT(manager_->GetActiveIMEState()->GetActiveInputMethodIds(), | 1564 EXPECT_THAT(manager_->GetActiveIMEState()->GetActiveInputMethodIds(), |
1558 testing::ElementsAre(ImeIdFromEngineId("xkb:us::eng"), | 1565 testing::ElementsAre(ImeIdFromEngineId("xkb:us::eng"), |
1559 ImeIdFromEngineId("xkb:de::ger"), | 1566 ImeIdFromEngineId("xkb:de::ger"), |
1560 ImeIdFromEngineId("xkb:fr::fra"))); | 1567 ImeIdFromEngineId("xkb:fr::fra"))); |
1561 } | 1568 } |
1562 | 1569 |
1563 } // namespace input_method | 1570 } // namespace input_method |
1564 } // namespace chromeos | 1571 } // namespace chromeos |
OLD | NEW |