Chromium Code Reviews| 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 "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 manager_->RemoveCandidateWindowObserver(&observer); | 230 manager_->RemoveCandidateWindowObserver(&observer); |
| 231 } | 231 } |
| 232 | 232 |
| 233 TEST_F(InputMethodManagerImplTest, TestObserver) { | 233 TEST_F(InputMethodManagerImplTest, TestObserver) { |
| 234 // For http://crbug.com/19655#c11 - (3). browser_state_monitor_unittest.cc is | 234 // For http://crbug.com/19655#c11 - (3). browser_state_monitor_unittest.cc is |
| 235 // also for the scenario. | 235 // also for the scenario. |
| 236 TestObserver observer; | 236 TestObserver observer; |
| 237 InitComponentExtension(); | 237 InitComponentExtension(); |
| 238 manager_->AddObserver(&observer); | 238 manager_->AddObserver(&observer); |
| 239 EXPECT_EQ(0, observer.input_method_changed_count_); | 239 EXPECT_EQ(0, observer.input_method_changed_count_); |
| 240 manager_->EnableLayouts("en-US", "xkb:us::eng"); | 240 manager_->EnableLoginLayouts("en-US", "xkb:us::eng"); |
| 241 EXPECT_EQ(1, observer.input_method_changed_count_); | 241 EXPECT_EQ(1, observer.input_method_changed_count_); |
| 242 EXPECT_EQ(1, observer.input_method_property_changed_count_); | 242 EXPECT_EQ(1, observer.input_method_property_changed_count_); |
| 243 manager_->ChangeInputMethod("xkb:us:dvorak:eng"); | 243 manager_->ChangeInputMethod("xkb:us:dvorak:eng"); |
| 244 EXPECT_FALSE(observer.last_show_message_); | 244 EXPECT_FALSE(observer.last_show_message_); |
| 245 EXPECT_EQ(2, observer.input_method_changed_count_); | 245 EXPECT_EQ(2, observer.input_method_changed_count_); |
| 246 EXPECT_EQ(2, observer.input_method_property_changed_count_); | 246 EXPECT_EQ(2, observer.input_method_property_changed_count_); |
| 247 manager_->ChangeInputMethod("xkb:us:dvorak:eng"); | 247 manager_->ChangeInputMethod("xkb:us:dvorak:eng"); |
| 248 EXPECT_FALSE(observer.last_show_message_); | 248 EXPECT_FALSE(observer.last_show_message_); |
| 249 | 249 |
| 250 // The observer is always notified even when the same input method ID is | 250 // The observer is always notified even when the same input method ID is |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 277 EXPECT_TRUE(Contain(*methods.get(), *id_to_find)); | 277 EXPECT_TRUE(Contain(*methods.get(), *id_to_find)); |
| 278 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( | 278 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( |
| 279 "xkb:fr::fra"); | 279 "xkb:fr::fra"); |
| 280 EXPECT_TRUE(Contain(*methods.get(), *id_to_find)); | 280 EXPECT_TRUE(Contain(*methods.get(), *id_to_find)); |
| 281 } | 281 } |
| 282 | 282 |
| 283 TEST_F(InputMethodManagerImplTest, TestEnableLayouts) { | 283 TEST_F(InputMethodManagerImplTest, TestEnableLayouts) { |
| 284 // Currently 5 keyboard layouts are supported for en-US, and 1 for ja. See | 284 // Currently 5 keyboard layouts are supported for en-US, and 1 for ja. See |
| 285 // ibus_input_method.txt. | 285 // ibus_input_method.txt. |
| 286 InitComponentExtension(); | 286 InitComponentExtension(); |
| 287 manager_->EnableLayouts("en-US", ""); | 287 manager_->EnableLoginLayouts("en-US", ""); |
| 288 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); | 288 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); |
| 289 for (size_t i = 0; i < manager_->GetActiveInputMethodIds().size(); ++i) | 289 for (size_t i = 0; i < manager_->GetActiveInputMethodIds().size(); ++i) |
| 290 LOG(ERROR) << manager_->GetActiveInputMethodIds().at(i); | 290 LOG(ERROR) << manager_->GetActiveInputMethodIds().at(i); |
| 291 | 291 |
| 292 // For http://crbug.com/19655#c11 - (5) | 292 // For http://crbug.com/19655#c11 - (5) |
| 293 // The hardware keyboard layout "xkb:us::eng" is always active, hence 2U. | 293 // The hardware keyboard layout "xkb:us::eng" is always active, hence 2U. |
| 294 manager_->EnableLayouts("ja", ""); // Japanese | 294 manager_->EnableLoginLayouts("ja", ""); // Japanese |
| 295 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 295 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
| 296 } | 296 } |
| 297 | 297 |
| 298 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsAndCurrentInputMethod) { | 298 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsAndCurrentInputMethod) { |
| 299 // For http://crbug.com/329061 | 299 // For http://crbug.com/329061 |
| 300 manager_->EnableLayouts("en-US", "xkb:se::swe"); | 300 manager_->EnableLoginLayouts("en-US", "xkb:se::swe"); |
| 301 const std::string im_id = manager_->GetCurrentInputMethod().id(); | 301 const std::string im_id = manager_->GetCurrentInputMethod().id(); |
| 302 EXPECT_EQ("xkb:se::swe", im_id); | 302 EXPECT_EQ("xkb:se::swe", im_id); |
| 303 } | 303 } |
| 304 | 304 |
| 305 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsNonUsHardwareKeyboard) { | 305 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsNonUsHardwareKeyboard) { |
| 306 // The physical layout is French. | 306 // The physical layout is French. |
| 307 delegate_->set_hardware_keyboard_layout("xkb:fr::fra"); | 307 delegate_->set_hardware_keyboard_layout("xkb:fr::fra"); |
| 308 manager_->EnableLayouts("en-US", ""); | 308 manager_->EnableLoginLayouts("en-US", ""); |
| 309 EXPECT_EQ(6U, manager_->GetNumActiveInputMethods()); // 5 + French | 309 EXPECT_EQ(6U, manager_->GetNumActiveInputMethods()); // 5 + French |
| 310 // The physical layout is Japanese. | 310 // The physical layout is Japanese. |
| 311 delegate_->set_hardware_keyboard_layout("xkb:jp::jpn"); | 311 delegate_->set_hardware_keyboard_layout("xkb:jp::jpn"); |
| 312 manager_->EnableLayouts("ja", ""); | 312 manager_->EnableLoginLayouts("ja", ""); |
| 313 // "xkb:us::eng" is not needed, hence 1. | 313 // "xkb:us::eng" is not needed, hence 1. |
| 314 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 314 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |
| 315 | |
| 316 // The physical layout is Russian. | |
| 317 delegate_->set_hardware_keyboard_layout("xkb:ru::rus"); | |
| 318 manager_->EnableLoginLayouts("ru", ""); | |
| 319 // "xkb:us::eng" only. | |
| 320 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | |
| 321 EXPECT_EQ(manager_->GetActiveInputMethodIds().front(), "xkb:us::eng"); | |
|
Hiro Komatsu
2014/01/28 06:21:24
EXPECT_EQ(expected, actual);
Alexander Alekseev
2014/01/29 13:37:01
Done.
| |
| 315 } | 322 } |
| 316 | 323 |
| 317 TEST_F(InputMethodManagerImplTest, TestActiveInputMethods) { | 324 TEST_F(InputMethodManagerImplTest, TestActiveInputMethods) { |
| 318 manager_->EnableLayouts("ja", ""); // Japanese | 325 manager_->EnableLoginLayouts("ja", ""); // Japanese |
| 319 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 326 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
| 320 scoped_ptr<InputMethodDescriptors> methods( | 327 scoped_ptr<InputMethodDescriptors> methods( |
| 321 manager_->GetActiveInputMethods()); | 328 manager_->GetActiveInputMethods()); |
| 322 ASSERT_TRUE(methods.get()); | 329 ASSERT_TRUE(methods.get()); |
| 323 EXPECT_EQ(2U, methods->size()); | 330 EXPECT_EQ(2U, methods->size()); |
| 324 const InputMethodDescriptor* id_to_find = | 331 const InputMethodDescriptor* id_to_find = |
| 325 manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( | 332 manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( |
| 326 "xkb:us::eng"); | 333 "xkb:us::eng"); |
| 327 EXPECT_TRUE(Contain(*methods.get(), *id_to_find)); | 334 EXPECT_TRUE(Contain(*methods.get(), *id_to_find)); |
| 328 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( | 335 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 ASSERT_EQ(1U, manager_->GetCurrentInputMethodProperties().size()); | 670 ASSERT_EQ(1U, manager_->GetCurrentInputMethodProperties().size()); |
| 664 EXPECT_EQ("key-chewing", | 671 EXPECT_EQ("key-chewing", |
| 665 manager_->GetCurrentInputMethodProperties().at(0).key); | 672 manager_->GetCurrentInputMethodProperties().at(0).key); |
| 666 } | 673 } |
| 667 | 674 |
| 668 TEST_F(InputMethodManagerImplTest, TestNextInputMethod) { | 675 TEST_F(InputMethodManagerImplTest, TestNextInputMethod) { |
| 669 TestObserver observer; | 676 TestObserver observer; |
| 670 manager_->AddObserver(&observer); | 677 manager_->AddObserver(&observer); |
| 671 InitComponentExtension(); | 678 InitComponentExtension(); |
| 672 // For http://crbug.com/19655#c11 - (1) | 679 // For http://crbug.com/19655#c11 - (1) |
| 673 manager_->EnableLayouts("en-US", "xkb:us::eng"); | 680 manager_->EnableLoginLayouts("en-US", "xkb:us::eng"); |
| 674 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); | 681 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); |
| 675 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); | 682 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); |
| 676 EXPECT_EQ("us", xkeyboard_->last_layout_); | 683 EXPECT_EQ("us", xkeyboard_->last_layout_); |
| 677 manager_->SwitchToNextInputMethod(); | 684 manager_->SwitchToNextInputMethod(); |
| 678 EXPECT_TRUE(observer.last_show_message_); | 685 EXPECT_TRUE(observer.last_show_message_); |
| 679 EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); | 686 EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); |
| 680 EXPECT_EQ("us(intl)", xkeyboard_->last_layout_); | 687 EXPECT_EQ("us(intl)", xkeyboard_->last_layout_); |
| 681 manager_->SwitchToNextInputMethod(); | 688 manager_->SwitchToNextInputMethod(); |
| 682 EXPECT_TRUE(observer.last_show_message_); | 689 EXPECT_TRUE(observer.last_show_message_); |
| 683 EXPECT_EQ("xkb:us:altgr-intl:eng", manager_->GetCurrentInputMethod().id()); | 690 EXPECT_EQ("xkb:us:altgr-intl:eng", manager_->GetCurrentInputMethod().id()); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 701 TEST_F(InputMethodManagerImplTest, TestPreviousInputMethod) { | 708 TEST_F(InputMethodManagerImplTest, TestPreviousInputMethod) { |
| 702 TestObserver observer; | 709 TestObserver observer; |
| 703 manager_->AddObserver(&observer); | 710 manager_->AddObserver(&observer); |
| 704 InitComponentExtension(); | 711 InitComponentExtension(); |
| 705 | 712 |
| 706 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); | 713 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); |
| 707 keydown_accelerator.set_type(ui::ET_KEY_PRESSED); | 714 keydown_accelerator.set_type(ui::ET_KEY_PRESSED); |
| 708 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); | 715 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); |
| 709 keyup_accelerator.set_type(ui::ET_KEY_RELEASED); | 716 keyup_accelerator.set_type(ui::ET_KEY_RELEASED); |
| 710 | 717 |
| 711 manager_->EnableLayouts("en-US", "xkb:us::eng"); | 718 manager_->EnableLoginLayouts("en-US", "xkb:us::eng"); |
| 712 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); | 719 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); |
| 713 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); | 720 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); |
| 714 EXPECT_EQ("us", xkeyboard_->last_layout_); | 721 EXPECT_EQ("us", xkeyboard_->last_layout_); |
| 715 EXPECT_TRUE(manager_->SwitchToNextInputMethod()); | 722 EXPECT_TRUE(manager_->SwitchToNextInputMethod()); |
| 716 EXPECT_TRUE(observer.last_show_message_); | 723 EXPECT_TRUE(observer.last_show_message_); |
| 717 EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); | 724 EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); |
| 718 EXPECT_EQ("us(intl)", xkeyboard_->last_layout_); | 725 EXPECT_EQ("us(intl)", xkeyboard_->last_layout_); |
| 719 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); | 726 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); |
| 720 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); | 727 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); |
| 721 EXPECT_TRUE(observer.last_show_message_); | 728 EXPECT_TRUE(observer.last_show_message_); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 774 EXPECT_FALSE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); | 781 EXPECT_FALSE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); |
| 775 EXPECT_FALSE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); | 782 EXPECT_FALSE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); |
| 776 | 783 |
| 777 manager_->RemoveObserver(&observer); | 784 manager_->RemoveObserver(&observer); |
| 778 } | 785 } |
| 779 | 786 |
| 780 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithUsLayouts) { | 787 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithUsLayouts) { |
| 781 TestObserver observer; | 788 TestObserver observer; |
| 782 manager_->AddObserver(&observer); | 789 manager_->AddObserver(&observer); |
| 783 InitComponentExtension(); | 790 InitComponentExtension(); |
| 784 manager_->EnableLayouts("en-US", "xkb:us::eng"); | 791 manager_->EnableLoginLayouts("en-US", "xkb:us::eng"); |
| 785 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); | 792 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); |
| 786 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); | 793 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); |
| 787 EXPECT_EQ("us", xkeyboard_->last_layout_); | 794 EXPECT_EQ("us", xkeyboard_->last_layout_); |
| 788 | 795 |
| 789 // Henkan, Muhenkan, ZenkakuHankaku should be ignored when no Japanese IMEs | 796 // Henkan, Muhenkan, ZenkakuHankaku should be ignored when no Japanese IMEs |
| 790 // and keyboards are enabled. | 797 // and keyboards are enabled. |
| 791 EXPECT_FALSE(manager_->SwitchInputMethod( | 798 EXPECT_FALSE(manager_->SwitchInputMethod( |
| 792 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE))); | 799 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE))); |
| 793 EXPECT_FALSE(observer.last_show_message_); | 800 EXPECT_FALSE(observer.last_show_message_); |
| 794 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); | 801 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 811 | 818 |
| 812 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpLayout) { | 819 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpLayout) { |
| 813 // Enable "xkb:jp::jpn" and press Muhenkan/ZenkakuHankaku. | 820 // Enable "xkb:jp::jpn" and press Muhenkan/ZenkakuHankaku. |
| 814 InitComponentExtension(); | 821 InitComponentExtension(); |
| 815 | 822 |
| 816 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); | 823 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); |
| 817 keydown_accelerator.set_type(ui::ET_KEY_PRESSED); | 824 keydown_accelerator.set_type(ui::ET_KEY_PRESSED); |
| 818 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); | 825 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); |
| 819 keyup_accelerator.set_type(ui::ET_KEY_RELEASED); | 826 keyup_accelerator.set_type(ui::ET_KEY_RELEASED); |
| 820 | 827 |
| 821 manager_->EnableLayouts("ja", "xkb:us::eng"); | 828 manager_->EnableLoginLayouts("ja", "xkb:us::eng"); |
| 822 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 829 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
| 823 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); | 830 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); |
| 824 EXPECT_EQ("us", xkeyboard_->last_layout_); | 831 EXPECT_EQ("us", xkeyboard_->last_layout_); |
| 825 EXPECT_TRUE(manager_->SwitchInputMethod( | 832 EXPECT_TRUE(manager_->SwitchInputMethod( |
| 826 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); | 833 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); |
| 827 EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); | 834 EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); |
| 828 EXPECT_EQ("jp", xkeyboard_->last_layout_); | 835 EXPECT_EQ("jp", xkeyboard_->last_layout_); |
| 829 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); | 836 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); |
| 830 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); | 837 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); |
| 831 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); | 838 EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1136 ids.push_back(ext_id2); | 1143 ids.push_back(ext_id2); |
| 1137 EXPECT_TRUE(manager_->EnableInputMethods(ids)); | 1144 EXPECT_TRUE(manager_->EnableInputMethods(ids)); |
| 1138 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 1145 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
| 1139 EXPECT_EQ(ext_id1, manager_->GetCurrentInputMethod().id()); | 1146 EXPECT_EQ(ext_id1, manager_->GetCurrentInputMethod().id()); |
| 1140 manager_->ChangeInputMethod(ext_id2); | 1147 manager_->ChangeInputMethod(ext_id2); |
| 1141 EXPECT_EQ(ext_id2, manager_->GetCurrentInputMethod().id()); | 1148 EXPECT_EQ(ext_id2, manager_->GetCurrentInputMethod().id()); |
| 1142 } | 1149 } |
| 1143 | 1150 |
| 1144 } // namespace input_method | 1151 } // namespace input_method |
| 1145 } // namespace chromeos | 1152 } // namespace chromeos |
| OLD | NEW |