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 "ui/gfx/render_text.h" | 5 #include "ui/gfx/render_text.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 render_text->selection().length()); | 102 render_text->selection().length()); |
103 } | 103 } |
104 | 104 |
105 // A test utility function to set the application default text direction. | 105 // A test utility function to set the application default text direction. |
106 void SetRTL(bool rtl) { | 106 void SetRTL(bool rtl) { |
107 // Override the current locale/direction. | 107 // Override the current locale/direction. |
108 base::i18n::SetICUDefaultLocale(rtl ? "he" : "en"); | 108 base::i18n::SetICUDefaultLocale(rtl ? "he" : "en"); |
109 EXPECT_EQ(rtl, base::i18n::IsRTL()); | 109 EXPECT_EQ(rtl, base::i18n::IsRTL()); |
110 } | 110 } |
111 | 111 |
112 // Execute MoveCursor on the given |render_text| instance for the given | |
113 // arguments and verify the selected range matches |expected|. Also, clears the | |
114 // expectations. | |
115 void RunMoveCursorTestAndClearExpectations(RenderText* render_text, | |
116 BreakType break_type, | |
117 VisualCursorDirection direction, | |
118 SelectionBehavior selection_behavior, | |
119 std::vector<Range>* expected) { | |
120 for (size_t i = 0; i < expected->size(); ++i) { | |
121 SCOPED_TRACE(base::StringPrintf( | |
122 "BreakType-%d VisualCursorDirection-%d SelectionBehavior-%d Case-%d.", | |
123 break_type, direction, selection_behavior, static_cast<int>(i))); | |
124 | |
125 render_text->MoveCursor(break_type, direction, selection_behavior); | |
126 EXPECT_EQ(expected->at(i), render_text->selection()); | |
127 } | |
128 expected->clear(); | |
129 } | |
130 | |
112 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 | 131 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 |
113 #if !defined(OS_MACOSX) | 132 #if !defined(OS_MACOSX) |
114 // Ensure cursor movement in the specified |direction| yields |expected| values. | 133 // Ensure cursor movement in the specified |direction| yields |expected| values. |
115 void RunMoveCursorLeftRightTest(RenderText* render_text, | 134 void RunMoveCursorLeftRightTest(RenderText* render_text, |
116 const std::vector<SelectionModel>& expected, | 135 const std::vector<SelectionModel>& expected, |
117 VisualCursorDirection direction) { | 136 VisualCursorDirection direction) { |
118 for (size_t i = 0; i < expected.size(); ++i) { | 137 for (size_t i = 0; i < expected.size(); ++i) { |
119 SCOPED_TRACE(base::StringPrintf("Going %s; expected value index %d.", | 138 SCOPED_TRACE(base::StringPrintf("Going %s; expected value index %d.", |
120 direction == CURSOR_LEFT ? "left" : "right", static_cast<int>(i))); | 139 direction == CURSOR_LEFT ? "left" : "right", static_cast<int>(i))); |
121 EXPECT_EQ(expected[i], render_text->selection_model()); | 140 EXPECT_EQ(expected[i], render_text->selection_model()); |
122 render_text->MoveCursor(CHARACTER_BREAK, direction, false); | 141 render_text->MoveCursor(CHARACTER_BREAK, direction, SELECTION_NONE); |
123 } | 142 } |
124 // Check that cursoring is clamped at the line edge. | 143 // Check that cursoring is clamped at the line edge. |
125 EXPECT_EQ(expected.back(), render_text->selection_model()); | 144 EXPECT_EQ(expected.back(), render_text->selection_model()); |
126 // Check that it is the line edge. | 145 // Check that it is the line edge. |
127 render_text->MoveCursor(LINE_BREAK, direction, false); | 146 render_text->MoveCursor(LINE_BREAK, direction, SELECTION_NONE); |
128 EXPECT_EQ(expected.back(), render_text->selection_model()); | 147 EXPECT_EQ(expected.back(), render_text->selection_model()); |
129 } | 148 } |
130 #endif // !defined(OS_MACOSX) | 149 #endif // !defined(OS_MACOSX) |
131 | 150 |
132 // The class which records the drawing operations so that the test case can | 151 // The class which records the drawing operations so that the test case can |
133 // verify where exactly the glyphs are drawn. | 152 // verify where exactly the glyphs are drawn. |
134 class TestSkiaTextRenderer : public internal::SkiaTextRenderer { | 153 class TestSkiaTextRenderer : public internal::SkiaTextRenderer { |
135 public: | 154 public: |
136 struct TextLog { | 155 struct TextLog { |
137 TextLog() : glyph_count(0u), color(SK_ColorTRANSPARENT) {} | 156 TextLog() : glyph_count(0u), color(SK_ColorTRANSPARENT) {} |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
481 render_text->styles()[UNDERLINE].EqualsForTesting(expected_style)); | 500 render_text->styles()[UNDERLINE].EqualsForTesting(expected_style)); |
482 // Ensure AppendText maintains current text styles. | 501 // Ensure AppendText maintains current text styles. |
483 render_text->AppendText(ASCIIToUTF16("def")); | 502 render_text->AppendText(ASCIIToUTF16("def")); |
484 EXPECT_EQ(render_text->GetDisplayText(), ASCIIToUTF16("abcdef")); | 503 EXPECT_EQ(render_text->GetDisplayText(), ASCIIToUTF16("abcdef")); |
485 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color)); | 504 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color)); |
486 EXPECT_TRUE(render_text->baselines().EqualsForTesting(expected_baseline)); | 505 EXPECT_TRUE(render_text->baselines().EqualsForTesting(expected_baseline)); |
487 EXPECT_TRUE( | 506 EXPECT_TRUE( |
488 render_text->styles()[UNDERLINE].EqualsForTesting(expected_style)); | 507 render_text->styles()[UNDERLINE].EqualsForTesting(expected_style)); |
489 } | 508 } |
490 | 509 |
491 void TestVisualCursorMotionInObscuredField(RenderText* render_text, | 510 void TestVisualCursorMotionInObscuredField( |
492 const base::string16& text, | 511 RenderText* render_text, |
493 bool select) { | 512 const base::string16& text, |
513 SelectionBehavior selection_behavior) { | |
514 const bool select = selection_behavior != SELECTION_NONE; | |
494 ASSERT_TRUE(render_text->obscured()); | 515 ASSERT_TRUE(render_text->obscured()); |
495 render_text->SetText(text); | 516 render_text->SetText(text); |
496 int len = text.length(); | 517 int len = text.length(); |
497 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, select); | 518 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, selection_behavior); |
498 EXPECT_EQ(SelectionModel(Range(select ? 0 : len, len), CURSOR_FORWARD), | 519 EXPECT_EQ(SelectionModel(Range(select ? 0 : len, len), CURSOR_FORWARD), |
499 render_text->selection_model()); | 520 render_text->selection_model()); |
500 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, select); | 521 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, selection_behavior); |
501 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); | 522 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); |
502 for (int j = 1; j <= len; ++j) { | 523 for (int j = 1; j <= len; ++j) { |
503 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, select); | 524 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, selection_behavior); |
504 EXPECT_EQ(SelectionModel(Range(select ? 0 : j, j), CURSOR_BACKWARD), | 525 EXPECT_EQ(SelectionModel(Range(select ? 0 : j, j), CURSOR_BACKWARD), |
505 render_text->selection_model()); | 526 render_text->selection_model()); |
506 } | 527 } |
507 for (int j = len - 1; j >= 0; --j) { | 528 for (int j = len - 1; j >= 0; --j) { |
508 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, select); | 529 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, selection_behavior); |
509 EXPECT_EQ(SelectionModel(Range(select ? 0 : j, j), CURSOR_FORWARD), | 530 EXPECT_EQ(SelectionModel(Range(select ? 0 : j, j), CURSOR_FORWARD), |
510 render_text->selection_model()); | 531 render_text->selection_model()); |
511 } | 532 } |
512 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, select); | 533 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, selection_behavior); |
513 EXPECT_EQ(SelectionModel(Range(select ? 0 : len, len), CURSOR_FORWARD), | 534 EXPECT_EQ(SelectionModel(Range(select ? 0 : len, len), CURSOR_FORWARD), |
514 render_text->selection_model()); | 535 render_text->selection_model()); |
515 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, select); | 536 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, selection_behavior); |
516 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); | 537 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); |
517 } | 538 } |
518 | 539 |
519 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 | 540 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 |
520 #if !defined(OS_MACOSX) | 541 #if !defined(OS_MACOSX) |
521 TEST_F(RenderTextTest, ObscuredText) { | 542 TEST_F(RenderTextTest, ObscuredText) { |
522 const base::string16 seuss = ASCIIToUTF16("hop on pop"); | 543 const base::string16 seuss = ASCIIToUTF16("hop on pop"); |
523 const base::string16 no_seuss = ASCIIToUTF16("**********"); | 544 const base::string16 no_seuss = ASCIIToUTF16("**********"); |
524 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 545 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
525 | 546 |
526 // GetLayoutText() returns asterisks when the obscured bit is set. | 547 // GetLayoutText() returns asterisks when the obscured bit is set. |
527 render_text->SetText(seuss); | 548 render_text->SetText(seuss); |
528 render_text->SetObscured(true); | 549 render_text->SetObscured(true); |
529 EXPECT_EQ(seuss, render_text->text()); | 550 EXPECT_EQ(seuss, render_text->text()); |
530 EXPECT_EQ(no_seuss, render_text->GetDisplayText()); | 551 EXPECT_EQ(no_seuss, render_text->GetDisplayText()); |
531 render_text->SetObscured(false); | 552 render_text->SetObscured(false); |
532 EXPECT_EQ(seuss, render_text->text()); | 553 EXPECT_EQ(seuss, render_text->text()); |
533 EXPECT_EQ(seuss, render_text->GetDisplayText()); | 554 EXPECT_EQ(seuss, render_text->GetDisplayText()); |
534 | 555 |
535 render_text->SetObscured(true); | 556 render_text->SetObscured(true); |
536 | 557 |
537 // Surrogate pairs are counted as one code point. | 558 // Surrogate pairs are counted as one code point. |
538 const base::char16 invalid_surrogates[] = {0xDC00, 0xD800, 0}; | 559 const base::char16 invalid_surrogates[] = {0xDC00, 0xD800, 0}; |
539 render_text->SetText(invalid_surrogates); | 560 render_text->SetText(invalid_surrogates); |
540 EXPECT_EQ(ASCIIToUTF16("**"), render_text->GetDisplayText()); | 561 EXPECT_EQ(ASCIIToUTF16("**"), render_text->GetDisplayText()); |
541 const base::char16 valid_surrogates[] = {0xD800, 0xDC00, 0}; | 562 const base::char16 valid_surrogates[] = {0xD800, 0xDC00, 0}; |
542 render_text->SetText(valid_surrogates); | 563 render_text->SetText(valid_surrogates); |
543 EXPECT_EQ(ASCIIToUTF16("*"), render_text->GetDisplayText()); | 564 EXPECT_EQ(ASCIIToUTF16("*"), render_text->GetDisplayText()); |
544 EXPECT_EQ(0U, render_text->cursor_position()); | 565 EXPECT_EQ(0U, render_text->cursor_position()); |
545 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 566 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
546 EXPECT_EQ(2U, render_text->cursor_position()); | 567 EXPECT_EQ(2U, render_text->cursor_position()); |
547 | 568 |
548 // Test index conversion and cursor validity with a valid surrogate pair. | 569 // Test index conversion and cursor validity with a valid surrogate pair. |
549 EXPECT_EQ(0U, render_text->TextIndexToDisplayIndex(0U)); | 570 EXPECT_EQ(0U, render_text->TextIndexToDisplayIndex(0U)); |
550 EXPECT_EQ(1U, render_text->TextIndexToDisplayIndex(1U)); | 571 EXPECT_EQ(1U, render_text->TextIndexToDisplayIndex(1U)); |
551 EXPECT_EQ(1U, render_text->TextIndexToDisplayIndex(2U)); | 572 EXPECT_EQ(1U, render_text->TextIndexToDisplayIndex(2U)); |
552 EXPECT_EQ(0U, render_text->DisplayIndexToTextIndex(0U)); | 573 EXPECT_EQ(0U, render_text->DisplayIndexToTextIndex(0U)); |
553 EXPECT_EQ(2U, render_text->DisplayIndexToTextIndex(1U)); | 574 EXPECT_EQ(2U, render_text->DisplayIndexToTextIndex(1U)); |
554 EXPECT_TRUE(render_text->IsValidCursorIndex(0U)); | 575 EXPECT_TRUE(render_text->IsValidCursorIndex(0U)); |
555 EXPECT_FALSE(render_text->IsValidCursorIndex(1U)); | 576 EXPECT_FALSE(render_text->IsValidCursorIndex(1U)); |
(...skipping 13 matching lines...) Expand all Loading... | |
569 static_cast<int>(render_text->GetGlyphBounds(0U).length())); | 590 static_cast<int>(render_text->GetGlyphBounds(0U).length())); |
570 | 591 |
571 // Cursoring is independent of underlying characters when text is obscured. | 592 // Cursoring is independent of underlying characters when text is obscured. |
572 const wchar_t* const texts[] = { | 593 const wchar_t* const texts[] = { |
573 kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, kRtlLtr, kRtlLtrRtl, | 594 kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, kRtlLtr, kRtlLtrRtl, |
574 L"hop on pop", // Check LTR word boundaries. | 595 L"hop on pop", // Check LTR word boundaries. |
575 L"\x05d0\x05d1 \x05d0\x05d2 \x05d1\x05d2", // Check RTL word boundaries. | 596 L"\x05d0\x05d1 \x05d0\x05d2 \x05d1\x05d2", // Check RTL word boundaries. |
576 }; | 597 }; |
577 for (size_t i = 0; i < arraysize(texts); ++i) { | 598 for (size_t i = 0; i < arraysize(texts); ++i) { |
578 base::string16 text = WideToUTF16(texts[i]); | 599 base::string16 text = WideToUTF16(texts[i]); |
579 TestVisualCursorMotionInObscuredField(render_text.get(), text, false); | 600 TestVisualCursorMotionInObscuredField(render_text.get(), text, |
580 TestVisualCursorMotionInObscuredField(render_text.get(), text, true); | 601 SELECTION_NONE); |
602 TestVisualCursorMotionInObscuredField(render_text.get(), text, | |
603 SELECTION_RETAIN); | |
581 } | 604 } |
582 } | 605 } |
583 #endif // !defined(OS_MACOSX) | 606 #endif // !defined(OS_MACOSX) |
584 | 607 |
585 TEST_F(RenderTextTest, RevealObscuredText) { | 608 TEST_F(RenderTextTest, RevealObscuredText) { |
586 const base::string16 seuss = ASCIIToUTF16("hop on pop"); | 609 const base::string16 seuss = ASCIIToUTF16("hop on pop"); |
587 const base::string16 no_seuss = ASCIIToUTF16("**********"); | 610 const base::string16 no_seuss = ASCIIToUTF16("**********"); |
588 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 611 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
589 | 612 |
590 render_text->SetText(seuss); | 613 render_text->SetText(seuss); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
653 {'*', '*', '*', '*', 0xD800, 0xDC00, 0}; | 676 {'*', '*', '*', '*', 0xD800, 0xDC00, 0}; |
654 EXPECT_EQ(valid_expect_5_and_6, render_text->GetDisplayText()); | 677 EXPECT_EQ(valid_expect_5_and_6, render_text->GetDisplayText()); |
655 render_text->RenderText::SetObscuredRevealIndex(6); | 678 render_text->RenderText::SetObscuredRevealIndex(6); |
656 EXPECT_EQ(valid_expect_5_and_6, render_text->GetDisplayText()); | 679 EXPECT_EQ(valid_expect_5_and_6, render_text->GetDisplayText()); |
657 } | 680 } |
658 | 681 |
659 TEST_F(RenderTextTest, ObscuredEmoji) { | 682 TEST_F(RenderTextTest, ObscuredEmoji) { |
660 // Ensures text itemization doesn't crash on obscured multi-char glyphs. | 683 // Ensures text itemization doesn't crash on obscured multi-char glyphs. |
661 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 684 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
662 render_text->SetObscured(true); | 685 render_text->SetObscured(true); |
663 gfx::Canvas canvas; | 686 Canvas canvas; |
664 // Test the "Grinning face with smiling eyes" character followed by 'y'. | 687 // Test the "Grinning face with smiling eyes" character followed by 'y'. |
665 render_text->SetText(UTF8ToUTF16("\xF0\x9F\x98\x81y")); | 688 render_text->SetText(UTF8ToUTF16("\xF0\x9F\x98\x81y")); |
666 render_text->Draw(&canvas); | 689 render_text->Draw(&canvas); |
667 // Test two "Camera" characters in a row. | 690 // Test two "Camera" characters in a row. |
668 render_text->SetText(UTF8ToUTF16("\xF0\x9F\x93\xB7\xF0\x9F\x93\xB7")); | 691 render_text->SetText(UTF8ToUTF16("\xF0\x9F\x93\xB7\xF0\x9F\x93\xB7")); |
669 render_text->Draw(&canvas); | 692 render_text->Draw(&canvas); |
670 } | 693 } |
671 | 694 |
672 // TODO(PORT): Fails for RenderTextMac. | 695 // TODO(PORT): Fails for RenderTextMac. |
673 #if !defined(OS_MACOSX) | 696 #if !defined(OS_MACOSX) |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
894 } | 917 } |
895 | 918 |
896 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 | 919 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 |
897 #if !defined(OS_MACOSX) | 920 #if !defined(OS_MACOSX) |
898 TEST_F(RenderTextTest, TruncatedCursorMovementLTR) { | 921 TEST_F(RenderTextTest, TruncatedCursorMovementLTR) { |
899 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 922 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
900 render_text->set_truncate_length(2); | 923 render_text->set_truncate_length(2); |
901 render_text->SetText(WideToUTF16(L"abcd")); | 924 render_text->SetText(WideToUTF16(L"abcd")); |
902 | 925 |
903 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); | 926 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); |
904 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 927 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
905 EXPECT_EQ(SelectionModel(4, CURSOR_FORWARD), render_text->selection_model()); | 928 EXPECT_EQ(SelectionModel(4, CURSOR_FORWARD), render_text->selection_model()); |
906 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 929 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE); |
907 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); | 930 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); |
908 | 931 |
909 std::vector<SelectionModel> expected; | 932 std::vector<SelectionModel> expected; |
910 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 933 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
911 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); | 934 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); |
912 // The cursor hops over the ellipsis and elided text to the line end. | 935 // The cursor hops over the ellipsis and elided text to the line end. |
913 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); | 936 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); |
914 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); | 937 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); |
915 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); | 938 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); |
916 | 939 |
917 expected.clear(); | 940 expected.clear(); |
918 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); | 941 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); |
919 // The cursor hops over the elided text to preceeding text. | 942 // The cursor hops over the elided text to preceeding text. |
920 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); | 943 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); |
921 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); | 944 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); |
922 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 945 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
923 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); | 946 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); |
924 } | 947 } |
925 | 948 |
926 TEST_F(RenderTextTest, TruncatedCursorMovementRTL) { | 949 TEST_F(RenderTextTest, TruncatedCursorMovementRTL) { |
927 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 950 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
928 render_text->set_truncate_length(2); | 951 render_text->set_truncate_length(2); |
929 render_text->SetText(WideToUTF16(L"\x5d0\x5d1\x5d2\x5d3")); | 952 render_text->SetText(WideToUTF16(L"\x5d0\x5d1\x5d2\x5d3")); |
930 | 953 |
931 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); | 954 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); |
932 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 955 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE); |
933 EXPECT_EQ(SelectionModel(4, CURSOR_FORWARD), render_text->selection_model()); | 956 EXPECT_EQ(SelectionModel(4, CURSOR_FORWARD), render_text->selection_model()); |
934 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 957 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
935 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); | 958 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); |
936 | 959 |
937 std::vector<SelectionModel> expected; | 960 std::vector<SelectionModel> expected; |
938 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 961 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
939 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); | 962 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); |
940 // The cursor hops over the ellipsis and elided text to the line end. | 963 // The cursor hops over the ellipsis and elided text to the line end. |
941 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); | 964 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); |
942 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); | 965 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); |
943 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); | 966 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); |
944 | 967 |
945 expected.clear(); | 968 expected.clear(); |
946 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); | 969 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); |
947 // The cursor hops over the elided text to preceeding text. | 970 // The cursor hops over the elided text to preceeding text. |
948 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); | 971 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); |
949 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); | 972 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); |
950 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 973 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
951 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); | 974 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); |
952 } | 975 } |
953 #endif // !defined(OS_MACOSX) | 976 #endif // !defined(OS_MACOSX) |
954 | 977 |
978 TEST_F(RenderTextTest, MoveCursor_Character) { | |
979 std::unique_ptr<RenderText> render_text( | |
980 RenderText::CreateInstanceForEditing()); | |
981 render_text->SetText(WideToUTF16(L"123 456 789")); | |
982 std::vector<Range> expected; | |
983 | |
984 // SELECTION_NONE. | |
985 render_text->SelectRange(Range(6)); | |
986 | |
987 // Move right twice. | |
988 expected.push_back(Range(7)); | |
989 expected.push_back(Range(8)); | |
990 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, | |
991 CURSOR_RIGHT, SELECTION_NONE, | |
992 &expected); | |
993 | |
994 // Move left twice. | |
995 expected.push_back(Range(7)); | |
996 expected.push_back(Range(6)); | |
997 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, | |
998 CURSOR_LEFT, SELECTION_NONE, &expected); | |
999 | |
1000 // SELECTION_CARET. | |
1001 render_text->SelectRange(Range(6)); | |
1002 expected.push_back(Range(6, 7)); | |
1003 | |
1004 // Move right. | |
1005 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, | |
1006 CURSOR_RIGHT, SELECTION_CARET, | |
1007 &expected); | |
1008 | |
1009 // Move left twice. | |
1010 expected.push_back(Range(6)); | |
1011 expected.push_back(Range(6, 5)); | |
1012 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, | |
1013 CURSOR_LEFT, SELECTION_CARET, | |
1014 &expected); | |
1015 | |
1016 // SELECTION_RETAIN. | |
1017 render_text->SelectRange(Range(6)); | |
1018 | |
1019 // Move right. | |
1020 expected.push_back(Range(6, 7)); | |
1021 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, | |
1022 CURSOR_RIGHT, SELECTION_RETAIN, | |
1023 &expected); | |
1024 | |
1025 // Move left twice. | |
1026 expected.push_back(Range(6)); | |
1027 expected.push_back(Range(6, 5)); | |
1028 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, | |
1029 CURSOR_LEFT, SELECTION_RETAIN, | |
1030 &expected); | |
1031 | |
1032 // SELECTION_EXTEND. | |
1033 render_text->SelectRange(Range(6)); | |
1034 | |
1035 // Move right. | |
1036 expected.push_back(Range(6, 7)); | |
1037 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, | |
1038 CURSOR_RIGHT, SELECTION_EXTEND, | |
1039 &expected); | |
1040 | |
1041 // Move left twice. | |
1042 expected.push_back(Range(7, 6)); | |
1043 expected.push_back(Range(7, 5)); | |
1044 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, | |
1045 CURSOR_LEFT, SELECTION_EXTEND, | |
1046 &expected); | |
1047 } | |
1048 | |
1049 TEST_F(RenderTextTest, MoveCursor_Word) { | |
msw
2016/08/16 18:37:58
aside: I'm glad this works on all the bots, we hav
| |
1050 std::unique_ptr<RenderText> render_text( | |
1051 RenderText::CreateInstanceForEditing()); | |
1052 render_text->SetText(WideToUTF16(L"123 456 789")); | |
1053 std::vector<Range> expected; | |
1054 | |
1055 // SELECTION_NONE. | |
1056 render_text->SelectRange(Range(6)); | |
1057 | |
1058 // Move left twice. | |
1059 expected.push_back(Range(4)); | |
1060 expected.push_back(Range(0)); | |
1061 RunMoveCursorTestAndClearExpectations(render_text.get(), WORD_BREAK, | |
1062 CURSOR_LEFT, SELECTION_NONE, &expected); | |
1063 | |
1064 // Move right twice. | |
1065 expected.push_back(Range(3)); | |
1066 expected.push_back(Range(7)); | |
1067 RunMoveCursorTestAndClearExpectations( | |
1068 render_text.get(), WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE, &expected); | |
1069 | |
1070 // SELECTION_CARET. | |
1071 render_text->SelectRange(Range(6)); | |
1072 | |
1073 // Move left. | |
1074 expected.push_back(Range(6, 4)); | |
1075 RunMoveCursorTestAndClearExpectations( | |
1076 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_CARET, &expected); | |
1077 | |
1078 // Move right twice. | |
1079 expected.push_back(Range(6)); | |
1080 expected.push_back(Range(6, 7)); | |
1081 RunMoveCursorTestAndClearExpectations( | |
1082 render_text.get(), WORD_BREAK, CURSOR_RIGHT, SELECTION_CARET, &expected); | |
1083 | |
1084 // Move left. | |
1085 expected.push_back(Range(6)); | |
1086 RunMoveCursorTestAndClearExpectations( | |
1087 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_CARET, &expected); | |
1088 | |
1089 // SELECTION_RETAIN. | |
1090 render_text->SelectRange(Range(6)); | |
1091 | |
1092 // Move left. | |
1093 expected.push_back(Range(6, 4)); | |
1094 RunMoveCursorTestAndClearExpectations( | |
1095 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_RETAIN, &expected); | |
1096 | |
1097 // Move right twice. | |
1098 expected.push_back(Range(6, 7)); | |
1099 expected.push_back(Range(6, 11)); | |
1100 RunMoveCursorTestAndClearExpectations( | |
1101 render_text.get(), WORD_BREAK, CURSOR_RIGHT, SELECTION_RETAIN, &expected); | |
1102 | |
1103 // Move left. | |
1104 expected.push_back(Range(6, 8)); | |
1105 RunMoveCursorTestAndClearExpectations( | |
1106 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_RETAIN, &expected); | |
1107 | |
1108 // SELECTION_EXTEND. | |
1109 render_text->SelectRange(Range(6)); | |
1110 | |
1111 // Move left. | |
1112 expected.push_back(Range(6, 4)); | |
1113 RunMoveCursorTestAndClearExpectations( | |
1114 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_EXTEND, &expected); | |
1115 | |
1116 // Move right twice. | |
1117 expected.push_back(Range(4, 7)); | |
1118 expected.push_back(Range(4, 11)); | |
1119 RunMoveCursorTestAndClearExpectations( | |
1120 render_text.get(), WORD_BREAK, CURSOR_RIGHT, SELECTION_EXTEND, &expected); | |
1121 | |
1122 // Move left. | |
1123 expected.push_back(Range(4, 8)); | |
1124 RunMoveCursorTestAndClearExpectations( | |
1125 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_EXTEND, &expected); | |
1126 } | |
1127 | |
1128 TEST_F(RenderTextTest, MoveCursor_Line) { | |
1129 std::unique_ptr<RenderText> render_text( | |
1130 RenderText::CreateInstanceForEditing()); | |
1131 render_text->SetText(WideToUTF16(L"123 456 789")); | |
1132 std::vector<Range> expected; | |
1133 | |
1134 // SELECTION_NONE. | |
1135 render_text->SelectRange(Range(6)); | |
1136 | |
1137 // Move right twice. | |
1138 expected.push_back(Range(11)); | |
1139 expected.push_back(Range(11)); | |
1140 RunMoveCursorTestAndClearExpectations( | |
1141 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE, &expected); | |
1142 | |
1143 // Move left twice. | |
1144 expected.push_back(Range(0)); | |
1145 expected.push_back(Range(0)); | |
1146 RunMoveCursorTestAndClearExpectations(render_text.get(), LINE_BREAK, | |
1147 CURSOR_LEFT, SELECTION_NONE, &expected); | |
1148 | |
1149 // SELECTION_CARET. | |
1150 render_text->SelectRange(Range(6)); | |
1151 | |
1152 // Move right. | |
1153 expected.push_back(Range(6, 11)); | |
1154 RunMoveCursorTestAndClearExpectations( | |
1155 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_CARET, &expected); | |
1156 | |
1157 // Move left twice. | |
1158 expected.push_back(Range(6)); | |
1159 expected.push_back(Range(6, 0)); | |
1160 RunMoveCursorTestAndClearExpectations( | |
1161 render_text.get(), LINE_BREAK, CURSOR_LEFT, SELECTION_CARET, &expected); | |
1162 | |
1163 // Move right. | |
1164 expected.push_back(Range(6)); | |
1165 RunMoveCursorTestAndClearExpectations( | |
1166 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_CARET, &expected); | |
1167 | |
1168 // SELECTION_RETAIN. | |
1169 render_text->SelectRange(Range(6)); | |
1170 | |
1171 // Move right. | |
1172 expected.push_back(Range(6, 11)); | |
1173 RunMoveCursorTestAndClearExpectations( | |
1174 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_RETAIN, &expected); | |
1175 | |
1176 // Move left twice. | |
1177 expected.push_back(Range(6, 0)); | |
1178 expected.push_back(Range(6, 0)); | |
1179 RunMoveCursorTestAndClearExpectations( | |
1180 render_text.get(), LINE_BREAK, CURSOR_LEFT, SELECTION_RETAIN, &expected); | |
1181 | |
1182 // Move right. | |
1183 expected.push_back(Range(6, 11)); | |
1184 RunMoveCursorTestAndClearExpectations( | |
1185 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_RETAIN, &expected); | |
1186 | |
1187 // SELECTION_EXTEND. | |
1188 render_text->SelectRange(Range(6)); | |
1189 | |
1190 // Move right. | |
1191 expected.push_back(Range(6, 11)); | |
1192 RunMoveCursorTestAndClearExpectations( | |
1193 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_EXTEND, &expected); | |
1194 | |
1195 // Move left twice. | |
1196 expected.push_back(Range(11, 0)); | |
1197 expected.push_back(Range(11, 0)); | |
1198 RunMoveCursorTestAndClearExpectations( | |
1199 render_text.get(), LINE_BREAK, CURSOR_LEFT, SELECTION_EXTEND, &expected); | |
1200 | |
1201 // Move right. | |
1202 expected.push_back(Range(0, 11)); | |
1203 RunMoveCursorTestAndClearExpectations( | |
1204 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_EXTEND, &expected); | |
1205 } | |
1206 | |
955 TEST_F(RenderTextTest, GetDisplayTextDirection) { | 1207 TEST_F(RenderTextTest, GetDisplayTextDirection) { |
956 struct { | 1208 struct { |
957 const wchar_t* text; | 1209 const wchar_t* text; |
958 const base::i18n::TextDirection text_direction; | 1210 const base::i18n::TextDirection text_direction; |
959 } cases[] = { | 1211 } cases[] = { |
960 // Blank strings and those with no/weak directionality default to LTR. | 1212 // Blank strings and those with no/weak directionality default to LTR. |
961 { L"", base::i18n::LEFT_TO_RIGHT }, | 1213 { L"", base::i18n::LEFT_TO_RIGHT }, |
962 { kWeak, base::i18n::LEFT_TO_RIGHT }, | 1214 { kWeak, base::i18n::LEFT_TO_RIGHT }, |
963 // Strings that begin with strong LTR characters. | 1215 // Strings that begin with strong LTR characters. |
964 { kLtr, base::i18n::LEFT_TO_RIGHT }, | 1216 { kLtr, base::i18n::LEFT_TO_RIGHT }, |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1077 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); | 1329 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); |
1078 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); | 1330 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); |
1079 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 1331 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
1080 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); | 1332 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); |
1081 } | 1333 } |
1082 | 1334 |
1083 TEST_F(RenderTextTest, MoveCursorLeftRightInRtl) { | 1335 TEST_F(RenderTextTest, MoveCursorLeftRightInRtl) { |
1084 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1336 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1085 // Pure RTL. | 1337 // Pure RTL. |
1086 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2")); | 1338 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2")); |
1087 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 1339 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1088 std::vector<SelectionModel> expected; | 1340 std::vector<SelectionModel> expected; |
1089 | 1341 |
1090 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 1342 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
1091 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); | 1343 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); |
1092 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); | 1344 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); |
1093 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); | 1345 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); |
1094 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | 1346 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
1095 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); | 1347 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); |
1096 | 1348 |
1097 expected.clear(); | 1349 expected.clear(); |
1098 | 1350 |
1099 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | 1351 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
1100 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); | 1352 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); |
1101 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); | 1353 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); |
1102 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); | 1354 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); |
1103 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 1355 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
1104 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); | 1356 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); |
1105 } | 1357 } |
1106 | 1358 |
1107 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtr) { | 1359 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtr) { |
1108 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1360 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1109 // RTL-LTR | 1361 // RTL-LTR |
1110 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2" L"abc")); | 1362 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2" L"abc")); |
1111 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 1363 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1112 std::vector<SelectionModel> expected; | 1364 std::vector<SelectionModel> expected; |
1113 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 1365 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
1114 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); | 1366 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); |
1115 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); | 1367 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); |
1116 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); | 1368 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); |
1117 expected.push_back(SelectionModel(5, CURSOR_FORWARD)); | 1369 expected.push_back(SelectionModel(5, CURSOR_FORWARD)); |
1118 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); | 1370 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); |
1119 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | 1371 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
1120 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); | 1372 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); |
1121 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); | 1373 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); |
1122 | 1374 |
1123 expected.clear(); | 1375 expected.clear(); |
1124 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); | 1376 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); |
1125 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); | 1377 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); |
1126 expected.push_back(SelectionModel(5, CURSOR_BACKWARD)); | 1378 expected.push_back(SelectionModel(5, CURSOR_BACKWARD)); |
1127 expected.push_back(SelectionModel(6, CURSOR_BACKWARD)); | 1379 expected.push_back(SelectionModel(6, CURSOR_BACKWARD)); |
1128 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); | 1380 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); |
1129 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); | 1381 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); |
1130 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); | 1382 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); |
1131 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 1383 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
1132 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); | 1384 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); |
1133 } | 1385 } |
1134 | 1386 |
1135 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtrRtl) { | 1387 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtrRtl) { |
1136 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1388 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1137 // RTL-LTR-RTL. | 1389 // RTL-LTR-RTL. |
1138 render_text->SetText(WideToUTF16(L"\x05d0" L"a" L"\x05d1")); | 1390 render_text->SetText(WideToUTF16(L"\x05d0" L"a" L"\x05d1")); |
1139 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 1391 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1140 std::vector<SelectionModel> expected; | 1392 std::vector<SelectionModel> expected; |
1141 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 1393 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
1142 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); | 1394 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); |
1143 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); | 1395 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); |
1144 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); | 1396 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); |
1145 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | 1397 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
1146 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); | 1398 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); |
1147 | 1399 |
1148 expected.clear(); | 1400 expected.clear(); |
1149 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | 1401 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
1150 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); | 1402 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); |
1151 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); | 1403 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); |
1152 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); | 1404 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); |
1153 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 1405 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
1154 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); | 1406 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); |
1155 } | 1407 } |
1156 | 1408 |
1157 TEST_F(RenderTextTest, MoveCursorLeftRight_ComplexScript) { | 1409 TEST_F(RenderTextTest, MoveCursorLeftRight_ComplexScript) { |
1158 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1410 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1159 | 1411 |
1160 render_text->SetText(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915")); | 1412 render_text->SetText(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915")); |
1161 EXPECT_EQ(0U, render_text->cursor_position()); | 1413 EXPECT_EQ(0U, render_text->cursor_position()); |
1162 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1414 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1163 EXPECT_EQ(2U, render_text->cursor_position()); | 1415 EXPECT_EQ(2U, render_text->cursor_position()); |
1164 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1416 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1165 EXPECT_EQ(4U, render_text->cursor_position()); | 1417 EXPECT_EQ(4U, render_text->cursor_position()); |
1166 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1418 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1167 EXPECT_EQ(5U, render_text->cursor_position()); | 1419 EXPECT_EQ(5U, render_text->cursor_position()); |
1168 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1420 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1169 EXPECT_EQ(5U, render_text->cursor_position()); | 1421 EXPECT_EQ(5U, render_text->cursor_position()); |
1170 | 1422 |
1171 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1423 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1172 EXPECT_EQ(4U, render_text->cursor_position()); | 1424 EXPECT_EQ(4U, render_text->cursor_position()); |
1173 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1425 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1174 EXPECT_EQ(2U, render_text->cursor_position()); | 1426 EXPECT_EQ(2U, render_text->cursor_position()); |
1175 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1427 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1176 EXPECT_EQ(0U, render_text->cursor_position()); | 1428 EXPECT_EQ(0U, render_text->cursor_position()); |
1177 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1429 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1178 EXPECT_EQ(0U, render_text->cursor_position()); | 1430 EXPECT_EQ(0U, render_text->cursor_position()); |
1179 } | 1431 } |
1180 | 1432 |
1181 TEST_F(RenderTextTest, MoveCursorLeftRight_MeiryoUILigatures) { | 1433 TEST_F(RenderTextTest, MoveCursorLeftRight_MeiryoUILigatures) { |
1182 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1434 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1183 // Meiryo UI uses single-glyph ligatures for 'ff' and 'ffi', but each letter | 1435 // Meiryo UI uses single-glyph ligatures for 'ff' and 'ffi', but each letter |
1184 // (code point) has unique bounds, so mid-glyph cursoring should be possible. | 1436 // (code point) has unique bounds, so mid-glyph cursoring should be possible. |
1185 render_text->SetFontList(FontList("Meiryo UI, 12px")); | 1437 render_text->SetFontList(FontList("Meiryo UI, 12px")); |
1186 render_text->SetText(WideToUTF16(L"ff ffi")); | 1438 render_text->SetText(WideToUTF16(L"ff ffi")); |
1187 EXPECT_EQ(0U, render_text->cursor_position()); | 1439 EXPECT_EQ(0U, render_text->cursor_position()); |
1188 for (size_t i = 0; i < render_text->text().length(); ++i) { | 1440 for (size_t i = 0; i < render_text->text().length(); ++i) { |
1189 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1441 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1190 EXPECT_EQ(i + 1, render_text->cursor_position()); | 1442 EXPECT_EQ(i + 1, render_text->cursor_position()); |
1191 } | 1443 } |
1192 EXPECT_EQ(6U, render_text->cursor_position()); | 1444 EXPECT_EQ(6U, render_text->cursor_position()); |
1193 } | 1445 } |
1194 | 1446 |
1195 TEST_F(RenderTextTest, GraphemePositions) { | 1447 TEST_F(RenderTextTest, GraphemePositions) { |
1196 // LTR 2-character grapheme, LTR abc, LTR 2-character grapheme. | 1448 // LTR 2-character grapheme, LTR abc, LTR 2-character grapheme. |
1197 const base::string16 kText1 = | 1449 const base::string16 kText1 = |
1198 WideToUTF16(L"\x0915\x093f" L"abc" L"\x0915\x093f"); | 1450 WideToUTF16(L"\x0915\x093f" L"abc" L"\x0915\x093f"); |
1199 | 1451 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1285 for (size_t i = 0; i < arraysize(cases); i++) { | 1537 for (size_t i = 0; i < arraysize(cases); i++) { |
1286 SCOPED_TRACE(base::StringPrintf("Testing cases[%" PRIuS "]", i)); | 1538 SCOPED_TRACE(base::StringPrintf("Testing cases[%" PRIuS "]", i)); |
1287 render_text->SetText(cases[i]); | 1539 render_text->SetText(cases[i]); |
1288 EXPECT_TRUE(render_text->IsValidLogicalIndex(1)); | 1540 EXPECT_TRUE(render_text->IsValidLogicalIndex(1)); |
1289 EXPECT_FALSE(render_text->IsValidCursorIndex(1)); | 1541 EXPECT_FALSE(render_text->IsValidCursorIndex(1)); |
1290 EXPECT_TRUE(render_text->SelectRange(Range(2, 1))); | 1542 EXPECT_TRUE(render_text->SelectRange(Range(2, 1))); |
1291 EXPECT_EQ(Range(2, 1), render_text->selection()); | 1543 EXPECT_EQ(Range(2, 1), render_text->selection()); |
1292 EXPECT_EQ(1U, render_text->cursor_position()); | 1544 EXPECT_EQ(1U, render_text->cursor_position()); |
1293 // Although selection bounds may be set within a multi-character grapheme, | 1545 // Although selection bounds may be set within a multi-character grapheme, |
1294 // cursor movement (e.g. via arrow key) should avoid those indices. | 1546 // cursor movement (e.g. via arrow key) should avoid those indices. |
1295 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1547 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1296 EXPECT_EQ(0U, render_text->cursor_position()); | 1548 EXPECT_EQ(0U, render_text->cursor_position()); |
1297 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1549 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1298 EXPECT_EQ(2U, render_text->cursor_position()); | 1550 EXPECT_EQ(2U, render_text->cursor_position()); |
1299 } | 1551 } |
1300 } | 1552 } |
1301 | 1553 |
1302 TEST_F(RenderTextTest, FindCursorPosition) { | 1554 TEST_F(RenderTextTest, FindCursorPosition) { |
1303 const wchar_t* kTestStrings[] = { kLtrRtl, kLtrRtlLtr, kRtlLtr, kRtlLtrRtl }; | 1555 const wchar_t* kTestStrings[] = { kLtrRtl, kLtrRtlLtr, kRtlLtr, kRtlLtrRtl }; |
1304 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1556 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1305 render_text->SetDisplayRect(Rect(0, 0, 100, 20)); | 1557 render_text->SetDisplayRect(Rect(0, 0, 100, 20)); |
1306 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { | 1558 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { |
1307 SCOPED_TRACE(base::StringPrintf("Testing case[%" PRIuS "]", i)); | 1559 SCOPED_TRACE(base::StringPrintf("Testing case[%" PRIuS "]", i)); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1392 | 1644 |
1393 EXPECT_EQ(was_rtl, base::i18n::IsRTL()); | 1645 EXPECT_EQ(was_rtl, base::i18n::IsRTL()); |
1394 } | 1646 } |
1395 | 1647 |
1396 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 | 1648 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 |
1397 #if !defined(OS_MACOSX) | 1649 #if !defined(OS_MACOSX) |
1398 TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) { | 1650 TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) { |
1399 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1651 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1400 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); | 1652 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); |
1401 // Left arrow on select ranging (6, 4). | 1653 // Left arrow on select ranging (6, 4). |
1402 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 1654 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1403 EXPECT_EQ(Range(6), render_text->selection()); | 1655 EXPECT_EQ(Range(6), render_text->selection()); |
1404 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1656 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1405 EXPECT_EQ(Range(4), render_text->selection()); | 1657 EXPECT_EQ(Range(4), render_text->selection()); |
1406 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1658 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1407 EXPECT_EQ(Range(5), render_text->selection()); | 1659 EXPECT_EQ(Range(5), render_text->selection()); |
1408 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1660 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1409 EXPECT_EQ(Range(6), render_text->selection()); | 1661 EXPECT_EQ(Range(6), render_text->selection()); |
1410 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, true); | 1662 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_RETAIN); |
1411 EXPECT_EQ(Range(6, 5), render_text->selection()); | 1663 EXPECT_EQ(Range(6, 5), render_text->selection()); |
1412 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, true); | 1664 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_RETAIN); |
1413 EXPECT_EQ(Range(6, 4), render_text->selection()); | 1665 EXPECT_EQ(Range(6, 4), render_text->selection()); |
1414 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1666 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1415 EXPECT_EQ(Range(6), render_text->selection()); | 1667 EXPECT_EQ(Range(6), render_text->selection()); |
1416 | 1668 |
1417 // Right arrow on select ranging (4, 6). | 1669 // Right arrow on select ranging (4, 6). |
1418 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 1670 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1419 EXPECT_EQ(Range(0), render_text->selection()); | 1671 EXPECT_EQ(Range(0), render_text->selection()); |
1420 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1672 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1421 EXPECT_EQ(Range(1), render_text->selection()); | 1673 EXPECT_EQ(Range(1), render_text->selection()); |
1422 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1674 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1423 EXPECT_EQ(Range(2), render_text->selection()); | 1675 EXPECT_EQ(Range(2), render_text->selection()); |
1424 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1676 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1425 EXPECT_EQ(Range(3), render_text->selection()); | 1677 EXPECT_EQ(Range(3), render_text->selection()); |
1426 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1678 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1427 EXPECT_EQ(Range(5), render_text->selection()); | 1679 EXPECT_EQ(Range(5), render_text->selection()); |
1428 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1680 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1429 EXPECT_EQ(Range(4), render_text->selection()); | 1681 EXPECT_EQ(Range(4), render_text->selection()); |
1430 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, true); | 1682 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_RETAIN); |
1431 EXPECT_EQ(Range(4, 5), render_text->selection()); | 1683 EXPECT_EQ(Range(4, 5), render_text->selection()); |
1432 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, true); | 1684 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_RETAIN); |
1433 EXPECT_EQ(Range(4, 6), render_text->selection()); | 1685 EXPECT_EQ(Range(4, 6), render_text->selection()); |
1434 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1686 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1435 EXPECT_EQ(Range(4), render_text->selection()); | 1687 EXPECT_EQ(Range(4), render_text->selection()); |
1436 } | 1688 } |
1437 #endif // !defined(OS_MACOSX) | 1689 #endif // !defined(OS_MACOSX) |
1438 | 1690 |
1439 TEST_F(RenderTextTest, CenteredDisplayOffset) { | 1691 TEST_F(RenderTextTest, CenteredDisplayOffset) { |
1440 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1692 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1441 render_text->SetText(ASCIIToUTF16("abcdefghij")); | 1693 render_text->SetText(ASCIIToUTF16("abcdefghij")); |
1442 render_text->SetHorizontalAlignment(ALIGN_CENTER); | 1694 render_text->SetHorizontalAlignment(ALIGN_CENTER); |
1443 | 1695 |
1444 const int kEnlargement = 10; | 1696 const int kEnlargement = 10; |
(...skipping 28 matching lines...) Expand all Loading... | |
1473 EXPECT_EQ(display_rect.right(), | 1725 EXPECT_EQ(display_rect.right(), |
1474 render_text->GetUpdatedCursorBounds().right()); | 1726 render_text->GetUpdatedCursorBounds().right()); |
1475 #endif // !defined(OS_MACOSX) | 1727 #endif // !defined(OS_MACOSX) |
1476 } | 1728 } |
1477 | 1729 |
1478 void MoveLeftRightByWordVerifier(RenderText* render_text, | 1730 void MoveLeftRightByWordVerifier(RenderText* render_text, |
1479 const wchar_t* str) { | 1731 const wchar_t* str) { |
1480 render_text->SetText(WideToUTF16(str)); | 1732 render_text->SetText(WideToUTF16(str)); |
1481 | 1733 |
1482 // Test moving by word from left ro right. | 1734 // Test moving by word from left ro right. |
1483 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 1735 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1484 bool first_word = true; | 1736 bool first_word = true; |
1485 while (true) { | 1737 while (true) { |
1486 // First, test moving by word from a word break position, such as from | 1738 // First, test moving by word from a word break position, such as from |
1487 // "|abc def" to "abc| def". | 1739 // "|abc def" to "abc| def". |
1488 SelectionModel start = render_text->selection_model(); | 1740 SelectionModel start = render_text->selection_model(); |
1489 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1741 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1490 SelectionModel end = render_text->selection_model(); | 1742 SelectionModel end = render_text->selection_model(); |
1491 if (end == start) // reach the end. | 1743 if (end == start) // reach the end. |
1492 break; | 1744 break; |
1493 | 1745 |
1494 // For testing simplicity, each word is a 3-character word. | 1746 // For testing simplicity, each word is a 3-character word. |
1495 int num_of_character_moves = first_word ? 3 : 4; | 1747 int num_of_character_moves = first_word ? 3 : 4; |
1496 first_word = false; | 1748 first_word = false; |
1497 render_text->MoveCursorTo(start); | 1749 render_text->MoveCursorTo(start); |
1498 for (int j = 0; j < num_of_character_moves; ++j) | 1750 for (int j = 0; j < num_of_character_moves; ++j) |
1499 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1751 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1500 EXPECT_EQ(end, render_text->selection_model()); | 1752 EXPECT_EQ(end, render_text->selection_model()); |
1501 | 1753 |
1502 // Then, test moving by word from positions inside the word, such as from | 1754 // Then, test moving by word from positions inside the word, such as from |
1503 // "a|bc def" to "abc| def", and from "ab|c def" to "abc| def". | 1755 // "a|bc def" to "abc| def", and from "ab|c def" to "abc| def". |
1504 for (int j = 1; j < num_of_character_moves; ++j) { | 1756 for (int j = 1; j < num_of_character_moves; ++j) { |
1505 render_text->MoveCursorTo(start); | 1757 render_text->MoveCursorTo(start); |
1506 for (int k = 0; k < j; ++k) | 1758 for (int k = 0; k < j; ++k) |
1507 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1759 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1508 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1760 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1509 EXPECT_EQ(end, render_text->selection_model()); | 1761 EXPECT_EQ(end, render_text->selection_model()); |
1510 } | 1762 } |
1511 } | 1763 } |
1512 | 1764 |
1513 // Test moving by word from right to left. | 1765 // Test moving by word from right to left. |
1514 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 1766 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1515 first_word = true; | 1767 first_word = true; |
1516 while (true) { | 1768 while (true) { |
1517 SelectionModel start = render_text->selection_model(); | 1769 SelectionModel start = render_text->selection_model(); |
1518 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); | 1770 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1519 SelectionModel end = render_text->selection_model(); | 1771 SelectionModel end = render_text->selection_model(); |
1520 if (end == start) // reach the end. | 1772 if (end == start) // reach the end. |
1521 break; | 1773 break; |
1522 | 1774 |
1523 int num_of_character_moves = first_word ? 3 : 4; | 1775 int num_of_character_moves = first_word ? 3 : 4; |
1524 first_word = false; | 1776 first_word = false; |
1525 render_text->MoveCursorTo(start); | 1777 render_text->MoveCursorTo(start); |
1526 for (int j = 0; j < num_of_character_moves; ++j) | 1778 for (int j = 0; j < num_of_character_moves; ++j) |
1527 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1779 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1528 EXPECT_EQ(end, render_text->selection_model()); | 1780 EXPECT_EQ(end, render_text->selection_model()); |
1529 | 1781 |
1530 for (int j = 1; j < num_of_character_moves; ++j) { | 1782 for (int j = 1; j < num_of_character_moves; ++j) { |
1531 render_text->MoveCursorTo(start); | 1783 render_text->MoveCursorTo(start); |
1532 for (int k = 0; k < j; ++k) | 1784 for (int k = 0; k < j; ++k) |
1533 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1785 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1534 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); | 1786 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1535 EXPECT_EQ(end, render_text->selection_model()); | 1787 EXPECT_EQ(end, render_text->selection_model()); |
1536 } | 1788 } |
1537 } | 1789 } |
1538 } | 1790 } |
1539 | 1791 |
1540 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 | 1792 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 |
1541 #if !defined(OS_MACOSX) | 1793 #if !defined(OS_MACOSX) |
1542 // TODO(msw): Make these work on Windows. | 1794 // TODO(msw): Make these work on Windows. |
1543 #if !defined(OS_WIN) | 1795 #if !defined(OS_WIN) |
1544 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText) { | 1796 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1577 } | 1829 } |
1578 | 1830 |
1579 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText_TestEndOfText) { | 1831 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText_TestEndOfText) { |
1580 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1832 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1581 | 1833 |
1582 render_text->SetText(WideToUTF16(L"ab\x05E1")); | 1834 render_text->SetText(WideToUTF16(L"ab\x05E1")); |
1583 // Moving the cursor by word from "abC|" to the left should return "|abC". | 1835 // Moving the cursor by word from "abC|" to the left should return "|abC". |
1584 // But since end of text is always treated as a word break, it returns | 1836 // But since end of text is always treated as a word break, it returns |
1585 // position "ab|C". | 1837 // position "ab|C". |
1586 // TODO(xji): Need to make it work as expected. | 1838 // TODO(xji): Need to make it work as expected. |
1587 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 1839 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1588 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); | 1840 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1589 // EXPECT_EQ(SelectionModel(), render_text->selection_model()); | 1841 // EXPECT_EQ(SelectionModel(), render_text->selection_model()); |
1590 | 1842 |
1591 // Moving the cursor by word from "|abC" to the right returns "abC|". | 1843 // Moving the cursor by word from "|abC" to the right returns "abC|". |
1592 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 1844 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1593 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1845 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1594 EXPECT_EQ(SelectionModel(3, CURSOR_FORWARD), render_text->selection_model()); | 1846 EXPECT_EQ(SelectionModel(3, CURSOR_FORWARD), render_text->selection_model()); |
1595 | 1847 |
1596 render_text->SetText(WideToUTF16(L"\x05E1\x05E2" L"a")); | 1848 render_text->SetText(WideToUTF16(L"\x05E1\x05E2" L"a")); |
1597 // For logical text "BCa", moving the cursor by word from "aCB|" to the left | 1849 // For logical text "BCa", moving the cursor by word from "aCB|" to the left |
1598 // returns "|aCB". | 1850 // returns "|aCB". |
1599 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 1851 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1600 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); | 1852 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1601 EXPECT_EQ(SelectionModel(3, CURSOR_FORWARD), render_text->selection_model()); | 1853 EXPECT_EQ(SelectionModel(3, CURSOR_FORWARD), render_text->selection_model()); |
1602 | 1854 |
1603 // Moving the cursor by word from "|aCB" to the right should return "aCB|". | 1855 // Moving the cursor by word from "|aCB" to the right should return "aCB|". |
1604 // But since end of text is always treated as a word break, it returns | 1856 // But since end of text is always treated as a word break, it returns |
1605 // position "a|CB". | 1857 // position "a|CB". |
1606 // TODO(xji): Need to make it work as expected. | 1858 // TODO(xji): Need to make it work as expected. |
1607 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 1859 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1608 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1860 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1609 // EXPECT_EQ(SelectionModel(), render_text->selection_model()); | 1861 // EXPECT_EQ(SelectionModel(), render_text->selection_model()); |
1610 } | 1862 } |
1611 | 1863 |
1612 TEST_F(RenderTextTest, MoveLeftRightByWordInTextWithMultiSpaces) { | 1864 TEST_F(RenderTextTest, MoveLeftRightByWordInTextWithMultiSpaces) { |
1613 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1865 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1614 render_text->SetText(WideToUTF16(L"abc def")); | 1866 render_text->SetText(WideToUTF16(L"abc def")); |
1615 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD)); | 1867 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD)); |
1616 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1868 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1617 EXPECT_EQ(11U, render_text->cursor_position()); | 1869 EXPECT_EQ(11U, render_text->cursor_position()); |
1618 | 1870 |
1619 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD)); | 1871 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD)); |
1620 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); | 1872 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1621 EXPECT_EQ(0U, render_text->cursor_position()); | 1873 EXPECT_EQ(0U, render_text->cursor_position()); |
1622 } | 1874 } |
1623 #endif // !defined(OS_WIN) | 1875 #endif // !defined(OS_WIN) |
1624 | 1876 |
1625 TEST_F(RenderTextTest, MoveLeftRightByWordInChineseText) { | 1877 TEST_F(RenderTextTest, MoveLeftRightByWordInChineseText) { |
1626 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1878 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1627 render_text->SetText(WideToUTF16(L"\x6211\x4EEC\x53BB\x516C\x56ED\x73A9")); | 1879 render_text->SetText(WideToUTF16(L"\x6211\x4EEC\x53BB\x516C\x56ED\x73A9")); |
1628 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 1880 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE); |
1629 EXPECT_EQ(0U, render_text->cursor_position()); | 1881 EXPECT_EQ(0U, render_text->cursor_position()); |
1630 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1882 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1631 EXPECT_EQ(2U, render_text->cursor_position()); | 1883 EXPECT_EQ(2U, render_text->cursor_position()); |
1632 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1884 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1633 EXPECT_EQ(3U, render_text->cursor_position()); | 1885 EXPECT_EQ(3U, render_text->cursor_position()); |
1634 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1886 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1635 EXPECT_EQ(5U, render_text->cursor_position()); | 1887 EXPECT_EQ(5U, render_text->cursor_position()); |
1636 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1888 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1637 EXPECT_EQ(6U, render_text->cursor_position()); | 1889 EXPECT_EQ(6U, render_text->cursor_position()); |
1638 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1890 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
1639 EXPECT_EQ(6U, render_text->cursor_position()); | 1891 EXPECT_EQ(6U, render_text->cursor_position()); |
1640 } | 1892 } |
1641 #endif // !defined(OS_MACOSX) | 1893 #endif // !defined(OS_MACOSX) |
1642 | 1894 |
1643 TEST_F(RenderTextTest, StringSizeSanity) { | 1895 TEST_F(RenderTextTest, StringSizeSanity) { |
1644 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1896 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1645 render_text->SetText(UTF8ToUTF16("Hello World")); | 1897 render_text->SetText(UTF8ToUTF16("Hello World")); |
1646 const Size string_size = render_text->GetStringSize(); | 1898 const Size string_size = render_text->GetStringSize(); |
1647 EXPECT_GT(string_size.width(), 0); | 1899 EXPECT_GT(string_size.width(), 0); |
1648 EXPECT_GT(string_size.height(), 0); | 1900 EXPECT_GT(string_size.height(), 0); |
(...skipping 1486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3135 render_text.SetFontList(font_list); | 3387 render_text.SetFontList(font_list); |
3136 // Korean character "han". | 3388 // Korean character "han". |
3137 render_text.SetText(WideToUTF16(L"\xd55c")); | 3389 render_text.SetText(WideToUTF16(L"\xd55c")); |
3138 render_text.EnsureLayout(); | 3390 render_text.EnsureLayout(); |
3139 internal::TextRunList* run_list = render_text.GetRunList(); | 3391 internal::TextRunList* run_list = render_text.GetRunList(); |
3140 ASSERT_EQ(1U, run_list->size()); | 3392 ASSERT_EQ(1U, run_list->size()); |
3141 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs()); | 3393 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs()); |
3142 } | 3394 } |
3143 #endif // defined(OS_WIN) | 3395 #endif // defined(OS_WIN) |
3144 | 3396 |
3145 // Ensure that the fallback fonts offered by gfx::GetFallbackFonts() are | 3397 // Ensure that the fallback fonts offered by GetFallbackFonts() are |
3146 // tried. Note this test assumes the font "Arial" doesn't provide a unicode | 3398 // tried. Note this test assumes the font "Arial" doesn't provide a unicode |
3147 // glyph for a particular character, and that there exists a system fallback | 3399 // glyph for a particular character, and that there exists a system fallback |
3148 // font which does. | 3400 // font which does. |
3149 // TODO(msw): Fallback doesn't find a glyph on Linux. | 3401 // TODO(msw): Fallback doesn't find a glyph on Linux. |
3150 #if !defined(OS_LINUX) | 3402 #if !defined(OS_LINUX) |
3151 TEST_F(RenderTextTest, HarfBuzz_UnicodeFallback) { | 3403 TEST_F(RenderTextTest, HarfBuzz_UnicodeFallback) { |
3152 RenderTextHarfBuzz render_text; | 3404 RenderTextHarfBuzz render_text; |
3153 render_text.SetFontList(FontList("Arial, 12px")); | 3405 render_text.SetFontList(FontList("Arial, 12px")); |
3154 | 3406 |
3155 // Korean character "han". | 3407 // Korean character "han". |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3431 EXPECT_FALSE(backend.paint().isLCDRenderText()); | 3683 EXPECT_FALSE(backend.paint().isLCDRenderText()); |
3432 backend.GetHarfbuzzRunList()->runs()[0]->render_params.subpixel_rendering = | 3684 backend.GetHarfbuzzRunList()->runs()[0]->render_params.subpixel_rendering = |
3433 FontRenderParams::SUBPIXEL_RENDERING_RGB; | 3685 FontRenderParams::SUBPIXEL_RENDERING_RGB; |
3434 backend.DrawVisualText(); | 3686 backend.DrawVisualText(); |
3435 #endif | 3687 #endif |
3436 EXPECT_FALSE(backend.paint().isLCDRenderText()); | 3688 EXPECT_FALSE(backend.paint().isLCDRenderText()); |
3437 } | 3689 } |
3438 } | 3690 } |
3439 | 3691 |
3440 } // namespace gfx | 3692 } // namespace gfx |
OLD | NEW |