| 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 17 matching lines...) Expand all Loading... |
| 28 #include "ui/gfx/geometry/rect.h" | 28 #include "ui/gfx/geometry/rect.h" |
| 29 | 29 |
| 30 using base::UTF8ToUTF16; | 30 using base::UTF8ToUTF16; |
| 31 using base::UTF16ToUTF8; | 31 using base::UTF16ToUTF8; |
| 32 | 32 |
| 33 namespace ui { | 33 namespace ui { |
| 34 namespace { | 34 namespace { |
| 35 typedef chromeos::IMEEngineHandlerInterface::KeyEventDoneCallback | 35 typedef chromeos::IMEEngineHandlerInterface::KeyEventDoneCallback |
| 36 KeyEventCallback; | 36 KeyEventCallback; |
| 37 | 37 |
| 38 uint32 GetOffsetInUTF16(const std::string& utf8_string, uint32 utf8_offset) { | 38 uint32 GetOffsetInUTF16( |
| 39 base::string16 utf16_string = UTF8ToUTF16(utf8_string); | 39 const base::string16& utf16_string, uint32 utf8_offset) { |
| 40 DCHECK_LT(utf8_offset, utf16_string.size()); | 40 DCHECK_LT(utf8_offset, utf16_string.size()); |
| 41 base::i18n::UTF16CharIterator char_iterator(&utf16_string); | 41 base::i18n::UTF16CharIterator char_iterator(&utf16_string); |
| 42 for (size_t i = 0; i < utf8_offset; ++i) | 42 for (size_t i = 0; i < utf8_offset; ++i) |
| 43 char_iterator.Advance(); | 43 char_iterator.Advance(); |
| 44 return char_iterator.array_pos(); | 44 return char_iterator.array_pos(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 bool IsEqualXKeyEvent(const XEvent& e1, const XEvent& e2) { | 47 bool IsEqualXKeyEvent(const XEvent& e1, const XEvent& e2) { |
| 48 if ((e1.type == KeyPress && e2.type == KeyPress) || | 48 if ((e1.type == KeyPress && e2.type == KeyPress) || |
| 49 (e1.type == KeyRelease && e2.type == KeyRelease)) { | 49 (e1.type == KeyRelease && e2.type == KeyRelease)) { |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 caret_bounds_ = gfx::Rect(0, 2, 3, 4); // unchanged | 568 caret_bounds_ = gfx::Rect(0, 2, 3, 4); // unchanged |
| 569 ime_->OnCaretBoundsChanged(this); | 569 ime_->OnCaretBoundsChanged(this); |
| 570 // Current InputMethodChromeOS implementation performs the IPC | 570 // Current InputMethodChromeOS implementation performs the IPC |
| 571 // regardless of the bounds are changed or not. | 571 // regardless of the bounds are changed or not. |
| 572 EXPECT_EQ( | 572 EXPECT_EQ( |
| 573 4, | 573 4, |
| 574 mock_ime_candidate_window_handler_->set_cursor_bounds_call_count()); | 574 mock_ime_candidate_window_handler_->set_cursor_bounds_call_count()); |
| 575 } | 575 } |
| 576 | 576 |
| 577 TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_NoAttribute) { | 577 TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_NoAttribute) { |
| 578 const char kSampleText[] = "Sample Text"; | 578 const base::string16 kSampleText = base::UTF8ToUTF16("Sample Text"); |
| 579 const uint32 kCursorPos = 2UL; | 579 const uint32 kCursorPos = 2UL; |
| 580 | 580 |
| 581 const base::string16 utf16_string = UTF8ToUTF16(kSampleText); | |
| 582 chromeos::CompositionText chromeos_composition_text; | 581 chromeos::CompositionText chromeos_composition_text; |
| 583 chromeos_composition_text.set_text(kSampleText); | 582 chromeos_composition_text.set_text(kSampleText); |
| 584 | 583 |
| 585 CompositionText composition_text; | 584 CompositionText composition_text; |
| 586 ime_->ExtractCompositionText( | 585 ime_->ExtractCompositionText( |
| 587 chromeos_composition_text, kCursorPos, &composition_text); | 586 chromeos_composition_text, kCursorPos, &composition_text); |
| 588 EXPECT_EQ(UTF8ToUTF16(kSampleText), composition_text.text); | 587 EXPECT_EQ(kSampleText, composition_text.text); |
| 589 // If there is no selection, |selection| represents cursor position. | 588 // If there is no selection, |selection| represents cursor position. |
| 590 EXPECT_EQ(kCursorPos, composition_text.selection.start()); | 589 EXPECT_EQ(kCursorPos, composition_text.selection.start()); |
| 591 EXPECT_EQ(kCursorPos, composition_text.selection.end()); | 590 EXPECT_EQ(kCursorPos, composition_text.selection.end()); |
| 592 // If there is no underline, |underlines| contains one underline and it is | 591 // If there is no underline, |underlines| contains one underline and it is |
| 593 // whole text underline. | 592 // whole text underline. |
| 594 ASSERT_EQ(1UL, composition_text.underlines.size()); | 593 ASSERT_EQ(1UL, composition_text.underlines.size()); |
| 595 EXPECT_EQ(0UL, composition_text.underlines[0].start_offset); | 594 EXPECT_EQ(0UL, composition_text.underlines[0].start_offset); |
| 596 EXPECT_EQ(utf16_string.size(), composition_text.underlines[0].end_offset); | 595 EXPECT_EQ(kSampleText.size(), composition_text.underlines[0].end_offset); |
| 597 EXPECT_FALSE(composition_text.underlines[0].thick); | 596 EXPECT_FALSE(composition_text.underlines[0].thick); |
| 598 } | 597 } |
| 599 | 598 |
| 600 TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_SingleUnderline) { | 599 TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_SingleUnderline) { |
| 601 const char kSampleText[] = "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86" | 600 const base::string16 kSampleText = base::UTF8ToUTF16( |
| 602 "\xE3\x81\x88\xE3\x81\x8A"; | 601 "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"); |
| 603 const uint32 kCursorPos = 2UL; | 602 const uint32 kCursorPos = 2UL; |
| 604 | 603 |
| 605 // Set up chromeos composition text with one underline attribute. | 604 // Set up chromeos composition text with one underline attribute. |
| 606 chromeos::CompositionText chromeos_composition_text; | 605 chromeos::CompositionText chromeos_composition_text; |
| 607 chromeos_composition_text.set_text(kSampleText); | 606 chromeos_composition_text.set_text(kSampleText); |
| 608 chromeos::CompositionText::UnderlineAttribute underline; | 607 chromeos::CompositionText::UnderlineAttribute underline; |
| 609 underline.type = chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_SINGLE; | 608 underline.type = chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_SINGLE; |
| 610 underline.start_index = 1UL; | 609 underline.start_index = 1UL; |
| 611 underline.end_index = 4UL; | 610 underline.end_index = 4UL; |
| 612 chromeos_composition_text.mutable_underline_attributes()->push_back( | 611 chromeos_composition_text.mutable_underline_attributes()->push_back( |
| 613 underline); | 612 underline); |
| 614 | 613 |
| 615 CompositionText composition_text; | 614 CompositionText composition_text; |
| 616 ime_->ExtractCompositionText( | 615 ime_->ExtractCompositionText( |
| 617 chromeos_composition_text, kCursorPos, &composition_text); | 616 chromeos_composition_text, kCursorPos, &composition_text); |
| 618 EXPECT_EQ(UTF8ToUTF16(kSampleText), composition_text.text); | 617 EXPECT_EQ(kSampleText, composition_text.text); |
| 619 // If there is no selection, |selection| represents cursor position. | 618 // If there is no selection, |selection| represents cursor position. |
| 620 EXPECT_EQ(kCursorPos, composition_text.selection.start()); | 619 EXPECT_EQ(kCursorPos, composition_text.selection.start()); |
| 621 EXPECT_EQ(kCursorPos, composition_text.selection.end()); | 620 EXPECT_EQ(kCursorPos, composition_text.selection.end()); |
| 622 ASSERT_EQ(1UL, composition_text.underlines.size()); | 621 ASSERT_EQ(1UL, composition_text.underlines.size()); |
| 623 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.start_index), | 622 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.start_index), |
| 624 composition_text.underlines[0].start_offset); | 623 composition_text.underlines[0].start_offset); |
| 625 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.end_index), | 624 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.end_index), |
| 626 composition_text.underlines[0].end_offset); | 625 composition_text.underlines[0].end_offset); |
| 627 // Single underline represents as black thin line. | 626 // Single underline represents as black thin line. |
| 628 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); | 627 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); |
| 629 EXPECT_FALSE(composition_text.underlines[0].thick); | 628 EXPECT_FALSE(composition_text.underlines[0].thick); |
| 630 } | 629 } |
| 631 | 630 |
| 632 TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_DoubleUnderline) { | 631 TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_DoubleUnderline) { |
| 633 const char kSampleText[] = "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86" | 632 const base::string16 kSampleText = base::UTF8ToUTF16( |
| 634 "\xE3\x81\x88\xE3\x81\x8A"; | 633 "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"); |
| 635 const uint32 kCursorPos = 2UL; | 634 const uint32 kCursorPos = 2UL; |
| 636 | 635 |
| 637 // Set up chromeos composition text with one underline attribute. | 636 // Set up chromeos composition text with one underline attribute. |
| 638 chromeos::CompositionText chromeos_composition_text; | 637 chromeos::CompositionText chromeos_composition_text; |
| 639 chromeos_composition_text.set_text(kSampleText); | 638 chromeos_composition_text.set_text(kSampleText); |
| 640 chromeos::CompositionText::UnderlineAttribute underline; | 639 chromeos::CompositionText::UnderlineAttribute underline; |
| 641 underline.type = chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_DOUBLE; | 640 underline.type = chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_DOUBLE; |
| 642 underline.start_index = 1UL; | 641 underline.start_index = 1UL; |
| 643 underline.end_index = 4UL; | 642 underline.end_index = 4UL; |
| 644 chromeos_composition_text.mutable_underline_attributes()->push_back( | 643 chromeos_composition_text.mutable_underline_attributes()->push_back( |
| 645 underline); | 644 underline); |
| 646 | 645 |
| 647 CompositionText composition_text; | 646 CompositionText composition_text; |
| 648 ime_->ExtractCompositionText( | 647 ime_->ExtractCompositionText( |
| 649 chromeos_composition_text, kCursorPos, &composition_text); | 648 chromeos_composition_text, kCursorPos, &composition_text); |
| 650 EXPECT_EQ(UTF8ToUTF16(kSampleText), composition_text.text); | 649 EXPECT_EQ(kSampleText, composition_text.text); |
| 651 // If there is no selection, |selection| represents cursor position. | 650 // If there is no selection, |selection| represents cursor position. |
| 652 EXPECT_EQ(kCursorPos, composition_text.selection.start()); | 651 EXPECT_EQ(kCursorPos, composition_text.selection.start()); |
| 653 EXPECT_EQ(kCursorPos, composition_text.selection.end()); | 652 EXPECT_EQ(kCursorPos, composition_text.selection.end()); |
| 654 ASSERT_EQ(1UL, composition_text.underlines.size()); | 653 ASSERT_EQ(1UL, composition_text.underlines.size()); |
| 655 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.start_index), | 654 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.start_index), |
| 656 composition_text.underlines[0].start_offset); | 655 composition_text.underlines[0].start_offset); |
| 657 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.end_index), | 656 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.end_index), |
| 658 composition_text.underlines[0].end_offset); | 657 composition_text.underlines[0].end_offset); |
| 659 // Double underline represents as black thick line. | 658 // Double underline represents as black thick line. |
| 660 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); | 659 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); |
| 661 EXPECT_TRUE(composition_text.underlines[0].thick); | 660 EXPECT_TRUE(composition_text.underlines[0].thick); |
| 662 } | 661 } |
| 663 | 662 |
| 664 TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_ErrorUnderline) { | 663 TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_ErrorUnderline) { |
| 665 const char kSampleText[] = "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86" | 664 const base::string16 kSampleText = base::UTF8ToUTF16( |
| 666 "\xE3\x81\x88\xE3\x81\x8A"; | 665 "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"); |
| 667 const uint32 kCursorPos = 2UL; | 666 const uint32 kCursorPos = 2UL; |
| 668 | 667 |
| 669 // Set up chromeos composition text with one underline attribute. | 668 // Set up chromeos composition text with one underline attribute. |
| 670 chromeos::CompositionText chromeos_composition_text; | 669 chromeos::CompositionText chromeos_composition_text; |
| 671 chromeos_composition_text.set_text(kSampleText); | 670 chromeos_composition_text.set_text(kSampleText); |
| 672 chromeos::CompositionText::UnderlineAttribute underline; | 671 chromeos::CompositionText::UnderlineAttribute underline; |
| 673 underline.type = chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_ERROR; | 672 underline.type = chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_ERROR; |
| 674 underline.start_index = 1UL; | 673 underline.start_index = 1UL; |
| 675 underline.end_index = 4UL; | 674 underline.end_index = 4UL; |
| 676 chromeos_composition_text.mutable_underline_attributes()->push_back( | 675 chromeos_composition_text.mutable_underline_attributes()->push_back( |
| 677 underline); | 676 underline); |
| 678 | 677 |
| 679 CompositionText composition_text; | 678 CompositionText composition_text; |
| 680 ime_->ExtractCompositionText( | 679 ime_->ExtractCompositionText( |
| 681 chromeos_composition_text, kCursorPos, &composition_text); | 680 chromeos_composition_text, kCursorPos, &composition_text); |
| 682 EXPECT_EQ(UTF8ToUTF16(kSampleText), composition_text.text); | 681 EXPECT_EQ(kSampleText, composition_text.text); |
| 683 EXPECT_EQ(kCursorPos, composition_text.selection.start()); | 682 EXPECT_EQ(kCursorPos, composition_text.selection.start()); |
| 684 EXPECT_EQ(kCursorPos, composition_text.selection.end()); | 683 EXPECT_EQ(kCursorPos, composition_text.selection.end()); |
| 685 ASSERT_EQ(1UL, composition_text.underlines.size()); | 684 ASSERT_EQ(1UL, composition_text.underlines.size()); |
| 686 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.start_index), | 685 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.start_index), |
| 687 composition_text.underlines[0].start_offset); | 686 composition_text.underlines[0].start_offset); |
| 688 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.end_index), | 687 EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.end_index), |
| 689 composition_text.underlines[0].end_offset); | 688 composition_text.underlines[0].end_offset); |
| 690 // Error underline represents as red thin line. | 689 // Error underline represents as red thin line. |
| 691 EXPECT_EQ(SK_ColorRED, composition_text.underlines[0].color); | 690 EXPECT_EQ(SK_ColorRED, composition_text.underlines[0].color); |
| 692 EXPECT_FALSE(composition_text.underlines[0].thick); | 691 EXPECT_FALSE(composition_text.underlines[0].thick); |
| 693 } | 692 } |
| 694 | 693 |
| 695 TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_Selection) { | 694 TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_Selection) { |
| 696 const char kSampleText[] = "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86" | 695 const base::string16 kSampleText = base::UTF8ToUTF16( |
| 697 "\xE3\x81\x88\xE3\x81\x8A"; | 696 "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"); |
| 698 const uint32 kCursorPos = 2UL; | 697 const uint32 kCursorPos = 2UL; |
| 699 | 698 |
| 700 // Set up chromeos composition text with one underline attribute. | 699 // Set up chromeos composition text with one underline attribute. |
| 701 chromeos::CompositionText chromeos_composition_text; | 700 chromeos::CompositionText chromeos_composition_text; |
| 702 chromeos_composition_text.set_text(kSampleText); | 701 chromeos_composition_text.set_text(kSampleText); |
| 703 chromeos_composition_text.set_selection_start(1UL); | 702 chromeos_composition_text.set_selection_start(1UL); |
| 704 chromeos_composition_text.set_selection_end(4UL); | 703 chromeos_composition_text.set_selection_end(4UL); |
| 705 | 704 |
| 706 CompositionText composition_text; | 705 CompositionText composition_text; |
| 707 ime_->ExtractCompositionText( | 706 ime_->ExtractCompositionText( |
| 708 chromeos_composition_text, kCursorPos, &composition_text); | 707 chromeos_composition_text, kCursorPos, &composition_text); |
| 709 EXPECT_EQ(UTF8ToUTF16(kSampleText), composition_text.text); | 708 EXPECT_EQ(kSampleText, composition_text.text); |
| 710 EXPECT_EQ(kCursorPos, composition_text.selection.start()); | 709 EXPECT_EQ(kCursorPos, composition_text.selection.start()); |
| 711 EXPECT_EQ(kCursorPos, composition_text.selection.end()); | 710 EXPECT_EQ(kCursorPos, composition_text.selection.end()); |
| 712 ASSERT_EQ(1UL, composition_text.underlines.size()); | 711 ASSERT_EQ(1UL, composition_text.underlines.size()); |
| 713 EXPECT_EQ(GetOffsetInUTF16(kSampleText, | 712 EXPECT_EQ(GetOffsetInUTF16(kSampleText, |
| 714 chromeos_composition_text.selection_start()), | 713 chromeos_composition_text.selection_start()), |
| 715 composition_text.underlines[0].start_offset); | 714 composition_text.underlines[0].start_offset); |
| 716 EXPECT_EQ(GetOffsetInUTF16(kSampleText, | 715 EXPECT_EQ(GetOffsetInUTF16(kSampleText, |
| 717 chromeos_composition_text.selection_end()), | 716 chromeos_composition_text.selection_end()), |
| 718 composition_text.underlines[0].end_offset); | 717 composition_text.underlines[0].end_offset); |
| 719 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); | 718 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); |
| 720 EXPECT_TRUE(composition_text.underlines[0].thick); | 719 EXPECT_TRUE(composition_text.underlines[0].thick); |
| 721 } | 720 } |
| 722 | 721 |
| 723 TEST_F(InputMethodChromeOSTest, | 722 TEST_F(InputMethodChromeOSTest, |
| 724 ExtractCompositionTextTest_SelectionStartWithCursor) { | 723 ExtractCompositionTextTest_SelectionStartWithCursor) { |
| 725 const char kSampleText[] = "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86" | 724 const base::string16 kSampleText = base::UTF8ToUTF16( |
| 726 "\xE3\x81\x88\xE3\x81\x8A"; | 725 "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"); |
| 727 const uint32 kCursorPos = 1UL; | 726 const uint32 kCursorPos = 1UL; |
| 728 | 727 |
| 729 // Set up chromeos composition text with one underline attribute. | 728 // Set up chromeos composition text with one underline attribute. |
| 730 chromeos::CompositionText chromeos_composition_text; | 729 chromeos::CompositionText chromeos_composition_text; |
| 731 chromeos_composition_text.set_text(kSampleText); | 730 chromeos_composition_text.set_text(kSampleText); |
| 732 chromeos_composition_text.set_selection_start(kCursorPos); | 731 chromeos_composition_text.set_selection_start(kCursorPos); |
| 733 chromeos_composition_text.set_selection_end(4UL); | 732 chromeos_composition_text.set_selection_end(4UL); |
| 734 | 733 |
| 735 CompositionText composition_text; | 734 CompositionText composition_text; |
| 736 ime_->ExtractCompositionText( | 735 ime_->ExtractCompositionText( |
| 737 chromeos_composition_text, kCursorPos, &composition_text); | 736 chromeos_composition_text, kCursorPos, &composition_text); |
| 738 EXPECT_EQ(UTF8ToUTF16(kSampleText), composition_text.text); | 737 EXPECT_EQ(kSampleText, composition_text.text); |
| 739 // If the cursor position is same as selection bounds, selection start | 738 // If the cursor position is same as selection bounds, selection start |
| 740 // position become opposit side of selection from cursor. | 739 // position become opposit side of selection from cursor. |
| 741 EXPECT_EQ(GetOffsetInUTF16(kSampleText, | 740 EXPECT_EQ(GetOffsetInUTF16(kSampleText, |
| 742 chromeos_composition_text.selection_end()), | 741 chromeos_composition_text.selection_end()), |
| 743 composition_text.selection.start()); | 742 composition_text.selection.start()); |
| 744 EXPECT_EQ(GetOffsetInUTF16(kSampleText, kCursorPos), | 743 EXPECT_EQ(GetOffsetInUTF16(kSampleText, kCursorPos), |
| 745 composition_text.selection.end()); | 744 composition_text.selection.end()); |
| 746 ASSERT_EQ(1UL, composition_text.underlines.size()); | 745 ASSERT_EQ(1UL, composition_text.underlines.size()); |
| 747 EXPECT_EQ(GetOffsetInUTF16(kSampleText, | 746 EXPECT_EQ(GetOffsetInUTF16(kSampleText, |
| 748 chromeos_composition_text.selection_start()), | 747 chromeos_composition_text.selection_start()), |
| 749 composition_text.underlines[0].start_offset); | 748 composition_text.underlines[0].start_offset); |
| 750 EXPECT_EQ(GetOffsetInUTF16(kSampleText, | 749 EXPECT_EQ(GetOffsetInUTF16(kSampleText, |
| 751 chromeos_composition_text.selection_end()), | 750 chromeos_composition_text.selection_end()), |
| 752 composition_text.underlines[0].end_offset); | 751 composition_text.underlines[0].end_offset); |
| 753 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); | 752 EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); |
| 754 EXPECT_TRUE(composition_text.underlines[0].thick); | 753 EXPECT_TRUE(composition_text.underlines[0].thick); |
| 755 } | 754 } |
| 756 | 755 |
| 757 TEST_F(InputMethodChromeOSTest, | 756 TEST_F(InputMethodChromeOSTest, |
| 758 ExtractCompositionTextTest_SelectionEndWithCursor) { | 757 ExtractCompositionTextTest_SelectionEndWithCursor) { |
| 759 const char kSampleText[] = "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86" | 758 const base::string16 kSampleText = base::UTF8ToUTF16( |
| 760 "\xE3\x81\x88\xE3\x81\x8A"; | 759 "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"); |
| 761 const uint32 kCursorPos = 4UL; | 760 const uint32 kCursorPos = 4UL; |
| 762 | 761 |
| 763 // Set up chromeos composition text with one underline attribute. | 762 // Set up chromeos composition text with one underline attribute. |
| 764 chromeos::CompositionText chromeos_composition_text; | 763 chromeos::CompositionText chromeos_composition_text; |
| 765 chromeos_composition_text.set_text(kSampleText); | 764 chromeos_composition_text.set_text(kSampleText); |
| 766 chromeos_composition_text.set_selection_start(1UL); | 765 chromeos_composition_text.set_selection_start(1UL); |
| 767 chromeos_composition_text.set_selection_end(kCursorPos); | 766 chromeos_composition_text.set_selection_end(kCursorPos); |
| 768 | 767 |
| 769 CompositionText composition_text; | 768 CompositionText composition_text; |
| 770 ime_->ExtractCompositionText( | 769 ime_->ExtractCompositionText( |
| 771 chromeos_composition_text, kCursorPos, &composition_text); | 770 chromeos_composition_text, kCursorPos, &composition_text); |
| 772 EXPECT_EQ(UTF8ToUTF16(kSampleText), composition_text.text); | 771 EXPECT_EQ(kSampleText, composition_text.text); |
| 773 // If the cursor position is same as selection bounds, selection start | 772 // If the cursor position is same as selection bounds, selection start |
| 774 // position become opposit side of selection from cursor. | 773 // position become opposit side of selection from cursor. |
| 775 EXPECT_EQ(GetOffsetInUTF16(kSampleText, | 774 EXPECT_EQ(GetOffsetInUTF16(kSampleText, |
| 776 chromeos_composition_text.selection_start()), | 775 chromeos_composition_text.selection_start()), |
| 777 composition_text.selection.start()); | 776 composition_text.selection.start()); |
| 778 EXPECT_EQ(GetOffsetInUTF16(kSampleText, kCursorPos), | 777 EXPECT_EQ(GetOffsetInUTF16(kSampleText, kCursorPos), |
| 779 composition_text.selection.end()); | 778 composition_text.selection.end()); |
| 780 ASSERT_EQ(1UL, composition_text.underlines.size()); | 779 ASSERT_EQ(1UL, composition_text.underlines.size()); |
| 781 EXPECT_EQ(GetOffsetInUTF16(kSampleText, | 780 EXPECT_EQ(GetOffsetInUTF16(kSampleText, |
| 782 chromeos_composition_text.selection_start()), | 781 chromeos_composition_text.selection_start()), |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 mock_ime_engine_handler_->last_set_surrounding_anchor_pos()); | 842 mock_ime_engine_handler_->last_set_surrounding_anchor_pos()); |
| 844 } | 843 } |
| 845 | 844 |
| 846 TEST_F(InputMethodChromeOSTest, SurroundingText_PartialText) { | 845 TEST_F(InputMethodChromeOSTest, SurroundingText_PartialText) { |
| 847 ime_->Init(true); | 846 ime_->Init(true); |
| 848 // Click a text input form. | 847 // Click a text input form. |
| 849 input_type_ = TEXT_INPUT_TYPE_TEXT; | 848 input_type_ = TEXT_INPUT_TYPE_TEXT; |
| 850 ime_->OnTextInputTypeChanged(this); | 849 ime_->OnTextInputTypeChanged(this); |
| 851 | 850 |
| 852 // Set the TextInputClient behaviors. | 851 // Set the TextInputClient behaviors. |
| 853 surrounding_text_ = UTF8ToUTF16("abcdefghij"); | 852 surrounding_text_ = base::UTF8ToUTF16("abcdefghij"); |
| 854 text_range_ = gfx::Range(5, 10); | 853 text_range_ = gfx::Range(5, 10); |
| 855 selection_range_ = gfx::Range(7, 9); | 854 selection_range_ = gfx::Range(7, 9); |
| 856 | 855 |
| 857 ime_->OnCaretBoundsChanged(this); | 856 ime_->OnCaretBoundsChanged(this); |
| 858 | 857 |
| 859 // Check the call count. | 858 // Check the call count. |
| 860 EXPECT_EQ(1, | 859 EXPECT_EQ(1, |
| 861 mock_ime_engine_handler_->set_surrounding_text_call_count()); | 860 mock_ime_engine_handler_->set_surrounding_text_call_count()); |
| 862 // Set the verifier for SetSurroundingText mock call. | 861 // Set the verifier for SetSurroundingText mock call. |
| 863 // Here (2, 4) is selection range in expected surrounding text coordinates. | 862 // Here (2, 4) is selection range in expected surrounding text coordinates. |
| 864 EXPECT_EQ("fghij", | 863 EXPECT_EQ("fghij", |
| 865 mock_ime_engine_handler_->last_set_surrounding_text()); | 864 mock_ime_engine_handler_->last_set_surrounding_text()); |
| 866 EXPECT_EQ(2U, | 865 EXPECT_EQ(2U, |
| 867 mock_ime_engine_handler_->last_set_surrounding_cursor_pos()); | 866 mock_ime_engine_handler_->last_set_surrounding_cursor_pos()); |
| 868 EXPECT_EQ(4U, | 867 EXPECT_EQ(4U, |
| 869 mock_ime_engine_handler_->last_set_surrounding_anchor_pos()); | 868 mock_ime_engine_handler_->last_set_surrounding_anchor_pos()); |
| 870 } | 869 } |
| 871 | 870 |
| 872 TEST_F(InputMethodChromeOSTest, SurroundingText_BecomeEmptyText) { | 871 TEST_F(InputMethodChromeOSTest, SurroundingText_BecomeEmptyText) { |
| 873 ime_->Init(true); | 872 ime_->Init(true); |
| 874 // Click a text input form. | 873 // Click a text input form. |
| 875 input_type_ = TEXT_INPUT_TYPE_TEXT; | 874 input_type_ = TEXT_INPUT_TYPE_TEXT; |
| 876 ime_->OnTextInputTypeChanged(this); | 875 ime_->OnTextInputTypeChanged(this); |
| 877 | 876 |
| 878 // Set the TextInputClient behaviors. | 877 // Set the TextInputClient behaviors. |
| 879 // If the surrounding text becomes empty, text_range become (0, 0) and | 878 // If the surrounding text becomes empty, text_range become (0, 0) and |
| 880 // selection range become invalid. | 879 // selection range become invalid. |
| 881 surrounding_text_ = UTF8ToUTF16(""); | 880 surrounding_text_ = base::UTF8ToUTF16(""); |
| 882 text_range_ = gfx::Range(0, 0); | 881 text_range_ = gfx::Range(0, 0); |
| 883 selection_range_ = gfx::Range::InvalidRange(); | 882 selection_range_ = gfx::Range::InvalidRange(); |
| 884 | 883 |
| 885 ime_->OnCaretBoundsChanged(this); | 884 ime_->OnCaretBoundsChanged(this); |
| 886 | 885 |
| 887 // Check the call count. | 886 // Check the call count. |
| 888 EXPECT_EQ(0, | 887 EXPECT_EQ(0, |
| 889 mock_ime_engine_handler_->set_surrounding_text_call_count()); | 888 mock_ime_engine_handler_->set_surrounding_text_call_count()); |
| 890 | 889 |
| 891 // Should not be called twice with same condition. | 890 // Should not be called twice with same condition. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 ime_->ResetContext(); | 1015 ime_->ResetContext(); |
| 1017 | 1016 |
| 1018 // Do callback. | 1017 // Do callback. |
| 1019 mock_ime_engine_handler_->last_passed_callback().Run(true); | 1018 mock_ime_engine_handler_->last_passed_callback().Run(true); |
| 1020 | 1019 |
| 1021 EXPECT_EQ(0, ime_->process_key_event_post_ime_call_count()); | 1020 EXPECT_EQ(0, ime_->process_key_event_post_ime_call_count()); |
| 1022 } | 1021 } |
| 1023 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593). | 1022 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593). |
| 1024 | 1023 |
| 1025 } // namespace ui | 1024 } // namespace ui |
| OLD | NEW |