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 25 matching lines...) Expand all Loading... |
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"; |
44 const char kExt2Engine2Id[] = "ext2_engine2-t-i0-engine_id"; | 44 const char kExt2Engine2Id[] = "ext2_engine2-t-i0-engine_id"; |
45 const char kPinyinImeId[] = "zh-t-i0-pinyin"; | 45 const char kPinyinImeId[] = "zh-t-i0-pinyin"; |
| 46 const char kExtensionId1[] = "00000000000000000000000000000000"; |
| 47 const char kExtensionId2[] = "11111111111111111111111111111111"; |
46 | 48 |
47 // Returns true if |descriptors| contain |target|. | 49 // Returns true if |descriptors| contain |target|. |
48 bool Contain(const InputMethodDescriptors& descriptors, | 50 bool Contain(const InputMethodDescriptors& descriptors, |
49 const InputMethodDescriptor& target) { | 51 const InputMethodDescriptor& target) { |
50 for (size_t i = 0; i < descriptors.size(); ++i) { | 52 for (size_t i = 0; i < descriptors.size(); ++i) { |
51 if (descriptors[i].id() == target.id()) | 53 if (descriptors[i].id() == target.id()) |
52 return true; | 54 return true; |
53 } | 55 } |
54 return false; | 56 return false; |
55 } | 57 } |
(...skipping 19 matching lines...) Expand all Loading... |
75 | 77 |
76 delegate_ = new FakeInputMethodDelegate(); | 78 delegate_ = new FakeInputMethodDelegate(); |
77 manager_.reset(new InputMethodManagerImpl( | 79 manager_.reset(new InputMethodManagerImpl( |
78 scoped_ptr<InputMethodDelegate>(delegate_))); | 80 scoped_ptr<InputMethodDelegate>(delegate_))); |
79 manager_->GetInputMethodUtil()->UpdateHardwareLayoutCache(); | 81 manager_->GetInputMethodUtil()->UpdateHardwareLayoutCache(); |
80 candidate_window_controller_ = new MockCandidateWindowController; | 82 candidate_window_controller_ = new MockCandidateWindowController; |
81 manager_->SetCandidateWindowControllerForTesting( | 83 manager_->SetCandidateWindowControllerForTesting( |
82 candidate_window_controller_); | 84 candidate_window_controller_); |
83 keyboard_ = new FakeImeKeyboard; | 85 keyboard_ = new FakeImeKeyboard; |
84 manager_->SetImeKeyboardForTesting(keyboard_); | 86 manager_->SetImeKeyboardForTesting(keyboard_); |
85 mock_engine_handler_.reset( | 87 mock_engine_handler_.reset(new MockInputMethodEngine()); |
86 new MockInputMethodEngine(InputMethodDescriptor())); | |
87 IMEBridge::Initialize(); | 88 IMEBridge::Initialize(); |
88 IMEBridge::Get()->SetCurrentEngineHandler(mock_engine_handler_.get()); | 89 IMEBridge::Get()->SetCurrentEngineHandler(mock_engine_handler_.get()); |
89 | 90 |
90 menu_manager_ = ash::ime::InputMethodMenuManager::GetInstance(); | 91 menu_manager_ = ash::ime::InputMethodMenuManager::GetInstance(); |
91 | 92 |
92 InitImeList(); | 93 InitImeList(); |
93 | 94 |
94 BrowserWithTestWindowTest::SetUp(); | 95 BrowserWithTestWindowTest::SetUp(); |
95 } | 96 } |
96 | 97 |
(...skipping 10 matching lines...) Expand all Loading... |
107 profile_manager_.reset(); | 108 profile_manager_.reset(); |
108 } | 109 } |
109 | 110 |
110 protected: | 111 protected: |
111 // Helper function to initialize component extension stuff for testing. | 112 // Helper function to initialize component extension stuff for testing. |
112 void InitComponentExtension() { | 113 void InitComponentExtension() { |
113 mock_delegate_ = new MockComponentExtIMEManagerDelegate(); | 114 mock_delegate_ = new MockComponentExtIMEManagerDelegate(); |
114 mock_delegate_->set_ime_list(ime_list_); | 115 mock_delegate_->set_ime_list(ime_list_); |
115 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(mock_delegate_); | 116 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(mock_delegate_); |
116 | 117 |
| 118 std::vector<std::string> layouts; |
| 119 layouts.push_back("us"); |
| 120 std::vector<std::string> languages; |
| 121 languages.push_back("en-US"); |
| 122 |
117 // Note, for production, these SetEngineHandler are called when | 123 // Note, for production, these SetEngineHandler are called when |
118 // IMEEngineHandlerInterface is initialized via | 124 // IMEEngineHandlerInterface is initialized via |
119 // InitializeComponentextension. | 125 // InitializeComponentextension. |
| 126 InputMethodDescriptors descriptors; |
120 manager_->AddInputMethodExtension(ImeIdFromEngineId(kNaclMozcUsId), | 127 manager_->AddInputMethodExtension(ImeIdFromEngineId(kNaclMozcUsId), |
121 mock_engine_handler_.get()); | 128 descriptors, |
122 manager_->AddInputMethodExtension(ImeIdFromEngineId(kNaclMozcJpId), | |
123 mock_engine_handler_.get()); | 129 mock_engine_handler_.get()); |
124 manager_->AddInputMethodExtension(ImeIdFromEngineId(kExt2Engine1Id), | 130 manager_->AddInputMethodExtension(ImeIdFromEngineId(kExt2Engine1Id), |
125 mock_engine_handler_.get()); | 131 descriptors, |
126 manager_->AddInputMethodExtension(ImeIdFromEngineId(kExt2Engine2Id), | |
127 mock_engine_handler_.get()); | 132 mock_engine_handler_.get()); |
128 manager_->InitializeComponentExtensionForTesting(delegate.Pass()); | 133 manager_->InitializeComponentExtensionForTesting(delegate.Pass()); |
129 } | 134 } |
130 | 135 |
131 void InitImeList() { | 136 void InitImeList() { |
132 ime_list_.clear(); | 137 ime_list_.clear(); |
133 | 138 |
134 ComponentExtensionIME ext_xkb; | 139 ComponentExtensionIME ext_xkb; |
135 ext_xkb.id = extension_ime_util::kXkbExtensionId; | 140 ext_xkb.id = extension_ime_util::kXkbExtensionId; |
136 ext_xkb.description = "ext_xkb_description"; | 141 ext_xkb.description = "ext_xkb_description"; |
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id()); | 1117 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id()); |
1113 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 1118 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
1114 | 1119 |
1115 // Add two Extension IMEs. | 1120 // Add two Extension IMEs. |
1116 std::vector<std::string> layouts; | 1121 std::vector<std::string> layouts; |
1117 layouts.push_back("us"); | 1122 layouts.push_back("us"); |
1118 std::vector<std::string> languages; | 1123 std::vector<std::string> languages; |
1119 languages.push_back("en-US"); | 1124 languages.push_back("en-US"); |
1120 | 1125 |
1121 const std::string ext1_id = | 1126 const std::string ext1_id = |
1122 extension_ime_util::GetInputMethodID("deadbeef", "engine_id"); | 1127 extension_ime_util::GetInputMethodID(kExtensionId1, "engine_id"); |
1123 const InputMethodDescriptor descriptor1(ext1_id, | 1128 const InputMethodDescriptor descriptor1(ext1_id, |
1124 "deadbeef input method", | 1129 "deadbeef input method", |
1125 "DB", | 1130 "DB", |
1126 layouts, | 1131 layouts, |
1127 languages, | 1132 languages, |
1128 false, // is_login_keyboard | 1133 false, // is_login_keyboard |
1129 GURL(), | 1134 GURL(), |
1130 GURL()); | 1135 GURL()); |
1131 MockInputMethodEngine engine(descriptor1); | 1136 MockInputMethodEngine engine; |
1132 manager_->AddInputMethodExtension(ext1_id, &engine); | 1137 InputMethodDescriptors descriptors; |
| 1138 descriptors.push_back(descriptor1); |
| 1139 manager_->AddInputMethodExtension(kExtensionId1, descriptors, &engine); |
1133 | 1140 |
1134 // Extension IMEs are not enabled by default. | 1141 // Extension IMEs are not enabled by default. |
1135 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1142 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |
1136 | 1143 |
1137 std::vector<std::string> extension_ime_ids; | 1144 std::vector<std::string> extension_ime_ids; |
1138 extension_ime_ids.push_back(ext1_id); | 1145 extension_ime_ids.push_back(ext1_id); |
1139 manager_->SetEnabledExtensionImes(&extension_ime_ids); | 1146 manager_->SetEnabledExtensionImes(&extension_ime_ids); |
1140 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1147 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
1141 | 1148 |
1142 { | 1149 { |
1143 scoped_ptr<InputMethodDescriptors> methods( | 1150 scoped_ptr<InputMethodDescriptors> methods( |
1144 manager_->GetActiveInputMethods()); | 1151 manager_->GetActiveInputMethods()); |
1145 ASSERT_EQ(2U, methods->size()); | 1152 ASSERT_EQ(2U, methods->size()); |
1146 // Ext IMEs should be at the end of the list. | 1153 // Ext IMEs should be at the end of the list. |
1147 EXPECT_EQ(ext1_id, methods->at(1).id()); | 1154 EXPECT_EQ(ext1_id, methods->at(1).id()); |
1148 } | 1155 } |
1149 | 1156 |
1150 const std::string ext2_id = | 1157 const std::string ext2_id = |
1151 extension_ime_util::GetInputMethodID("cafebabe", "engine_id"); | 1158 extension_ime_util::GetInputMethodID(kExtensionId2, "engine_id"); |
1152 const InputMethodDescriptor descriptor2(ext2_id, | 1159 const InputMethodDescriptor descriptor2(ext2_id, |
1153 "cafebabe input method", | 1160 "cafebabe input method", |
1154 "CB", | 1161 "CB", |
1155 layouts, | 1162 layouts, |
1156 languages, | 1163 languages, |
1157 false, // is_login_keyboard | 1164 false, // is_login_keyboard |
1158 GURL(), | 1165 GURL(), |
1159 GURL()); | 1166 GURL()); |
1160 MockInputMethodEngine engine2(descriptor2); | 1167 descriptors.clear(); |
1161 manager_->AddInputMethodExtension(ext2_id, &engine2); | 1168 descriptors.push_back(descriptor2); |
| 1169 MockInputMethodEngine engine2; |
| 1170 manager_->AddInputMethodExtension(kExtensionId2, descriptors, &engine2); |
1162 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1171 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
1163 | 1172 |
1164 extension_ime_ids.push_back(ext2_id); | 1173 extension_ime_ids.push_back(ext2_id); |
1165 manager_->SetEnabledExtensionImes(&extension_ime_ids); | 1174 manager_->SetEnabledExtensionImes(&extension_ime_ids); |
1166 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); | 1175 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); |
1167 { | 1176 { |
1168 scoped_ptr<InputMethodDescriptors> methods( | 1177 scoped_ptr<InputMethodDescriptors> methods( |
1169 manager_->GetActiveInputMethods()); | 1178 manager_->GetActiveInputMethods()); |
1170 ASSERT_EQ(3U, methods->size()); | 1179 ASSERT_EQ(3U, methods->size()); |
1171 // Ext IMEs should be at the end of the list. | 1180 // Ext IMEs should be at the end of the list. |
1172 EXPECT_EQ(ext1_id, methods->at(1).id()); | 1181 EXPECT_EQ(ext1_id, methods->at(1).id()); |
1173 EXPECT_EQ(ext2_id, methods->at(2).id()); | 1182 EXPECT_EQ(ext2_id, methods->at(2).id()); |
1174 } | 1183 } |
1175 | 1184 |
1176 // Remove them. | 1185 // Remove them. |
1177 manager_->RemoveInputMethodExtension(ext1_id); | 1186 manager_->RemoveInputMethodExtension(kExtensionId1); |
1178 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1187 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
1179 manager_->RemoveInputMethodExtension(ext2_id); | 1188 manager_->RemoveInputMethodExtension(kExtensionId2); |
1180 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1189 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |
1181 } | 1190 } |
1182 | 1191 |
1183 TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) { | 1192 TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) { |
1184 TestObserver observer; | 1193 TestObserver observer; |
1185 InitComponentExtension(); | 1194 InitComponentExtension(); |
1186 manager_->AddObserver(&observer); | 1195 manager_->AddObserver(&observer); |
1187 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 1196 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); |
1188 std::vector<std::string> ids; | 1197 std::vector<std::string> ids; |
1189 ids.push_back(ImeIdFromEngineId("xkb:us::eng")); | 1198 ids.push_back(ImeIdFromEngineId("xkb:us::eng")); |
1190 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 1199 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); |
1191 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1200 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |
1192 EXPECT_EQ(1, observer.input_method_changed_count_); | 1201 EXPECT_EQ(1, observer.input_method_changed_count_); |
1193 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id()); | 1202 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id()); |
1194 EXPECT_EQ("us", keyboard_->last_layout_); | 1203 EXPECT_EQ("us", keyboard_->last_layout_); |
1195 | 1204 |
1196 // Add an Extension IME. | 1205 // Add an Extension IME. |
1197 std::vector<std::string> layouts; | 1206 std::vector<std::string> layouts; |
1198 layouts.push_back("us(dvorak)"); | 1207 layouts.push_back("us(dvorak)"); |
1199 std::vector<std::string> languages; | 1208 std::vector<std::string> languages; |
1200 languages.push_back("en-US"); | 1209 languages.push_back("en-US"); |
1201 | 1210 |
1202 const std::string ext_id = | 1211 const std::string ext_id = |
1203 extension_ime_util::GetInputMethodID("deadbeef", "engine_id"); | 1212 extension_ime_util::GetInputMethodID(kExtensionId1, "engine_id"); |
1204 const InputMethodDescriptor descriptor(ext_id, | 1213 const InputMethodDescriptor descriptor(ext_id, |
1205 "deadbeef input method", | 1214 "deadbeef input method", |
1206 "DB", | 1215 "DB", |
1207 layouts, | 1216 layouts, |
1208 languages, | 1217 languages, |
1209 false, // is_login_keyboard | 1218 false, // is_login_keyboard |
1210 GURL(), | 1219 GURL(), |
1211 GURL()); | 1220 GURL()); |
1212 MockInputMethodEngine engine(descriptor); | 1221 MockInputMethodEngine engine; |
1213 manager_->AddInputMethodExtension(ext_id, &engine); | 1222 InputMethodDescriptors descriptors; |
| 1223 descriptors.push_back(descriptor); |
| 1224 manager_->AddInputMethodExtension(kExtensionId1, descriptors, &engine); |
1214 | 1225 |
1215 // Extension IME is not enabled by default. | 1226 // Extension IME is not enabled by default. |
1216 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1227 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |
1217 EXPECT_EQ(1, observer.input_method_changed_count_); | 1228 EXPECT_EQ(1, observer.input_method_changed_count_); |
1218 | 1229 |
1219 std::vector<std::string> extension_ime_ids; | 1230 std::vector<std::string> extension_ime_ids; |
1220 extension_ime_ids.push_back(ext_id); | 1231 extension_ime_ids.push_back(ext_id); |
1221 manager_->SetEnabledExtensionImes(&extension_ime_ids); | 1232 manager_->SetEnabledExtensionImes(&extension_ime_ids); |
1222 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1233 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
1223 | 1234 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1299 ASSERT_EQ(4U, input_method_ids.size()); | 1310 ASSERT_EQ(4U, input_method_ids.size()); |
1300 | 1311 |
1301 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), input_method_ids[0]); | 1312 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), input_method_ids[0]); |
1302 EXPECT_EQ(ImeIdFromEngineId("xkb:fr::fra"), input_method_ids[1]); | 1313 EXPECT_EQ(ImeIdFromEngineId("xkb:fr::fra"), input_method_ids[1]); |
1303 EXPECT_EQ("_comp_ime_asdf_pinyin", input_method_ids[2]); | 1314 EXPECT_EQ("_comp_ime_asdf_pinyin", input_method_ids[2]); |
1304 EXPECT_EQ(ImeIdFromEngineId("zh-t-i0-pinyin"), input_method_ids[3]); | 1315 EXPECT_EQ(ImeIdFromEngineId("zh-t-i0-pinyin"), input_method_ids[3]); |
1305 } | 1316 } |
1306 | 1317 |
1307 } // namespace input_method | 1318 } // namespace input_method |
1308 } // namespace chromeos | 1319 } // namespace chromeos |
OLD | NEW |