Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc

Issue 133273032: Guest Mode: input method should default to the underlying latin keyboard layout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-upload missing CL. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 return false; 49 return false;
50 } 50 }
51 51
52 class InputMethodManagerImplTest : public testing::Test { 52 class InputMethodManagerImplTest : public testing::Test {
53 public: 53 public:
54 InputMethodManagerImplTest() 54 InputMethodManagerImplTest()
55 : delegate_(NULL), 55 : delegate_(NULL),
56 candidate_window_controller_(NULL), 56 candidate_window_controller_(NULL),
57 xkeyboard_(NULL) { 57 xkeyboard_(NULL) {
58 } 58 }
59 virtual ~InputMethodManagerImplTest() {} 59 virtual ~InputMethodManagerImplTest() {
60 InputMethodManager::Shutdown();
61 }
60 62
61 virtual void SetUp() OVERRIDE { 63 virtual void SetUp() OVERRIDE {
62 delegate_ = new FakeInputMethodDelegate(); 64 delegate_ = new FakeInputMethodDelegate();
63 manager_.reset(new InputMethodManagerImpl( 65 InputMethodManager::Shutdown();
64 scoped_ptr<InputMethodDelegate>(delegate_))); 66 InputMethodManager::Initialize(
67 new InputMethodManagerImpl(scoped_ptr<InputMethodDelegate>(delegate_)));
65 candidate_window_controller_ = new MockCandidateWindowController; 68 candidate_window_controller_ = new MockCandidateWindowController;
66 manager_->SetCandidateWindowControllerForTesting( 69 manager()->SetCandidateWindowControllerForTesting(
67 candidate_window_controller_); 70 candidate_window_controller_);
68 xkeyboard_ = new MockXKeyboard; 71 xkeyboard_ = new MockXKeyboard;
69 manager_->SetXKeyboardForTesting(xkeyboard_); 72 manager()->SetXKeyboardForTesting(xkeyboard_);
70 mock_engine_handler_.reset(new MockIMEEngineHandler()); 73 mock_engine_handler_.reset(new MockIMEEngineHandler());
71 IBusBridge::Initialize(); 74 IBusBridge::Initialize();
72 IBusBridge::Get()->SetCurrentEngineHandler(mock_engine_handler_.get()); 75 IBusBridge::Get()->SetCurrentEngineHandler(mock_engine_handler_.get());
73 76
74 ime_list_.clear(); 77 ime_list_.clear();
75 78
76 ComponentExtensionIME ext1; 79 ComponentExtensionIME ext1;
77 ext1.id = "fpfbhcjppmaeaijcidgiibchfbnhbelj"; 80 ext1.id = "fpfbhcjppmaeaijcidgiibchfbnhbelj";
78 ext1.description = "ext1_description"; 81 ext1.description = "ext1_description";
79 ext1.path = base::FilePath("ext1_file_path"); 82 ext1.path = base::FilePath("ext1_file_path");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 ext2_engine2.layouts.push_back("us(dvorak)"); 116 ext2_engine2.layouts.push_back("us(dvorak)");
114 ext2.engines.push_back(ext2_engine2); 117 ext2.engines.push_back(ext2_engine2);
115 118
116 ime_list_.push_back(ext2); 119 ime_list_.push_back(ext2);
117 } 120 }
118 121
119 virtual void TearDown() OVERRIDE { 122 virtual void TearDown() OVERRIDE {
120 delegate_ = NULL; 123 delegate_ = NULL;
121 candidate_window_controller_ = NULL; 124 candidate_window_controller_ = NULL;
122 xkeyboard_ = NULL; 125 xkeyboard_ = NULL;
123 manager_.reset(); 126 InputMethodManager::Shutdown();
124 IBusBridge::Get()->SetCurrentEngineHandler(NULL); 127 IBusBridge::Get()->SetCurrentEngineHandler(NULL);
125 IBusBridge::Shutdown(); 128 IBusBridge::Shutdown();
126 } 129 }
127 130
128 protected: 131 protected:
129 // Helper function to initialize component extension stuff for testing. 132 // Helper function to initialize component extension stuff for testing.
130 void InitComponentExtension() { 133 void InitComponentExtension() {
131 mock_delegate_ = new MockComponentExtIMEManagerDelegate(); 134 mock_delegate_ = new MockComponentExtIMEManagerDelegate();
132 mock_delegate_->set_ime_list(ime_list_); 135 mock_delegate_->set_ime_list(ime_list_);
133 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(mock_delegate_); 136 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(mock_delegate_);
134 // Note, for production, these SetEngineHandler are called when 137 // Note, for production, these SetEngineHandler are called when
135 // IBusEngineHandlerInterface is initialized via 138 // IBusEngineHandlerInterface is initialized via
136 // InitializeComponentextension. 139 // InitializeComponentextension.
137 IBusBridge::Get()->SetEngineHandler(kNaclMozcUsId, 140 IBusBridge::Get()->SetEngineHandler(kNaclMozcUsId,
138 mock_engine_handler_.get()); 141 mock_engine_handler_.get());
139 IBusBridge::Get()->SetEngineHandler(kNaclMozcJpId, 142 IBusBridge::Get()->SetEngineHandler(kNaclMozcJpId,
140 mock_engine_handler_.get()); 143 mock_engine_handler_.get());
141 IBusBridge::Get()->SetEngineHandler(kExt2Engine1Id, 144 IBusBridge::Get()->SetEngineHandler(kExt2Engine1Id,
142 mock_engine_handler_.get()); 145 mock_engine_handler_.get());
143 IBusBridge::Get()->SetEngineHandler(kExt2Engine2Id, 146 IBusBridge::Get()->SetEngineHandler(kExt2Engine2Id,
144 mock_engine_handler_.get()); 147 mock_engine_handler_.get());
145 manager_->InitializeComponentExtensionForTesting(delegate.Pass()); 148 manager()->InitializeComponentExtensionForTesting(delegate.Pass());
146 } 149 }
147 150
148 scoped_ptr<InputMethodManagerImpl> manager_; 151 InputMethodManagerImpl* manager() const {
152 return static_cast<InputMethodManagerImpl*>(InputMethodManager::Get());
153 }
154
149 FakeInputMethodDelegate* delegate_; 155 FakeInputMethodDelegate* delegate_;
150 MockCandidateWindowController* candidate_window_controller_; 156 MockCandidateWindowController* candidate_window_controller_;
151 scoped_ptr<MockIMEEngineHandler> mock_engine_handler_; 157 scoped_ptr<MockIMEEngineHandler> mock_engine_handler_;
152 MockXKeyboard* xkeyboard_; 158 MockXKeyboard* xkeyboard_;
153 base::MessageLoop message_loop_; 159 base::MessageLoop message_loop_;
154 MockComponentExtIMEManagerDelegate* mock_delegate_; 160 MockComponentExtIMEManagerDelegate* mock_delegate_;
155 std::vector<ComponentExtensionIME> ime_list_; 161 std::vector<ComponentExtensionIME> ime_list_;
156 162
157 private: 163 private:
158 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImplTest); 164 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImplTest);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 209
204 int candidate_window_opened_count_; 210 int candidate_window_opened_count_;
205 int candidate_window_closed_count_; 211 int candidate_window_closed_count_;
206 212
207 private: 213 private:
208 DISALLOW_COPY_AND_ASSIGN(TestCandidateWindowObserver); 214 DISALLOW_COPY_AND_ASSIGN(TestCandidateWindowObserver);
209 }; 215 };
210 } // namespace 216 } // namespace
211 217
212 TEST_F(InputMethodManagerImplTest, TestGetXKeyboard) { 218 TEST_F(InputMethodManagerImplTest, TestGetXKeyboard) {
213 EXPECT_TRUE(manager_->GetXKeyboard()); 219 EXPECT_TRUE(manager()->GetXKeyboard());
214 EXPECT_EQ(xkeyboard_, manager_->GetXKeyboard()); 220 EXPECT_EQ(xkeyboard_, manager()->GetXKeyboard());
215 } 221 }
216 222
217 TEST_F(InputMethodManagerImplTest, TestCandidateWindowObserver) { 223 TEST_F(InputMethodManagerImplTest, TestCandidateWindowObserver) {
218 TestCandidateWindowObserver observer; 224 TestCandidateWindowObserver observer;
219 candidate_window_controller_->NotifyCandidateWindowOpened(); // nop 225 candidate_window_controller_->NotifyCandidateWindowOpened(); // nop
220 candidate_window_controller_->NotifyCandidateWindowClosed(); // nop 226 candidate_window_controller_->NotifyCandidateWindowClosed(); // nop
221 manager_->AddCandidateWindowObserver(&observer); 227 manager()->AddCandidateWindowObserver(&observer);
222 candidate_window_controller_->NotifyCandidateWindowOpened(); 228 candidate_window_controller_->NotifyCandidateWindowOpened();
223 EXPECT_EQ(1, observer.candidate_window_opened_count_); 229 EXPECT_EQ(1, observer.candidate_window_opened_count_);
224 candidate_window_controller_->NotifyCandidateWindowClosed(); 230 candidate_window_controller_->NotifyCandidateWindowClosed();
225 EXPECT_EQ(1, observer.candidate_window_closed_count_); 231 EXPECT_EQ(1, observer.candidate_window_closed_count_);
226 candidate_window_controller_->NotifyCandidateWindowOpened(); 232 candidate_window_controller_->NotifyCandidateWindowOpened();
227 EXPECT_EQ(2, observer.candidate_window_opened_count_); 233 EXPECT_EQ(2, observer.candidate_window_opened_count_);
228 candidate_window_controller_->NotifyCandidateWindowClosed(); 234 candidate_window_controller_->NotifyCandidateWindowClosed();
229 EXPECT_EQ(2, observer.candidate_window_closed_count_); 235 EXPECT_EQ(2, observer.candidate_window_closed_count_);
230 manager_->RemoveCandidateWindowObserver(&observer); 236 manager()->RemoveCandidateWindowObserver(&observer);
231 } 237 }
232 238
233 TEST_F(InputMethodManagerImplTest, TestObserver) { 239 TEST_F(InputMethodManagerImplTest, TestObserver) {
234 // For http://crbug.com/19655#c11 - (3). browser_state_monitor_unittest.cc is 240 // For http://crbug.com/19655#c11 - (3). browser_state_monitor_unittest.cc is
235 // also for the scenario. 241 // also for the scenario.
236 TestObserver observer; 242 TestObserver observer;
237 InitComponentExtension(); 243 InitComponentExtension();
238 manager_->AddObserver(&observer); 244 manager()->AddObserver(&observer);
239 EXPECT_EQ(0, observer.input_method_changed_count_); 245 EXPECT_EQ(0, observer.input_method_changed_count_);
240 manager_->EnableLayouts("en-US", "xkb:us::eng"); 246 manager()->EnableLayouts("en-US", "xkb:us::eng", true);
241 EXPECT_EQ(1, observer.input_method_changed_count_); 247 EXPECT_EQ(1, observer.input_method_changed_count_);
242 EXPECT_EQ(1, observer.input_method_property_changed_count_); 248 EXPECT_EQ(1, observer.input_method_property_changed_count_);
243 manager_->ChangeInputMethod("xkb:us:dvorak:eng"); 249 manager()->ChangeInputMethod("xkb:us:dvorak:eng");
244 EXPECT_FALSE(observer.last_show_message_); 250 EXPECT_FALSE(observer.last_show_message_);
245 EXPECT_EQ(2, observer.input_method_changed_count_); 251 EXPECT_EQ(2, observer.input_method_changed_count_);
246 EXPECT_EQ(2, observer.input_method_property_changed_count_); 252 EXPECT_EQ(2, observer.input_method_property_changed_count_);
247 manager_->ChangeInputMethod("xkb:us:dvorak:eng"); 253 manager()->ChangeInputMethod("xkb:us:dvorak:eng");
248 EXPECT_FALSE(observer.last_show_message_); 254 EXPECT_FALSE(observer.last_show_message_);
249 255
250 // The observer is always notified even when the same input method ID is 256 // The observer is always notified even when the same input method ID is
251 // passed to ChangeInputMethod() more than twice. 257 // passed to ChangeInputMethod() more than twice.
252 // TODO(komatsu): Revisit if this is neccessary. 258 // TODO(komatsu): Revisit if this is neccessary.
253 EXPECT_EQ(3, observer.input_method_changed_count_); 259 EXPECT_EQ(3, observer.input_method_changed_count_);
254 260
255 // If the same input method ID is passed, PropertyChanged() is not 261 // If the same input method ID is passed, PropertyChanged() is not
256 // notified. 262 // notified.
257 EXPECT_EQ(2, observer.input_method_property_changed_count_); 263 EXPECT_EQ(2, observer.input_method_property_changed_count_);
258 264
259 manager_->RemoveObserver(&observer); 265 manager()->RemoveObserver(&observer);
260 } 266 }
261 267
262 TEST_F(InputMethodManagerImplTest, TestGetSupportedInputMethods) { 268 TEST_F(InputMethodManagerImplTest, TestGetSupportedInputMethods) {
263 InitComponentExtension(); 269 InitComponentExtension();
264 scoped_ptr<InputMethodDescriptors> methods( 270 scoped_ptr<InputMethodDescriptors> methods(
265 manager_->GetSupportedInputMethods()); 271 manager()->GetSupportedInputMethods());
266 ASSERT_TRUE(methods.get()); 272 ASSERT_TRUE(methods.get());
267 // Try to find random 4-5 layuts and IMEs to make sure the returned list is 273 // Try to find random 4-5 layuts and IMEs to make sure the returned list is
268 // correct. 274 // correct.
269 const InputMethodDescriptor* id_to_find = 275 const InputMethodDescriptor* id_to_find =
270 manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( 276 manager()->GetInputMethodUtil()->GetInputMethodDescriptorFromId(
271 kNaclMozcUsId); 277 kNaclMozcUsId);
272 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( 278 id_to_find = manager()->GetInputMethodUtil()->GetInputMethodDescriptorFromId(
273 "xkb:us::eng"); 279 "xkb:us::eng");
274 EXPECT_TRUE(Contain(*methods.get(), *id_to_find)); 280 EXPECT_TRUE(Contain(*methods.get(), *id_to_find));
275 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( 281 id_to_find = manager()->GetInputMethodUtil()->GetInputMethodDescriptorFromId(
276 "xkb:us:dvorak:eng"); 282 "xkb:us:dvorak:eng");
277 EXPECT_TRUE(Contain(*methods.get(), *id_to_find)); 283 EXPECT_TRUE(Contain(*methods.get(), *id_to_find));
278 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( 284 id_to_find = manager()->GetInputMethodUtil()->GetInputMethodDescriptorFromId(
279 "xkb:fr::fra"); 285 "xkb:fr::fra");
280 EXPECT_TRUE(Contain(*methods.get(), *id_to_find)); 286 EXPECT_TRUE(Contain(*methods.get(), *id_to_find));
281 } 287 }
282 288
283 TEST_F(InputMethodManagerImplTest, TestEnableLayouts) { 289 TEST_F(InputMethodManagerImplTest, TestEnableLayouts) {
284 // Currently 5 keyboard layouts are supported for en-US, and 1 for ja. See 290 // Currently 5 keyboard layouts are supported for en-US, and 1 for ja. See
285 // ibus_input_method.txt. 291 // ibus_input_method.txt.
286 InitComponentExtension(); 292 InitComponentExtension();
287 manager_->EnableLayouts("en-US", ""); 293 manager()->EnableLayouts("en-US", "", true);
288 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); 294 EXPECT_EQ(5U, manager()->GetNumActiveInputMethods());
289 for (size_t i = 0; i < manager_->GetActiveInputMethodIds().size(); ++i) 295 for (size_t i = 0; i < manager()->GetActiveInputMethodIds().size(); ++i)
290 LOG(ERROR) << manager_->GetActiveInputMethodIds().at(i); 296 LOG(ERROR) << manager()->GetActiveInputMethodIds().at(i);
291 297
292 // For http://crbug.com/19655#c11 - (5) 298 // For http://crbug.com/19655#c11 - (5)
293 // The hardware keyboard layout "xkb:us::eng" is always active, hence 2U. 299 // The hardware keyboard layout "xkb:us::eng" is always active, hence 2U.
294 manager_->EnableLayouts("ja", ""); // Japanese 300 manager()->EnableLayouts("ja", "", true); // Japanese
295 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 301 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
296 } 302 }
297 303
298 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsAndCurrentInputMethod) { 304 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsAndCurrentInputMethod) {
299 // For http://crbug.com/329061 305 // For http://crbug.com/329061
300 manager_->EnableLayouts("en-US", "xkb:se::swe"); 306 manager()->EnableLayouts("en-US", "xkb:se::swe", true);
301 const std::string im_id = manager_->GetCurrentInputMethod().id(); 307 const std::string im_id = manager()->GetCurrentInputMethod().id();
302 EXPECT_EQ("xkb:se::swe", im_id); 308 EXPECT_EQ("xkb:se::swe", im_id);
303 } 309 }
304 310
305 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsNonUsHardwareKeyboard) { 311 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsNonUsHardwareKeyboard) {
306 // The physical layout is French. 312 // The physical layout is French.
307 delegate_->set_hardware_keyboard_layout("xkb:fr::fra"); 313 delegate_->set_hardware_keyboard_layout("xkb:fr::fra");
308 manager_->EnableLayouts("en-US", ""); 314 manager()->EnableLayouts("en-US", "", true);
309 EXPECT_EQ(6U, manager_->GetNumActiveInputMethods()); // 5 + French 315 EXPECT_EQ(6U, manager()->GetNumActiveInputMethods()); // 5 + French
310 // The physical layout is Japanese. 316 // The physical layout is Japanese.
311 delegate_->set_hardware_keyboard_layout("xkb:jp::jpn"); 317 delegate_->set_hardware_keyboard_layout("xkb:jp::jpn");
312 manager_->EnableLayouts("ja", ""); 318 manager()->EnableLayouts("ja", "", true);
313 // "xkb:us::eng" is not needed, hence 1. 319 // "xkb:us::eng" is not needed, hence 1.
314 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 320 EXPECT_EQ(1U, manager()->GetNumActiveInputMethods());
321
322 // The physical layout is Russian.
323 delegate_->set_hardware_keyboard_layout("xkb:ru::rus");
324 manager()->EnableLayouts("ru", "", true);
325 // "xkb:us::eng" only.
326 EXPECT_EQ(1U, manager()->GetNumActiveInputMethods());
327 EXPECT_TRUE(manager()->GetActiveInputMethodIds().front() == "xkb:us::eng");
328 manager()->EnableLayouts("ru", "", false);
329 EXPECT_EQ(3U, manager()->GetNumActiveInputMethods());
330 EXPECT_TRUE(manager()->GetActiveInputMethodIds().at(0) == "xkb:ru::rus");
331 EXPECT_TRUE(manager()->GetActiveInputMethodIds().at(1) ==
332 "xkb:ru:phonetic:rus");
333 EXPECT_TRUE(manager()->GetActiveInputMethodIds().at(2) == "xkb:us::eng");
334 // "xkb:us::eng" is Hardware Login Layout for Russian locale
335 manager()->EnableLayouts("ru", "xkb:us::eng", false);
336 EXPECT_EQ(3U, manager()->GetNumActiveInputMethods());
337 EXPECT_TRUE(manager()->GetActiveInputMethodIds().at(0) == "xkb:us::eng");
338 EXPECT_TRUE(manager()->GetActiveInputMethodIds().at(1) == "xkb:ru::rus");
339 EXPECT_TRUE(manager()->GetActiveInputMethodIds().at(2) ==
340 "xkb:ru:phonetic:rus");
315 } 341 }
316 342
317 TEST_F(InputMethodManagerImplTest, TestActiveInputMethods) { 343 TEST_F(InputMethodManagerImplTest, TestActiveInputMethods) {
318 manager_->EnableLayouts("ja", ""); // Japanese 344 manager()->EnableLayouts("ja", "", true); // Japanese
319 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 345 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
320 scoped_ptr<InputMethodDescriptors> methods( 346 scoped_ptr<InputMethodDescriptors> methods(
321 manager_->GetActiveInputMethods()); 347 manager()->GetActiveInputMethods());
322 ASSERT_TRUE(methods.get()); 348 ASSERT_TRUE(methods.get());
323 EXPECT_EQ(2U, methods->size()); 349 EXPECT_EQ(2U, methods->size());
324 const InputMethodDescriptor* id_to_find = 350 const InputMethodDescriptor* id_to_find =
325 manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( 351 manager()->GetInputMethodUtil()->GetInputMethodDescriptorFromId(
326 "xkb:us::eng"); 352 "xkb:us::eng");
327 EXPECT_TRUE(Contain(*methods.get(), *id_to_find)); 353 EXPECT_TRUE(Contain(*methods.get(), *id_to_find));
328 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( 354 id_to_find = manager()->GetInputMethodUtil()->GetInputMethodDescriptorFromId(
329 "xkb:jp::jpn"); 355 "xkb:jp::jpn");
330 EXPECT_TRUE(Contain(*methods.get(), *id_to_find)); 356 EXPECT_TRUE(Contain(*methods.get(), *id_to_find));
331 } 357 }
332 358
333 TEST_F(InputMethodManagerImplTest, TestEnableTwoLayouts) { 359 TEST_F(InputMethodManagerImplTest, TestEnableTwoLayouts) {
334 // For http://crbug.com/19655#c11 - (8), step 6. 360 // For http://crbug.com/19655#c11 - (8), step 6.
335 TestObserver observer; 361 TestObserver observer;
336 manager_->AddObserver(&observer); 362 manager()->AddObserver(&observer);
337 InitComponentExtension(); 363 InitComponentExtension();
338 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 364 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
339 std::vector<std::string> ids; 365 std::vector<std::string> ids;
340 ids.push_back("xkb:us:dvorak:eng"); 366 ids.push_back("xkb:us:dvorak:eng");
341 ids.push_back("xkb:us:colemak:eng"); 367 ids.push_back("xkb:us:colemak:eng");
342 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 368 EXPECT_TRUE(manager()->EnableInputMethods(ids));
343 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 369 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
344 // Since all the IDs added avobe are keyboard layouts, Start() should not be 370 // Since all the IDs added avobe are keyboard layouts, Start() should not be
345 // called. 371 // called.
346 EXPECT_EQ(1, observer.input_method_changed_count_); 372 EXPECT_EQ(1, observer.input_method_changed_count_);
347 EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); 373 EXPECT_EQ(ids[0], manager()->GetCurrentInputMethod().id());
348 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 374 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
349 // Disable Dvorak. 375 // Disable Dvorak.
350 ids.erase(ids.begin()); 376 ids.erase(ids.begin());
351 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 377 EXPECT_TRUE(manager()->EnableInputMethods(ids));
352 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 378 EXPECT_EQ(1U, manager()->GetNumActiveInputMethods());
353 EXPECT_EQ(2, observer.input_method_changed_count_); 379 EXPECT_EQ(2, observer.input_method_changed_count_);
354 EXPECT_EQ(ids[0], // colemak 380 EXPECT_EQ(ids[0], // colemak
355 manager_->GetCurrentInputMethod().id()); 381 manager()->GetCurrentInputMethod().id());
356 EXPECT_EQ("us(colemak)", xkeyboard_->last_layout_); 382 EXPECT_EQ("us(colemak)", xkeyboard_->last_layout_);
357 manager_->RemoveObserver(&observer); 383 manager()->RemoveObserver(&observer);
358 } 384 }
359 385
360 TEST_F(InputMethodManagerImplTest, TestEnableThreeLayouts) { 386 TEST_F(InputMethodManagerImplTest, TestEnableThreeLayouts) {
361 // For http://crbug.com/19655#c11 - (9). 387 // For http://crbug.com/19655#c11 - (9).
362 TestObserver observer; 388 TestObserver observer;
363 manager_->AddObserver(&observer); 389 manager()->AddObserver(&observer);
364 InitComponentExtension(); 390 InitComponentExtension();
365 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 391 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
366 std::vector<std::string> ids; 392 std::vector<std::string> ids;
367 ids.push_back("xkb:us::eng"); 393 ids.push_back("xkb:us::eng");
368 ids.push_back("xkb:us:dvorak:eng"); 394 ids.push_back("xkb:us:dvorak:eng");
369 ids.push_back("xkb:us:colemak:eng"); 395 ids.push_back("xkb:us:colemak:eng");
370 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 396 EXPECT_TRUE(manager()->EnableInputMethods(ids));
371 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); 397 EXPECT_EQ(3U, manager()->GetNumActiveInputMethods());
372 EXPECT_EQ(1, observer.input_method_changed_count_); 398 EXPECT_EQ(1, observer.input_method_changed_count_);
373 EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); 399 EXPECT_EQ(ids[0], manager()->GetCurrentInputMethod().id());
374 EXPECT_EQ("us", xkeyboard_->last_layout_); 400 EXPECT_EQ("us", xkeyboard_->last_layout_);
375 // Switch to Dvorak. 401 // Switch to Dvorak.
376 manager_->SwitchToNextInputMethod(); 402 manager()->SwitchToNextInputMethod();
377 EXPECT_EQ(2, observer.input_method_changed_count_); 403 EXPECT_EQ(2, observer.input_method_changed_count_);
378 EXPECT_EQ(ids[1], manager_->GetCurrentInputMethod().id()); 404 EXPECT_EQ(ids[1], manager()->GetCurrentInputMethod().id());
379 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 405 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
380 // Disable Dvorak. 406 // Disable Dvorak.
381 ids.erase(ids.begin() + 1); 407 ids.erase(ids.begin() + 1);
382 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 408 EXPECT_TRUE(manager()->EnableInputMethods(ids));
383 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 409 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
384 EXPECT_EQ(3, observer.input_method_changed_count_); 410 EXPECT_EQ(3, observer.input_method_changed_count_);
385 EXPECT_EQ(ids[0], // US Qwerty 411 EXPECT_EQ(ids[0], // US Qwerty
386 manager_->GetCurrentInputMethod().id()); 412 manager()->GetCurrentInputMethod().id());
387 EXPECT_EQ("us", xkeyboard_->last_layout_); 413 EXPECT_EQ("us", xkeyboard_->last_layout_);
388 manager_->RemoveObserver(&observer); 414 manager()->RemoveObserver(&observer);
389 } 415 }
390 416
391 TEST_F(InputMethodManagerImplTest, TestEnableLayoutAndIme) { 417 TEST_F(InputMethodManagerImplTest, TestEnableLayoutAndIme) {
392 // For http://crbug.com/19655#c11 - (10). 418 // For http://crbug.com/19655#c11 - (10).
393 TestObserver observer; 419 TestObserver observer;
394 manager_->AddObserver(&observer); 420 manager()->AddObserver(&observer);
395 InitComponentExtension(); 421 InitComponentExtension();
396 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 422 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
397 std::vector<std::string> ids; 423 std::vector<std::string> ids;
398 ids.push_back("xkb:us:dvorak:eng"); 424 ids.push_back("xkb:us:dvorak:eng");
399 ids.push_back(kNaclMozcUsId); 425 ids.push_back(kNaclMozcUsId);
400 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 426 EXPECT_TRUE(manager()->EnableInputMethods(ids));
401 EXPECT_EQ(1, observer.input_method_changed_count_); 427 EXPECT_EQ(1, observer.input_method_changed_count_);
402 EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); 428 EXPECT_EQ(ids[0], manager()->GetCurrentInputMethod().id());
403 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 429 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
404 // Switch to Mozc 430 // Switch to Mozc
405 manager_->SwitchToNextInputMethod(); 431 manager()->SwitchToNextInputMethod();
406 EXPECT_EQ(2, observer.input_method_changed_count_); 432 EXPECT_EQ(2, observer.input_method_changed_count_);
407 EXPECT_EQ(ids[1], manager_->GetCurrentInputMethod().id()); 433 EXPECT_EQ(ids[1], manager()->GetCurrentInputMethod().id());
408 EXPECT_EQ("us", xkeyboard_->last_layout_); 434 EXPECT_EQ("us", xkeyboard_->last_layout_);
409 // Disable Mozc. 435 // Disable Mozc.
410 ids.erase(ids.begin() + 1); 436 ids.erase(ids.begin() + 1);
411 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 437 EXPECT_TRUE(manager()->EnableInputMethods(ids));
412 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 438 EXPECT_EQ(1U, manager()->GetNumActiveInputMethods());
413 EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); 439 EXPECT_EQ(ids[0], manager()->GetCurrentInputMethod().id());
414 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 440 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
415 } 441 }
416 442
417 TEST_F(InputMethodManagerImplTest, TestEnableLayoutAndIme2) { 443 TEST_F(InputMethodManagerImplTest, TestEnableLayoutAndIme2) {
418 // For http://crbug.com/19655#c11 - (11). 444 // For http://crbug.com/19655#c11 - (11).
419 TestObserver observer; 445 TestObserver observer;
420 manager_->AddObserver(&observer); 446 manager()->AddObserver(&observer);
421 InitComponentExtension(); 447 InitComponentExtension();
422 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 448 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
423 std::vector<std::string> ids; 449 std::vector<std::string> ids;
424 ids.push_back("xkb:us:dvorak:eng"); 450 ids.push_back("xkb:us:dvorak:eng");
425 ids.push_back(kNaclMozcUsId); 451 ids.push_back(kNaclMozcUsId);
426 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 452 EXPECT_TRUE(manager()->EnableInputMethods(ids));
427 EXPECT_EQ(1, observer.input_method_changed_count_); 453 EXPECT_EQ(1, observer.input_method_changed_count_);
428 EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); 454 EXPECT_EQ(ids[0], manager()->GetCurrentInputMethod().id());
429 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 455 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
430 456
431 // Disable Dvorak. 457 // Disable Dvorak.
432 ids.erase(ids.begin()); 458 ids.erase(ids.begin());
433 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 459 EXPECT_TRUE(manager()->EnableInputMethods(ids));
434 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 460 EXPECT_EQ(1U, manager()->GetNumActiveInputMethods());
435 EXPECT_EQ(ids[0], // Mozc 461 EXPECT_EQ(ids[0], // Mozc
436 manager_->GetCurrentInputMethod().id()); 462 manager()->GetCurrentInputMethod().id());
437 EXPECT_EQ("us", xkeyboard_->last_layout_); 463 EXPECT_EQ("us", xkeyboard_->last_layout_);
438 manager_->RemoveObserver(&observer); 464 manager()->RemoveObserver(&observer);
439 } 465 }
440 466
441 TEST_F(InputMethodManagerImplTest, TestEnableImes) { 467 TEST_F(InputMethodManagerImplTest, TestEnableImes) {
442 TestObserver observer; 468 TestObserver observer;
443 manager_->AddObserver(&observer); 469 manager()->AddObserver(&observer);
444 InitComponentExtension(); 470 InitComponentExtension();
445 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 471 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
446 std::vector<std::string> ids; 472 std::vector<std::string> ids;
447 ids.push_back(kExt2Engine1Id); 473 ids.push_back(kExt2Engine1Id);
448 ids.push_back("mozc-dv"); 474 ids.push_back("mozc-dv");
449 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 475 EXPECT_TRUE(manager()->EnableInputMethods(ids));
450 EXPECT_EQ(1, observer.input_method_changed_count_); 476 EXPECT_EQ(1, observer.input_method_changed_count_);
451 EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); 477 EXPECT_EQ(ids[0], manager()->GetCurrentInputMethod().id());
452 EXPECT_EQ("us", xkeyboard_->last_layout_); 478 EXPECT_EQ("us", xkeyboard_->last_layout_);
453 manager_->RemoveObserver(&observer); 479 manager()->RemoveObserver(&observer);
454 } 480 }
455 481
456 TEST_F(InputMethodManagerImplTest, TestEnableUnknownIds) { 482 TEST_F(InputMethodManagerImplTest, TestEnableUnknownIds) {
457 TestObserver observer; 483 TestObserver observer;
458 manager_->AddObserver(&observer); 484 manager()->AddObserver(&observer);
459 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 485 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
460 std::vector<std::string> ids; 486 std::vector<std::string> ids;
461 ids.push_back("xkb:tl::tlh"); // Klingon, which is not supported. 487 ids.push_back("xkb:tl::tlh"); // Klingon, which is not supported.
462 ids.push_back("unknown-super-cool-ime"); 488 ids.push_back("unknown-super-cool-ime");
463 EXPECT_FALSE(manager_->EnableInputMethods(ids)); 489 EXPECT_FALSE(manager()->EnableInputMethods(ids));
464 490
465 // TODO(yusukes): Should we fall back to the hardware keyboard layout in this 491 // TODO(yusukes): Should we fall back to the hardware keyboard layout in this
466 // case? 492 // case?
467 EXPECT_EQ(0, observer.input_method_changed_count_); 493 EXPECT_EQ(0, observer.input_method_changed_count_);
468 494
469 manager_->RemoveObserver(&observer); 495 manager()->RemoveObserver(&observer);
470 } 496 }
471 497
472 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsThenLock) { 498 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsThenLock) {
473 // For http://crbug.com/19655#c11 - (14). 499 // For http://crbug.com/19655#c11 - (14).
474 TestObserver observer; 500 TestObserver observer;
475 manager_->AddObserver(&observer); 501 manager()->AddObserver(&observer);
476 InitComponentExtension(); 502 InitComponentExtension();
477 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 503 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
478 std::vector<std::string> ids; 504 std::vector<std::string> ids;
479 ids.push_back("xkb:us::eng"); 505 ids.push_back("xkb:us::eng");
480 ids.push_back("xkb:us:dvorak:eng"); 506 ids.push_back("xkb:us:dvorak:eng");
481 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 507 EXPECT_TRUE(manager()->EnableInputMethods(ids));
482 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 508 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
483 EXPECT_EQ(1, observer.input_method_changed_count_); 509 EXPECT_EQ(1, observer.input_method_changed_count_);
484 EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); 510 EXPECT_EQ(ids[0], manager()->GetCurrentInputMethod().id());
485 EXPECT_EQ("us", xkeyboard_->last_layout_); 511 EXPECT_EQ("us", xkeyboard_->last_layout_);
486 512
487 // Switch to Dvorak. 513 // Switch to Dvorak.
488 manager_->SwitchToNextInputMethod(); 514 manager()->SwitchToNextInputMethod();
489 EXPECT_EQ(2, observer.input_method_changed_count_); 515 EXPECT_EQ(2, observer.input_method_changed_count_);
490 EXPECT_EQ(ids[1], manager_->GetCurrentInputMethod().id()); 516 EXPECT_EQ(ids[1], manager()->GetCurrentInputMethod().id());
491 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 517 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
492 518
493 // Lock screen 519 // Lock screen
494 manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN); 520 manager()->SetState(InputMethodManager::STATE_LOCK_SCREEN);
495 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 521 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
496 EXPECT_EQ(ids[1], // still Dvorak 522 EXPECT_EQ(ids[1], // still Dvorak
497 manager_->GetCurrentInputMethod().id()); 523 manager()->GetCurrentInputMethod().id());
498 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 524 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
499 // Switch back to Qwerty. 525 // Switch back to Qwerty.
500 manager_->SwitchToNextInputMethod(); 526 manager()->SwitchToNextInputMethod();
501 EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); 527 EXPECT_EQ(ids[0], manager()->GetCurrentInputMethod().id());
502 EXPECT_EQ("us", xkeyboard_->last_layout_); 528 EXPECT_EQ("us", xkeyboard_->last_layout_);
503 529
504 // Unlock screen. The original state, Dvorak, is restored. 530 // Unlock screen. The original state, Dvorak, is restored.
505 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 531 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
506 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 532 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
507 EXPECT_EQ(ids[1], manager_->GetCurrentInputMethod().id()); 533 EXPECT_EQ(ids[1], manager()->GetCurrentInputMethod().id());
508 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 534 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
509 535
510 manager_->RemoveObserver(&observer); 536 manager()->RemoveObserver(&observer);
511 } 537 }
512 538
513 TEST_F(InputMethodManagerImplTest, SwitchInputMethodTest) { 539 TEST_F(InputMethodManagerImplTest, SwitchInputMethodTest) {
514 // For http://crbug.com/19655#c11 - (15). 540 // For http://crbug.com/19655#c11 - (15).
515 TestObserver observer; 541 TestObserver observer;
516 manager_->AddObserver(&observer); 542 manager()->AddObserver(&observer);
517 InitComponentExtension(); 543 InitComponentExtension();
518 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 544 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
519 std::vector<std::string> ids; 545 std::vector<std::string> ids;
520 ids.push_back("xkb:us:dvorak:eng"); 546 ids.push_back("xkb:us:dvorak:eng");
521 ids.push_back(kExt2Engine2Id); 547 ids.push_back(kExt2Engine2Id);
522 ids.push_back(kExt2Engine1Id); 548 ids.push_back(kExt2Engine1Id);
523 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 549 EXPECT_TRUE(manager()->EnableInputMethods(ids));
524 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); 550 EXPECT_EQ(3U, manager()->GetNumActiveInputMethods());
525 EXPECT_EQ(1, observer.input_method_changed_count_); 551 EXPECT_EQ(1, observer.input_method_changed_count_);
526 EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); 552 EXPECT_EQ(ids[0], manager()->GetCurrentInputMethod().id());
527 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 553 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
528 554
529 // Switch to Mozc. 555 // Switch to Mozc.
530 manager_->SwitchToNextInputMethod(); 556 manager()->SwitchToNextInputMethod();
531 EXPECT_EQ(2, observer.input_method_changed_count_); 557 EXPECT_EQ(2, observer.input_method_changed_count_);
532 EXPECT_EQ(ids[1], manager_->GetCurrentInputMethod().id()); 558 EXPECT_EQ(ids[1], manager()->GetCurrentInputMethod().id());
533 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 559 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
534 560
535 // Lock screen 561 // Lock screen
536 manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN); 562 manager()->SetState(InputMethodManager::STATE_LOCK_SCREEN);
537 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); // Qwerty+Dvorak. 563 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods()); // Qwerty+Dvorak.
538 EXPECT_EQ("xkb:us:dvorak:eng", 564 EXPECT_EQ("xkb:us:dvorak:eng", manager()->GetCurrentInputMethod().id());
539 manager_->GetCurrentInputMethod().id()); 565 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
540 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 566 manager()->SwitchToNextInputMethod();
541 manager_->SwitchToNextInputMethod();
542 EXPECT_EQ("xkb:us::eng", // The hardware keyboard layout. 567 EXPECT_EQ("xkb:us::eng", // The hardware keyboard layout.
543 manager_->GetCurrentInputMethod().id()); 568 manager()->GetCurrentInputMethod().id());
544 EXPECT_EQ("us", xkeyboard_->last_layout_); 569 EXPECT_EQ("us", xkeyboard_->last_layout_);
545 570
546 // Unlock screen. The original state, pinyin-dv, is restored. 571 // Unlock screen. The original state, pinyin-dv, is restored.
547 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 572 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
548 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); // Dvorak and 2 IMEs. 573 EXPECT_EQ(3U, manager()->GetNumActiveInputMethods()); // Dvorak and 2 IMEs.
549 EXPECT_EQ(ids[1], manager_->GetCurrentInputMethod().id()); 574 EXPECT_EQ(ids[1], manager()->GetCurrentInputMethod().id());
550 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 575 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
551 576
552 manager_->RemoveObserver(&observer); 577 manager()->RemoveObserver(&observer);
553 } 578 }
554 579
555 TEST_F(InputMethodManagerImplTest, TestXkbSetting) { 580 TEST_F(InputMethodManagerImplTest, TestXkbSetting) {
556 // For http://crbug.com/19655#c11 - (8), step 7-11. 581 // For http://crbug.com/19655#c11 - (8), step 7-11.
557 InitComponentExtension(); 582 InitComponentExtension();
558 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 583 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
559 std::vector<std::string> ids; 584 std::vector<std::string> ids;
560 ids.push_back("xkb:us:dvorak:eng"); 585 ids.push_back("xkb:us:dvorak:eng");
561 ids.push_back("xkb:us:colemak:eng"); 586 ids.push_back("xkb:us:colemak:eng");
562 ids.push_back(kNaclMozcJpId); 587 ids.push_back(kNaclMozcJpId);
563 ids.push_back(kNaclMozcUsId); 588 ids.push_back(kNaclMozcUsId);
564 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 589 EXPECT_TRUE(manager()->EnableInputMethods(ids));
565 EXPECT_EQ(4U, manager_->GetNumActiveInputMethods()); 590 EXPECT_EQ(4U, manager()->GetNumActiveInputMethods());
566 EXPECT_EQ(1, xkeyboard_->set_current_keyboard_layout_by_name_count_); 591 EXPECT_EQ(1, xkeyboard_->set_current_keyboard_layout_by_name_count_);
567 // See input_methods.txt for an expected XKB layout name. 592 // See input_methods.txt for an expected XKB layout name.
568 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 593 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
569 manager_->SwitchToNextInputMethod(); 594 manager()->SwitchToNextInputMethod();
570 EXPECT_EQ(2, xkeyboard_->set_current_keyboard_layout_by_name_count_); 595 EXPECT_EQ(2, xkeyboard_->set_current_keyboard_layout_by_name_count_);
571 EXPECT_EQ("us(colemak)", xkeyboard_->last_layout_); 596 EXPECT_EQ("us(colemak)", xkeyboard_->last_layout_);
572 manager_->SwitchToNextInputMethod(); 597 manager()->SwitchToNextInputMethod();
573 EXPECT_EQ(3, xkeyboard_->set_current_keyboard_layout_by_name_count_); 598 EXPECT_EQ(3, xkeyboard_->set_current_keyboard_layout_by_name_count_);
574 EXPECT_EQ("jp", xkeyboard_->last_layout_); 599 EXPECT_EQ("jp", xkeyboard_->last_layout_);
575 manager_->SwitchToNextInputMethod(); 600 manager()->SwitchToNextInputMethod();
576 EXPECT_EQ(4, xkeyboard_->set_current_keyboard_layout_by_name_count_); 601 EXPECT_EQ(4, xkeyboard_->set_current_keyboard_layout_by_name_count_);
577 EXPECT_EQ("us", xkeyboard_->last_layout_); 602 EXPECT_EQ("us", xkeyboard_->last_layout_);
578 manager_->SwitchToNextInputMethod(); 603 manager()->SwitchToNextInputMethod();
579 EXPECT_EQ(5, xkeyboard_->set_current_keyboard_layout_by_name_count_); 604 EXPECT_EQ(5, xkeyboard_->set_current_keyboard_layout_by_name_count_);
580 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 605 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
581 // Disable Dvorak. 606 // Disable Dvorak.
582 ids.erase(ids.begin()); 607 ids.erase(ids.begin());
583 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 608 EXPECT_TRUE(manager()->EnableInputMethods(ids));
584 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); 609 EXPECT_EQ(3U, manager()->GetNumActiveInputMethods());
585 EXPECT_EQ(6, xkeyboard_->set_current_keyboard_layout_by_name_count_); 610 EXPECT_EQ(6, xkeyboard_->set_current_keyboard_layout_by_name_count_);
586 EXPECT_EQ("us(colemak)", xkeyboard_->last_layout_); 611 EXPECT_EQ("us(colemak)", xkeyboard_->last_layout_);
587 } 612 }
588 613
589 TEST_F(InputMethodManagerImplTest, TestActivateInputMethodProperty) { 614 TEST_F(InputMethodManagerImplTest, TestActivateInputMethodProperty) {
590 const std::string kKey = "key"; 615 const std::string kKey = "key";
591 InputMethodPropertyList property_list; 616 InputMethodPropertyList property_list;
592 property_list.push_back(InputMethodProperty(kKey, "label", false, false)); 617 property_list.push_back(InputMethodProperty(kKey, "label", false, false));
593 manager_->SetCurrentInputMethodProperties(property_list); 618 manager()->SetCurrentInputMethodProperties(property_list);
594 619
595 manager_->ActivateInputMethodProperty(kKey); 620 manager()->ActivateInputMethodProperty(kKey);
596 EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property()); 621 EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property());
597 622
598 // Key2 is not registered, so activated property should not be changed. 623 // Key2 is not registered, so activated property should not be changed.
599 manager_->ActivateInputMethodProperty("key2"); 624 manager()->ActivateInputMethodProperty("key2");
600 EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property()); 625 EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property());
601 } 626 }
602 627
603 TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodProperties) { 628 TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodProperties) {
604 InitComponentExtension(); 629 InitComponentExtension();
605 EXPECT_TRUE(manager_->GetCurrentInputMethodProperties().empty()); 630 EXPECT_TRUE(manager()->GetCurrentInputMethodProperties().empty());
606 631
607 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 632 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
608 std::vector<std::string> ids; 633 std::vector<std::string> ids;
609 ids.push_back("xkb:us::eng"); 634 ids.push_back("xkb:us::eng");
610 ids.push_back(kNaclMozcUsId); 635 ids.push_back(kNaclMozcUsId);
611 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 636 EXPECT_TRUE(manager()->EnableInputMethods(ids));
612 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 637 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
613 EXPECT_TRUE(manager_->GetCurrentInputMethodProperties().empty()); 638 EXPECT_TRUE(manager()->GetCurrentInputMethodProperties().empty());
614 manager_->ChangeInputMethod(kNaclMozcUsId); 639 manager()->ChangeInputMethod(kNaclMozcUsId);
615 640
616 InputMethodPropertyList current_property_list; 641 InputMethodPropertyList current_property_list;
617 current_property_list.push_back(InputMethodProperty("key", 642 current_property_list.push_back(InputMethodProperty("key",
618 "label", 643 "label",
619 false, 644 false,
620 false)); 645 false));
621 manager_->SetCurrentInputMethodProperties(current_property_list); 646 manager()->SetCurrentInputMethodProperties(current_property_list);
622 647
623 ASSERT_EQ(1U, manager_->GetCurrentInputMethodProperties().size()); 648 ASSERT_EQ(1U, manager()->GetCurrentInputMethodProperties().size());
624 EXPECT_EQ("key", manager_->GetCurrentInputMethodProperties().at(0).key); 649 EXPECT_EQ("key", manager()->GetCurrentInputMethodProperties().at(0).key);
625 650
626 manager_->ChangeInputMethod("xkb:us::eng"); 651 manager()->ChangeInputMethod("xkb:us::eng");
627 EXPECT_TRUE(manager_->GetCurrentInputMethodProperties().empty()); 652 EXPECT_TRUE(manager()->GetCurrentInputMethodProperties().empty());
628 } 653 }
629 654
630 TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodPropertiesTwoImes) { 655 TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodPropertiesTwoImes) {
631 InitComponentExtension(); 656 InitComponentExtension();
632 EXPECT_TRUE(manager_->GetCurrentInputMethodProperties().empty()); 657 EXPECT_TRUE(manager()->GetCurrentInputMethodProperties().empty());
633 658
634 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 659 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
635 std::vector<std::string> ids; 660 std::vector<std::string> ids;
636 ids.push_back(kNaclMozcUsId); // Japanese 661 ids.push_back(kNaclMozcUsId); // Japanese
637 ids.push_back(kExt2Engine1Id); // T-Chinese 662 ids.push_back(kExt2Engine1Id); // T-Chinese
638 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 663 EXPECT_TRUE(manager()->EnableInputMethods(ids));
639 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 664 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
640 EXPECT_TRUE(manager_->GetCurrentInputMethodProperties().empty()); 665 EXPECT_TRUE(manager()->GetCurrentInputMethodProperties().empty());
641 666
642 InputMethodPropertyList current_property_list; 667 InputMethodPropertyList current_property_list;
643 current_property_list.push_back(InputMethodProperty("key-mozc", 668 current_property_list.push_back(InputMethodProperty("key-mozc",
644 "label", 669 "label",
645 false, 670 false,
646 false)); 671 false));
647 manager_->SetCurrentInputMethodProperties(current_property_list); 672 manager()->SetCurrentInputMethodProperties(current_property_list);
648 673
649 ASSERT_EQ(1U, manager_->GetCurrentInputMethodProperties().size()); 674 ASSERT_EQ(1U, manager()->GetCurrentInputMethodProperties().size());
650 EXPECT_EQ("key-mozc", manager_->GetCurrentInputMethodProperties().at(0).key); 675 EXPECT_EQ("key-mozc", manager()->GetCurrentInputMethodProperties().at(0).key);
651 676
652 manager_->ChangeInputMethod(kExt2Engine1Id); 677 manager()->ChangeInputMethod(kExt2Engine1Id);
653 // Since the IME is changed, the property for mozc Japanese should be hidden. 678 // Since the IME is changed, the property for mozc Japanese should be hidden.
654 EXPECT_TRUE(manager_->GetCurrentInputMethodProperties().empty()); 679 EXPECT_TRUE(manager()->GetCurrentInputMethodProperties().empty());
655 680
656 // Asynchronous property update signal from mozc-chewing. 681 // Asynchronous property update signal from mozc-chewing.
657 current_property_list.clear(); 682 current_property_list.clear();
658 current_property_list.push_back(InputMethodProperty("key-chewing", 683 current_property_list.push_back(InputMethodProperty("key-chewing",
659 "label", 684 "label",
660 false, 685 false,
661 false)); 686 false));
662 manager_->SetCurrentInputMethodProperties(current_property_list); 687 manager()->SetCurrentInputMethodProperties(current_property_list);
663 ASSERT_EQ(1U, manager_->GetCurrentInputMethodProperties().size()); 688 ASSERT_EQ(1U, manager()->GetCurrentInputMethodProperties().size());
664 EXPECT_EQ("key-chewing", 689 EXPECT_EQ("key-chewing",
665 manager_->GetCurrentInputMethodProperties().at(0).key); 690 manager()->GetCurrentInputMethodProperties().at(0).key);
666 } 691 }
667 692
668 TEST_F(InputMethodManagerImplTest, TestNextInputMethod) { 693 TEST_F(InputMethodManagerImplTest, TestNextInputMethod) {
669 TestObserver observer; 694 TestObserver observer;
670 manager_->AddObserver(&observer); 695 manager()->AddObserver(&observer);
671 InitComponentExtension(); 696 InitComponentExtension();
672 // For http://crbug.com/19655#c11 - (1) 697 // For http://crbug.com/19655#c11 - (1)
673 manager_->EnableLayouts("en-US", "xkb:us::eng"); 698 manager()->EnableLayouts("en-US", "xkb:us::eng", true);
674 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); 699 EXPECT_EQ(5U, manager()->GetNumActiveInputMethods());
675 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); 700 EXPECT_EQ("xkb:us::eng", manager()->GetCurrentInputMethod().id());
676 EXPECT_EQ("us", xkeyboard_->last_layout_); 701 EXPECT_EQ("us", xkeyboard_->last_layout_);
677 manager_->SwitchToNextInputMethod(); 702 manager()->SwitchToNextInputMethod();
678 EXPECT_TRUE(observer.last_show_message_); 703 EXPECT_TRUE(observer.last_show_message_);
679 EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); 704 EXPECT_EQ("xkb:us:intl:eng", manager()->GetCurrentInputMethod().id());
680 EXPECT_EQ("us(intl)", xkeyboard_->last_layout_); 705 EXPECT_EQ("us(intl)", xkeyboard_->last_layout_);
681 manager_->SwitchToNextInputMethod(); 706 manager()->SwitchToNextInputMethod();
682 EXPECT_TRUE(observer.last_show_message_); 707 EXPECT_TRUE(observer.last_show_message_);
683 EXPECT_EQ("xkb:us:altgr-intl:eng", manager_->GetCurrentInputMethod().id()); 708 EXPECT_EQ("xkb:us:altgr-intl:eng", manager()->GetCurrentInputMethod().id());
684 EXPECT_EQ("us(altgr-intl)", xkeyboard_->last_layout_); 709 EXPECT_EQ("us(altgr-intl)", xkeyboard_->last_layout_);
685 manager_->SwitchToNextInputMethod(); 710 manager()->SwitchToNextInputMethod();
686 EXPECT_TRUE(observer.last_show_message_); 711 EXPECT_TRUE(observer.last_show_message_);
687 EXPECT_EQ("xkb:us:dvorak:eng", manager_->GetCurrentInputMethod().id()); 712 EXPECT_EQ("xkb:us:dvorak:eng", manager()->GetCurrentInputMethod().id());
688 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 713 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
689 manager_->SwitchToNextInputMethod(); 714 manager()->SwitchToNextInputMethod();
690 EXPECT_TRUE(observer.last_show_message_); 715 EXPECT_TRUE(observer.last_show_message_);
691 EXPECT_EQ("xkb:us:colemak:eng", manager_->GetCurrentInputMethod().id()); 716 EXPECT_EQ("xkb:us:colemak:eng", manager()->GetCurrentInputMethod().id());
692 EXPECT_EQ("us(colemak)", xkeyboard_->last_layout_); 717 EXPECT_EQ("us(colemak)", xkeyboard_->last_layout_);
693 manager_->SwitchToNextInputMethod(); 718 manager()->SwitchToNextInputMethod();
694 EXPECT_TRUE(observer.last_show_message_); 719 EXPECT_TRUE(observer.last_show_message_);
695 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); 720 EXPECT_EQ("xkb:us::eng", manager()->GetCurrentInputMethod().id());
696 EXPECT_EQ("us", xkeyboard_->last_layout_); 721 EXPECT_EQ("us", xkeyboard_->last_layout_);
697 722
698 manager_->RemoveObserver(&observer); 723 manager()->RemoveObserver(&observer);
699 } 724 }
700 725
701 TEST_F(InputMethodManagerImplTest, TestPreviousInputMethod) { 726 TEST_F(InputMethodManagerImplTest, TestPreviousInputMethod) {
702 TestObserver observer; 727 TestObserver observer;
703 manager_->AddObserver(&observer); 728 manager()->AddObserver(&observer);
704 InitComponentExtension(); 729 InitComponentExtension();
705 730
706 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); 731 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN);
707 keydown_accelerator.set_type(ui::ET_KEY_PRESSED); 732 keydown_accelerator.set_type(ui::ET_KEY_PRESSED);
708 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); 733 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN);
709 keyup_accelerator.set_type(ui::ET_KEY_RELEASED); 734 keyup_accelerator.set_type(ui::ET_KEY_RELEASED);
710 735
711 manager_->EnableLayouts("en-US", "xkb:us::eng"); 736 manager()->EnableLayouts("en-US", "xkb:us::eng", true);
712 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); 737 EXPECT_EQ(5U, manager()->GetNumActiveInputMethods());
713 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); 738 EXPECT_EQ("xkb:us::eng", manager()->GetCurrentInputMethod().id());
714 EXPECT_EQ("us", xkeyboard_->last_layout_); 739 EXPECT_EQ("us", xkeyboard_->last_layout_);
715 EXPECT_TRUE(manager_->SwitchToNextInputMethod()); 740 EXPECT_TRUE(manager()->SwitchToNextInputMethod());
716 EXPECT_TRUE(observer.last_show_message_); 741 EXPECT_TRUE(observer.last_show_message_);
717 EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); 742 EXPECT_EQ("xkb:us:intl:eng", manager()->GetCurrentInputMethod().id());
718 EXPECT_EQ("us(intl)", xkeyboard_->last_layout_); 743 EXPECT_EQ("us(intl)", xkeyboard_->last_layout_);
719 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); 744 EXPECT_TRUE(manager()->SwitchToPreviousInputMethod(keydown_accelerator));
720 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); 745 EXPECT_TRUE(manager()->SwitchToPreviousInputMethod(keyup_accelerator));
721 EXPECT_TRUE(observer.last_show_message_); 746 EXPECT_TRUE(observer.last_show_message_);
722 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); 747 EXPECT_EQ("xkb:us::eng", manager()->GetCurrentInputMethod().id());
723 EXPECT_EQ("us", xkeyboard_->last_layout_); 748 EXPECT_EQ("us", xkeyboard_->last_layout_);
724 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); 749 EXPECT_TRUE(manager()->SwitchToPreviousInputMethod(keydown_accelerator));
725 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); 750 EXPECT_TRUE(manager()->SwitchToPreviousInputMethod(keyup_accelerator));
726 EXPECT_TRUE(observer.last_show_message_); 751 EXPECT_TRUE(observer.last_show_message_);
727 EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); 752 EXPECT_EQ("xkb:us:intl:eng", manager()->GetCurrentInputMethod().id());
728 EXPECT_EQ("us(intl)", xkeyboard_->last_layout_); 753 EXPECT_EQ("us(intl)", xkeyboard_->last_layout_);
729 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); 754 EXPECT_TRUE(manager()->SwitchToPreviousInputMethod(keydown_accelerator));
730 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); 755 EXPECT_TRUE(manager()->SwitchToPreviousInputMethod(keyup_accelerator));
731 EXPECT_TRUE(observer.last_show_message_); 756 EXPECT_TRUE(observer.last_show_message_);
732 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); 757 EXPECT_EQ("xkb:us::eng", manager()->GetCurrentInputMethod().id());
733 EXPECT_EQ("us", xkeyboard_->last_layout_); 758 EXPECT_EQ("us", xkeyboard_->last_layout_);
734 EXPECT_TRUE(manager_->SwitchToNextInputMethod()); 759 EXPECT_TRUE(manager()->SwitchToNextInputMethod());
735 EXPECT_TRUE(observer.last_show_message_); 760 EXPECT_TRUE(observer.last_show_message_);
736 EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); 761 EXPECT_EQ("xkb:us:intl:eng", manager()->GetCurrentInputMethod().id());
737 EXPECT_EQ("us(intl)", xkeyboard_->last_layout_); 762 EXPECT_EQ("us(intl)", xkeyboard_->last_layout_);
738 EXPECT_TRUE(manager_->SwitchToNextInputMethod()); 763 EXPECT_TRUE(manager()->SwitchToNextInputMethod());
739 EXPECT_TRUE(observer.last_show_message_); 764 EXPECT_TRUE(observer.last_show_message_);
740 EXPECT_EQ("xkb:us:altgr-intl:eng", manager_->GetCurrentInputMethod().id()); 765 EXPECT_EQ("xkb:us:altgr-intl:eng", manager()->GetCurrentInputMethod().id());
741 EXPECT_EQ("us(altgr-intl)", xkeyboard_->last_layout_); 766 EXPECT_EQ("us(altgr-intl)", xkeyboard_->last_layout_);
742 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); 767 EXPECT_TRUE(manager()->SwitchToPreviousInputMethod(keydown_accelerator));
743 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); 768 EXPECT_TRUE(manager()->SwitchToPreviousInputMethod(keyup_accelerator));
744 EXPECT_TRUE(observer.last_show_message_); 769 EXPECT_TRUE(observer.last_show_message_);
745 EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); 770 EXPECT_EQ("xkb:us:intl:eng", manager()->GetCurrentInputMethod().id());
746 EXPECT_EQ("us(intl)", xkeyboard_->last_layout_); 771 EXPECT_EQ("us(intl)", xkeyboard_->last_layout_);
747 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); 772 EXPECT_TRUE(manager()->SwitchToPreviousInputMethod(keydown_accelerator));
748 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); 773 EXPECT_TRUE(manager()->SwitchToPreviousInputMethod(keyup_accelerator));
749 EXPECT_TRUE(observer.last_show_message_); 774 EXPECT_TRUE(observer.last_show_message_);
750 EXPECT_EQ("xkb:us:altgr-intl:eng", manager_->GetCurrentInputMethod().id()); 775 EXPECT_EQ("xkb:us:altgr-intl:eng", manager()->GetCurrentInputMethod().id());
751 EXPECT_EQ("us(altgr-intl)", xkeyboard_->last_layout_); 776 EXPECT_EQ("us(altgr-intl)", xkeyboard_->last_layout_);
752 777
753 manager_->RemoveObserver(&observer); 778 manager()->RemoveObserver(&observer);
754 } 779 }
755 780
756 TEST_F(InputMethodManagerImplTest, 781 TEST_F(InputMethodManagerImplTest,
757 TestSwitchToPreviousInputMethodForOneActiveInputMethod) { 782 TestSwitchToPreviousInputMethodForOneActiveInputMethod) {
758 TestObserver observer; 783 TestObserver observer;
759 manager_->AddObserver(&observer); 784 manager()->AddObserver(&observer);
760 InitComponentExtension(); 785 InitComponentExtension();
761 786
762 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); 787 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN);
763 keydown_accelerator.set_type(ui::ET_KEY_PRESSED); 788 keydown_accelerator.set_type(ui::ET_KEY_PRESSED);
764 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); 789 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN);
765 keyup_accelerator.set_type(ui::ET_KEY_RELEASED); 790 keyup_accelerator.set_type(ui::ET_KEY_RELEASED);
766 791
767 std::vector<std::string> ids; 792 std::vector<std::string> ids;
768 ids.push_back("xkb:us:dvorak:eng"); 793 ids.push_back("xkb:us:dvorak:eng");
769 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 794 EXPECT_TRUE(manager()->EnableInputMethods(ids));
770 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 795 EXPECT_EQ(1U, manager()->GetNumActiveInputMethods());
771 796
772 // Ctrl+Space accelerator should not be consumed if there is only one active 797 // Ctrl+Space accelerator should not be consumed if there is only one active
773 // input method. 798 // input method.
774 EXPECT_FALSE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); 799 EXPECT_FALSE(manager()->SwitchToPreviousInputMethod(keydown_accelerator));
775 EXPECT_FALSE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); 800 EXPECT_FALSE(manager()->SwitchToPreviousInputMethod(keyup_accelerator));
776 801
777 manager_->RemoveObserver(&observer); 802 manager()->RemoveObserver(&observer);
778 } 803 }
779 804
780 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithUsLayouts) { 805 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithUsLayouts) {
781 TestObserver observer; 806 TestObserver observer;
782 manager_->AddObserver(&observer); 807 manager()->AddObserver(&observer);
783 InitComponentExtension(); 808 InitComponentExtension();
784 manager_->EnableLayouts("en-US", "xkb:us::eng"); 809 manager()->EnableLayouts("en-US", "xkb:us::eng", true);
785 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); 810 EXPECT_EQ(5U, manager()->GetNumActiveInputMethods());
786 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); 811 EXPECT_EQ("xkb:us::eng", manager()->GetCurrentInputMethod().id());
787 EXPECT_EQ("us", xkeyboard_->last_layout_); 812 EXPECT_EQ("us", xkeyboard_->last_layout_);
788 813
789 // Henkan, Muhenkan, ZenkakuHankaku should be ignored when no Japanese IMEs 814 // Henkan, Muhenkan, ZenkakuHankaku should be ignored when no Japanese IMEs
790 // and keyboards are enabled. 815 // and keyboards are enabled.
791 EXPECT_FALSE(manager_->SwitchInputMethod( 816 EXPECT_FALSE(manager()->SwitchInputMethod(
792 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE))); 817 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE)));
793 EXPECT_FALSE(observer.last_show_message_); 818 EXPECT_FALSE(observer.last_show_message_);
794 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); 819 EXPECT_EQ("xkb:us::eng", manager()->GetCurrentInputMethod().id());
795 EXPECT_EQ("us", xkeyboard_->last_layout_); 820 EXPECT_EQ("us", xkeyboard_->last_layout_);
796 EXPECT_FALSE(manager_->SwitchInputMethod( 821 EXPECT_FALSE(manager()->SwitchInputMethod(
797 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); 822 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE)));
798 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); 823 EXPECT_EQ("xkb:us::eng", manager()->GetCurrentInputMethod().id());
799 EXPECT_EQ("us", xkeyboard_->last_layout_); 824 EXPECT_EQ("us", xkeyboard_->last_layout_);
800 EXPECT_FALSE(manager_->SwitchInputMethod( 825 EXPECT_FALSE(manager()->SwitchInputMethod(
801 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); 826 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE)));
802 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); 827 EXPECT_EQ("xkb:us::eng", manager()->GetCurrentInputMethod().id());
803 EXPECT_EQ("us", xkeyboard_->last_layout_); 828 EXPECT_EQ("us", xkeyboard_->last_layout_);
804 EXPECT_FALSE(manager_->SwitchInputMethod( 829 EXPECT_FALSE(manager()->SwitchInputMethod(
805 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); 830 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE)));
806 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); 831 EXPECT_EQ("xkb:us::eng", manager()->GetCurrentInputMethod().id());
807 EXPECT_EQ("us", xkeyboard_->last_layout_); 832 EXPECT_EQ("us", xkeyboard_->last_layout_);
808 833
809 manager_->RemoveObserver(&observer); 834 manager()->RemoveObserver(&observer);
810 } 835 }
811 836
812 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpLayout) { 837 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpLayout) {
813 // Enable "xkb:jp::jpn" and press Muhenkan/ZenkakuHankaku. 838 // Enable "xkb:jp::jpn" and press Muhenkan/ZenkakuHankaku.
814 InitComponentExtension(); 839 InitComponentExtension();
815 840
816 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); 841 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN);
817 keydown_accelerator.set_type(ui::ET_KEY_PRESSED); 842 keydown_accelerator.set_type(ui::ET_KEY_PRESSED);
818 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); 843 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN);
819 keyup_accelerator.set_type(ui::ET_KEY_RELEASED); 844 keyup_accelerator.set_type(ui::ET_KEY_RELEASED);
820 845
821 manager_->EnableLayouts("ja", "xkb:us::eng"); 846 manager()->EnableLayouts("ja", "xkb:us::eng", true);
822 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 847 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
823 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); 848 EXPECT_EQ("xkb:us::eng", manager()->GetCurrentInputMethod().id());
824 EXPECT_EQ("us", xkeyboard_->last_layout_); 849 EXPECT_EQ("us", xkeyboard_->last_layout_);
825 EXPECT_TRUE(manager_->SwitchInputMethod( 850 EXPECT_TRUE(manager()->SwitchInputMethod(
826 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); 851 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE)));
827 EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); 852 EXPECT_EQ("xkb:jp::jpn", manager()->GetCurrentInputMethod().id());
828 EXPECT_EQ("jp", xkeyboard_->last_layout_); 853 EXPECT_EQ("jp", xkeyboard_->last_layout_);
829 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); 854 EXPECT_TRUE(manager()->SwitchToPreviousInputMethod(keydown_accelerator));
830 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); 855 EXPECT_TRUE(manager()->SwitchToPreviousInputMethod(keyup_accelerator));
831 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); 856 EXPECT_EQ("xkb:us::eng", manager()->GetCurrentInputMethod().id());
832 EXPECT_EQ("us", xkeyboard_->last_layout_); 857 EXPECT_EQ("us", xkeyboard_->last_layout_);
833 EXPECT_TRUE(manager_->SwitchInputMethod( 858 EXPECT_TRUE(manager()->SwitchInputMethod(
834 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); 859 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE)));
835 EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); 860 EXPECT_EQ("xkb:jp::jpn", manager()->GetCurrentInputMethod().id());
836 EXPECT_EQ("jp", xkeyboard_->last_layout_); 861 EXPECT_EQ("jp", xkeyboard_->last_layout_);
837 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); 862 EXPECT_TRUE(manager()->SwitchToPreviousInputMethod(keydown_accelerator));
838 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); 863 EXPECT_TRUE(manager()->SwitchToPreviousInputMethod(keyup_accelerator));
839 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); 864 EXPECT_EQ("xkb:us::eng", manager()->GetCurrentInputMethod().id());
840 EXPECT_EQ("us", xkeyboard_->last_layout_); 865 EXPECT_EQ("us", xkeyboard_->last_layout_);
841 EXPECT_TRUE(manager_->SwitchInputMethod( 866 EXPECT_TRUE(manager()->SwitchInputMethod(
842 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); 867 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE)));
843 EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); 868 EXPECT_EQ("xkb:jp::jpn", manager()->GetCurrentInputMethod().id());
844 EXPECT_EQ("jp", xkeyboard_->last_layout_); 869 EXPECT_EQ("jp", xkeyboard_->last_layout_);
845 } 870 }
846 871
847 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpIme) { 872 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpIme) {
848 InitComponentExtension(); 873 InitComponentExtension();
849 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 874 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
850 std::vector<std::string> ids; 875 std::vector<std::string> ids;
851 ids.push_back("xkb:jp::jpn"); 876 ids.push_back("xkb:jp::jpn");
852 ids.push_back(kNaclMozcJpId); 877 ids.push_back(kNaclMozcJpId);
853 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 878 EXPECT_TRUE(manager()->EnableInputMethods(ids));
854 EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); 879 EXPECT_EQ("xkb:jp::jpn", manager()->GetCurrentInputMethod().id());
855 EXPECT_EQ("jp", xkeyboard_->last_layout_); 880 EXPECT_EQ("jp", xkeyboard_->last_layout_);
856 EXPECT_TRUE(manager_->SwitchInputMethod( 881 EXPECT_TRUE(manager()->SwitchInputMethod(
857 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); 882 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE)));
858 EXPECT_EQ(kNaclMozcJpId, manager_->GetCurrentInputMethod().id()); 883 EXPECT_EQ(kNaclMozcJpId, manager()->GetCurrentInputMethod().id());
859 EXPECT_EQ("jp", xkeyboard_->last_layout_); 884 EXPECT_EQ("jp", xkeyboard_->last_layout_);
860 EXPECT_TRUE(manager_->SwitchInputMethod( 885 EXPECT_TRUE(manager()->SwitchInputMethod(
861 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); 886 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE)));
862 EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); 887 EXPECT_EQ("xkb:jp::jpn", manager()->GetCurrentInputMethod().id());
863 EXPECT_EQ("jp", xkeyboard_->last_layout_); 888 EXPECT_EQ("jp", xkeyboard_->last_layout_);
864 EXPECT_TRUE(manager_->SwitchInputMethod( 889 EXPECT_TRUE(manager()->SwitchInputMethod(
865 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE))); 890 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE)));
866 EXPECT_EQ(kNaclMozcJpId, manager_->GetCurrentInputMethod().id()); 891 EXPECT_EQ(kNaclMozcJpId, manager()->GetCurrentInputMethod().id());
867 EXPECT_EQ("jp", xkeyboard_->last_layout_); 892 EXPECT_EQ("jp", xkeyboard_->last_layout_);
868 EXPECT_TRUE(manager_->SwitchInputMethod( 893 EXPECT_TRUE(manager()->SwitchInputMethod(
869 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE))); 894 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE)));
870 EXPECT_EQ(kNaclMozcJpId, manager_->GetCurrentInputMethod().id()); 895 EXPECT_EQ(kNaclMozcJpId, manager()->GetCurrentInputMethod().id());
871 EXPECT_EQ("jp", xkeyboard_->last_layout_); 896 EXPECT_EQ("jp", xkeyboard_->last_layout_);
872 EXPECT_TRUE(manager_->SwitchInputMethod( 897 EXPECT_TRUE(manager()->SwitchInputMethod(
873 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); 898 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE)));
874 EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); 899 EXPECT_EQ("xkb:jp::jpn", manager()->GetCurrentInputMethod().id());
875 EXPECT_EQ("jp", xkeyboard_->last_layout_); 900 EXPECT_EQ("jp", xkeyboard_->last_layout_);
876 EXPECT_TRUE(manager_->SwitchInputMethod( 901 EXPECT_TRUE(manager()->SwitchInputMethod(
877 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); 902 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE)));
878 EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); 903 EXPECT_EQ("xkb:jp::jpn", manager()->GetCurrentInputMethod().id());
879 EXPECT_EQ("jp", xkeyboard_->last_layout_); 904 EXPECT_EQ("jp", xkeyboard_->last_layout_);
880 905
881 // Add Dvorak. 906 // Add Dvorak.
882 ids.push_back("xkb:us:dvorak:eng"); 907 ids.push_back("xkb:us:dvorak:eng");
883 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 908 EXPECT_TRUE(manager()->EnableInputMethods(ids));
884 EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); 909 EXPECT_EQ("xkb:jp::jpn", manager()->GetCurrentInputMethod().id());
885 EXPECT_EQ("jp", xkeyboard_->last_layout_); 910 EXPECT_EQ("jp", xkeyboard_->last_layout_);
886 EXPECT_TRUE(manager_->SwitchInputMethod( 911 EXPECT_TRUE(manager()->SwitchInputMethod(
887 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); 912 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE)));
888 EXPECT_EQ(kNaclMozcJpId, manager_->GetCurrentInputMethod().id()); 913 EXPECT_EQ(kNaclMozcJpId, manager()->GetCurrentInputMethod().id());
889 EXPECT_EQ("jp", xkeyboard_->last_layout_); 914 EXPECT_EQ("jp", xkeyboard_->last_layout_);
890 EXPECT_TRUE(manager_->SwitchInputMethod( 915 EXPECT_TRUE(manager()->SwitchInputMethod(
891 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); 916 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE)));
892 EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); 917 EXPECT_EQ("xkb:jp::jpn", manager()->GetCurrentInputMethod().id());
893 EXPECT_EQ("jp", xkeyboard_->last_layout_); 918 EXPECT_EQ("jp", xkeyboard_->last_layout_);
894 } 919 }
895 920
896 TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) { 921 TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) {
897 TestObserver observer; 922 TestObserver observer;
898 manager_->AddObserver(&observer); 923 manager()->AddObserver(&observer);
899 InitComponentExtension(); 924 InitComponentExtension();
900 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 925 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
901 std::vector<std::string> ids; 926 std::vector<std::string> ids;
902 ids.push_back("xkb:us:dvorak:eng"); 927 ids.push_back("xkb:us:dvorak:eng");
903 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 928 EXPECT_TRUE(manager()->EnableInputMethods(ids));
904 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 929 EXPECT_EQ(1U, manager()->GetNumActiveInputMethods());
905 EXPECT_EQ(1, observer.input_method_changed_count_); 930 EXPECT_EQ(1, observer.input_method_changed_count_);
906 EXPECT_EQ(ids[0], 931 EXPECT_EQ(ids[0], manager()->GetCurrentInputMethod().id());
907 manager_->GetCurrentInputMethod().id());
908 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 932 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
909 933
910 // Add two Extension IMEs. 934 // Add two Extension IMEs.
911 std::vector<std::string> layouts; 935 std::vector<std::string> layouts;
912 layouts.push_back("us"); 936 layouts.push_back("us");
913 std::vector<std::string> languages; 937 std::vector<std::string> languages;
914 languages.push_back("en-US"); 938 languages.push_back("en-US");
915 939
916 const std::string ext1_id = 940 const std::string ext1_id =
917 extension_ime_util::GetInputMethodID("deadbeef", "engine_id"); 941 extension_ime_util::GetInputMethodID("deadbeef", "engine_id");
918 const InputMethodDescriptor descriptor1(ext1_id, 942 const InputMethodDescriptor descriptor1(ext1_id,
919 "deadbeef input method", 943 "deadbeef input method",
920 layouts, 944 layouts,
921 languages, 945 languages,
922 false, // is_login_keyboard 946 false, // is_login_keyboard
923 GURL(), 947 GURL(),
924 GURL()); 948 GURL());
925 MockInputMethodEngine engine(descriptor1); 949 MockInputMethodEngine engine(descriptor1);
926 manager_->AddInputMethodExtension(ext1_id, &engine); 950 manager()->AddInputMethodExtension(ext1_id, &engine);
927 951
928 // Extension IMEs are not enabled by default. 952 // Extension IMEs are not enabled by default.
929 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 953 EXPECT_EQ(1U, manager()->GetNumActiveInputMethods());
930 954
931 std::vector<std::string> extension_ime_ids; 955 std::vector<std::string> extension_ime_ids;
932 extension_ime_ids.push_back(ext1_id); 956 extension_ime_ids.push_back(ext1_id);
933 manager_->SetEnabledExtensionImes(&extension_ime_ids); 957 manager()->SetEnabledExtensionImes(&extension_ime_ids);
934 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 958 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
935 959
936 { 960 {
937 scoped_ptr<InputMethodDescriptors> methods( 961 scoped_ptr<InputMethodDescriptors> methods(
938 manager_->GetActiveInputMethods()); 962 manager()->GetActiveInputMethods());
939 ASSERT_EQ(2U, methods->size()); 963 ASSERT_EQ(2U, methods->size());
940 // Ext IMEs should be at the end of the list. 964 // Ext IMEs should be at the end of the list.
941 EXPECT_EQ(ext1_id, methods->at(1).id()); 965 EXPECT_EQ(ext1_id, methods->at(1).id());
942 } 966 }
943 967
944 const std::string ext2_id = 968 const std::string ext2_id =
945 extension_ime_util::GetInputMethodID("cafebabe", "engine_id"); 969 extension_ime_util::GetInputMethodID("cafebabe", "engine_id");
946 const InputMethodDescriptor descriptor2(ext2_id, 970 const InputMethodDescriptor descriptor2(ext2_id,
947 "cafebabe input method", 971 "cafebabe input method",
948 layouts, 972 layouts,
949 languages, 973 languages,
950 false, // is_login_keyboard 974 false, // is_login_keyboard
951 GURL(), 975 GURL(),
952 GURL()); 976 GURL());
953 MockInputMethodEngine engine2(descriptor2); 977 MockInputMethodEngine engine2(descriptor2);
954 manager_->AddInputMethodExtension(ext2_id, &engine2); 978 manager()->AddInputMethodExtension(ext2_id, &engine2);
955 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 979 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
956 980
957 extension_ime_ids.push_back(ext2_id); 981 extension_ime_ids.push_back(ext2_id);
958 manager_->SetEnabledExtensionImes(&extension_ime_ids); 982 manager()->SetEnabledExtensionImes(&extension_ime_ids);
959 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); 983 EXPECT_EQ(3U, manager()->GetNumActiveInputMethods());
960 { 984 {
961 scoped_ptr<InputMethodDescriptors> methods( 985 scoped_ptr<InputMethodDescriptors> methods(
962 manager_->GetActiveInputMethods()); 986 manager()->GetActiveInputMethods());
963 ASSERT_EQ(3U, methods->size()); 987 ASSERT_EQ(3U, methods->size());
964 // Ext IMEs should be at the end of the list. 988 // Ext IMEs should be at the end of the list.
965 EXPECT_EQ(ext1_id, methods->at(1).id()); 989 EXPECT_EQ(ext1_id, methods->at(1).id());
966 EXPECT_EQ(ext2_id, methods->at(2).id()); 990 EXPECT_EQ(ext2_id, methods->at(2).id());
967 } 991 }
968 992
969 // Remove them. 993 // Remove them.
970 manager_->RemoveInputMethodExtension(ext1_id); 994 manager()->RemoveInputMethodExtension(ext1_id);
971 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 995 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
972 manager_->RemoveInputMethodExtension(ext2_id); 996 manager()->RemoveInputMethodExtension(ext2_id);
973 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 997 EXPECT_EQ(1U, manager()->GetNumActiveInputMethods());
974 } 998 }
975 999
976 TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) { 1000 TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) {
977 TestObserver observer; 1001 TestObserver observer;
978 InitComponentExtension(); 1002 InitComponentExtension();
979 manager_->AddObserver(&observer); 1003 manager()->AddObserver(&observer);
980 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 1004 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
981 std::vector<std::string> ids; 1005 std::vector<std::string> ids;
982 ids.push_back("xkb:us::eng"); 1006 ids.push_back("xkb:us::eng");
983 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 1007 EXPECT_TRUE(manager()->EnableInputMethods(ids));
984 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 1008 EXPECT_EQ(1U, manager()->GetNumActiveInputMethods());
985 EXPECT_EQ(1, observer.input_method_changed_count_); 1009 EXPECT_EQ(1, observer.input_method_changed_count_);
986 EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); 1010 EXPECT_EQ(ids[0], manager()->GetCurrentInputMethod().id());
987 EXPECT_EQ("us", xkeyboard_->last_layout_); 1011 EXPECT_EQ("us", xkeyboard_->last_layout_);
988 1012
989 // Add an Extension IME. 1013 // Add an Extension IME.
990 std::vector<std::string> layouts; 1014 std::vector<std::string> layouts;
991 layouts.push_back("us(dvorak)"); 1015 layouts.push_back("us(dvorak)");
992 std::vector<std::string> languages; 1016 std::vector<std::string> languages;
993 languages.push_back("en-US"); 1017 languages.push_back("en-US");
994 1018
995 const std::string ext_id = 1019 const std::string ext_id =
996 extension_ime_util::GetInputMethodID("deadbeef", "engine_id"); 1020 extension_ime_util::GetInputMethodID("deadbeef", "engine_id");
997 const InputMethodDescriptor descriptor(ext_id, 1021 const InputMethodDescriptor descriptor(ext_id,
998 "deadbeef input method", 1022 "deadbeef input method",
999 layouts, 1023 layouts,
1000 languages, 1024 languages,
1001 false, // is_login_keyboard 1025 false, // is_login_keyboard
1002 GURL(), 1026 GURL(),
1003 GURL()); 1027 GURL());
1004 MockInputMethodEngine engine(descriptor); 1028 MockInputMethodEngine engine(descriptor);
1005 manager_->AddInputMethodExtension(ext_id, &engine); 1029 manager()->AddInputMethodExtension(ext_id, &engine);
1006 1030
1007 // Extension IME is not enabled by default. 1031 // Extension IME is not enabled by default.
1008 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 1032 EXPECT_EQ(1U, manager()->GetNumActiveInputMethods());
1009 EXPECT_EQ(1, observer.input_method_changed_count_); 1033 EXPECT_EQ(1, observer.input_method_changed_count_);
1010 1034
1011 std::vector<std::string> extension_ime_ids; 1035 std::vector<std::string> extension_ime_ids;
1012 extension_ime_ids.push_back(ext_id); 1036 extension_ime_ids.push_back(ext_id);
1013 manager_->SetEnabledExtensionImes(&extension_ime_ids); 1037 manager()->SetEnabledExtensionImes(&extension_ime_ids);
1014 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 1038 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
1015 1039
1016 // Switch to the IME. 1040 // Switch to the IME.
1017 manager_->SwitchToNextInputMethod(); 1041 manager()->SwitchToNextInputMethod();
1018 EXPECT_EQ(3, observer.input_method_changed_count_); 1042 EXPECT_EQ(3, observer.input_method_changed_count_);
1019 EXPECT_EQ(ext_id, manager_->GetCurrentInputMethod().id()); 1043 EXPECT_EQ(ext_id, manager()->GetCurrentInputMethod().id());
1020 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 1044 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
1021 1045
1022 // Lock the screen. This is for crosbug.com/27049. 1046 // Lock the screen. This is for crosbug.com/27049.
1023 manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN); 1047 manager()->SetState(InputMethodManager::STATE_LOCK_SCREEN);
1024 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); // Qwerty. No Ext. IME 1048 EXPECT_EQ(1U, manager()->GetNumActiveInputMethods()); // Qwerty. No Ext. IME
1025 EXPECT_EQ("xkb:us::eng", 1049 EXPECT_EQ("xkb:us::eng", manager()->GetCurrentInputMethod().id());
1026 manager_->GetCurrentInputMethod().id());
1027 EXPECT_EQ("us", xkeyboard_->last_layout_); 1050 EXPECT_EQ("us", xkeyboard_->last_layout_);
1028 1051
1029 // Unlock the screen. 1052 // Unlock the screen.
1030 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 1053 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
1031 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 1054 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
1032 EXPECT_EQ(ext_id, manager_->GetCurrentInputMethod().id()); 1055 EXPECT_EQ(ext_id, manager()->GetCurrentInputMethod().id());
1033 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 1056 EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_);
1034 { 1057 {
1035 // This is for crosbug.com/27052. 1058 // This is for crosbug.com/27052.
1036 scoped_ptr<InputMethodDescriptors> methods( 1059 scoped_ptr<InputMethodDescriptors> methods(
1037 manager_->GetActiveInputMethods()); 1060 manager()->GetActiveInputMethods());
1038 ASSERT_EQ(2U, methods->size()); 1061 ASSERT_EQ(2U, methods->size());
1039 // Ext. IMEs should be at the end of the list. 1062 // Ext. IMEs should be at the end of the list.
1040 EXPECT_EQ(ext_id, methods->at(1).id()); 1063 EXPECT_EQ(ext_id, methods->at(1).id());
1041 } 1064 }
1042 manager_->RemoveObserver(&observer); 1065 manager()->RemoveObserver(&observer);
1043 } 1066 }
1044 1067
1045 TEST_F(InputMethodManagerImplTest, 1068 TEST_F(InputMethodManagerImplTest,
1046 ChangeInputMethodBeforeComponentExtensionInitialization_OneIME) { 1069 ChangeInputMethodBeforeComponentExtensionInitialization_OneIME) {
1047 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 1070 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
1048 std::vector<std::string> ids; 1071 std::vector<std::string> ids;
1049 ids.push_back(kNaclMozcUsId); 1072 ids.push_back(kNaclMozcUsId);
1050 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 1073 EXPECT_TRUE(manager()->EnableInputMethods(ids));
1051 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 1074 EXPECT_EQ(1U, manager()->GetNumActiveInputMethods());
1052 manager_->ChangeInputMethod(kNaclMozcUsId); 1075 manager()->ChangeInputMethod(kNaclMozcUsId);
1053 1076
1054 InitComponentExtension(); 1077 InitComponentExtension();
1055 EXPECT_EQ(kNaclMozcUsId, manager_->GetCurrentInputMethod().id()); 1078 EXPECT_EQ(kNaclMozcUsId, manager()->GetCurrentInputMethod().id());
1056 } 1079 }
1057 1080
1058 TEST_F(InputMethodManagerImplTest, 1081 TEST_F(InputMethodManagerImplTest,
1059 ChangeInputMethodBeforeComponentExtensionInitialization_TwoIME) { 1082 ChangeInputMethodBeforeComponentExtensionInitialization_TwoIME) {
1060 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 1083 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
1061 std::vector<std::string> ids; 1084 std::vector<std::string> ids;
1062 ids.push_back(kNaclMozcUsId); 1085 ids.push_back(kNaclMozcUsId);
1063 ids.push_back(kNaclMozcJpId); 1086 ids.push_back(kNaclMozcJpId);
1064 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 1087 EXPECT_TRUE(manager()->EnableInputMethods(ids));
1065 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 1088 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
1066 manager_->ChangeInputMethod(kNaclMozcUsId); 1089 manager()->ChangeInputMethod(kNaclMozcUsId);
1067 manager_->ChangeInputMethod(kNaclMozcJpId); 1090 manager()->ChangeInputMethod(kNaclMozcJpId);
1068 1091
1069 InitComponentExtension(); 1092 InitComponentExtension();
1070 EXPECT_EQ(kNaclMozcJpId, manager_->GetCurrentInputMethod().id()); 1093 EXPECT_EQ(kNaclMozcJpId, manager()->GetCurrentInputMethod().id());
1071 } 1094 }
1072 1095
1073 TEST_F(InputMethodManagerImplTest, 1096 TEST_F(InputMethodManagerImplTest,
1074 ChangeInputMethodBeforeComponentExtensionInitialization_CompOneIME) { 1097 ChangeInputMethodBeforeComponentExtensionInitialization_CompOneIME) {
1075 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 1098 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
1076 const std::string ext_id = extension_ime_util::GetComponentInputMethodID( 1099 const std::string ext_id = extension_ime_util::GetComponentInputMethodID(
1077 ime_list_[0].id, 1100 ime_list_[0].id,
1078 ime_list_[0].engines[0].engine_id); 1101 ime_list_[0].engines[0].engine_id);
1079 std::vector<std::string> ids; 1102 std::vector<std::string> ids;
1080 ids.push_back(ext_id); 1103 ids.push_back(ext_id);
1081 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 1104 EXPECT_TRUE(manager()->EnableInputMethods(ids));
1082 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 1105 EXPECT_EQ(1U, manager()->GetNumActiveInputMethods());
1083 manager_->ChangeInputMethod(ext_id); 1106 manager()->ChangeInputMethod(ext_id);
1084 1107
1085 InitComponentExtension(); 1108 InitComponentExtension();
1086 EXPECT_EQ(ext_id, manager_->GetCurrentInputMethod().id()); 1109 EXPECT_EQ(ext_id, manager()->GetCurrentInputMethod().id());
1087 } 1110 }
1088 1111
1089 TEST_F(InputMethodManagerImplTest, 1112 TEST_F(InputMethodManagerImplTest,
1090 ChangeInputMethodBeforeComponentExtensionInitialization_CompTwoIME) { 1113 ChangeInputMethodBeforeComponentExtensionInitialization_CompTwoIME) {
1091 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 1114 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
1092 const std::string ext_id1 = extension_ime_util::GetComponentInputMethodID( 1115 const std::string ext_id1 = extension_ime_util::GetComponentInputMethodID(
1093 ime_list_[0].id, 1116 ime_list_[0].id,
1094 ime_list_[0].engines[0].engine_id); 1117 ime_list_[0].engines[0].engine_id);
1095 const std::string ext_id2 = extension_ime_util::GetComponentInputMethodID( 1118 const std::string ext_id2 = extension_ime_util::GetComponentInputMethodID(
1096 ime_list_[1].id, 1119 ime_list_[1].id,
1097 ime_list_[1].engines[0].engine_id); 1120 ime_list_[1].engines[0].engine_id);
1098 std::vector<std::string> ids; 1121 std::vector<std::string> ids;
1099 ids.push_back(ext_id1); 1122 ids.push_back(ext_id1);
1100 ids.push_back(ext_id2); 1123 ids.push_back(ext_id2);
1101 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 1124 EXPECT_TRUE(manager()->EnableInputMethods(ids));
1102 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 1125 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
1103 manager_->ChangeInputMethod(ext_id1); 1126 manager()->ChangeInputMethod(ext_id1);
1104 manager_->ChangeInputMethod(ext_id2); 1127 manager()->ChangeInputMethod(ext_id2);
1105 1128
1106 InitComponentExtension(); 1129 InitComponentExtension();
1107 EXPECT_EQ(ext_id2, manager_->GetCurrentInputMethod().id()); 1130 EXPECT_EQ(ext_id2, manager()->GetCurrentInputMethod().id());
1108 } 1131 }
1109 1132
1110 TEST_F(InputMethodManagerImplTest, 1133 TEST_F(InputMethodManagerImplTest,
1111 ChangeInputMethod_ComponenteExtensionOneIME) { 1134 ChangeInputMethod_ComponenteExtensionOneIME) {
1112 InitComponentExtension(); 1135 InitComponentExtension();
1113 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 1136 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
1114 const std::string ext_id = extension_ime_util::GetComponentInputMethodID( 1137 const std::string ext_id = extension_ime_util::GetComponentInputMethodID(
1115 ime_list_[0].id, 1138 ime_list_[0].id,
1116 ime_list_[0].engines[0].engine_id); 1139 ime_list_[0].engines[0].engine_id);
1117 std::vector<std::string> ids; 1140 std::vector<std::string> ids;
1118 ids.push_back(ext_id); 1141 ids.push_back(ext_id);
1119 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 1142 EXPECT_TRUE(manager()->EnableInputMethods(ids));
1120 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 1143 EXPECT_EQ(1U, manager()->GetNumActiveInputMethods());
1121 EXPECT_EQ(ext_id, manager_->GetCurrentInputMethod().id()); 1144 EXPECT_EQ(ext_id, manager()->GetCurrentInputMethod().id());
1122 } 1145 }
1123 1146
1124 TEST_F(InputMethodManagerImplTest, 1147 TEST_F(InputMethodManagerImplTest,
1125 ChangeInputMethod_ComponenteExtensionTwoIME) { 1148 ChangeInputMethod_ComponenteExtensionTwoIME) {
1126 InitComponentExtension(); 1149 InitComponentExtension();
1127 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 1150 manager()->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
1128 const std::string ext_id1 = extension_ime_util::GetComponentInputMethodID( 1151 const std::string ext_id1 = extension_ime_util::GetComponentInputMethodID(
1129 ime_list_[0].id, 1152 ime_list_[0].id,
1130 ime_list_[0].engines[0].engine_id); 1153 ime_list_[0].engines[0].engine_id);
1131 const std::string ext_id2 = extension_ime_util::GetComponentInputMethodID( 1154 const std::string ext_id2 = extension_ime_util::GetComponentInputMethodID(
1132 ime_list_[1].id, 1155 ime_list_[1].id,
1133 ime_list_[1].engines[0].engine_id); 1156 ime_list_[1].engines[0].engine_id);
1134 std::vector<std::string> ids; 1157 std::vector<std::string> ids;
1135 ids.push_back(ext_id1); 1158 ids.push_back(ext_id1);
1136 ids.push_back(ext_id2); 1159 ids.push_back(ext_id2);
1137 EXPECT_TRUE(manager_->EnableInputMethods(ids)); 1160 EXPECT_TRUE(manager()->EnableInputMethods(ids));
1138 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 1161 EXPECT_EQ(2U, manager()->GetNumActiveInputMethods());
1139 EXPECT_EQ(ext_id1, manager_->GetCurrentInputMethod().id()); 1162 EXPECT_EQ(ext_id1, manager()->GetCurrentInputMethod().id());
1140 manager_->ChangeInputMethod(ext_id2); 1163 manager()->ChangeInputMethod(ext_id2);
1141 EXPECT_EQ(ext_id2, manager_->GetCurrentInputMethod().id()); 1164 EXPECT_EQ(ext_id2, manager()->GetCurrentInputMethod().id());
1142 } 1165 }
1143 1166
1144 } // namespace input_method 1167 } // namespace input_method
1145 } // namespace chromeos 1168 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698