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" | |
10 #include "ash/ime/input_method_menu_manager.h" | |
11 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
12 #include "base/bind.h" | 10 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
14 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
15 #include "base/logging.h" | 13 #include "base/logging.h" |
16 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
17 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
18 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
19 #include "chrome/browser/chromeos/input_method/input_method_engine_interface.h" | 17 #include "chrome/browser/chromeos/input_method/input_method_engine_interface.h" |
20 #include "chrome/browser/chromeos/input_method/mock_candidate_window_controller.
h" | 18 #include "chrome/browser/chromeos/input_method/mock_candidate_window_controller.
h" |
21 #include "chrome/browser/chromeos/input_method/mock_input_method_engine.h" | 19 #include "chrome/browser/chromeos/input_method/mock_input_method_engine.h" |
22 #include "chrome/test/base/browser_with_test_window_test.h" | 20 #include "chrome/test/base/browser_with_test_window_test.h" |
23 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
24 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
25 #include "chrome/test/base/testing_profile_manager.h" | 23 #include "chrome/test/base/testing_profile_manager.h" |
26 #include "chromeos/ime/extension_ime_util.h" | 24 #include "chromeos/ime/extension_ime_util.h" |
27 #include "chromeos/ime/fake_ime_keyboard.h" | 25 #include "chromeos/ime/fake_ime_keyboard.h" |
28 #include "chromeos/ime/fake_input_method_delegate.h" | 26 #include "chromeos/ime/fake_input_method_delegate.h" |
29 #include "chromeos/ime/mock_component_extension_ime_manager_delegate.h" | 27 #include "chromeos/ime/mock_component_extension_ime_manager_delegate.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
31 #include "ui/base/accelerators/accelerator.h" | 29 #include "ui/base/accelerators/accelerator.h" |
32 #include "ui/base/ime/chromeos/mock_ime_engine_handler.h" | 30 #include "ui/base/ime/chromeos/mock_ime_engine_handler.h" |
33 #include "ui/base/ime/input_method_initializer.h" | 31 #include "ui/base/ime/input_method_initializer.h" |
| 32 #include "ui/chromeos/ime/input_method_menu_item.h" |
| 33 #include "ui/chromeos/ime/input_method_menu_manager.h" |
34 #include "ui/events/keycodes/keyboard_codes.h" | 34 #include "ui/events/keycodes/keyboard_codes.h" |
35 | 35 |
36 namespace chromeos { | 36 namespace chromeos { |
37 | 37 |
38 namespace input_method { | 38 namespace input_method { |
39 namespace { | 39 namespace { |
40 | 40 |
41 const char kNaclMozcUsId[] = "nacl_mozc_us"; | 41 const char kNaclMozcUsId[] = "nacl_mozc_us"; |
42 const char kNaclMozcJpId[] = "nacl_mozc_jp"; | 42 const char kNaclMozcJpId[] = "nacl_mozc_jp"; |
43 const char kExt2Engine1Id[] = "ext2_engine1-t-i0-engine_id"; | 43 const char kExt2Engine1Id[] = "ext2_engine1-t-i0-engine_id"; |
(...skipping 10 matching lines...) Expand all Loading... |
54 return true; | 54 return true; |
55 } | 55 } |
56 return false; | 56 return false; |
57 } | 57 } |
58 | 58 |
59 std::string ImeIdFromEngineId(const std::string& id) { | 59 std::string ImeIdFromEngineId(const std::string& id) { |
60 return extension_ime_util::GetInputMethodIDByEngineID(id); | 60 return extension_ime_util::GetInputMethodIDByEngineID(id); |
61 } | 61 } |
62 | 62 |
63 class TestObserver : public InputMethodManager::Observer, | 63 class TestObserver : public InputMethodManager::Observer, |
64 public ash::ime::InputMethodMenuManager::Observer { | 64 public ui::ime::InputMethodMenuManager::Observer { |
65 public: | 65 public: |
66 TestObserver() | 66 TestObserver() |
67 : input_method_changed_count_(0), | 67 : input_method_changed_count_(0), |
68 input_method_menu_item_changed_count_(0), | 68 input_method_menu_item_changed_count_(0), |
69 last_show_message_(false) { | 69 last_show_message_(false) { |
70 } | 70 } |
71 virtual ~TestObserver() {} | 71 virtual ~TestObserver() {} |
72 | 72 |
73 virtual void InputMethodChanged(InputMethodManager* manager, | 73 virtual void InputMethodChanged(InputMethodManager* manager, |
74 bool show_message) override { | 74 bool show_message) override { |
75 ++input_method_changed_count_; | 75 ++input_method_changed_count_; |
76 last_show_message_ = show_message; | 76 last_show_message_ = show_message; |
77 } | 77 } |
78 virtual void InputMethodMenuItemChanged( | 78 virtual void InputMethodMenuItemChanged( |
79 ash::ime::InputMethodMenuManager* manager) override { | 79 ui::ime::InputMethodMenuManager* manager) override { |
80 ++input_method_menu_item_changed_count_; | 80 ++input_method_menu_item_changed_count_; |
81 } | 81 } |
82 | 82 |
83 int input_method_changed_count_; | 83 int input_method_changed_count_; |
84 int input_method_menu_item_changed_count_; | 84 int input_method_menu_item_changed_count_; |
85 bool last_show_message_; | 85 bool last_show_message_; |
86 | 86 |
87 private: | 87 private: |
88 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 88 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
89 }; | 89 }; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 manager_->GetInputMethodUtil()->UpdateHardwareLayoutCache(); | 134 manager_->GetInputMethodUtil()->UpdateHardwareLayoutCache(); |
135 candidate_window_controller_ = new MockCandidateWindowController; | 135 candidate_window_controller_ = new MockCandidateWindowController; |
136 manager_->SetCandidateWindowControllerForTesting( | 136 manager_->SetCandidateWindowControllerForTesting( |
137 candidate_window_controller_); | 137 candidate_window_controller_); |
138 keyboard_ = new FakeImeKeyboard; | 138 keyboard_ = new FakeImeKeyboard; |
139 manager_->SetImeKeyboardForTesting(keyboard_); | 139 manager_->SetImeKeyboardForTesting(keyboard_); |
140 mock_engine_handler_.reset(new MockInputMethodEngine()); | 140 mock_engine_handler_.reset(new MockInputMethodEngine()); |
141 IMEBridge::Initialize(); | 141 IMEBridge::Initialize(); |
142 IMEBridge::Get()->SetCurrentEngineHandler(mock_engine_handler_.get()); | 142 IMEBridge::Get()->SetCurrentEngineHandler(mock_engine_handler_.get()); |
143 | 143 |
144 menu_manager_ = ash::ime::InputMethodMenuManager::GetInstance(); | 144 menu_manager_ = ui::ime::InputMethodMenuManager::GetInstance(); |
145 | 145 |
146 InitImeList(); | 146 InitImeList(); |
147 | 147 |
148 BrowserWithTestWindowTest::SetUp(); | 148 BrowserWithTestWindowTest::SetUp(); |
149 } | 149 } |
150 | 150 |
151 virtual void TearDown() override { | 151 virtual void TearDown() override { |
152 BrowserWithTestWindowTest::TearDown(); | 152 BrowserWithTestWindowTest::TearDown(); |
153 | 153 |
154 ui::ShutdownInputMethodForTesting(); | 154 ui::ShutdownInputMethodForTesting(); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 } | 318 } |
319 | 319 |
320 scoped_ptr<TestingProfileManager> profile_manager_; | 320 scoped_ptr<TestingProfileManager> profile_manager_; |
321 scoped_ptr<InputMethodManagerImpl> manager_; | 321 scoped_ptr<InputMethodManagerImpl> manager_; |
322 FakeInputMethodDelegate* delegate_; | 322 FakeInputMethodDelegate* delegate_; |
323 MockCandidateWindowController* candidate_window_controller_; | 323 MockCandidateWindowController* candidate_window_controller_; |
324 scoped_ptr<MockInputMethodEngine> mock_engine_handler_; | 324 scoped_ptr<MockInputMethodEngine> mock_engine_handler_; |
325 FakeImeKeyboard* keyboard_; | 325 FakeImeKeyboard* keyboard_; |
326 MockComponentExtIMEManagerDelegate* mock_delegate_; | 326 MockComponentExtIMEManagerDelegate* mock_delegate_; |
327 std::vector<ComponentExtensionIME> ime_list_; | 327 std::vector<ComponentExtensionIME> ime_list_; |
328 ash::ime::InputMethodMenuManager* menu_manager_; | 328 ui::ime::InputMethodMenuManager* menu_manager_; |
329 | 329 |
330 private: | 330 private: |
331 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImplTest); | 331 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImplTest); |
332 }; | 332 }; |
333 | 333 |
334 TEST_F(InputMethodManagerImplTest, TestGetImeKeyboard) { | 334 TEST_F(InputMethodManagerImplTest, TestGetImeKeyboard) { |
335 EXPECT_TRUE(manager_->GetImeKeyboard()); | 335 EXPECT_TRUE(manager_->GetImeKeyboard()); |
336 EXPECT_EQ(keyboard_, manager_->GetImeKeyboard()); | 336 EXPECT_EQ(keyboard_, manager_->GetImeKeyboard()); |
337 } | 337 } |
338 | 338 |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 // Disable Dvorak. | 792 // Disable Dvorak. |
793 ids.erase(ids.begin()); | 793 ids.erase(ids.begin()); |
794 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); | 794 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
795 EXPECT_EQ(3U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); | 795 EXPECT_EQ(3U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
796 EXPECT_EQ(6, keyboard_->set_current_keyboard_layout_by_name_count_); | 796 EXPECT_EQ(6, keyboard_->set_current_keyboard_layout_by_name_count_); |
797 EXPECT_EQ("us(colemak)", keyboard_->last_layout_); | 797 EXPECT_EQ("us(colemak)", keyboard_->last_layout_); |
798 } | 798 } |
799 | 799 |
800 TEST_F(InputMethodManagerImplTest, TestActivateInputMethodMenuItem) { | 800 TEST_F(InputMethodManagerImplTest, TestActivateInputMethodMenuItem) { |
801 const std::string kKey = "key"; | 801 const std::string kKey = "key"; |
802 ash::ime::InputMethodMenuItemList menu_list; | 802 ui::ime::InputMethodMenuItemList menu_list; |
803 menu_list.push_back(ash::ime::InputMethodMenuItem( | 803 menu_list.push_back(ui::ime::InputMethodMenuItem( |
804 kKey, "label", false, false)); | 804 kKey, "label", false, false)); |
805 menu_manager_->SetCurrentInputMethodMenuItemList(menu_list); | 805 menu_manager_->SetCurrentInputMethodMenuItemList(menu_list); |
806 | 806 |
807 manager_->ActivateInputMethodMenuItem(kKey); | 807 manager_->ActivateInputMethodMenuItem(kKey); |
808 EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property()); | 808 EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property()); |
809 | 809 |
810 // Key2 is not registered, so activated property should not be changed. | 810 // Key2 is not registered, so activated property should not be changed. |
811 manager_->ActivateInputMethodMenuItem("key2"); | 811 manager_->ActivateInputMethodMenuItem("key2"); |
812 EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property()); | 812 EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property()); |
813 } | 813 } |
814 | 814 |
815 TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodProperties) { | 815 TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodProperties) { |
816 InitComponentExtension(); | 816 InitComponentExtension(); |
817 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); | 817 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); |
818 | 818 |
819 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); | 819 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
820 std::vector<std::string> ids; | 820 std::vector<std::string> ids; |
821 ids.push_back(ImeIdFromEngineId("xkb:us::eng")); | 821 ids.push_back(ImeIdFromEngineId("xkb:us::eng")); |
822 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId)); | 822 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId)); |
823 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); | 823 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
824 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); | 824 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
825 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); | 825 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); |
826 manager_->GetActiveIMEState()->ChangeInputMethod( | 826 manager_->GetActiveIMEState()->ChangeInputMethod( |
827 ImeIdFromEngineId(kNaclMozcUsId), false /* show_message */); | 827 ImeIdFromEngineId(kNaclMozcUsId), false /* show_message */); |
828 | 828 |
829 ash::ime::InputMethodMenuItemList current_property_list; | 829 ui::ime::InputMethodMenuItemList current_property_list; |
830 current_property_list.push_back(ash::ime::InputMethodMenuItem( | 830 current_property_list.push_back(ui::ime::InputMethodMenuItem( |
831 "key", "label", false, false)); | 831 "key", "label", false, false)); |
832 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list); | 832 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list); |
833 | 833 |
834 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size()); | 834 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size()); |
835 EXPECT_EQ("key", | 835 EXPECT_EQ("key", |
836 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key); | 836 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key); |
837 | 837 |
838 manager_->GetActiveIMEState()->ChangeInputMethod("xkb:us::eng", | 838 manager_->GetActiveIMEState()->ChangeInputMethod("xkb:us::eng", |
839 false /* show_message */); | 839 false /* show_message */); |
840 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); | 840 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); |
841 } | 841 } |
842 | 842 |
843 TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodPropertiesTwoImes) { | 843 TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodPropertiesTwoImes) { |
844 InitComponentExtension(); | 844 InitComponentExtension(); |
845 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); | 845 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); |
846 | 846 |
847 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); | 847 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
848 std::vector<std::string> ids; | 848 std::vector<std::string> ids; |
849 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId)); // Japanese | 849 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId)); // Japanese |
850 ids.push_back(ImeIdFromEngineId(kExt2Engine1Id)); // T-Chinese | 850 ids.push_back(ImeIdFromEngineId(kExt2Engine1Id)); // T-Chinese |
851 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); | 851 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
852 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); | 852 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
853 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); | 853 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); |
854 | 854 |
855 ash::ime::InputMethodMenuItemList current_property_list; | 855 ui::ime::InputMethodMenuItemList current_property_list; |
856 current_property_list.push_back(ash::ime::InputMethodMenuItem("key-mozc", | 856 current_property_list.push_back(ui::ime::InputMethodMenuItem("key-mozc", |
857 "label", | 857 "label", |
858 false, | 858 false, |
859 false)); | 859 false)); |
860 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list); | 860 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list); |
861 | 861 |
862 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size()); | 862 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size()); |
863 EXPECT_EQ("key-mozc", | 863 EXPECT_EQ("key-mozc", |
864 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key); | 864 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key); |
865 | 865 |
866 manager_->GetActiveIMEState()->ChangeInputMethod( | 866 manager_->GetActiveIMEState()->ChangeInputMethod( |
867 ImeIdFromEngineId(kExt2Engine1Id), false /* show_message */); | 867 ImeIdFromEngineId(kExt2Engine1Id), false /* show_message */); |
868 // Since the IME is changed, the property for mozc Japanese should be hidden. | 868 // Since the IME is changed, the property for mozc Japanese should be hidden. |
869 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); | 869 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); |
870 | 870 |
871 // Asynchronous property update signal from mozc-chewing. | 871 // Asynchronous property update signal from mozc-chewing. |
872 current_property_list.clear(); | 872 current_property_list.clear(); |
873 current_property_list.push_back(ash::ime::InputMethodMenuItem( | 873 current_property_list.push_back(ui::ime::InputMethodMenuItem( |
874 "key-chewing", "label", false, false)); | 874 "key-chewing", "label", false, false)); |
875 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list); | 875 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list); |
876 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size()); | 876 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size()); |
877 EXPECT_EQ("key-chewing", | 877 EXPECT_EQ("key-chewing", |
878 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key); | 878 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key); |
879 } | 879 } |
880 | 880 |
881 TEST_F(InputMethodManagerImplTest, TestNextInputMethod) { | 881 TEST_F(InputMethodManagerImplTest, TestNextInputMethod) { |
882 TestObserver observer; | 882 TestObserver observer; |
883 manager_->AddObserver(&observer); | 883 manager_->AddObserver(&observer); |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1391 ASSERT_EQ(4U, input_method_ids.size()); | 1391 ASSERT_EQ(4U, input_method_ids.size()); |
1392 | 1392 |
1393 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), input_method_ids[0]); | 1393 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), input_method_ids[0]); |
1394 EXPECT_EQ(ImeIdFromEngineId("xkb:fr::fra"), input_method_ids[1]); | 1394 EXPECT_EQ(ImeIdFromEngineId("xkb:fr::fra"), input_method_ids[1]); |
1395 EXPECT_EQ("_comp_ime_asdf_pinyin", input_method_ids[2]); | 1395 EXPECT_EQ("_comp_ime_asdf_pinyin", input_method_ids[2]); |
1396 EXPECT_EQ(ImeIdFromEngineId("zh-t-i0-pinyin"), input_method_ids[3]); | 1396 EXPECT_EQ(ImeIdFromEngineId("zh-t-i0-pinyin"), input_method_ids[3]); |
1397 } | 1397 } |
1398 | 1398 |
1399 } // namespace input_method | 1399 } // namespace input_method |
1400 } // namespace chromeos | 1400 } // namespace chromeos |
OLD | NEW |