| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 profile_manager_.reset(); | 161 profile_manager_.reset(); |
| 162 } | 162 } |
| 163 | 163 |
| 164 protected: | 164 protected: |
| 165 // Helper function to initialize component extension stuff for testing. | 165 // Helper function to initialize component extension stuff for testing. |
| 166 void InitComponentExtension() { | 166 void InitComponentExtension() { |
| 167 mock_delegate_ = new MockComponentExtIMEManagerDelegate(); | 167 mock_delegate_ = new MockComponentExtIMEManagerDelegate(); |
| 168 mock_delegate_->set_ime_list(ime_list_); | 168 mock_delegate_->set_ime_list(ime_list_); |
| 169 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(mock_delegate_); | 169 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(mock_delegate_); |
| 170 | 170 |
| 171 manager_->SetState(manager_->CreateNewState(NULL)); |
| 172 |
| 171 std::vector<std::string> layouts; | 173 std::vector<std::string> layouts; |
| 172 layouts.push_back("us"); | 174 layouts.push_back("us"); |
| 173 std::vector<std::string> languages; | 175 std::vector<std::string> languages; |
| 174 languages.push_back("en-US"); | 176 languages.push_back("en-US"); |
| 175 | 177 |
| 176 // Note, for production, these SetEngineHandler are called when | 178 // Note, for production, these SetEngineHandler are called when |
| 177 // IMEEngineHandlerInterface is initialized via | 179 // IMEEngineHandlerInterface is initialized via |
| 178 // InitializeComponentextension. | 180 // InitializeComponentextension. |
| 179 InputMethodDescriptors descriptors; | 181 InputMethodDescriptors descriptors; |
| 180 manager_->AddInputMethodExtension(ImeIdFromEngineId(kNaclMozcUsId), | 182 manager_->GetActiveIMEState()->AddInputMethodExtension( |
| 181 descriptors, | 183 ImeIdFromEngineId(kNaclMozcUsId), |
| 182 mock_engine_handler_.get()); | 184 descriptors, |
| 183 manager_->AddInputMethodExtension(ImeIdFromEngineId(kExt2Engine1Id), | 185 mock_engine_handler_.get()); |
| 184 descriptors, | 186 manager_->GetActiveIMEState()->AddInputMethodExtension( |
| 185 mock_engine_handler_.get()); | 187 ImeIdFromEngineId(kExt2Engine1Id), |
| 188 descriptors, |
| 189 mock_engine_handler_.get()); |
| 186 manager_->InitializeComponentExtensionForTesting(delegate.Pass()); | 190 manager_->InitializeComponentExtensionForTesting(delegate.Pass()); |
| 187 } | 191 } |
| 188 | 192 |
| 189 void InitImeList() { | 193 void InitImeList() { |
| 190 ime_list_.clear(); | 194 ime_list_.clear(); |
| 191 | 195 |
| 192 ComponentExtensionIME ext_xkb; | 196 ComponentExtensionIME ext_xkb; |
| 193 ext_xkb.id = extension_ime_util::kXkbExtensionId; | 197 ext_xkb.id = extension_ime_util::kXkbExtensionId; |
| 194 ext_xkb.description = "ext_xkb_description"; | 198 ext_xkb.description = "ext_xkb_description"; |
| 195 ext_xkb.path = base::FilePath("ext_xkb_file_path"); | 199 ext_xkb.path = base::FilePath("ext_xkb_file_path"); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 // For http://crbug.com/19655#c11 - (3). browser_state_monitor_unittest.cc is | 356 // For http://crbug.com/19655#c11 - (3). browser_state_monitor_unittest.cc is |
| 353 // also for the scenario. | 357 // also for the scenario. |
| 354 std::vector<std::string> keyboard_layouts; | 358 std::vector<std::string> keyboard_layouts; |
| 355 keyboard_layouts.push_back("xkb:us::eng"); | 359 keyboard_layouts.push_back("xkb:us::eng"); |
| 356 | 360 |
| 357 TestObserver observer; | 361 TestObserver observer; |
| 358 InitComponentExtension(); | 362 InitComponentExtension(); |
| 359 manager_->AddObserver(&observer); | 363 manager_->AddObserver(&observer); |
| 360 menu_manager_->AddObserver(&observer); | 364 menu_manager_->AddObserver(&observer); |
| 361 EXPECT_EQ(0, observer.input_method_changed_count_); | 365 EXPECT_EQ(0, observer.input_method_changed_count_); |
| 362 manager_->EnableLoginLayouts("en-US", keyboard_layouts); | 366 manager_->GetActiveIMEState()->EnableLoginLayouts("en-US", keyboard_layouts); |
| 363 EXPECT_EQ(5U, manager_->GetActiveInputMethods()->size()); | 367 EXPECT_EQ(5U, manager_->GetActiveIMEState()->GetActiveInputMethods()->size()); |
| 364 EXPECT_EQ(1, observer.input_method_changed_count_); | 368 EXPECT_EQ(1, observer.input_method_changed_count_); |
| 365 EXPECT_EQ(1, observer.input_method_menu_item_changed_count_); | 369 EXPECT_EQ(1, observer.input_method_menu_item_changed_count_); |
| 366 manager_->ChangeInputMethod(ImeIdFromEngineId("xkb:us:dvorak:eng")); | 370 manager_->GetActiveIMEState()->ChangeInputMethod( |
| 371 ImeIdFromEngineId("xkb:us:dvorak:eng"), false /* show_message */); |
| 367 EXPECT_FALSE(observer.last_show_message_); | 372 EXPECT_FALSE(observer.last_show_message_); |
| 368 EXPECT_EQ(2, observer.input_method_changed_count_); | 373 EXPECT_EQ(2, observer.input_method_changed_count_); |
| 369 EXPECT_EQ(2, observer.input_method_menu_item_changed_count_); | 374 EXPECT_EQ(2, observer.input_method_menu_item_changed_count_); |
| 370 manager_->ChangeInputMethod(ImeIdFromEngineId("xkb:us:dvorak:eng")); | 375 manager_->GetActiveIMEState()->ChangeInputMethod( |
| 376 ImeIdFromEngineId("xkb:us:dvorak:eng"), false /* show_message */); |
| 371 EXPECT_FALSE(observer.last_show_message_); | 377 EXPECT_FALSE(observer.last_show_message_); |
| 372 | 378 |
| 373 // The observer is always notified even when the same input method ID is | 379 // The observer is always notified even when the same input method ID is |
| 374 // passed to ChangeInputMethod() more than twice. | 380 // passed to ChangeInputMethod() more than twice. |
| 375 // TODO(komatsu): Revisit if this is neccessary. | 381 // TODO(komatsu): Revisit if this is neccessary. |
| 376 EXPECT_EQ(3, observer.input_method_changed_count_); | 382 EXPECT_EQ(3, observer.input_method_changed_count_); |
| 377 | 383 |
| 378 // If the same input method ID is passed, PropertyChanged() is not | 384 // If the same input method ID is passed, PropertyChanged() is not |
| 379 // notified. | 385 // notified. |
| 380 EXPECT_EQ(2, observer.input_method_menu_item_changed_count_); | 386 EXPECT_EQ(2, observer.input_method_menu_item_changed_count_); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 403 ImeIdFromEngineId("xkb:fr::fra")); | 409 ImeIdFromEngineId("xkb:fr::fra")); |
| 404 EXPECT_TRUE(Contain(methods, *id_to_find)); | 410 EXPECT_TRUE(Contain(methods, *id_to_find)); |
| 405 } | 411 } |
| 406 | 412 |
| 407 TEST_F(InputMethodManagerImplTest, TestEnableLayouts) { | 413 TEST_F(InputMethodManagerImplTest, TestEnableLayouts) { |
| 408 // Currently 5 keyboard layouts are supported for en-US, and 1 for ja. See | 414 // Currently 5 keyboard layouts are supported for en-US, and 1 for ja. See |
| 409 // ibus_input_method.txt. | 415 // ibus_input_method.txt. |
| 410 std::vector<std::string> keyboard_layouts; | 416 std::vector<std::string> keyboard_layouts; |
| 411 | 417 |
| 412 InitComponentExtension(); | 418 InitComponentExtension(); |
| 413 manager_->EnableLoginLayouts("en-US", keyboard_layouts); | 419 manager_->GetActiveIMEState()->EnableLoginLayouts("en-US", keyboard_layouts); |
| 414 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); | 420 EXPECT_EQ(5U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 415 | 421 |
| 416 // For http://crbug.com/19655#c11 - (5) | 422 // For http://crbug.com/19655#c11 - (5) |
| 417 // The hardware keyboard layout "xkb:us::eng" is always active, hence 2U. | 423 // The hardware keyboard layout "xkb:us::eng" is always active, hence 2U. |
| 418 manager_->EnableLoginLayouts("ja", keyboard_layouts); // Japanese | 424 manager_->GetActiveIMEState()->EnableLoginLayouts( |
| 419 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 425 "ja", keyboard_layouts); // Japanese |
| 426 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 420 } | 427 } |
| 421 | 428 |
| 422 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsAndCurrentInputMethod) { | 429 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsAndCurrentInputMethod) { |
| 423 // For http://crbug.com/329061 | 430 // For http://crbug.com/329061 |
| 424 std::vector<std::string> keyboard_layouts; | 431 std::vector<std::string> keyboard_layouts; |
| 425 keyboard_layouts.push_back(ImeIdFromEngineId("xkb:se::swe")); | 432 keyboard_layouts.push_back(ImeIdFromEngineId("xkb:se::swe")); |
| 426 | 433 |
| 427 InitComponentExtension(); | 434 InitComponentExtension(); |
| 428 manager_->EnableLoginLayouts("en-US", keyboard_layouts); | 435 manager_->GetActiveIMEState()->EnableLoginLayouts("en-US", keyboard_layouts); |
| 429 const std::string im_id = manager_->GetCurrentInputMethod().id(); | 436 const std::string im_id = |
| 437 manager_->GetActiveIMEState()->GetCurrentInputMethod().id(); |
| 430 EXPECT_EQ(ImeIdFromEngineId("xkb:se::swe"), im_id); | 438 EXPECT_EQ(ImeIdFromEngineId("xkb:se::swe"), im_id); |
| 431 } | 439 } |
| 432 | 440 |
| 433 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsNonUsHardwareKeyboard) { | 441 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsNonUsHardwareKeyboard) { |
| 434 InitComponentExtension(); | 442 InitComponentExtension(); |
| 435 // The physical layout is French. | 443 // The physical layout is French. |
| 436 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting( | 444 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting( |
| 437 "xkb:fr::fra"); | 445 "xkb:fr::fra"); |
| 438 manager_->EnableLoginLayouts( | 446 manager_->GetActiveIMEState()->EnableLoginLayouts( |
| 439 "en-US", | 447 "en-US", |
| 440 manager_->GetInputMethodUtil()->GetHardwareLoginInputMethodIds()); | 448 manager_->GetInputMethodUtil()->GetHardwareLoginInputMethodIds()); |
| 441 EXPECT_EQ(6U, manager_->GetNumActiveInputMethods()); // 5 + French | 449 EXPECT_EQ( |
| 450 6U, |
| 451 manager_->GetActiveIMEState()->GetNumActiveInputMethods()); // 5 + French |
| 442 // The physical layout is Japanese. | 452 // The physical layout is Japanese. |
| 443 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting( | 453 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting( |
| 444 "xkb:jp::jpn"); | 454 "xkb:jp::jpn"); |
| 445 manager_->EnableLoginLayouts( | 455 manager_->GetActiveIMEState()->EnableLoginLayouts( |
| 446 "ja", | 456 "ja", manager_->GetInputMethodUtil()->GetHardwareLoginInputMethodIds()); |
| 447 manager_->GetInputMethodUtil()->GetHardwareLoginInputMethodIds()); | |
| 448 // "xkb:us::eng" is not needed, hence 1. | 457 // "xkb:us::eng" is not needed, hence 1. |
| 449 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 458 EXPECT_EQ(1U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 450 | 459 |
| 451 // The physical layout is Russian. | 460 // The physical layout is Russian. |
| 452 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting( | 461 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting( |
| 453 "xkb:ru::rus"); | 462 "xkb:ru::rus"); |
| 454 manager_->EnableLoginLayouts( | 463 manager_->GetActiveIMEState()->EnableLoginLayouts( |
| 455 "ru", | 464 "ru", manager_->GetInputMethodUtil()->GetHardwareLoginInputMethodIds()); |
| 456 manager_->GetInputMethodUtil()->GetHardwareLoginInputMethodIds()); | |
| 457 // "xkb:us::eng" only. | 465 // "xkb:us::eng" only. |
| 458 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 466 EXPECT_EQ(1U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 459 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), | 467 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), |
| 460 manager_->GetActiveInputMethodIds().front()); | 468 manager_->GetActiveIMEState()->GetActiveInputMethodIds().front()); |
| 461 } | 469 } |
| 462 | 470 |
| 463 TEST_F(InputMethodManagerImplTest, TestEnableMultipleHardwareKeyboardLayout) { | 471 TEST_F(InputMethodManagerImplTest, TestEnableMultipleHardwareKeyboardLayout) { |
| 464 InitComponentExtension(); | 472 InitComponentExtension(); |
| 465 // The physical layouts are French and Hungarian. | 473 // The physical layouts are French and Hungarian. |
| 466 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting( | 474 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting( |
| 467 "xkb:fr::fra,xkb:hu::hun"); | 475 "xkb:fr::fra,xkb:hu::hun"); |
| 468 manager_->EnableLoginLayouts( | 476 manager_->GetActiveIMEState()->EnableLoginLayouts( |
| 469 "en-US", | 477 "en-US", |
| 470 manager_->GetInputMethodUtil()->GetHardwareLoginInputMethodIds()); | 478 manager_->GetInputMethodUtil()->GetHardwareLoginInputMethodIds()); |
| 471 // 5 + French + Hungarian | 479 // 5 + French + Hungarian |
| 472 EXPECT_EQ(7U, manager_->GetNumActiveInputMethods()); | 480 EXPECT_EQ(7U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 473 } | 481 } |
| 474 | 482 |
| 475 TEST_F(InputMethodManagerImplTest, | 483 TEST_F(InputMethodManagerImplTest, |
| 476 TestEnableMultipleHardwareKeyboardLayout_NoLoginKeyboard) { | 484 TestEnableMultipleHardwareKeyboardLayout_NoLoginKeyboard) { |
| 477 InitComponentExtension(); | 485 InitComponentExtension(); |
| 478 // The physical layouts are English (US) and Russian. | 486 // The physical layouts are English (US) and Russian. |
| 479 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting( | 487 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting( |
| 480 "xkb:us::eng,xkb:ru::rus"); | 488 "xkb:us::eng,xkb:ru::rus"); |
| 481 manager_->EnableLoginLayouts( | 489 manager_->GetActiveIMEState()->EnableLoginLayouts( |
| 482 "ru", | 490 "ru", manager_->GetInputMethodUtil()->GetHardwareLoginInputMethodIds()); |
| 483 manager_->GetInputMethodUtil()->GetHardwareLoginInputMethodIds()); | |
| 484 // xkb:us:eng | 491 // xkb:us:eng |
| 485 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 492 EXPECT_EQ(1U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 486 } | 493 } |
| 487 | 494 |
| 488 TEST_F(InputMethodManagerImplTest, TestActiveInputMethods) { | 495 TEST_F(InputMethodManagerImplTest, TestActiveInputMethods) { |
| 489 InitComponentExtension(); | 496 InitComponentExtension(); |
| 490 std::vector<std::string> keyboard_layouts; | 497 std::vector<std::string> keyboard_layouts; |
| 491 manager_->EnableLoginLayouts("ja", keyboard_layouts); // Japanese | 498 manager_->GetActiveIMEState()->EnableLoginLayouts( |
| 492 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 499 "ja", keyboard_layouts); // Japanese |
| 500 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 493 scoped_ptr<InputMethodDescriptors> methods( | 501 scoped_ptr<InputMethodDescriptors> methods( |
| 494 manager_->GetActiveInputMethods()); | 502 manager_->GetActiveIMEState()->GetActiveInputMethods()); |
| 495 ASSERT_TRUE(methods.get()); | 503 ASSERT_TRUE(methods.get()); |
| 496 EXPECT_EQ(2U, methods->size()); | 504 EXPECT_EQ(2U, methods->size()); |
| 497 const InputMethodDescriptor* id_to_find = | 505 const InputMethodDescriptor* id_to_find = |
| 498 manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( | 506 manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( |
| 499 ImeIdFromEngineId("xkb:us::eng")); | 507 ImeIdFromEngineId("xkb:us::eng")); |
| 500 EXPECT_TRUE(id_to_find && Contain(*methods.get(), *id_to_find)); | 508 EXPECT_TRUE(id_to_find && Contain(*methods.get(), *id_to_find)); |
| 501 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( | 509 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( |
| 502 ImeIdFromEngineId("xkb:jp::jpn")); | 510 ImeIdFromEngineId("xkb:jp::jpn")); |
| 503 EXPECT_TRUE(id_to_find && Contain(*methods.get(), *id_to_find)); | 511 EXPECT_TRUE(id_to_find && Contain(*methods.get(), *id_to_find)); |
| 504 } | 512 } |
| 505 | 513 |
| 506 TEST_F(InputMethodManagerImplTest, TestEnableTwoLayouts) { | 514 TEST_F(InputMethodManagerImplTest, TestEnableTwoLayouts) { |
| 507 // For http://crbug.com/19655#c11 - (8), step 6. | 515 // For http://crbug.com/19655#c11 - (8), step 6. |
| 508 TestObserver observer; | 516 TestObserver observer; |
| 509 manager_->AddObserver(&observer); | 517 manager_->AddObserver(&observer); |
| 510 InitComponentExtension(); | 518 InitComponentExtension(); |
| 511 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 519 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 512 std::vector<std::string> ids; | 520 std::vector<std::string> ids; |
| 513 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); | 521 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); |
| 514 ids.push_back(ImeIdFromEngineId("xkb:us:colemak:eng")); | 522 ids.push_back(ImeIdFromEngineId("xkb:us:colemak:eng")); |
| 515 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 523 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 516 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 524 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 517 // Since all the IDs added avobe are keyboard layouts, Start() should not be | 525 // Since all the IDs added avobe are keyboard layouts, Start() should not be |
| 518 // called. | 526 // called. |
| 519 EXPECT_EQ(1, observer.input_method_changed_count_); | 527 EXPECT_EQ(1, observer.input_method_changed_count_); |
| 520 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id()); | 528 EXPECT_EQ(ImeIdFromEngineId(ids[0]), |
| 529 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 521 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 530 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 522 // Disable Dvorak. | 531 // Disable Dvorak. |
| 523 ids.erase(ids.begin()); | 532 ids.erase(ids.begin()); |
| 524 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 533 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 525 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 534 EXPECT_EQ(1U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 526 EXPECT_EQ(2, observer.input_method_changed_count_); | 535 EXPECT_EQ(2, observer.input_method_changed_count_); |
| 527 EXPECT_EQ(ImeIdFromEngineId(ids[0]), // colemak | 536 EXPECT_EQ(ImeIdFromEngineId(ids[0]), // colemak |
| 528 manager_->GetCurrentInputMethod().id()); | 537 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 529 EXPECT_EQ("us(colemak)", keyboard_->last_layout_); | 538 EXPECT_EQ("us(colemak)", keyboard_->last_layout_); |
| 530 manager_->RemoveObserver(&observer); | 539 manager_->RemoveObserver(&observer); |
| 531 } | 540 } |
| 532 | 541 |
| 533 TEST_F(InputMethodManagerImplTest, TestEnableThreeLayouts) { | 542 TEST_F(InputMethodManagerImplTest, TestEnableThreeLayouts) { |
| 534 // For http://crbug.com/19655#c11 - (9). | 543 // For http://crbug.com/19655#c11 - (9). |
| 535 TestObserver observer; | 544 TestObserver observer; |
| 536 manager_->AddObserver(&observer); | 545 manager_->AddObserver(&observer); |
| 537 InitComponentExtension(); | 546 InitComponentExtension(); |
| 538 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 547 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 539 std::vector<std::string> ids; | 548 std::vector<std::string> ids; |
| 540 ids.push_back(ImeIdFromEngineId("xkb:us::eng")); | 549 ids.push_back(ImeIdFromEngineId("xkb:us::eng")); |
| 541 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); | 550 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); |
| 542 ids.push_back(ImeIdFromEngineId("xkb:us:colemak:eng")); | 551 ids.push_back(ImeIdFromEngineId("xkb:us:colemak:eng")); |
| 543 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 552 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 544 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); | 553 EXPECT_EQ(3U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 545 EXPECT_EQ(1, observer.input_method_changed_count_); | 554 EXPECT_EQ(1, observer.input_method_changed_count_); |
| 546 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id()); | 555 EXPECT_EQ(ImeIdFromEngineId(ids[0]), |
| 556 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 547 EXPECT_EQ("us", keyboard_->last_layout_); | 557 EXPECT_EQ("us", keyboard_->last_layout_); |
| 548 // Switch to Dvorak. | 558 // Switch to Dvorak. |
| 549 manager_->SwitchToNextInputMethod(); | 559 manager_->GetActiveIMEState()->SwitchToNextInputMethod(); |
| 550 EXPECT_EQ(2, observer.input_method_changed_count_); | 560 EXPECT_EQ(2, observer.input_method_changed_count_); |
| 551 EXPECT_EQ(ImeIdFromEngineId(ids[1]), manager_->GetCurrentInputMethod().id()); | 561 EXPECT_EQ(ImeIdFromEngineId(ids[1]), |
| 562 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 552 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 563 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 553 // Disable Dvorak. | 564 // Disable Dvorak. |
| 554 ids.erase(ids.begin() + 1); | 565 ids.erase(ids.begin() + 1); |
| 555 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 566 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 556 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 567 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 557 EXPECT_EQ(3, observer.input_method_changed_count_); | 568 EXPECT_EQ(3, observer.input_method_changed_count_); |
| 558 EXPECT_EQ(ImeIdFromEngineId(ids[0]), // US Qwerty | 569 EXPECT_EQ(ImeIdFromEngineId(ids[0]), // US Qwerty |
| 559 manager_->GetCurrentInputMethod().id()); | 570 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 560 EXPECT_EQ("us", keyboard_->last_layout_); | 571 EXPECT_EQ("us", keyboard_->last_layout_); |
| 561 manager_->RemoveObserver(&observer); | 572 manager_->RemoveObserver(&observer); |
| 562 } | 573 } |
| 563 | 574 |
| 564 TEST_F(InputMethodManagerImplTest, TestEnableLayoutAndIme) { | 575 TEST_F(InputMethodManagerImplTest, TestEnableLayoutAndIme) { |
| 565 // For http://crbug.com/19655#c11 - (10). | 576 // For http://crbug.com/19655#c11 - (10). |
| 566 TestObserver observer; | 577 TestObserver observer; |
| 567 manager_->AddObserver(&observer); | 578 manager_->AddObserver(&observer); |
| 568 InitComponentExtension(); | 579 InitComponentExtension(); |
| 569 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 580 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 570 std::vector<std::string> ids; | 581 std::vector<std::string> ids; |
| 571 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); | 582 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); |
| 572 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId)); | 583 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId)); |
| 573 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 584 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 574 EXPECT_EQ(1, observer.input_method_changed_count_); | 585 EXPECT_EQ(1, observer.input_method_changed_count_); |
| 575 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id()); | 586 EXPECT_EQ(ImeIdFromEngineId(ids[0]), |
| 587 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 576 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 588 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 577 // Switch to Mozc | 589 // Switch to Mozc |
| 578 manager_->SwitchToNextInputMethod(); | 590 manager_->GetActiveIMEState()->SwitchToNextInputMethod(); |
| 579 EXPECT_EQ(2, observer.input_method_changed_count_); | 591 EXPECT_EQ(2, observer.input_method_changed_count_); |
| 580 EXPECT_EQ(ImeIdFromEngineId(ids[1]), manager_->GetCurrentInputMethod().id()); | 592 EXPECT_EQ(ImeIdFromEngineId(ids[1]), |
| 593 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 581 EXPECT_EQ("us", keyboard_->last_layout_); | 594 EXPECT_EQ("us", keyboard_->last_layout_); |
| 582 // Disable Mozc. | 595 // Disable Mozc. |
| 583 ids.erase(ids.begin() + 1); | 596 ids.erase(ids.begin() + 1); |
| 584 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 597 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 585 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 598 EXPECT_EQ(1U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 586 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id()); | 599 EXPECT_EQ(ImeIdFromEngineId(ids[0]), |
| 600 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 587 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 601 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 588 } | 602 } |
| 589 | 603 |
| 590 TEST_F(InputMethodManagerImplTest, TestEnableLayoutAndIme2) { | 604 TEST_F(InputMethodManagerImplTest, TestEnableLayoutAndIme2) { |
| 591 // For http://crbug.com/19655#c11 - (11). | 605 // For http://crbug.com/19655#c11 - (11). |
| 592 TestObserver observer; | 606 TestObserver observer; |
| 593 manager_->AddObserver(&observer); | 607 manager_->AddObserver(&observer); |
| 594 InitComponentExtension(); | 608 InitComponentExtension(); |
| 595 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 609 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 596 std::vector<std::string> ids; | 610 std::vector<std::string> ids; |
| 597 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); | 611 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); |
| 598 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId)); | 612 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId)); |
| 599 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 613 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 600 EXPECT_EQ(1, observer.input_method_changed_count_); | 614 EXPECT_EQ(1, observer.input_method_changed_count_); |
| 601 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id()); | 615 EXPECT_EQ(ImeIdFromEngineId(ids[0]), |
| 616 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 602 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 617 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 603 | 618 |
| 604 // Disable Dvorak. | 619 // Disable Dvorak. |
| 605 ids.erase(ids.begin()); | 620 ids.erase(ids.begin()); |
| 606 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 621 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 607 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 622 EXPECT_EQ(1U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 608 EXPECT_EQ(ImeIdFromEngineId(ids[0]), // Mozc | 623 EXPECT_EQ(ImeIdFromEngineId(ids[0]), // Mozc |
| 609 manager_->GetCurrentInputMethod().id()); | 624 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 610 EXPECT_EQ("us", keyboard_->last_layout_); | 625 EXPECT_EQ("us", keyboard_->last_layout_); |
| 611 manager_->RemoveObserver(&observer); | 626 manager_->RemoveObserver(&observer); |
| 612 } | 627 } |
| 613 | 628 |
| 614 TEST_F(InputMethodManagerImplTest, TestEnableImes) { | 629 TEST_F(InputMethodManagerImplTest, TestEnableImes) { |
| 615 TestObserver observer; | 630 TestObserver observer; |
| 616 manager_->AddObserver(&observer); | 631 manager_->AddObserver(&observer); |
| 617 InitComponentExtension(); | 632 InitComponentExtension(); |
| 618 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 633 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 619 std::vector<std::string> ids; | 634 std::vector<std::string> ids; |
| 620 ids.push_back(ImeIdFromEngineId(kExt2Engine1Id)); | 635 ids.push_back(ImeIdFromEngineId(kExt2Engine1Id)); |
| 621 ids.push_back("mozc-dv"); | 636 ids.push_back("mozc-dv"); |
| 622 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 637 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 623 EXPECT_EQ(1, observer.input_method_changed_count_); | 638 EXPECT_EQ(1, observer.input_method_changed_count_); |
| 624 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id()); | 639 EXPECT_EQ(ImeIdFromEngineId(ids[0]), |
| 640 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 625 EXPECT_EQ("us", keyboard_->last_layout_); | 641 EXPECT_EQ("us", keyboard_->last_layout_); |
| 626 manager_->RemoveObserver(&observer); | 642 manager_->RemoveObserver(&observer); |
| 627 } | 643 } |
| 628 | 644 |
| 629 TEST_F(InputMethodManagerImplTest, TestEnableUnknownIds) { | 645 TEST_F(InputMethodManagerImplTest, TestEnableUnknownIds) { |
| 630 TestObserver observer; | 646 TestObserver observer; |
| 631 manager_->AddObserver(&observer); | 647 manager_->AddObserver(&observer); |
| 632 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 648 InitComponentExtension(); |
| 649 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 633 std::vector<std::string> ids; | 650 std::vector<std::string> ids; |
| 634 ids.push_back("xkb:tl::tlh"); // Klingon, which is not supported. | 651 ids.push_back("xkb:tl::tlh"); // Klingon, which is not supported. |
| 635 ids.push_back("unknown-super-cool-ime"); | 652 ids.push_back("unknown-super-cool-ime"); |
| 636 EXPECT_FALSE(manager_->ReplaceEnabledInputMethods(ids)); | 653 EXPECT_FALSE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 637 | 654 |
| 638 // TODO(yusukes): Should we fall back to the hardware keyboard layout in this | 655 // TODO(yusukes): Should we fall back to the hardware keyboard layout in this |
| 639 // case? | 656 // case? |
| 640 EXPECT_EQ(0, observer.input_method_changed_count_); | 657 EXPECT_EQ(0, observer.input_method_changed_count_); |
| 641 | 658 |
| 642 manager_->RemoveObserver(&observer); | 659 manager_->RemoveObserver(&observer); |
| 643 } | 660 } |
| 644 | 661 |
| 645 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsThenLock) { | 662 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsThenLock) { |
| 646 // For http://crbug.com/19655#c11 - (14). | 663 // For http://crbug.com/19655#c11 - (14). |
| 647 TestObserver observer; | 664 TestObserver observer; |
| 648 manager_->AddObserver(&observer); | 665 manager_->AddObserver(&observer); |
| 649 InitComponentExtension(); | 666 InitComponentExtension(); |
| 650 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 667 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 651 std::vector<std::string> ids; | 668 std::vector<std::string> ids; |
| 652 ids.push_back(ImeIdFromEngineId("xkb:us::eng")); | 669 ids.push_back(ImeIdFromEngineId("xkb:us::eng")); |
| 653 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); | 670 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); |
| 654 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 671 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 655 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 672 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 656 EXPECT_EQ(1, observer.input_method_changed_count_); | 673 EXPECT_EQ(1, observer.input_method_changed_count_); |
| 657 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id()); | 674 EXPECT_EQ(ImeIdFromEngineId(ids[0]), |
| 675 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 658 EXPECT_EQ("us", keyboard_->last_layout_); | 676 EXPECT_EQ("us", keyboard_->last_layout_); |
| 659 | 677 |
| 660 // Switch to Dvorak. | 678 // Switch to Dvorak. |
| 661 manager_->SwitchToNextInputMethod(); | 679 manager_->GetActiveIMEState()->SwitchToNextInputMethod(); |
| 662 EXPECT_EQ(2, observer.input_method_changed_count_); | 680 EXPECT_EQ(2, observer.input_method_changed_count_); |
| 663 EXPECT_EQ(ImeIdFromEngineId(ids[1]), manager_->GetCurrentInputMethod().id()); | 681 EXPECT_EQ(ImeIdFromEngineId(ids[1]), |
| 682 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 664 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 683 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 665 | 684 |
| 666 // Lock screen | 685 // Lock screen |
| 667 manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN); | 686 scoped_refptr<input_method::InputMethodManager::State> saved_ime_state = |
| 668 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 687 manager_->GetActiveIMEState(); |
| 688 manager_->SetState(saved_ime_state->Clone()); |
| 689 manager_->GetActiveIMEState()->EnableLockScreenLayouts(); |
| 690 manager_->SetUISessionState(InputMethodManager::STATE_LOCK_SCREEN); |
| 691 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 669 EXPECT_EQ(ImeIdFromEngineId(ids[1]), // still Dvorak | 692 EXPECT_EQ(ImeIdFromEngineId(ids[1]), // still Dvorak |
| 670 manager_->GetCurrentInputMethod().id()); | 693 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 671 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 694 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 672 // Switch back to Qwerty. | 695 // Switch back to Qwerty. |
| 673 manager_->SwitchToNextInputMethod(); | 696 manager_->GetActiveIMEState()->SwitchToNextInputMethod(); |
| 674 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id()); | 697 EXPECT_EQ(ImeIdFromEngineId(ids[0]), |
| 698 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 675 EXPECT_EQ("us", keyboard_->last_layout_); | 699 EXPECT_EQ("us", keyboard_->last_layout_); |
| 676 | 700 |
| 677 // Unlock screen. The original state, Dvorak, is restored. | 701 // Unlock screen. The original state, Dvorak, is restored. |
| 678 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 702 manager_->SetState(saved_ime_state); |
| 679 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 703 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 680 EXPECT_EQ(ImeIdFromEngineId(ids[1]), manager_->GetCurrentInputMethod().id()); | 704 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 705 EXPECT_EQ(ImeIdFromEngineId(ids[1]), |
| 706 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 681 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 707 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 682 | 708 |
| 683 manager_->RemoveObserver(&observer); | 709 manager_->RemoveObserver(&observer); |
| 684 } | 710 } |
| 685 | 711 |
| 686 TEST_F(InputMethodManagerImplTest, SwitchInputMethodTest) { | 712 TEST_F(InputMethodManagerImplTest, SwitchInputMethodTest) { |
| 687 // For http://crbug.com/19655#c11 - (15). | 713 // For http://crbug.com/19655#c11 - (15). |
| 688 TestObserver observer; | 714 TestObserver observer; |
| 689 manager_->AddObserver(&observer); | 715 manager_->AddObserver(&observer); |
| 690 InitComponentExtension(); | 716 InitComponentExtension(); |
| 691 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 717 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 692 std::vector<std::string> ids; | 718 std::vector<std::string> ids; |
| 693 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); | 719 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); |
| 694 ids.push_back(ImeIdFromEngineId(kExt2Engine2Id)); | 720 ids.push_back(ImeIdFromEngineId(kExt2Engine2Id)); |
| 695 ids.push_back(ImeIdFromEngineId(kExt2Engine1Id)); | 721 ids.push_back(ImeIdFromEngineId(kExt2Engine1Id)); |
| 696 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 722 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 697 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); | 723 EXPECT_EQ(3U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 698 EXPECT_EQ(1, observer.input_method_changed_count_); | 724 EXPECT_EQ(1, observer.input_method_changed_count_); |
| 699 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id()); | 725 EXPECT_EQ(ImeIdFromEngineId(ids[0]), |
| 726 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 700 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 727 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 701 | 728 |
| 702 // Switch to Mozc. | 729 // Switch to Mozc. |
| 703 manager_->SwitchToNextInputMethod(); | 730 manager_->GetActiveIMEState()->SwitchToNextInputMethod(); |
| 704 EXPECT_EQ(2, observer.input_method_changed_count_); | 731 EXPECT_EQ(2, observer.input_method_changed_count_); |
| 705 EXPECT_EQ(ImeIdFromEngineId(ids[1]), manager_->GetCurrentInputMethod().id()); | 732 EXPECT_EQ(ImeIdFromEngineId(ids[1]), |
| 733 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 706 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 734 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 707 | 735 |
| 708 // Lock screen | 736 // Lock screen |
| 709 manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN); | 737 scoped_refptr<input_method::InputMethodManager::State> saved_ime_state = |
| 710 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); // Qwerty+Dvorak. | 738 manager_->GetActiveIMEState(); |
| 739 manager_->SetState(saved_ime_state->Clone()); |
| 740 manager_->GetActiveIMEState()->EnableLockScreenLayouts(); |
| 741 manager_->SetUISessionState(InputMethodManager::STATE_LOCK_SCREEN); |
| 742 EXPECT_EQ(2U, |
| 743 manager_->GetActiveIMEState() |
| 744 ->GetNumActiveInputMethods()); // Qwerty+Dvorak. |
| 711 EXPECT_EQ(ImeIdFromEngineId("xkb:us:dvorak:eng"), | 745 EXPECT_EQ(ImeIdFromEngineId("xkb:us:dvorak:eng"), |
| 712 manager_->GetCurrentInputMethod().id()); | 746 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 713 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 747 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 714 manager_->SwitchToNextInputMethod(); | 748 manager_->GetActiveIMEState()->SwitchToNextInputMethod(); |
| 715 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), // The hardware keyboard layout. | 749 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), // The hardware keyboard layout. |
| 716 manager_->GetCurrentInputMethod().id()); | 750 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 717 EXPECT_EQ("us", keyboard_->last_layout_); | 751 EXPECT_EQ("us", keyboard_->last_layout_); |
| 718 | 752 |
| 719 // Unlock screen. The original state, pinyin-dv, is restored. | 753 // Unlock screen. The original state, pinyin-dv, is restored. |
| 720 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 754 manager_->SetState(saved_ime_state); |
| 721 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); // Dvorak and 2 IMEs. | 755 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 722 EXPECT_EQ(ImeIdFromEngineId(ids[1]), manager_->GetCurrentInputMethod().id()); | 756 EXPECT_EQ(3U, |
| 757 manager_->GetActiveIMEState() |
| 758 ->GetNumActiveInputMethods()); // Dvorak and 2 IMEs. |
| 759 EXPECT_EQ(ImeIdFromEngineId(ids[1]), |
| 760 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 723 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 761 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 724 | 762 |
| 725 manager_->RemoveObserver(&observer); | 763 manager_->RemoveObserver(&observer); |
| 726 } | 764 } |
| 727 | 765 |
| 728 TEST_F(InputMethodManagerImplTest, TestXkbSetting) { | 766 TEST_F(InputMethodManagerImplTest, TestXkbSetting) { |
| 729 // For http://crbug.com/19655#c11 - (8), step 7-11. | 767 // For http://crbug.com/19655#c11 - (8), step 7-11. |
| 730 InitComponentExtension(); | 768 InitComponentExtension(); |
| 731 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 769 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 732 std::vector<std::string> ids; | 770 std::vector<std::string> ids; |
| 733 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); | 771 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); |
| 734 ids.push_back(ImeIdFromEngineId("xkb:us:colemak:eng")); | 772 ids.push_back(ImeIdFromEngineId("xkb:us:colemak:eng")); |
| 735 ids.push_back(ImeIdFromEngineId(kNaclMozcJpId)); | 773 ids.push_back(ImeIdFromEngineId(kNaclMozcJpId)); |
| 736 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId)); | 774 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId)); |
| 737 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 775 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 738 EXPECT_EQ(4U, manager_->GetNumActiveInputMethods()); | 776 EXPECT_EQ(4U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 739 EXPECT_EQ(1, keyboard_->set_current_keyboard_layout_by_name_count_); | 777 EXPECT_EQ(1, keyboard_->set_current_keyboard_layout_by_name_count_); |
| 740 // See input_methods.txt for an expected XKB layout name. | 778 // See input_methods.txt for an expected XKB layout name. |
| 741 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 779 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 742 manager_->SwitchToNextInputMethod(); | 780 manager_->GetActiveIMEState()->SwitchToNextInputMethod(); |
| 743 EXPECT_EQ(2, keyboard_->set_current_keyboard_layout_by_name_count_); | 781 EXPECT_EQ(2, keyboard_->set_current_keyboard_layout_by_name_count_); |
| 744 EXPECT_EQ("us(colemak)", keyboard_->last_layout_); | 782 EXPECT_EQ("us(colemak)", keyboard_->last_layout_); |
| 745 manager_->SwitchToNextInputMethod(); | 783 manager_->GetActiveIMEState()->SwitchToNextInputMethod(); |
| 746 EXPECT_EQ(3, keyboard_->set_current_keyboard_layout_by_name_count_); | 784 EXPECT_EQ(3, keyboard_->set_current_keyboard_layout_by_name_count_); |
| 747 EXPECT_EQ("jp", keyboard_->last_layout_); | 785 EXPECT_EQ("jp", keyboard_->last_layout_); |
| 748 manager_->SwitchToNextInputMethod(); | 786 manager_->GetActiveIMEState()->SwitchToNextInputMethod(); |
| 749 EXPECT_EQ(4, keyboard_->set_current_keyboard_layout_by_name_count_); | 787 EXPECT_EQ(4, keyboard_->set_current_keyboard_layout_by_name_count_); |
| 750 EXPECT_EQ("us", keyboard_->last_layout_); | 788 EXPECT_EQ("us", keyboard_->last_layout_); |
| 751 manager_->SwitchToNextInputMethod(); | 789 manager_->GetActiveIMEState()->SwitchToNextInputMethod(); |
| 752 EXPECT_EQ(5, keyboard_->set_current_keyboard_layout_by_name_count_); | 790 EXPECT_EQ(5, keyboard_->set_current_keyboard_layout_by_name_count_); |
| 753 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 791 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 754 // Disable Dvorak. | 792 // Disable Dvorak. |
| 755 ids.erase(ids.begin()); | 793 ids.erase(ids.begin()); |
| 756 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 794 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 757 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); | 795 EXPECT_EQ(3U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 758 EXPECT_EQ(6, keyboard_->set_current_keyboard_layout_by_name_count_); | 796 EXPECT_EQ(6, keyboard_->set_current_keyboard_layout_by_name_count_); |
| 759 EXPECT_EQ("us(colemak)", keyboard_->last_layout_); | 797 EXPECT_EQ("us(colemak)", keyboard_->last_layout_); |
| 760 } | 798 } |
| 761 | 799 |
| 762 TEST_F(InputMethodManagerImplTest, TestActivateInputMethodMenuItem) { | 800 TEST_F(InputMethodManagerImplTest, TestActivateInputMethodMenuItem) { |
| 763 const std::string kKey = "key"; | 801 const std::string kKey = "key"; |
| 764 ash::ime::InputMethodMenuItemList menu_list; | 802 ash::ime::InputMethodMenuItemList menu_list; |
| 765 menu_list.push_back(ash::ime::InputMethodMenuItem( | 803 menu_list.push_back(ash::ime::InputMethodMenuItem( |
| 766 kKey, "label", false, false)); | 804 kKey, "label", false, false)); |
| 767 menu_manager_->SetCurrentInputMethodMenuItemList(menu_list); | 805 menu_manager_->SetCurrentInputMethodMenuItemList(menu_list); |
| 768 | 806 |
| 769 manager_->ActivateInputMethodMenuItem(kKey); | 807 manager_->ActivateInputMethodMenuItem(kKey); |
| 770 EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property()); | 808 EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property()); |
| 771 | 809 |
| 772 // Key2 is not registered, so activated property should not be changed. | 810 // Key2 is not registered, so activated property should not be changed. |
| 773 manager_->ActivateInputMethodMenuItem("key2"); | 811 manager_->ActivateInputMethodMenuItem("key2"); |
| 774 EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property()); | 812 EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property()); |
| 775 } | 813 } |
| 776 | 814 |
| 777 TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodProperties) { | 815 TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodProperties) { |
| 778 InitComponentExtension(); | 816 InitComponentExtension(); |
| 779 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); | 817 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); |
| 780 | 818 |
| 781 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 819 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 782 std::vector<std::string> ids; | 820 std::vector<std::string> ids; |
| 783 ids.push_back(ImeIdFromEngineId("xkb:us::eng")); | 821 ids.push_back(ImeIdFromEngineId("xkb:us::eng")); |
| 784 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId)); | 822 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId)); |
| 785 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 823 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 786 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 824 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 787 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); | 825 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); |
| 788 manager_->ChangeInputMethod(ImeIdFromEngineId(kNaclMozcUsId)); | 826 manager_->GetActiveIMEState()->ChangeInputMethod( |
| 827 ImeIdFromEngineId(kNaclMozcUsId), false /* show_message */); |
| 789 | 828 |
| 790 ash::ime::InputMethodMenuItemList current_property_list; | 829 ash::ime::InputMethodMenuItemList current_property_list; |
| 791 current_property_list.push_back(ash::ime::InputMethodMenuItem( | 830 current_property_list.push_back(ash::ime::InputMethodMenuItem( |
| 792 "key", "label", false, false)); | 831 "key", "label", false, false)); |
| 793 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list); | 832 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list); |
| 794 | 833 |
| 795 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size()); | 834 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size()); |
| 796 EXPECT_EQ("key", | 835 EXPECT_EQ("key", |
| 797 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key); | 836 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key); |
| 798 | 837 |
| 799 manager_->ChangeInputMethod("xkb:us::eng"); | 838 manager_->GetActiveIMEState()->ChangeInputMethod("xkb:us::eng", |
| 839 false /* show_message */); |
| 800 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); | 840 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); |
| 801 } | 841 } |
| 802 | 842 |
| 803 TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodPropertiesTwoImes) { | 843 TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodPropertiesTwoImes) { |
| 804 InitComponentExtension(); | 844 InitComponentExtension(); |
| 805 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); | 845 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); |
| 806 | 846 |
| 807 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 847 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 808 std::vector<std::string> ids; | 848 std::vector<std::string> ids; |
| 809 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId)); // Japanese | 849 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId)); // Japanese |
| 810 ids.push_back(ImeIdFromEngineId(kExt2Engine1Id)); // T-Chinese | 850 ids.push_back(ImeIdFromEngineId(kExt2Engine1Id)); // T-Chinese |
| 811 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 851 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 812 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 852 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 813 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); | 853 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); |
| 814 | 854 |
| 815 ash::ime::InputMethodMenuItemList current_property_list; | 855 ash::ime::InputMethodMenuItemList current_property_list; |
| 816 current_property_list.push_back(ash::ime::InputMethodMenuItem("key-mozc", | 856 current_property_list.push_back(ash::ime::InputMethodMenuItem("key-mozc", |
| 817 "label", | 857 "label", |
| 818 false, | 858 false, |
| 819 false)); | 859 false)); |
| 820 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list); | 860 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list); |
| 821 | 861 |
| 822 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size()); | 862 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size()); |
| 823 EXPECT_EQ("key-mozc", | 863 EXPECT_EQ("key-mozc", |
| 824 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key); | 864 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key); |
| 825 | 865 |
| 826 manager_->ChangeInputMethod(ImeIdFromEngineId(kExt2Engine1Id)); | 866 manager_->GetActiveIMEState()->ChangeInputMethod( |
| 867 ImeIdFromEngineId(kExt2Engine1Id), false /* show_message */); |
| 827 // Since the IME is changed, the property for mozc Japanese should be hidden. | 868 // Since the IME is changed, the property for mozc Japanese should be hidden. |
| 828 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); | 869 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); |
| 829 | 870 |
| 830 // Asynchronous property update signal from mozc-chewing. | 871 // Asynchronous property update signal from mozc-chewing. |
| 831 current_property_list.clear(); | 872 current_property_list.clear(); |
| 832 current_property_list.push_back(ash::ime::InputMethodMenuItem( | 873 current_property_list.push_back(ash::ime::InputMethodMenuItem( |
| 833 "key-chewing", "label", false, false)); | 874 "key-chewing", "label", false, false)); |
| 834 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list); | 875 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list); |
| 835 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size()); | 876 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size()); |
| 836 EXPECT_EQ("key-chewing", | 877 EXPECT_EQ("key-chewing", |
| 837 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key); | 878 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key); |
| 838 } | 879 } |
| 839 | 880 |
| 840 TEST_F(InputMethodManagerImplTest, TestNextInputMethod) { | 881 TEST_F(InputMethodManagerImplTest, TestNextInputMethod) { |
| 841 TestObserver observer; | 882 TestObserver observer; |
| 842 manager_->AddObserver(&observer); | 883 manager_->AddObserver(&observer); |
| 843 InitComponentExtension(); | 884 InitComponentExtension(); |
| 844 std::vector<std::string> keyboard_layouts; | 885 std::vector<std::string> keyboard_layouts; |
| 845 keyboard_layouts.push_back(ImeIdFromEngineId("xkb:us::eng")); | 886 keyboard_layouts.push_back(ImeIdFromEngineId("xkb:us::eng")); |
| 846 // For http://crbug.com/19655#c11 - (1) | 887 // For http://crbug.com/19655#c11 - (1) |
| 847 manager_->EnableLoginLayouts("en-US", keyboard_layouts); | 888 manager_->GetActiveIMEState()->EnableLoginLayouts("en-US", keyboard_layouts); |
| 848 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); | 889 EXPECT_EQ(5U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 849 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), | 890 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), |
| 850 manager_->GetCurrentInputMethod().id()); | 891 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 851 EXPECT_EQ("us", keyboard_->last_layout_); | 892 EXPECT_EQ("us", keyboard_->last_layout_); |
| 852 manager_->SwitchToNextInputMethod(); | 893 manager_->GetActiveIMEState()->SwitchToNextInputMethod(); |
| 853 EXPECT_TRUE(observer.last_show_message_); | 894 EXPECT_TRUE(observer.last_show_message_); |
| 854 EXPECT_EQ(ImeIdFromEngineId("xkb:us:intl:eng"), | 895 EXPECT_EQ(ImeIdFromEngineId("xkb:us:intl:eng"), |
| 855 manager_->GetCurrentInputMethod().id()); | 896 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 856 EXPECT_EQ("us(intl)", keyboard_->last_layout_); | 897 EXPECT_EQ("us(intl)", keyboard_->last_layout_); |
| 857 manager_->SwitchToNextInputMethod(); | 898 manager_->GetActiveIMEState()->SwitchToNextInputMethod(); |
| 858 EXPECT_TRUE(observer.last_show_message_); | 899 EXPECT_TRUE(observer.last_show_message_); |
| 859 EXPECT_EQ(ImeIdFromEngineId("xkb:us:altgr-intl:eng"), | 900 EXPECT_EQ(ImeIdFromEngineId("xkb:us:altgr-intl:eng"), |
| 860 manager_->GetCurrentInputMethod().id()); | 901 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 861 EXPECT_EQ("us(altgr-intl)", keyboard_->last_layout_); | 902 EXPECT_EQ("us(altgr-intl)", keyboard_->last_layout_); |
| 862 manager_->SwitchToNextInputMethod(); | 903 manager_->GetActiveIMEState()->SwitchToNextInputMethod(); |
| 863 EXPECT_TRUE(observer.last_show_message_); | 904 EXPECT_TRUE(observer.last_show_message_); |
| 864 EXPECT_EQ(ImeIdFromEngineId("xkb:us:dvorak:eng"), | 905 EXPECT_EQ(ImeIdFromEngineId("xkb:us:dvorak:eng"), |
| 865 manager_->GetCurrentInputMethod().id()); | 906 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 866 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 907 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 867 manager_->SwitchToNextInputMethod(); | 908 manager_->GetActiveIMEState()->SwitchToNextInputMethod(); |
| 868 EXPECT_TRUE(observer.last_show_message_); | 909 EXPECT_TRUE(observer.last_show_message_); |
| 869 EXPECT_EQ(ImeIdFromEngineId("xkb:us:colemak:eng"), | 910 EXPECT_EQ(ImeIdFromEngineId("xkb:us:colemak:eng"), |
| 870 manager_->GetCurrentInputMethod().id()); | 911 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 871 EXPECT_EQ("us(colemak)", keyboard_->last_layout_); | 912 EXPECT_EQ("us(colemak)", keyboard_->last_layout_); |
| 872 manager_->SwitchToNextInputMethod(); | 913 manager_->GetActiveIMEState()->SwitchToNextInputMethod(); |
| 873 EXPECT_TRUE(observer.last_show_message_); | 914 EXPECT_TRUE(observer.last_show_message_); |
| 874 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), | 915 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), |
| 875 manager_->GetCurrentInputMethod().id()); | 916 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 876 EXPECT_EQ("us", keyboard_->last_layout_); | 917 EXPECT_EQ("us", keyboard_->last_layout_); |
| 877 | 918 |
| 878 manager_->RemoveObserver(&observer); | 919 manager_->RemoveObserver(&observer); |
| 879 } | 920 } |
| 880 | 921 |
| 881 TEST_F(InputMethodManagerImplTest, TestPreviousInputMethod) { | 922 TEST_F(InputMethodManagerImplTest, TestPreviousInputMethod) { |
| 882 TestObserver observer; | 923 TestObserver observer; |
| 883 manager_->AddObserver(&observer); | 924 manager_->AddObserver(&observer); |
| 884 InitComponentExtension(); | 925 InitComponentExtension(); |
| 885 | 926 |
| 886 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); | 927 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); |
| 887 keydown_accelerator.set_type(ui::ET_KEY_PRESSED); | 928 keydown_accelerator.set_type(ui::ET_KEY_PRESSED); |
| 888 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); | 929 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); |
| 889 keyup_accelerator.set_type(ui::ET_KEY_RELEASED); | 930 keyup_accelerator.set_type(ui::ET_KEY_RELEASED); |
| 890 | 931 |
| 891 std::vector<std::string> keyboard_layouts; | 932 std::vector<std::string> keyboard_layouts; |
| 892 keyboard_layouts.push_back(ImeIdFromEngineId("xkb:us::eng")); | 933 keyboard_layouts.push_back(ImeIdFromEngineId("xkb:us::eng")); |
| 893 manager_->EnableLoginLayouts("en-US", keyboard_layouts); | 934 manager_->GetActiveIMEState()->EnableLoginLayouts("en-US", keyboard_layouts); |
| 894 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); | 935 EXPECT_EQ(5U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 895 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), | 936 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), |
| 896 manager_->GetCurrentInputMethod().id()); | 937 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 897 EXPECT_EQ("us", keyboard_->last_layout_); | 938 EXPECT_EQ("us", keyboard_->last_layout_); |
| 898 EXPECT_TRUE(manager_->SwitchToNextInputMethod()); | 939 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchToNextInputMethod()); |
| 899 EXPECT_TRUE(observer.last_show_message_); | 940 EXPECT_TRUE(observer.last_show_message_); |
| 900 EXPECT_EQ(ImeIdFromEngineId("xkb:us:intl:eng"), | 941 EXPECT_EQ(ImeIdFromEngineId("xkb:us:intl:eng"), |
| 901 manager_->GetCurrentInputMethod().id()); | 942 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 902 EXPECT_EQ("us(intl)", keyboard_->last_layout_); | 943 EXPECT_EQ("us(intl)", keyboard_->last_layout_); |
| 903 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); | 944 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchToPreviousInputMethod( |
| 904 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); | 945 keydown_accelerator)); |
| 946 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchToPreviousInputMethod( |
| 947 keyup_accelerator)); |
| 905 EXPECT_TRUE(observer.last_show_message_); | 948 EXPECT_TRUE(observer.last_show_message_); |
| 906 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), | 949 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), |
| 907 manager_->GetCurrentInputMethod().id()); | 950 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 908 EXPECT_EQ("us", keyboard_->last_layout_); | 951 EXPECT_EQ("us", keyboard_->last_layout_); |
| 909 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); | 952 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchToPreviousInputMethod( |
| 910 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); | 953 keydown_accelerator)); |
| 954 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchToPreviousInputMethod( |
| 955 keyup_accelerator)); |
| 911 EXPECT_TRUE(observer.last_show_message_); | 956 EXPECT_TRUE(observer.last_show_message_); |
| 912 EXPECT_EQ(ImeIdFromEngineId("xkb:us:intl:eng"), | 957 EXPECT_EQ(ImeIdFromEngineId("xkb:us:intl:eng"), |
| 913 manager_->GetCurrentInputMethod().id()); | 958 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 914 EXPECT_EQ("us(intl)", keyboard_->last_layout_); | 959 EXPECT_EQ("us(intl)", keyboard_->last_layout_); |
| 915 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); | 960 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchToPreviousInputMethod( |
| 916 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); | 961 keydown_accelerator)); |
| 962 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchToPreviousInputMethod( |
| 963 keyup_accelerator)); |
| 917 EXPECT_TRUE(observer.last_show_message_); | 964 EXPECT_TRUE(observer.last_show_message_); |
| 918 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), | 965 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), |
| 919 manager_->GetCurrentInputMethod().id()); | 966 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 920 EXPECT_EQ("us", keyboard_->last_layout_); | 967 EXPECT_EQ("us", keyboard_->last_layout_); |
| 921 EXPECT_TRUE(manager_->SwitchToNextInputMethod()); | 968 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchToNextInputMethod()); |
| 922 EXPECT_TRUE(observer.last_show_message_); | 969 EXPECT_TRUE(observer.last_show_message_); |
| 923 EXPECT_EQ(ImeIdFromEngineId("xkb:us:intl:eng"), | 970 EXPECT_EQ(ImeIdFromEngineId("xkb:us:intl:eng"), |
| 924 manager_->GetCurrentInputMethod().id()); | 971 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 925 EXPECT_EQ("us(intl)", keyboard_->last_layout_); | 972 EXPECT_EQ("us(intl)", keyboard_->last_layout_); |
| 926 EXPECT_TRUE(manager_->SwitchToNextInputMethod()); | 973 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchToNextInputMethod()); |
| 927 EXPECT_TRUE(observer.last_show_message_); | 974 EXPECT_TRUE(observer.last_show_message_); |
| 928 EXPECT_EQ(ImeIdFromEngineId("xkb:us:altgr-intl:eng"), | 975 EXPECT_EQ(ImeIdFromEngineId("xkb:us:altgr-intl:eng"), |
| 929 manager_->GetCurrentInputMethod().id()); | 976 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 930 EXPECT_EQ("us(altgr-intl)", keyboard_->last_layout_); | 977 EXPECT_EQ("us(altgr-intl)", keyboard_->last_layout_); |
| 931 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); | 978 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchToPreviousInputMethod( |
| 932 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); | 979 keydown_accelerator)); |
| 980 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchToPreviousInputMethod( |
| 981 keyup_accelerator)); |
| 933 EXPECT_TRUE(observer.last_show_message_); | 982 EXPECT_TRUE(observer.last_show_message_); |
| 934 EXPECT_EQ(ImeIdFromEngineId("xkb:us:intl:eng"), | 983 EXPECT_EQ(ImeIdFromEngineId("xkb:us:intl:eng"), |
| 935 manager_->GetCurrentInputMethod().id()); | 984 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 936 EXPECT_EQ("us(intl)", keyboard_->last_layout_); | 985 EXPECT_EQ("us(intl)", keyboard_->last_layout_); |
| 937 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); | 986 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchToPreviousInputMethod( |
| 938 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); | 987 keydown_accelerator)); |
| 988 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchToPreviousInputMethod( |
| 989 keyup_accelerator)); |
| 939 EXPECT_TRUE(observer.last_show_message_); | 990 EXPECT_TRUE(observer.last_show_message_); |
| 940 EXPECT_EQ(ImeIdFromEngineId("xkb:us:altgr-intl:eng"), | 991 EXPECT_EQ(ImeIdFromEngineId("xkb:us:altgr-intl:eng"), |
| 941 manager_->GetCurrentInputMethod().id()); | 992 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 942 EXPECT_EQ("us(altgr-intl)", keyboard_->last_layout_); | 993 EXPECT_EQ("us(altgr-intl)", keyboard_->last_layout_); |
| 943 | 994 |
| 944 manager_->RemoveObserver(&observer); | 995 manager_->RemoveObserver(&observer); |
| 945 } | 996 } |
| 946 | 997 |
| 947 TEST_F(InputMethodManagerImplTest, | 998 TEST_F(InputMethodManagerImplTest, |
| 948 TestSwitchToPreviousInputMethodForOneActiveInputMethod) { | 999 TestSwitchToPreviousInputMethodForOneActiveInputMethod) { |
| 949 TestObserver observer; | 1000 TestObserver observer; |
| 950 manager_->AddObserver(&observer); | 1001 manager_->AddObserver(&observer); |
| 951 InitComponentExtension(); | 1002 InitComponentExtension(); |
| 952 | 1003 |
| 953 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); | 1004 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); |
| 954 keydown_accelerator.set_type(ui::ET_KEY_PRESSED); | 1005 keydown_accelerator.set_type(ui::ET_KEY_PRESSED); |
| 955 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); | 1006 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); |
| 956 keyup_accelerator.set_type(ui::ET_KEY_RELEASED); | 1007 keyup_accelerator.set_type(ui::ET_KEY_RELEASED); |
| 957 | 1008 |
| 958 std::vector<std::string> ids; | 1009 std::vector<std::string> ids; |
| 959 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); | 1010 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); |
| 960 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 1011 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 961 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1012 EXPECT_EQ(1U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 962 | 1013 |
| 963 // Ctrl+Space accelerator should not be consumed if there is only one active | 1014 // Ctrl+Space accelerator should not be consumed if there is only one active |
| 964 // input method. | 1015 // input method. |
| 965 EXPECT_FALSE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); | 1016 EXPECT_FALSE(manager_->GetActiveIMEState()->SwitchToPreviousInputMethod( |
| 966 EXPECT_FALSE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); | 1017 keydown_accelerator)); |
| 1018 EXPECT_FALSE(manager_->GetActiveIMEState()->SwitchToPreviousInputMethod( |
| 1019 keyup_accelerator)); |
| 967 | 1020 |
| 968 manager_->RemoveObserver(&observer); | 1021 manager_->RemoveObserver(&observer); |
| 969 } | 1022 } |
| 970 | 1023 |
| 971 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithUsLayouts) { | 1024 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithUsLayouts) { |
| 972 std::string expect_id = ImeIdFromEngineId("xkb:us::eng"); | 1025 std::string expect_id = ImeIdFromEngineId("xkb:us::eng"); |
| 973 TestObserver observer; | 1026 TestObserver observer; |
| 974 manager_->AddObserver(&observer); | 1027 manager_->AddObserver(&observer); |
| 975 InitComponentExtension(); | 1028 InitComponentExtension(); |
| 976 std::vector<std::string> keyboard_layouts; | 1029 std::vector<std::string> keyboard_layouts; |
| 977 keyboard_layouts.push_back(ImeIdFromEngineId("xkb:us::eng")); | 1030 keyboard_layouts.push_back(ImeIdFromEngineId("xkb:us::eng")); |
| 978 manager_->EnableLoginLayouts("en-US", keyboard_layouts); | 1031 manager_->GetActiveIMEState()->EnableLoginLayouts("en-US", keyboard_layouts); |
| 979 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); | 1032 EXPECT_EQ(5U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 980 EXPECT_EQ(expect_id, manager_->GetCurrentInputMethod().id()); | 1033 EXPECT_EQ(expect_id, |
| 1034 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 981 EXPECT_EQ("us", keyboard_->last_layout_); | 1035 EXPECT_EQ("us", keyboard_->last_layout_); |
| 982 | 1036 |
| 983 // Henkan, Muhenkan, ZenkakuHankaku should be ignored when no Japanese IMEs | 1037 // Henkan, Muhenkan, ZenkakuHankaku should be ignored when no Japanese IMEs |
| 984 // and keyboards are enabled. | 1038 // and keyboards are enabled. |
| 985 EXPECT_FALSE(manager_->SwitchInputMethod( | 1039 EXPECT_FALSE(manager_->GetActiveIMEState()->SwitchInputMethod( |
| 986 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE))); | 1040 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE))); |
| 987 EXPECT_FALSE(observer.last_show_message_); | 1041 EXPECT_FALSE(observer.last_show_message_); |
| 988 EXPECT_EQ(expect_id, manager_->GetCurrentInputMethod().id()); | 1042 EXPECT_EQ(expect_id, |
| 1043 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 989 EXPECT_EQ("us", keyboard_->last_layout_); | 1044 EXPECT_EQ("us", keyboard_->last_layout_); |
| 990 EXPECT_FALSE(manager_->SwitchInputMethod( | 1045 EXPECT_FALSE(manager_->GetActiveIMEState()->SwitchInputMethod( |
| 991 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); | 1046 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); |
| 992 EXPECT_EQ(expect_id, manager_->GetCurrentInputMethod().id()); | 1047 EXPECT_EQ(expect_id, |
| 1048 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 993 EXPECT_EQ("us", keyboard_->last_layout_); | 1049 EXPECT_EQ("us", keyboard_->last_layout_); |
| 994 EXPECT_FALSE(manager_->SwitchInputMethod( | 1050 EXPECT_FALSE(manager_->GetActiveIMEState()->SwitchInputMethod( |
| 995 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); | 1051 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); |
| 996 EXPECT_EQ(expect_id, manager_->GetCurrentInputMethod().id()); | 1052 EXPECT_EQ(expect_id, |
| 1053 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 997 EXPECT_EQ("us", keyboard_->last_layout_); | 1054 EXPECT_EQ("us", keyboard_->last_layout_); |
| 998 EXPECT_FALSE(manager_->SwitchInputMethod( | 1055 EXPECT_FALSE(manager_->GetActiveIMEState()->SwitchInputMethod( |
| 999 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); | 1056 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); |
| 1000 EXPECT_EQ(expect_id, manager_->GetCurrentInputMethod().id()); | 1057 EXPECT_EQ(expect_id, |
| 1058 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1001 EXPECT_EQ("us", keyboard_->last_layout_); | 1059 EXPECT_EQ("us", keyboard_->last_layout_); |
| 1002 | 1060 |
| 1003 manager_->RemoveObserver(&observer); | 1061 manager_->RemoveObserver(&observer); |
| 1004 } | 1062 } |
| 1005 | 1063 |
| 1006 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpLayout) { | 1064 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpLayout) { |
| 1007 // Enable "xkb:jp::jpn" and press Muhenkan/ZenkakuHankaku. | 1065 // Enable "xkb:jp::jpn" and press Muhenkan/ZenkakuHankaku. |
| 1008 InitComponentExtension(); | 1066 InitComponentExtension(); |
| 1009 | 1067 |
| 1010 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); | 1068 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); |
| 1011 keydown_accelerator.set_type(ui::ET_KEY_PRESSED); | 1069 keydown_accelerator.set_type(ui::ET_KEY_PRESSED); |
| 1012 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); | 1070 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); |
| 1013 keyup_accelerator.set_type(ui::ET_KEY_RELEASED); | 1071 keyup_accelerator.set_type(ui::ET_KEY_RELEASED); |
| 1014 | 1072 |
| 1015 std::vector<std::string> keyboard_layouts; | 1073 std::vector<std::string> keyboard_layouts; |
| 1016 keyboard_layouts.push_back(ImeIdFromEngineId("xkb:us::eng")); | 1074 keyboard_layouts.push_back(ImeIdFromEngineId("xkb:us::eng")); |
| 1017 manager_->EnableLoginLayouts("ja", keyboard_layouts); | 1075 manager_->GetActiveIMEState()->EnableLoginLayouts("ja", keyboard_layouts); |
| 1018 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1076 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 1019 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), | 1077 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), |
| 1020 manager_->GetCurrentInputMethod().id()); | 1078 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1021 EXPECT_EQ("us", keyboard_->last_layout_); | 1079 EXPECT_EQ("us", keyboard_->last_layout_); |
| 1022 EXPECT_TRUE(manager_->SwitchInputMethod( | 1080 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchInputMethod( |
| 1023 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); | 1081 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); |
| 1024 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), | 1082 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), |
| 1025 manager_->GetCurrentInputMethod().id()); | 1083 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1026 EXPECT_EQ("jp", keyboard_->last_layout_); | 1084 EXPECT_EQ("jp", keyboard_->last_layout_); |
| 1027 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); | 1085 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchToPreviousInputMethod( |
| 1028 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); | 1086 keydown_accelerator)); |
| 1087 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchToPreviousInputMethod( |
| 1088 keyup_accelerator)); |
| 1029 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), | 1089 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), |
| 1030 manager_->GetCurrentInputMethod().id()); | 1090 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1031 EXPECT_EQ("us", keyboard_->last_layout_); | 1091 EXPECT_EQ("us", keyboard_->last_layout_); |
| 1032 EXPECT_TRUE(manager_->SwitchInputMethod( | 1092 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchInputMethod( |
| 1033 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); | 1093 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); |
| 1034 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), | 1094 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), |
| 1035 manager_->GetCurrentInputMethod().id()); | 1095 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1036 EXPECT_EQ("jp", keyboard_->last_layout_); | 1096 EXPECT_EQ("jp", keyboard_->last_layout_); |
| 1037 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); | 1097 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchToPreviousInputMethod( |
| 1038 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); | 1098 keydown_accelerator)); |
| 1099 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchToPreviousInputMethod( |
| 1100 keyup_accelerator)); |
| 1039 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), | 1101 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), |
| 1040 manager_->GetCurrentInputMethod().id()); | 1102 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1041 EXPECT_EQ("us", keyboard_->last_layout_); | 1103 EXPECT_EQ("us", keyboard_->last_layout_); |
| 1042 EXPECT_TRUE(manager_->SwitchInputMethod( | 1104 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchInputMethod( |
| 1043 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); | 1105 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); |
| 1044 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), | 1106 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), |
| 1045 manager_->GetCurrentInputMethod().id()); | 1107 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1046 EXPECT_EQ("jp", keyboard_->last_layout_); | 1108 EXPECT_EQ("jp", keyboard_->last_layout_); |
| 1047 } | 1109 } |
| 1048 | 1110 |
| 1049 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpIme) { | 1111 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpIme) { |
| 1050 InitComponentExtension(); | 1112 InitComponentExtension(); |
| 1051 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 1113 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 1052 std::vector<std::string> ids; | 1114 std::vector<std::string> ids; |
| 1053 ids.push_back(ImeIdFromEngineId("xkb:jp::jpn")); | 1115 ids.push_back(ImeIdFromEngineId("xkb:jp::jpn")); |
| 1054 ids.push_back(ImeIdFromEngineId(kNaclMozcJpId)); | 1116 ids.push_back(ImeIdFromEngineId(kNaclMozcJpId)); |
| 1055 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 1117 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 1056 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), | 1118 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), |
| 1057 manager_->GetCurrentInputMethod().id()); | 1119 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1058 EXPECT_EQ("jp", keyboard_->last_layout_); | 1120 EXPECT_EQ("jp", keyboard_->last_layout_); |
| 1059 EXPECT_TRUE(manager_->SwitchInputMethod( | 1121 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchInputMethod( |
| 1060 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); | 1122 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); |
| 1061 EXPECT_EQ(ImeIdFromEngineId(kNaclMozcJpId), | 1123 EXPECT_EQ(ImeIdFromEngineId(kNaclMozcJpId), |
| 1062 manager_->GetCurrentInputMethod().id()); | 1124 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1063 EXPECT_EQ("jp", keyboard_->last_layout_); | 1125 EXPECT_EQ("jp", keyboard_->last_layout_); |
| 1064 EXPECT_TRUE(manager_->SwitchInputMethod( | 1126 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchInputMethod( |
| 1065 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); | 1127 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); |
| 1066 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), | 1128 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), |
| 1067 manager_->GetCurrentInputMethod().id()); | 1129 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1068 EXPECT_EQ("jp", keyboard_->last_layout_); | 1130 EXPECT_EQ("jp", keyboard_->last_layout_); |
| 1069 EXPECT_TRUE(manager_->SwitchInputMethod( | 1131 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchInputMethod( |
| 1070 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE))); | 1132 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE))); |
| 1071 EXPECT_EQ(ImeIdFromEngineId(kNaclMozcJpId), | 1133 EXPECT_EQ(ImeIdFromEngineId(kNaclMozcJpId), |
| 1072 manager_->GetCurrentInputMethod().id()); | 1134 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1073 EXPECT_EQ("jp", keyboard_->last_layout_); | 1135 EXPECT_EQ("jp", keyboard_->last_layout_); |
| 1074 EXPECT_TRUE(manager_->SwitchInputMethod( | 1136 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchInputMethod( |
| 1075 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE))); | 1137 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE))); |
| 1076 EXPECT_EQ(ImeIdFromEngineId(kNaclMozcJpId), | 1138 EXPECT_EQ(ImeIdFromEngineId(kNaclMozcJpId), |
| 1077 manager_->GetCurrentInputMethod().id()); | 1139 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1078 EXPECT_EQ("jp", keyboard_->last_layout_); | 1140 EXPECT_EQ("jp", keyboard_->last_layout_); |
| 1079 EXPECT_TRUE(manager_->SwitchInputMethod( | 1141 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchInputMethod( |
| 1080 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); | 1142 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); |
| 1081 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), | 1143 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), |
| 1082 manager_->GetCurrentInputMethod().id()); | 1144 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1083 EXPECT_EQ("jp", keyboard_->last_layout_); | 1145 EXPECT_EQ("jp", keyboard_->last_layout_); |
| 1084 EXPECT_TRUE(manager_->SwitchInputMethod( | 1146 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchInputMethod( |
| 1085 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); | 1147 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); |
| 1086 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), | 1148 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), |
| 1087 manager_->GetCurrentInputMethod().id()); | 1149 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1088 EXPECT_EQ("jp", keyboard_->last_layout_); | 1150 EXPECT_EQ("jp", keyboard_->last_layout_); |
| 1089 | 1151 |
| 1090 // Add Dvorak. | 1152 // Add Dvorak. |
| 1091 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); | 1153 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); |
| 1092 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 1154 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 1093 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), | 1155 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), |
| 1094 manager_->GetCurrentInputMethod().id()); | 1156 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1095 EXPECT_EQ("jp", keyboard_->last_layout_); | 1157 EXPECT_EQ("jp", keyboard_->last_layout_); |
| 1096 EXPECT_TRUE(manager_->SwitchInputMethod( | 1158 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchInputMethod( |
| 1097 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); | 1159 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); |
| 1098 EXPECT_EQ(ImeIdFromEngineId(kNaclMozcJpId), | 1160 EXPECT_EQ(ImeIdFromEngineId(kNaclMozcJpId), |
| 1099 manager_->GetCurrentInputMethod().id()); | 1161 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1100 EXPECT_EQ("jp", keyboard_->last_layout_); | 1162 EXPECT_EQ("jp", keyboard_->last_layout_); |
| 1101 EXPECT_TRUE(manager_->SwitchInputMethod( | 1163 EXPECT_TRUE(manager_->GetActiveIMEState()->SwitchInputMethod( |
| 1102 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); | 1164 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); |
| 1103 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), | 1165 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"), |
| 1104 manager_->GetCurrentInputMethod().id()); | 1166 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1105 EXPECT_EQ("jp", keyboard_->last_layout_); | 1167 EXPECT_EQ("jp", keyboard_->last_layout_); |
| 1106 } | 1168 } |
| 1107 | 1169 |
| 1108 TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) { | 1170 TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) { |
| 1109 TestObserver observer; | 1171 TestObserver observer; |
| 1110 manager_->AddObserver(&observer); | 1172 manager_->AddObserver(&observer); |
| 1111 InitComponentExtension(); | 1173 InitComponentExtension(); |
| 1112 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 1174 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 1113 std::vector<std::string> ids; | 1175 std::vector<std::string> ids; |
| 1114 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); | 1176 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng")); |
| 1115 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 1177 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 1116 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1178 EXPECT_EQ(1U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 1117 EXPECT_EQ(1, observer.input_method_changed_count_); | 1179 EXPECT_EQ(1, observer.input_method_changed_count_); |
| 1118 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id()); | 1180 EXPECT_EQ(ImeIdFromEngineId(ids[0]), |
| 1181 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1119 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 1182 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 1120 | 1183 |
| 1121 // Add two Extension IMEs. | 1184 // Add two Extension IMEs. |
| 1122 std::vector<std::string> layouts; | 1185 std::vector<std::string> layouts; |
| 1123 layouts.push_back("us"); | 1186 layouts.push_back("us"); |
| 1124 std::vector<std::string> languages; | 1187 std::vector<std::string> languages; |
| 1125 languages.push_back("en-US"); | 1188 languages.push_back("en-US"); |
| 1126 | 1189 |
| 1127 const std::string ext1_id = | 1190 const std::string ext1_id = |
| 1128 extension_ime_util::GetInputMethodID(kExtensionId1, "engine_id"); | 1191 extension_ime_util::GetInputMethodID(kExtensionId1, "engine_id"); |
| 1129 const InputMethodDescriptor descriptor1(ext1_id, | 1192 const InputMethodDescriptor descriptor1(ext1_id, |
| 1130 "deadbeef input method", | 1193 "deadbeef input method", |
| 1131 "DB", | 1194 "DB", |
| 1132 layouts, | 1195 layouts, |
| 1133 languages, | 1196 languages, |
| 1134 false, // is_login_keyboard | 1197 false, // is_login_keyboard |
| 1135 GURL(), | 1198 GURL(), |
| 1136 GURL()); | 1199 GURL()); |
| 1137 MockInputMethodEngine engine; | 1200 MockInputMethodEngine engine; |
| 1138 InputMethodDescriptors descriptors; | 1201 InputMethodDescriptors descriptors; |
| 1139 descriptors.push_back(descriptor1); | 1202 descriptors.push_back(descriptor1); |
| 1140 manager_->AddInputMethodExtension(kExtensionId1, descriptors, &engine); | 1203 manager_->GetActiveIMEState()->AddInputMethodExtension( |
| 1204 kExtensionId1, descriptors, &engine); |
| 1141 | 1205 |
| 1142 // Extension IMEs are not enabled by default. | 1206 // Extension IMEs are not enabled by default. |
| 1143 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1207 EXPECT_EQ(1U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 1144 | 1208 |
| 1145 std::vector<std::string> extension_ime_ids; | 1209 std::vector<std::string> extension_ime_ids; |
| 1146 extension_ime_ids.push_back(ext1_id); | 1210 extension_ime_ids.push_back(ext1_id); |
| 1147 manager_->SetEnabledExtensionImes(&extension_ime_ids); | 1211 manager_->GetActiveIMEState()->SetEnabledExtensionImes(&extension_ime_ids); |
| 1148 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1212 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 1149 | 1213 |
| 1150 { | 1214 { |
| 1151 scoped_ptr<InputMethodDescriptors> methods( | 1215 scoped_ptr<InputMethodDescriptors> methods( |
| 1152 manager_->GetActiveInputMethods()); | 1216 manager_->GetActiveIMEState()->GetActiveInputMethods()); |
| 1153 ASSERT_EQ(2U, methods->size()); | 1217 ASSERT_EQ(2U, methods->size()); |
| 1154 // Ext IMEs should be at the end of the list. | 1218 // Ext IMEs should be at the end of the list. |
| 1155 EXPECT_EQ(ext1_id, methods->at(1).id()); | 1219 EXPECT_EQ(ext1_id, methods->at(1).id()); |
| 1156 } | 1220 } |
| 1157 | 1221 |
| 1158 const std::string ext2_id = | 1222 const std::string ext2_id = |
| 1159 extension_ime_util::GetInputMethodID(kExtensionId2, "engine_id"); | 1223 extension_ime_util::GetInputMethodID(kExtensionId2, "engine_id"); |
| 1160 const InputMethodDescriptor descriptor2(ext2_id, | 1224 const InputMethodDescriptor descriptor2(ext2_id, |
| 1161 "cafebabe input method", | 1225 "cafebabe input method", |
| 1162 "CB", | 1226 "CB", |
| 1163 layouts, | 1227 layouts, |
| 1164 languages, | 1228 languages, |
| 1165 false, // is_login_keyboard | 1229 false, // is_login_keyboard |
| 1166 GURL(), | 1230 GURL(), |
| 1167 GURL()); | 1231 GURL()); |
| 1168 descriptors.clear(); | 1232 descriptors.clear(); |
| 1169 descriptors.push_back(descriptor2); | 1233 descriptors.push_back(descriptor2); |
| 1170 MockInputMethodEngine engine2; | 1234 MockInputMethodEngine engine2; |
| 1171 manager_->AddInputMethodExtension(kExtensionId2, descriptors, &engine2); | 1235 manager_->GetActiveIMEState()->AddInputMethodExtension( |
| 1172 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1236 kExtensionId2, descriptors, &engine2); |
| 1237 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 1173 | 1238 |
| 1174 extension_ime_ids.push_back(ext2_id); | 1239 extension_ime_ids.push_back(ext2_id); |
| 1175 manager_->SetEnabledExtensionImes(&extension_ime_ids); | 1240 manager_->GetActiveIMEState()->SetEnabledExtensionImes(&extension_ime_ids); |
| 1176 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); | 1241 EXPECT_EQ(3U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 1177 { | 1242 { |
| 1178 scoped_ptr<InputMethodDescriptors> methods( | 1243 scoped_ptr<InputMethodDescriptors> methods( |
| 1179 manager_->GetActiveInputMethods()); | 1244 manager_->GetActiveIMEState()->GetActiveInputMethods()); |
| 1180 ASSERT_EQ(3U, methods->size()); | 1245 ASSERT_EQ(3U, methods->size()); |
| 1181 // Ext IMEs should be at the end of the list. | 1246 // Ext IMEs should be at the end of the list. |
| 1182 EXPECT_EQ(ext1_id, methods->at(1).id()); | 1247 EXPECT_EQ(ext1_id, methods->at(1).id()); |
| 1183 EXPECT_EQ(ext2_id, methods->at(2).id()); | 1248 EXPECT_EQ(ext2_id, methods->at(2).id()); |
| 1184 } | 1249 } |
| 1185 | 1250 |
| 1186 // Remove them. | 1251 // Remove them. |
| 1187 manager_->RemoveInputMethodExtension(kExtensionId1); | 1252 manager_->GetActiveIMEState()->RemoveInputMethodExtension(kExtensionId1); |
| 1188 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1253 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 1189 manager_->RemoveInputMethodExtension(kExtensionId2); | 1254 manager_->GetActiveIMEState()->RemoveInputMethodExtension(kExtensionId2); |
| 1190 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1255 EXPECT_EQ(1U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 1191 } | 1256 } |
| 1192 | 1257 |
| 1193 TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) { | 1258 TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) { |
| 1194 TestObserver observer; | 1259 TestObserver observer; |
| 1195 InitComponentExtension(); | 1260 InitComponentExtension(); |
| 1196 manager_->AddObserver(&observer); | 1261 manager_->AddObserver(&observer); |
| 1197 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 1262 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 1198 std::vector<std::string> ids; | 1263 std::vector<std::string> ids; |
| 1199 ids.push_back(ImeIdFromEngineId("xkb:us::eng")); | 1264 ids.push_back(ImeIdFromEngineId("xkb:us::eng")); |
| 1200 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 1265 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 1201 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1266 EXPECT_EQ(1U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 1202 EXPECT_EQ(1, observer.input_method_changed_count_); | 1267 EXPECT_EQ(1, observer.input_method_changed_count_); |
| 1203 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id()); | 1268 EXPECT_EQ(ImeIdFromEngineId(ids[0]), |
| 1269 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1204 EXPECT_EQ("us", keyboard_->last_layout_); | 1270 EXPECT_EQ("us", keyboard_->last_layout_); |
| 1205 | 1271 |
| 1206 // Add an Extension IME. | 1272 // Add an Extension IME. |
| 1207 std::vector<std::string> layouts; | 1273 std::vector<std::string> layouts; |
| 1208 layouts.push_back("us(dvorak)"); | 1274 layouts.push_back("us(dvorak)"); |
| 1209 std::vector<std::string> languages; | 1275 std::vector<std::string> languages; |
| 1210 languages.push_back("en-US"); | 1276 languages.push_back("en-US"); |
| 1211 | 1277 |
| 1212 const std::string ext_id = | 1278 const std::string ext_id = |
| 1213 extension_ime_util::GetInputMethodID(kExtensionId1, "engine_id"); | 1279 extension_ime_util::GetInputMethodID(kExtensionId1, "engine_id"); |
| 1214 const InputMethodDescriptor descriptor(ext_id, | 1280 const InputMethodDescriptor descriptor(ext_id, |
| 1215 "deadbeef input method", | 1281 "deadbeef input method", |
| 1216 "DB", | 1282 "DB", |
| 1217 layouts, | 1283 layouts, |
| 1218 languages, | 1284 languages, |
| 1219 false, // is_login_keyboard | 1285 false, // is_login_keyboard |
| 1220 GURL(), | 1286 GURL(), |
| 1221 GURL()); | 1287 GURL()); |
| 1222 MockInputMethodEngine engine; | 1288 MockInputMethodEngine engine; |
| 1223 InputMethodDescriptors descriptors; | 1289 InputMethodDescriptors descriptors; |
| 1224 descriptors.push_back(descriptor); | 1290 descriptors.push_back(descriptor); |
| 1225 manager_->AddInputMethodExtension(kExtensionId1, descriptors, &engine); | 1291 manager_->GetActiveIMEState()->AddInputMethodExtension( |
| 1292 kExtensionId1, descriptors, &engine); |
| 1226 | 1293 |
| 1227 // Extension IME is not enabled by default. | 1294 // Extension IME is not enabled by default. |
| 1228 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1295 EXPECT_EQ(1U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 1229 EXPECT_EQ(1, observer.input_method_changed_count_); | 1296 EXPECT_EQ(1, observer.input_method_changed_count_); |
| 1230 | 1297 |
| 1231 std::vector<std::string> extension_ime_ids; | 1298 std::vector<std::string> extension_ime_ids; |
| 1232 extension_ime_ids.push_back(ext_id); | 1299 extension_ime_ids.push_back(ext_id); |
| 1233 manager_->SetEnabledExtensionImes(&extension_ime_ids); | 1300 manager_->GetActiveIMEState()->SetEnabledExtensionImes(&extension_ime_ids); |
| 1234 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1301 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 1235 | 1302 |
| 1236 // Switch to the IME. | 1303 // Switch to the IME. |
| 1237 manager_->SwitchToNextInputMethod(); | 1304 manager_->GetActiveIMEState()->SwitchToNextInputMethod(); |
| 1238 EXPECT_EQ(3, observer.input_method_changed_count_); | 1305 EXPECT_EQ(3, observer.input_method_changed_count_); |
| 1239 EXPECT_EQ(ext_id, manager_->GetCurrentInputMethod().id()); | 1306 EXPECT_EQ(ext_id, |
| 1307 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1240 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 1308 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 1241 | 1309 |
| 1242 // Lock the screen. This is for crosbug.com/27049. | 1310 // Lock the screen. This is for crosbug.com/27049. |
| 1243 manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN); | 1311 scoped_refptr<input_method::InputMethodManager::State> saved_ime_state = |
| 1244 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); // Qwerty. No Ext. IME | 1312 manager_->GetActiveIMEState(); |
| 1313 manager_->SetState(saved_ime_state->Clone()); |
| 1314 manager_->GetActiveIMEState()->EnableLockScreenLayouts(); |
| 1315 manager_->SetUISessionState(InputMethodManager::STATE_LOCK_SCREEN); |
| 1316 EXPECT_EQ(1U, |
| 1317 manager_->GetActiveIMEState() |
| 1318 ->GetNumActiveInputMethods()); // Qwerty. No Ext. IME |
| 1245 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), | 1319 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), |
| 1246 manager_->GetCurrentInputMethod().id()); | 1320 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1247 EXPECT_EQ("us", keyboard_->last_layout_); | 1321 EXPECT_EQ("us", keyboard_->last_layout_); |
| 1248 | 1322 |
| 1249 // Unlock the screen. | 1323 // Unlock the screen. |
| 1250 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 1324 manager_->SetState(saved_ime_state); |
| 1251 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1325 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 1252 EXPECT_EQ(ext_id, manager_->GetCurrentInputMethod().id()); | 1326 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 1327 EXPECT_EQ(ext_id, |
| 1328 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1253 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); | 1329 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); |
| 1254 { | 1330 { |
| 1255 // This is for crosbug.com/27052. | 1331 // This is for crosbug.com/27052. |
| 1256 scoped_ptr<InputMethodDescriptors> methods( | 1332 scoped_ptr<InputMethodDescriptors> methods( |
| 1257 manager_->GetActiveInputMethods()); | 1333 manager_->GetActiveIMEState()->GetActiveInputMethods()); |
| 1258 ASSERT_EQ(2U, methods->size()); | 1334 ASSERT_EQ(2U, methods->size()); |
| 1259 // Ext. IMEs should be at the end of the list. | 1335 // Ext. IMEs should be at the end of the list. |
| 1260 EXPECT_EQ(ext_id, methods->at(1).id()); | 1336 EXPECT_EQ(ext_id, methods->at(1).id()); |
| 1261 } | 1337 } |
| 1262 manager_->RemoveObserver(&observer); | 1338 manager_->RemoveObserver(&observer); |
| 1263 } | 1339 } |
| 1264 | 1340 |
| 1265 TEST_F(InputMethodManagerImplTest, | 1341 TEST_F(InputMethodManagerImplTest, |
| 1266 ChangeInputMethod_ComponenteExtensionOneIME) { | 1342 ChangeInputMethod_ComponenteExtensionOneIME) { |
| 1267 InitComponentExtension(); | 1343 InitComponentExtension(); |
| 1268 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 1344 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 1269 const std::string ext_id = extension_ime_util::GetComponentInputMethodID( | 1345 const std::string ext_id = extension_ime_util::GetComponentInputMethodID( |
| 1270 ime_list_[1].id, | 1346 ime_list_[1].id, |
| 1271 ime_list_[1].engines[0].engine_id); | 1347 ime_list_[1].engines[0].engine_id); |
| 1272 std::vector<std::string> ids; | 1348 std::vector<std::string> ids; |
| 1273 ids.push_back(ext_id); | 1349 ids.push_back(ext_id); |
| 1274 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 1350 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 1275 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 1351 EXPECT_EQ(1U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 1276 EXPECT_EQ(ext_id, manager_->GetCurrentInputMethod().id()); | 1352 EXPECT_EQ(ext_id, |
| 1353 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1277 } | 1354 } |
| 1278 | 1355 |
| 1279 TEST_F(InputMethodManagerImplTest, | 1356 TEST_F(InputMethodManagerImplTest, |
| 1280 ChangeInputMethod_ComponenteExtensionTwoIME) { | 1357 ChangeInputMethod_ComponenteExtensionTwoIME) { |
| 1281 InitComponentExtension(); | 1358 InitComponentExtension(); |
| 1282 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 1359 manager_->SetUISessionState(InputMethodManager::STATE_BROWSER_SCREEN); |
| 1283 const std::string ext_id1 = extension_ime_util::GetComponentInputMethodID( | 1360 const std::string ext_id1 = extension_ime_util::GetComponentInputMethodID( |
| 1284 ime_list_[1].id, | 1361 ime_list_[1].id, |
| 1285 ime_list_[1].engines[0].engine_id); | 1362 ime_list_[1].engines[0].engine_id); |
| 1286 const std::string ext_id2 = extension_ime_util::GetComponentInputMethodID( | 1363 const std::string ext_id2 = extension_ime_util::GetComponentInputMethodID( |
| 1287 ime_list_[2].id, | 1364 ime_list_[2].id, |
| 1288 ime_list_[2].engines[0].engine_id); | 1365 ime_list_[2].engines[0].engine_id); |
| 1289 std::vector<std::string> ids; | 1366 std::vector<std::string> ids; |
| 1290 ids.push_back(ext_id1); | 1367 ids.push_back(ext_id1); |
| 1291 ids.push_back(ext_id2); | 1368 ids.push_back(ext_id2); |
| 1292 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); | 1369 EXPECT_TRUE(manager_->GetActiveIMEState()->ReplaceEnabledInputMethods(ids)); |
| 1293 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1370 EXPECT_EQ(2U, manager_->GetActiveIMEState()->GetNumActiveInputMethods()); |
| 1294 EXPECT_EQ(ext_id1, manager_->GetCurrentInputMethod().id()); | 1371 EXPECT_EQ(ext_id1, |
| 1295 manager_->ChangeInputMethod(ext_id2); | 1372 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1296 EXPECT_EQ(ext_id2, manager_->GetCurrentInputMethod().id()); | 1373 manager_->GetActiveIMEState()->ChangeInputMethod(ext_id2, |
| 1374 false /* show_message */); |
| 1375 EXPECT_EQ(ext_id2, |
| 1376 manager_->GetActiveIMEState()->GetCurrentInputMethod().id()); |
| 1297 } | 1377 } |
| 1298 | 1378 |
| 1299 TEST_F(InputMethodManagerImplTest, MigrateInputMethodTest) { | 1379 TEST_F(InputMethodManagerImplTest, MigrateInputMethodTest) { |
| 1300 std::vector<std::string> input_method_ids; | 1380 std::vector<std::string> input_method_ids; |
| 1301 input_method_ids.push_back("xkb:us::eng"); | 1381 input_method_ids.push_back("xkb:us::eng"); |
| 1302 input_method_ids.push_back("xkb:fr::fra"); | 1382 input_method_ids.push_back("xkb:fr::fra"); |
| 1303 input_method_ids.push_back(ImeIdFromEngineId("xkb:us::eng")); | 1383 input_method_ids.push_back(ImeIdFromEngineId("xkb:us::eng")); |
| 1304 input_method_ids.push_back("xkb:fr::fra"); | 1384 input_method_ids.push_back("xkb:fr::fra"); |
| 1305 input_method_ids.push_back(ImeIdFromEngineId("xkb:us::eng")); | 1385 input_method_ids.push_back(ImeIdFromEngineId("xkb:us::eng")); |
| 1306 input_method_ids.push_back("_comp_ime_asdf_pinyin"); | 1386 input_method_ids.push_back("_comp_ime_asdf_pinyin"); |
| 1307 input_method_ids.push_back(ImeIdFromEngineId(kPinyinImeId)); | 1387 input_method_ids.push_back(ImeIdFromEngineId(kPinyinImeId)); |
| 1308 | 1388 |
| 1309 manager_->MigrateInputMethods(&input_method_ids); | 1389 manager_->MigrateInputMethods(&input_method_ids); |
| 1310 | 1390 |
| 1311 ASSERT_EQ(4U, input_method_ids.size()); | 1391 ASSERT_EQ(4U, input_method_ids.size()); |
| 1312 | 1392 |
| 1313 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), input_method_ids[0]); | 1393 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), input_method_ids[0]); |
| 1314 EXPECT_EQ(ImeIdFromEngineId("xkb:fr::fra"), input_method_ids[1]); | 1394 EXPECT_EQ(ImeIdFromEngineId("xkb:fr::fra"), input_method_ids[1]); |
| 1315 EXPECT_EQ("_comp_ime_asdf_pinyin", input_method_ids[2]); | 1395 EXPECT_EQ("_comp_ime_asdf_pinyin", input_method_ids[2]); |
| 1316 EXPECT_EQ(ImeIdFromEngineId("zh-t-i0-pinyin"), input_method_ids[3]); | 1396 EXPECT_EQ(ImeIdFromEngineId("zh-t-i0-pinyin"), input_method_ids[3]); |
| 1317 } | 1397 } |
| 1318 | 1398 |
| 1319 } // namespace input_method | 1399 } // namespace input_method |
| 1320 } // namespace chromeos | 1400 } // namespace chromeos |
| OLD | NEW |