| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/base/ime/input_method_chromeos.h" | 5 #include "ui/base/ime/input_method_chromeos.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 #undef Bool | 8 #undef Bool |
| 9 #undef FocusIn | 9 #undef FocusIn |
| 10 #undef FocusOut | 10 #undef FocusOut |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 EXPECT_EQ(kCursorPos, composition_text.selection.start()); | 632 EXPECT_EQ(kCursorPos, composition_text.selection.start()); |
| 633 EXPECT_EQ(kCursorPos, composition_text.selection.end()); | 633 EXPECT_EQ(kCursorPos, composition_text.selection.end()); |
| 634 ASSERT_EQ(1UL, composition_text.underlines.size()); | 634 ASSERT_EQ(1UL, composition_text.underlines.size()); |
| 635 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.start_index), | 635 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.start_index), |
| 636 composition_text.underlines[0].start_offset); | 636 composition_text.underlines[0].start_offset); |
| 637 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.end_index), | 637 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.end_index), |
| 638 composition_text.underlines[0].end_offset); | 638 composition_text.underlines[0].end_offset); |
| 639 // Single underline represents as black thin line. | 639 // Single underline represents as black thin line. |
| 640 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); | 640 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); |
| 641 EXPECT_FALSE(composition_text.underlines[0].thick); | 641 EXPECT_FALSE(composition_text.underlines[0].thick); |
| 642 EXPECT_EQ(SK_ColorTRANSPARENT, |
| 643 composition_text.underlines[0].background_color); |
| 642 } | 644 } |
| 643 | 645 |
| 644 TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_DoubleUnderline) { | 646 TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_DoubleUnderline) { |
| 645 const uint32 kCursorPos = 2UL; | 647 const uint32 kCursorPos = 2UL; |
| 646 | 648 |
| 647 // Set up chromeos composition text with one underline attribute. | 649 // Set up chromeos composition text with one underline attribute. |
| 648 chromeos::CompositionText chromeos_composition_text; | 650 chromeos::CompositionText chromeos_composition_text; |
| 649 chromeos_composition_text.set_text(kSampleText); | 651 chromeos_composition_text.set_text(kSampleText); |
| 650 chromeos::CompositionText::UnderlineAttribute underline; | 652 chromeos::CompositionText::UnderlineAttribute underline; |
| 651 underline.type = chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_DOUBLE; | 653 underline.type = chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_DOUBLE; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 662 EXPECT_EQ(kCursorPos, composition_text.selection.start()); | 664 EXPECT_EQ(kCursorPos, composition_text.selection.start()); |
| 663 EXPECT_EQ(kCursorPos, composition_text.selection.end()); | 665 EXPECT_EQ(kCursorPos, composition_text.selection.end()); |
| 664 ASSERT_EQ(1UL, composition_text.underlines.size()); | 666 ASSERT_EQ(1UL, composition_text.underlines.size()); |
| 665 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.start_index), | 667 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.start_index), |
| 666 composition_text.underlines[0].start_offset); | 668 composition_text.underlines[0].start_offset); |
| 667 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.end_index), | 669 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.end_index), |
| 668 composition_text.underlines[0].end_offset); | 670 composition_text.underlines[0].end_offset); |
| 669 // Double underline represents as black thick line. | 671 // Double underline represents as black thick line. |
| 670 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); | 672 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); |
| 671 EXPECT_TRUE(composition_text.underlines[0].thick); | 673 EXPECT_TRUE(composition_text.underlines[0].thick); |
| 674 EXPECT_EQ(SK_ColorTRANSPARENT, |
| 675 composition_text.underlines[0].background_color); |
| 672 } | 676 } |
| 673 | 677 |
| 674 TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_ErrorUnderline) { | 678 TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_ErrorUnderline) { |
| 675 const uint32 kCursorPos = 2UL; | 679 const uint32 kCursorPos = 2UL; |
| 676 | 680 |
| 677 // Set up chromeos composition text with one underline attribute. | 681 // Set up chromeos composition text with one underline attribute. |
| 678 chromeos::CompositionText chromeos_composition_text; | 682 chromeos::CompositionText chromeos_composition_text; |
| 679 chromeos_composition_text.set_text(kSampleText); | 683 chromeos_composition_text.set_text(kSampleText); |
| 680 chromeos::CompositionText::UnderlineAttribute underline; | 684 chromeos::CompositionText::UnderlineAttribute underline; |
| 681 underline.type = chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_ERROR; | 685 underline.type = chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_ERROR; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 EXPECT_EQ(kCursorPos, composition_text.selection.end()); | 721 EXPECT_EQ(kCursorPos, composition_text.selection.end()); |
| 718 ASSERT_EQ(1UL, composition_text.underlines.size()); | 722 ASSERT_EQ(1UL, composition_text.underlines.size()); |
| 719 EXPECT_EQ(GetOffsetInUTF16(kSampleText, | 723 EXPECT_EQ(GetOffsetInUTF16(kSampleText, |
| 720 chromeos_composition_text.selection_start()), | 724 chromeos_composition_text.selection_start()), |
| 721 composition_text.underlines[0].start_offset); | 725 composition_text.underlines[0].start_offset); |
| 722 EXPECT_EQ(GetOffsetInUTF16(kSampleText, | 726 EXPECT_EQ(GetOffsetInUTF16(kSampleText, |
| 723 chromeos_composition_text.selection_end()), | 727 chromeos_composition_text.selection_end()), |
| 724 composition_text.underlines[0].end_offset); | 728 composition_text.underlines[0].end_offset); |
| 725 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); | 729 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); |
| 726 EXPECT_TRUE(composition_text.underlines[0].thick); | 730 EXPECT_TRUE(composition_text.underlines[0].thick); |
| 731 EXPECT_EQ(SK_ColorTRANSPARENT, |
| 732 composition_text.underlines[0].background_color); |
| 727 } | 733 } |
| 728 | 734 |
| 729 TEST_F(InputMethodChromeOSTest, | 735 TEST_F(InputMethodChromeOSTest, |
| 730 ExtractCompositionTextTest_SelectionStartWithCursor) { | 736 ExtractCompositionTextTest_SelectionStartWithCursor) { |
| 731 const uint32 kCursorPos = 1UL; | 737 const uint32 kCursorPos = 1UL; |
| 732 | 738 |
| 733 // Set up chromeos composition text with one underline attribute. | 739 // Set up chromeos composition text with one underline attribute. |
| 734 chromeos::CompositionText chromeos_composition_text; | 740 chromeos::CompositionText chromeos_composition_text; |
| 735 chromeos_composition_text.set_text(kSampleText); | 741 chromeos_composition_text.set_text(kSampleText); |
| 736 chromeos_composition_text.set_selection_start(kCursorPos); | 742 chromeos_composition_text.set_selection_start(kCursorPos); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 749 composition_text.selection.end()); | 755 composition_text.selection.end()); |
| 750 ASSERT_EQ(1UL, composition_text.underlines.size()); | 756 ASSERT_EQ(1UL, composition_text.underlines.size()); |
| 751 EXPECT_EQ(GetOffsetInUTF16(kSampleText, | 757 EXPECT_EQ(GetOffsetInUTF16(kSampleText, |
| 752 chromeos_composition_text.selection_start()), | 758 chromeos_composition_text.selection_start()), |
| 753 composition_text.underlines[0].start_offset); | 759 composition_text.underlines[0].start_offset); |
| 754 EXPECT_EQ(GetOffsetInUTF16(kSampleText, | 760 EXPECT_EQ(GetOffsetInUTF16(kSampleText, |
| 755 chromeos_composition_text.selection_end()), | 761 chromeos_composition_text.selection_end()), |
| 756 composition_text.underlines[0].end_offset); | 762 composition_text.underlines[0].end_offset); |
| 757 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); | 763 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); |
| 758 EXPECT_TRUE(composition_text.underlines[0].thick); | 764 EXPECT_TRUE(composition_text.underlines[0].thick); |
| 765 EXPECT_EQ(SK_ColorTRANSPARENT, |
| 766 composition_text.underlines[0].background_color); |
| 759 } | 767 } |
| 760 | 768 |
| 761 TEST_F(InputMethodChromeOSTest, | 769 TEST_F(InputMethodChromeOSTest, |
| 762 ExtractCompositionTextTest_SelectionEndWithCursor) { | 770 ExtractCompositionTextTest_SelectionEndWithCursor) { |
| 763 const uint32 kCursorPos = 4UL; | 771 const uint32 kCursorPos = 4UL; |
| 764 | 772 |
| 765 // Set up chromeos composition text with one underline attribute. | 773 // Set up chromeos composition text with one underline attribute. |
| 766 chromeos::CompositionText chromeos_composition_text; | 774 chromeos::CompositionText chromeos_composition_text; |
| 767 chromeos_composition_text.set_text(kSampleText); | 775 chromeos_composition_text.set_text(kSampleText); |
| 768 chromeos_composition_text.set_selection_start(1UL); | 776 chromeos_composition_text.set_selection_start(1UL); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 781 composition_text.selection.end()); | 789 composition_text.selection.end()); |
| 782 ASSERT_EQ(1UL, composition_text.underlines.size()); | 790 ASSERT_EQ(1UL, composition_text.underlines.size()); |
| 783 EXPECT_EQ(GetOffsetInUTF16(kSampleText, | 791 EXPECT_EQ(GetOffsetInUTF16(kSampleText, |
| 784 chromeos_composition_text.selection_start()), | 792 chromeos_composition_text.selection_start()), |
| 785 composition_text.underlines[0].start_offset); | 793 composition_text.underlines[0].start_offset); |
| 786 EXPECT_EQ(GetOffsetInUTF16(kSampleText, | 794 EXPECT_EQ(GetOffsetInUTF16(kSampleText, |
| 787 chromeos_composition_text.selection_end()), | 795 chromeos_composition_text.selection_end()), |
| 788 composition_text.underlines[0].end_offset); | 796 composition_text.underlines[0].end_offset); |
| 789 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); | 797 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); |
| 790 EXPECT_TRUE(composition_text.underlines[0].thick); | 798 EXPECT_TRUE(composition_text.underlines[0].thick); |
| 799 EXPECT_EQ(SK_ColorTRANSPARENT, |
| 800 composition_text.underlines[0].background_color); |
| 791 } | 801 } |
| 792 | 802 |
| 793 TEST_F(InputMethodChromeOSTest, SurroundingText_NoSelectionTest) { | 803 TEST_F(InputMethodChromeOSTest, SurroundingText_NoSelectionTest) { |
| 794 ime_->Init(true); | 804 ime_->Init(true); |
| 795 // Click a text input form. | 805 // Click a text input form. |
| 796 input_type_ = TEXT_INPUT_TYPE_TEXT; | 806 input_type_ = TEXT_INPUT_TYPE_TEXT; |
| 797 ime_->OnTextInputTypeChanged(this); | 807 ime_->OnTextInputTypeChanged(this); |
| 798 | 808 |
| 799 // Set the TextInputClient behaviors. | 809 // Set the TextInputClient behaviors. |
| 800 surrounding_text_ = UTF8ToUTF16("abcdef"); | 810 surrounding_text_ = UTF8ToUTF16("abcdef"); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 ime_->ResetContext(); | 1028 ime_->ResetContext(); |
| 1019 | 1029 |
| 1020 // Do callback. | 1030 // Do callback. |
| 1021 mock_ime_engine_handler_->last_passed_callback().Run(true); | 1031 mock_ime_engine_handler_->last_passed_callback().Run(true); |
| 1022 | 1032 |
| 1023 EXPECT_EQ(0, ime_->process_key_event_post_ime_call_count()); | 1033 EXPECT_EQ(0, ime_->process_key_event_post_ime_call_count()); |
| 1024 } | 1034 } |
| 1025 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593). | 1035 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593). |
| 1026 | 1036 |
| 1027 } // namespace ui | 1037 } // namespace ui |
| OLD | NEW |