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 | |
114 // and verify the selected range matches |expected|. Also, clears the | |
115 // expectations. | |
116 void RunMoveCursorTestAndClearExpectations(RenderText* render_text, | |
117 BreakType break_type, | |
118 VisualCursorDirection direction, | |
119 SelectionBehavior selection_behavior, | |
120 std::vector<Range>* expected) { | |
121 for (size_t i = 0; i < expected->size(); ++i) { | |
122 SCOPED_TRACE(base::StringPrintf( | |
123 "BreakType-%d Direction-%d SelectionBehavior-%d Case-%d.", break_type, | |
124 direction, selection_behavior, static_cast<int>(i))); | |
125 | |
126 render_text->MoveCursor(break_type, direction, selection_behavior); | |
127 EXPECT_EQ(expected->at(i), render_text->selection()); | |
128 } | |
129 expected->clear(); | |
130 } | |
131 | |
112 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 | 132 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 |
113 #if !defined(OS_MACOSX) | 133 #if !defined(OS_MACOSX) |
114 // Ensure cursor movement in the specified |direction| yields |expected| values. | 134 // Ensure cursor movement in the specified |direction| yields |expected| values. |
115 void RunMoveCursorLeftRightTest(RenderText* render_text, | 135 void RunMoveCursorLeftRightTest(RenderText* render_text, |
116 const std::vector<SelectionModel>& expected, | 136 const std::vector<SelectionModel>& expected, |
117 VisualCursorDirection direction) { | 137 VisualCursorDirection direction) { |
118 for (size_t i = 0; i < expected.size(); ++i) { | 138 for (size_t i = 0; i < expected.size(); ++i) { |
119 SCOPED_TRACE(base::StringPrintf("Going %s; expected value index %d.", | 139 SCOPED_TRACE(base::StringPrintf("Going %s; expected value index %d.", |
120 direction == CURSOR_LEFT ? "left" : "right", static_cast<int>(i))); | 140 direction == CURSOR_LEFT ? "left" : "right", static_cast<int>(i))); |
121 EXPECT_EQ(expected[i], render_text->selection_model()); | 141 EXPECT_EQ(expected[i], render_text->selection_model()); |
122 render_text->MoveCursor(CHARACTER_BREAK, direction, false); | 142 render_text->MoveCursor(CHARACTER_BREAK, direction, gfx::SELECTION_NONE); |
123 } | 143 } |
124 // Check that cursoring is clamped at the line edge. | 144 // Check that cursoring is clamped at the line edge. |
125 EXPECT_EQ(expected.back(), render_text->selection_model()); | 145 EXPECT_EQ(expected.back(), render_text->selection_model()); |
126 // Check that it is the line edge. | 146 // Check that it is the line edge. |
127 render_text->MoveCursor(LINE_BREAK, direction, false); | 147 render_text->MoveCursor(LINE_BREAK, direction, gfx::SELECTION_NONE); |
128 EXPECT_EQ(expected.back(), render_text->selection_model()); | 148 EXPECT_EQ(expected.back(), render_text->selection_model()); |
129 } | 149 } |
130 #endif // !defined(OS_MACOSX) | 150 #endif // !defined(OS_MACOSX) |
131 | 151 |
132 // The class which records the drawing operations so that the test case can | 152 // The class which records the drawing operations so that the test case can |
133 // verify where exactly the glyphs are drawn. | 153 // verify where exactly the glyphs are drawn. |
134 class TestSkiaTextRenderer : public internal::SkiaTextRenderer { | 154 class TestSkiaTextRenderer : public internal::SkiaTextRenderer { |
135 public: | 155 public: |
136 struct TextLog { | 156 struct TextLog { |
137 TextLog() : glyph_count(0u), color(SK_ColorTRANSPARENT) {} | 157 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)); | 501 render_text->styles()[UNDERLINE].EqualsForTesting(expected_style)); |
482 // Ensure AppendText maintains current text styles. | 502 // Ensure AppendText maintains current text styles. |
483 render_text->AppendText(ASCIIToUTF16("def")); | 503 render_text->AppendText(ASCIIToUTF16("def")); |
484 EXPECT_EQ(render_text->GetDisplayText(), ASCIIToUTF16("abcdef")); | 504 EXPECT_EQ(render_text->GetDisplayText(), ASCIIToUTF16("abcdef")); |
485 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color)); | 505 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color)); |
486 EXPECT_TRUE(render_text->baselines().EqualsForTesting(expected_baseline)); | 506 EXPECT_TRUE(render_text->baselines().EqualsForTesting(expected_baseline)); |
487 EXPECT_TRUE( | 507 EXPECT_TRUE( |
488 render_text->styles()[UNDERLINE].EqualsForTesting(expected_style)); | 508 render_text->styles()[UNDERLINE].EqualsForTesting(expected_style)); |
489 } | 509 } |
490 | 510 |
491 void TestVisualCursorMotionInObscuredField(RenderText* render_text, | 511 void TestVisualCursorMotionInObscuredField( |
492 const base::string16& text, | 512 RenderText* render_text, |
493 bool select) { | 513 const base::string16& text, |
514 gfx::SelectionBehavior selection_behavior) { | |
515 const bool select = selection_behavior != gfx::SELECTION_NONE; | |
494 ASSERT_TRUE(render_text->obscured()); | 516 ASSERT_TRUE(render_text->obscured()); |
495 render_text->SetText(text); | 517 render_text->SetText(text); |
496 int len = text.length(); | 518 int len = text.length(); |
497 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, select); | 519 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, selection_behavior); |
498 EXPECT_EQ(SelectionModel(Range(select ? 0 : len, len), CURSOR_FORWARD), | 520 EXPECT_EQ(SelectionModel(Range(select ? 0 : len, len), CURSOR_FORWARD), |
499 render_text->selection_model()); | 521 render_text->selection_model()); |
500 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, select); | 522 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, selection_behavior); |
501 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); | 523 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); |
502 for (int j = 1; j <= len; ++j) { | 524 for (int j = 1; j <= len; ++j) { |
503 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, select); | 525 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, selection_behavior); |
504 EXPECT_EQ(SelectionModel(Range(select ? 0 : j, j), CURSOR_BACKWARD), | 526 EXPECT_EQ(SelectionModel(Range(select ? 0 : j, j), CURSOR_BACKWARD), |
505 render_text->selection_model()); | 527 render_text->selection_model()); |
506 } | 528 } |
507 for (int j = len - 1; j >= 0; --j) { | 529 for (int j = len - 1; j >= 0; --j) { |
508 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, select); | 530 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, selection_behavior); |
509 EXPECT_EQ(SelectionModel(Range(select ? 0 : j, j), CURSOR_FORWARD), | 531 EXPECT_EQ(SelectionModel(Range(select ? 0 : j, j), CURSOR_FORWARD), |
510 render_text->selection_model()); | 532 render_text->selection_model()); |
511 } | 533 } |
512 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, select); | 534 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, selection_behavior); |
513 EXPECT_EQ(SelectionModel(Range(select ? 0 : len, len), CURSOR_FORWARD), | 535 EXPECT_EQ(SelectionModel(Range(select ? 0 : len, len), CURSOR_FORWARD), |
514 render_text->selection_model()); | 536 render_text->selection_model()); |
515 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, select); | 537 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, selection_behavior); |
516 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); | 538 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); |
517 } | 539 } |
518 | 540 |
519 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 | 541 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 |
520 #if !defined(OS_MACOSX) | 542 #if !defined(OS_MACOSX) |
521 TEST_F(RenderTextTest, ObscuredText) { | 543 TEST_F(RenderTextTest, ObscuredText) { |
522 const base::string16 seuss = ASCIIToUTF16("hop on pop"); | 544 const base::string16 seuss = ASCIIToUTF16("hop on pop"); |
523 const base::string16 no_seuss = ASCIIToUTF16("**********"); | 545 const base::string16 no_seuss = ASCIIToUTF16("**********"); |
524 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 546 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
525 | 547 |
526 // GetLayoutText() returns asterisks when the obscured bit is set. | 548 // GetLayoutText() returns asterisks when the obscured bit is set. |
527 render_text->SetText(seuss); | 549 render_text->SetText(seuss); |
528 render_text->SetObscured(true); | 550 render_text->SetObscured(true); |
529 EXPECT_EQ(seuss, render_text->text()); | 551 EXPECT_EQ(seuss, render_text->text()); |
530 EXPECT_EQ(no_seuss, render_text->GetDisplayText()); | 552 EXPECT_EQ(no_seuss, render_text->GetDisplayText()); |
531 render_text->SetObscured(false); | 553 render_text->SetObscured(false); |
532 EXPECT_EQ(seuss, render_text->text()); | 554 EXPECT_EQ(seuss, render_text->text()); |
533 EXPECT_EQ(seuss, render_text->GetDisplayText()); | 555 EXPECT_EQ(seuss, render_text->GetDisplayText()); |
534 | 556 |
535 render_text->SetObscured(true); | 557 render_text->SetObscured(true); |
536 | 558 |
537 // Surrogate pairs are counted as one code point. | 559 // Surrogate pairs are counted as one code point. |
538 const base::char16 invalid_surrogates[] = {0xDC00, 0xD800, 0}; | 560 const base::char16 invalid_surrogates[] = {0xDC00, 0xD800, 0}; |
539 render_text->SetText(invalid_surrogates); | 561 render_text->SetText(invalid_surrogates); |
540 EXPECT_EQ(ASCIIToUTF16("**"), render_text->GetDisplayText()); | 562 EXPECT_EQ(ASCIIToUTF16("**"), render_text->GetDisplayText()); |
541 const base::char16 valid_surrogates[] = {0xD800, 0xDC00, 0}; | 563 const base::char16 valid_surrogates[] = {0xD800, 0xDC00, 0}; |
542 render_text->SetText(valid_surrogates); | 564 render_text->SetText(valid_surrogates); |
543 EXPECT_EQ(ASCIIToUTF16("*"), render_text->GetDisplayText()); | 565 EXPECT_EQ(ASCIIToUTF16("*"), render_text->GetDisplayText()); |
544 EXPECT_EQ(0U, render_text->cursor_position()); | 566 EXPECT_EQ(0U, render_text->cursor_position()); |
545 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 567 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
546 EXPECT_EQ(2U, render_text->cursor_position()); | 568 EXPECT_EQ(2U, render_text->cursor_position()); |
547 | 569 |
548 // Test index conversion and cursor validity with a valid surrogate pair. | 570 // Test index conversion and cursor validity with a valid surrogate pair. |
549 EXPECT_EQ(0U, render_text->TextIndexToDisplayIndex(0U)); | 571 EXPECT_EQ(0U, render_text->TextIndexToDisplayIndex(0U)); |
550 EXPECT_EQ(1U, render_text->TextIndexToDisplayIndex(1U)); | 572 EXPECT_EQ(1U, render_text->TextIndexToDisplayIndex(1U)); |
551 EXPECT_EQ(1U, render_text->TextIndexToDisplayIndex(2U)); | 573 EXPECT_EQ(1U, render_text->TextIndexToDisplayIndex(2U)); |
552 EXPECT_EQ(0U, render_text->DisplayIndexToTextIndex(0U)); | 574 EXPECT_EQ(0U, render_text->DisplayIndexToTextIndex(0U)); |
553 EXPECT_EQ(2U, render_text->DisplayIndexToTextIndex(1U)); | 575 EXPECT_EQ(2U, render_text->DisplayIndexToTextIndex(1U)); |
554 EXPECT_TRUE(render_text->IsValidCursorIndex(0U)); | 576 EXPECT_TRUE(render_text->IsValidCursorIndex(0U)); |
555 EXPECT_FALSE(render_text->IsValidCursorIndex(1U)); | 577 EXPECT_FALSE(render_text->IsValidCursorIndex(1U)); |
(...skipping 13 matching lines...) Expand all Loading... | |
569 static_cast<int>(render_text->GetGlyphBounds(0U).length())); | 591 static_cast<int>(render_text->GetGlyphBounds(0U).length())); |
570 | 592 |
571 // Cursoring is independent of underlying characters when text is obscured. | 593 // Cursoring is independent of underlying characters when text is obscured. |
572 const wchar_t* const texts[] = { | 594 const wchar_t* const texts[] = { |
573 kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, kRtlLtr, kRtlLtrRtl, | 595 kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, kRtlLtr, kRtlLtrRtl, |
574 L"hop on pop", // Check LTR word boundaries. | 596 L"hop on pop", // Check LTR word boundaries. |
575 L"\x05d0\x05d1 \x05d0\x05d2 \x05d1\x05d2", // Check RTL word boundaries. | 597 L"\x05d0\x05d1 \x05d0\x05d2 \x05d1\x05d2", // Check RTL word boundaries. |
576 }; | 598 }; |
577 for (size_t i = 0; i < arraysize(texts); ++i) { | 599 for (size_t i = 0; i < arraysize(texts); ++i) { |
578 base::string16 text = WideToUTF16(texts[i]); | 600 base::string16 text = WideToUTF16(texts[i]); |
579 TestVisualCursorMotionInObscuredField(render_text.get(), text, false); | 601 TestVisualCursorMotionInObscuredField(render_text.get(), text, |
580 TestVisualCursorMotionInObscuredField(render_text.get(), text, true); | 602 gfx::SELECTION_NONE); |
603 TestVisualCursorMotionInObscuredField(render_text.get(), text, | |
604 gfx::SELECTION_DEFAULT); | |
581 } | 605 } |
582 } | 606 } |
583 #endif // !defined(OS_MACOSX) | 607 #endif // !defined(OS_MACOSX) |
584 | 608 |
585 TEST_F(RenderTextTest, RevealObscuredText) { | 609 TEST_F(RenderTextTest, RevealObscuredText) { |
586 const base::string16 seuss = ASCIIToUTF16("hop on pop"); | 610 const base::string16 seuss = ASCIIToUTF16("hop on pop"); |
587 const base::string16 no_seuss = ASCIIToUTF16("**********"); | 611 const base::string16 no_seuss = ASCIIToUTF16("**********"); |
588 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 612 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
589 | 613 |
590 render_text->SetText(seuss); | 614 render_text->SetText(seuss); |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
889 render_text->set_truncate_length(3); | 913 render_text->set_truncate_length(3); |
890 render_text->SetObscured(true); | 914 render_text->SetObscured(true); |
891 render_text->SetText(WideToUTF16(L"abcdef")); | 915 render_text->SetText(WideToUTF16(L"abcdef")); |
892 EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text()); | 916 EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text()); |
893 EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetDisplayText()); | 917 EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetDisplayText()); |
894 } | 918 } |
895 | 919 |
896 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 | 920 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 |
897 #if !defined(OS_MACOSX) | 921 #if !defined(OS_MACOSX) |
898 TEST_F(RenderTextTest, TruncatedCursorMovementLTR) { | 922 TEST_F(RenderTextTest, TruncatedCursorMovementLTR) { |
899 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 923 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
tapted
2016/08/16 03:28:31
Changing this to RenderText::CreateInstanceForEdit
| |
900 render_text->set_truncate_length(2); | 924 render_text->set_truncate_length(2); |
901 render_text->SetText(WideToUTF16(L"abcd")); | 925 render_text->SetText(WideToUTF16(L"abcd")); |
902 | 926 |
903 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); | 927 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); |
904 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 928 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
905 EXPECT_EQ(SelectionModel(4, CURSOR_FORWARD), render_text->selection_model()); | 929 EXPECT_EQ(SelectionModel(4, CURSOR_FORWARD), render_text->selection_model()); |
906 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 930 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
907 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); | 931 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); |
908 | 932 |
909 std::vector<SelectionModel> expected; | 933 std::vector<SelectionModel> expected; |
910 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 934 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
911 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); | 935 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); |
912 // The cursor hops over the ellipsis and elided text to the line end. | 936 // The cursor hops over the ellipsis and elided text to the line end. |
913 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); | 937 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); |
914 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); | 938 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); |
915 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); | 939 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); |
916 | 940 |
917 expected.clear(); | 941 expected.clear(); |
918 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); | 942 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); |
919 // The cursor hops over the elided text to preceeding text. | 943 // The cursor hops over the elided text to preceeding text. |
920 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); | 944 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); |
921 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); | 945 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); |
922 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 946 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
923 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); | 947 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); |
924 } | 948 } |
925 | 949 |
926 TEST_F(RenderTextTest, TruncatedCursorMovementRTL) { | 950 TEST_F(RenderTextTest, TruncatedCursorMovementRTL) { |
927 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 951 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
928 render_text->set_truncate_length(2); | 952 render_text->set_truncate_length(2); |
929 render_text->SetText(WideToUTF16(L"\x5d0\x5d1\x5d2\x5d3")); | 953 render_text->SetText(WideToUTF16(L"\x5d0\x5d1\x5d2\x5d3")); |
930 | 954 |
931 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); | 955 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); |
932 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 956 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
933 EXPECT_EQ(SelectionModel(4, CURSOR_FORWARD), render_text->selection_model()); | 957 EXPECT_EQ(SelectionModel(4, CURSOR_FORWARD), render_text->selection_model()); |
934 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 958 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
935 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); | 959 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); |
936 | 960 |
937 std::vector<SelectionModel> expected; | 961 std::vector<SelectionModel> expected; |
938 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 962 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
939 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); | 963 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); |
940 // The cursor hops over the ellipsis and elided text to the line end. | 964 // The cursor hops over the ellipsis and elided text to the line end. |
941 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); | 965 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); |
942 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); | 966 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); |
943 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); | 967 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); |
944 | 968 |
945 expected.clear(); | 969 expected.clear(); |
946 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); | 970 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); |
947 // The cursor hops over the elided text to preceeding text. | 971 // The cursor hops over the elided text to preceeding text. |
948 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); | 972 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); |
949 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); | 973 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); |
950 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 974 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
951 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); | 975 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); |
952 } | 976 } |
953 #endif // !defined(OS_MACOSX) | 977 #endif // !defined(OS_MACOSX) |
954 | 978 |
979 TEST_F(RenderTextTest, MoveCursor_Character) { | |
980 std::unique_ptr<RenderText> render_text( | |
981 RenderText::CreateInstanceForEditing()); | |
982 render_text->SetText(WideToUTF16(L"123 456 789")); | |
983 std::vector<gfx::Range> expected; | |
984 | |
985 // SELECTION_NONE | |
986 render_text->SelectRange(gfx::Range(6)); | |
987 expected.push_back(gfx::Range(7)); | |
988 expected.push_back(gfx::Range(8)); | |
989 | |
990 // Move right twice. | |
991 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, | |
992 CURSOR_RIGHT, SELECTION_NONE, | |
993 &expected); | |
994 | |
995 // Move left twice. | |
996 expected.push_back(gfx::Range(7)); | |
997 expected.push_back(gfx::Range(6)); | |
998 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, | |
999 CURSOR_LEFT, SELECTION_NONE, &expected); | |
1000 | |
1001 // SELECTION_CARET | |
1002 render_text->SelectRange(gfx::Range(6)); | |
1003 expected.push_back(gfx::Range(6, 7)); | |
1004 | |
1005 // Move right. | |
1006 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, | |
1007 CURSOR_RIGHT, SELECTION_CARET, | |
1008 &expected); | |
1009 | |
1010 // Move left twice. | |
1011 expected.push_back(gfx::Range(6)); | |
1012 expected.push_back(gfx::Range(6, 5)); | |
1013 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, | |
1014 CURSOR_LEFT, SELECTION_CARET, | |
1015 &expected); | |
1016 | |
1017 // SELECTION_DEFAULT | |
1018 render_text->SelectRange(gfx::Range(6)); | |
1019 expected.push_back(gfx::Range(6, 7)); | |
1020 | |
1021 // Move right. | |
1022 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, | |
1023 CURSOR_RIGHT, SELECTION_DEFAULT, | |
1024 &expected); | |
1025 | |
1026 // Move left twice. | |
1027 expected.push_back(gfx::Range(6)); | |
1028 expected.push_back(gfx::Range(6, 5)); | |
1029 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, | |
1030 CURSOR_LEFT, SELECTION_DEFAULT, | |
1031 &expected); | |
1032 | |
1033 // SELECTION_EXTEND | |
1034 render_text->SelectRange(gfx::Range(6)); | |
1035 expected.push_back(gfx::Range(6, 7)); | |
1036 | |
1037 // Move right. | |
1038 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, | |
1039 CURSOR_RIGHT, SELECTION_EXTEND, | |
1040 &expected); | |
1041 | |
1042 // Move left twice. | |
1043 expected.push_back(gfx::Range(7, 6)); | |
1044 expected.push_back(gfx::Range(7, 5)); | |
1045 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, | |
1046 CURSOR_LEFT, SELECTION_EXTEND, | |
1047 &expected); | |
1048 } | |
1049 | |
1050 TEST_F(RenderTextTest, MoveCursor_Word) { | |
1051 std::unique_ptr<RenderText> render_text( | |
1052 RenderText::CreateInstanceForEditing()); | |
1053 render_text->SetText(WideToUTF16(L"123 456 789")); | |
1054 std::vector<gfx::Range> expected; | |
1055 | |
1056 // SELECTION_NONE | |
1057 render_text->SelectRange(gfx::Range(6)); | |
1058 expected.push_back(gfx::Range(4)); | |
1059 expected.push_back(gfx::Range(0)); | |
1060 | |
1061 // Move left twice by word. | |
1062 RunMoveCursorTestAndClearExpectations(render_text.get(), WORD_BREAK, | |
1063 CURSOR_LEFT, SELECTION_NONE, &expected); | |
1064 | |
1065 // Move right twice by word. | |
1066 expected.push_back(gfx::Range(3)); | |
1067 expected.push_back(gfx::Range(7)); | |
1068 RunMoveCursorTestAndClearExpectations( | |
1069 render_text.get(), WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE, &expected); | |
1070 | |
1071 // SELECTION_CARET | |
1072 render_text->SelectRange(gfx::Range(6)); | |
1073 expected.push_back(gfx::Range(6, 4)); | |
1074 | |
1075 // Move left. | |
1076 RunMoveCursorTestAndClearExpectations( | |
1077 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_CARET, &expected); | |
1078 | |
1079 // Move right twice. | |
1080 expected.push_back(gfx::Range(6)); | |
1081 expected.push_back(gfx::Range(6, 7)); | |
1082 RunMoveCursorTestAndClearExpectations( | |
1083 render_text.get(), WORD_BREAK, CURSOR_RIGHT, SELECTION_CARET, &expected); | |
1084 | |
1085 expected.push_back(gfx::Range(6)); | |
1086 | |
1087 // Move left. | |
1088 RunMoveCursorTestAndClearExpectations( | |
1089 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_CARET, &expected); | |
1090 | |
1091 // SELECTION_DEFAULT | |
1092 render_text->SelectRange(gfx::Range(6)); | |
1093 expected.push_back(gfx::Range(6, 4)); | |
1094 | |
1095 // Move left. | |
1096 RunMoveCursorTestAndClearExpectations( | |
1097 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_DEFAULT, &expected); | |
1098 | |
1099 // Move right twice. | |
1100 expected.push_back(gfx::Range(6, 7)); | |
1101 expected.push_back(gfx::Range(6, 11)); | |
1102 RunMoveCursorTestAndClearExpectations(render_text.get(), WORD_BREAK, | |
1103 CURSOR_RIGHT, SELECTION_DEFAULT, | |
1104 &expected); | |
1105 | |
1106 expected.push_back(gfx::Range(6, 8)); | |
1107 | |
1108 // Move left. | |
1109 RunMoveCursorTestAndClearExpectations( | |
1110 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_DEFAULT, &expected); | |
1111 | |
1112 // // SELECTION_EXTEND | |
1113 render_text->SelectRange(gfx::Range(6)); | |
1114 expected.push_back(gfx::Range(6, 4)); | |
1115 | |
1116 // Move left. | |
1117 RunMoveCursorTestAndClearExpectations( | |
1118 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_EXTEND, &expected); | |
1119 | |
1120 // Move right twice. | |
1121 expected.push_back(gfx::Range(4, 7)); | |
1122 expected.push_back(gfx::Range(4, 11)); | |
1123 RunMoveCursorTestAndClearExpectations( | |
1124 render_text.get(), WORD_BREAK, CURSOR_RIGHT, SELECTION_EXTEND, &expected); | |
1125 | |
1126 expected.push_back(gfx::Range(4, 8)); | |
1127 | |
1128 // Move left. | |
1129 RunMoveCursorTestAndClearExpectations( | |
1130 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_EXTEND, &expected); | |
1131 } | |
1132 | |
1133 TEST_F(RenderTextTest, MoveCursor_Line) { | |
1134 std::unique_ptr<RenderText> render_text( | |
1135 RenderText::CreateInstanceForEditing()); | |
1136 render_text->SetText(WideToUTF16(L"123 456 789")); | |
1137 std::vector<gfx::Range> expected; | |
1138 | |
1139 // SELECTION_NONE | |
1140 render_text->SelectRange(gfx::Range(6)); | |
1141 expected.push_back(gfx::Range(11)); | |
1142 expected.push_back(gfx::Range(11)); | |
1143 | |
1144 // Move right twice. | |
1145 RunMoveCursorTestAndClearExpectations( | |
1146 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE, &expected); | |
1147 | |
1148 // Move left twice. | |
1149 expected.push_back(gfx::Range(0)); | |
1150 expected.push_back(gfx::Range(0)); | |
1151 RunMoveCursorTestAndClearExpectations(render_text.get(), LINE_BREAK, | |
1152 CURSOR_LEFT, SELECTION_NONE, &expected); | |
1153 | |
1154 // SELECTION_CARET | |
1155 render_text->SelectRange(gfx::Range(6)); | |
1156 expected.push_back(gfx::Range(6, 11)); | |
1157 | |
1158 // Move right. | |
1159 RunMoveCursorTestAndClearExpectations( | |
1160 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_CARET, &expected); | |
1161 | |
1162 // Move left twice. | |
1163 expected.push_back(gfx::Range(6)); | |
1164 expected.push_back(gfx::Range(6, 0)); | |
1165 RunMoveCursorTestAndClearExpectations( | |
1166 render_text.get(), LINE_BREAK, CURSOR_LEFT, SELECTION_CARET, &expected); | |
1167 | |
1168 expected.push_back(gfx::Range(6)); | |
1169 | |
1170 // Move right. | |
1171 RunMoveCursorTestAndClearExpectations( | |
1172 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_CARET, &expected); | |
1173 | |
1174 // SELECTION_DEFAULT | |
1175 render_text->SelectRange(gfx::Range(6)); | |
1176 expected.push_back(gfx::Range(6, 11)); | |
1177 | |
1178 // Move right. | |
1179 RunMoveCursorTestAndClearExpectations(render_text.get(), LINE_BREAK, | |
1180 CURSOR_RIGHT, SELECTION_DEFAULT, | |
1181 &expected); | |
1182 | |
1183 // Move left twice. | |
1184 expected.push_back(gfx::Range(6, 0)); | |
1185 expected.push_back(gfx::Range(6, 0)); | |
1186 RunMoveCursorTestAndClearExpectations( | |
1187 render_text.get(), LINE_BREAK, CURSOR_LEFT, SELECTION_DEFAULT, &expected); | |
1188 | |
1189 expected.push_back(gfx::Range(6, 11)); | |
1190 // Move right. | |
1191 RunMoveCursorTestAndClearExpectations(render_text.get(), LINE_BREAK, | |
1192 CURSOR_RIGHT, SELECTION_DEFAULT, | |
1193 &expected); | |
1194 | |
1195 // SELECTION_EXTEND | |
1196 render_text->SelectRange(gfx::Range(6)); | |
1197 expected.push_back(gfx::Range(6, 11)); | |
1198 | |
1199 // Move right. | |
1200 RunMoveCursorTestAndClearExpectations( | |
1201 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_EXTEND, &expected); | |
1202 | |
1203 // Move left twice. | |
1204 expected.push_back(gfx::Range(11, 0)); | |
1205 expected.push_back(gfx::Range(11, 0)); | |
1206 RunMoveCursorTestAndClearExpectations( | |
1207 render_text.get(), LINE_BREAK, CURSOR_LEFT, SELECTION_EXTEND, &expected); | |
1208 | |
1209 expected.push_back(gfx::Range(0, 11)); | |
1210 // Move right. | |
1211 RunMoveCursorTestAndClearExpectations( | |
1212 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_EXTEND, &expected); | |
1213 } | |
1214 | |
955 TEST_F(RenderTextTest, GetDisplayTextDirection) { | 1215 TEST_F(RenderTextTest, GetDisplayTextDirection) { |
956 struct { | 1216 struct { |
957 const wchar_t* text; | 1217 const wchar_t* text; |
958 const base::i18n::TextDirection text_direction; | 1218 const base::i18n::TextDirection text_direction; |
959 } cases[] = { | 1219 } cases[] = { |
960 // Blank strings and those with no/weak directionality default to LTR. | 1220 // Blank strings and those with no/weak directionality default to LTR. |
961 { L"", base::i18n::LEFT_TO_RIGHT }, | 1221 { L"", base::i18n::LEFT_TO_RIGHT }, |
962 { kWeak, base::i18n::LEFT_TO_RIGHT }, | 1222 { kWeak, base::i18n::LEFT_TO_RIGHT }, |
963 // Strings that begin with strong LTR characters. | 1223 // Strings that begin with strong LTR characters. |
964 { kLtr, base::i18n::LEFT_TO_RIGHT }, | 1224 { kLtr, base::i18n::LEFT_TO_RIGHT }, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1001 render_text->SetDirectionalityMode(DIRECTIONALITY_FROM_TEXT); | 1261 render_text->SetDirectionalityMode(DIRECTIONALITY_FROM_TEXT); |
1002 render_text->SetText(WideToUTF16(kLtr)); | 1262 render_text->SetText(WideToUTF16(kLtr)); |
1003 EXPECT_EQ(render_text->GetDisplayTextDirection(), base::i18n::LEFT_TO_RIGHT); | 1263 EXPECT_EQ(render_text->GetDisplayTextDirection(), base::i18n::LEFT_TO_RIGHT); |
1004 render_text->SetText(WideToUTF16(kRtl)); | 1264 render_text->SetText(WideToUTF16(kRtl)); |
1005 EXPECT_EQ(render_text->GetDisplayTextDirection(), base::i18n::RIGHT_TO_LEFT); | 1265 EXPECT_EQ(render_text->GetDisplayTextDirection(), base::i18n::RIGHT_TO_LEFT); |
1006 } | 1266 } |
1007 | 1267 |
1008 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 | 1268 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 |
1009 #if !defined(OS_MACOSX) | 1269 #if !defined(OS_MACOSX) |
1010 TEST_F(RenderTextTest, MoveCursorLeftRightInLtr) { | 1270 TEST_F(RenderTextTest, MoveCursorLeftRightInLtr) { |
1011 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1271 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
tapted
2016/08/16 03:28:31
same here, and a bunch of things below
| |
1012 | 1272 |
1013 // Pure LTR. | 1273 // Pure LTR. |
1014 render_text->SetText(ASCIIToUTF16("abc")); | 1274 render_text->SetText(ASCIIToUTF16("abc")); |
1015 // |expected| saves the expected SelectionModel when moving cursor from left | 1275 // |expected| saves the expected SelectionModel when moving cursor from left |
1016 // to right. | 1276 // to right. |
1017 std::vector<SelectionModel> expected; | 1277 std::vector<SelectionModel> expected; |
1018 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 1278 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
1019 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); | 1279 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); |
1020 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); | 1280 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); |
1021 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); | 1281 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1077 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); | 1337 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); |
1078 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); | 1338 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); |
1079 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 1339 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
1080 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); | 1340 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); |
1081 } | 1341 } |
1082 | 1342 |
1083 TEST_F(RenderTextTest, MoveCursorLeftRightInRtl) { | 1343 TEST_F(RenderTextTest, MoveCursorLeftRightInRtl) { |
1084 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1344 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1085 // Pure RTL. | 1345 // Pure RTL. |
1086 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2")); | 1346 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2")); |
1087 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 1347 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1088 std::vector<SelectionModel> expected; | 1348 std::vector<SelectionModel> expected; |
1089 | 1349 |
1090 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 1350 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
1091 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); | 1351 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); |
1092 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); | 1352 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); |
1093 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); | 1353 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); |
1094 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | 1354 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
1095 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); | 1355 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); |
1096 | 1356 |
1097 expected.clear(); | 1357 expected.clear(); |
1098 | 1358 |
1099 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | 1359 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
1100 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); | 1360 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); |
1101 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); | 1361 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); |
1102 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); | 1362 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); |
1103 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 1363 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
1104 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); | 1364 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); |
1105 } | 1365 } |
1106 | 1366 |
1107 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtr) { | 1367 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtr) { |
1108 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1368 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1109 // RTL-LTR | 1369 // RTL-LTR |
1110 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2" L"abc")); | 1370 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2" L"abc")); |
1111 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 1371 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1112 std::vector<SelectionModel> expected; | 1372 std::vector<SelectionModel> expected; |
1113 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 1373 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
1114 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); | 1374 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); |
1115 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); | 1375 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); |
1116 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); | 1376 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); |
1117 expected.push_back(SelectionModel(5, CURSOR_FORWARD)); | 1377 expected.push_back(SelectionModel(5, CURSOR_FORWARD)); |
1118 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); | 1378 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); |
1119 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | 1379 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
1120 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); | 1380 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); |
1121 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); | 1381 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); |
1122 | 1382 |
1123 expected.clear(); | 1383 expected.clear(); |
1124 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); | 1384 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); |
1125 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); | 1385 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); |
1126 expected.push_back(SelectionModel(5, CURSOR_BACKWARD)); | 1386 expected.push_back(SelectionModel(5, CURSOR_BACKWARD)); |
1127 expected.push_back(SelectionModel(6, CURSOR_BACKWARD)); | 1387 expected.push_back(SelectionModel(6, CURSOR_BACKWARD)); |
1128 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); | 1388 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); |
1129 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); | 1389 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); |
1130 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); | 1390 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); |
1131 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 1391 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
1132 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); | 1392 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); |
1133 } | 1393 } |
1134 | 1394 |
1135 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtrRtl) { | 1395 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtrRtl) { |
1136 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1396 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1137 // RTL-LTR-RTL. | 1397 // RTL-LTR-RTL. |
1138 render_text->SetText(WideToUTF16(L"\x05d0" L"a" L"\x05d1")); | 1398 render_text->SetText(WideToUTF16(L"\x05d0" L"a" L"\x05d1")); |
1139 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 1399 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1140 std::vector<SelectionModel> expected; | 1400 std::vector<SelectionModel> expected; |
1141 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 1401 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
1142 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); | 1402 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); |
1143 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); | 1403 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); |
1144 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); | 1404 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); |
1145 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | 1405 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
1146 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); | 1406 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); |
1147 | 1407 |
1148 expected.clear(); | 1408 expected.clear(); |
1149 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | 1409 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
1150 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); | 1410 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); |
1151 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); | 1411 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); |
1152 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); | 1412 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); |
1153 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 1413 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
1154 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); | 1414 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); |
1155 } | 1415 } |
1156 | 1416 |
1157 TEST_F(RenderTextTest, MoveCursorLeftRight_ComplexScript) { | 1417 TEST_F(RenderTextTest, MoveCursorLeftRight_ComplexScript) { |
1158 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1418 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1159 | 1419 |
1160 render_text->SetText(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915")); | 1420 render_text->SetText(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915")); |
1161 EXPECT_EQ(0U, render_text->cursor_position()); | 1421 EXPECT_EQ(0U, render_text->cursor_position()); |
1162 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1422 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1163 EXPECT_EQ(2U, render_text->cursor_position()); | 1423 EXPECT_EQ(2U, render_text->cursor_position()); |
1164 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1424 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1165 EXPECT_EQ(4U, render_text->cursor_position()); | 1425 EXPECT_EQ(4U, render_text->cursor_position()); |
1166 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1426 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1167 EXPECT_EQ(5U, render_text->cursor_position()); | 1427 EXPECT_EQ(5U, render_text->cursor_position()); |
1168 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1428 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1169 EXPECT_EQ(5U, render_text->cursor_position()); | 1429 EXPECT_EQ(5U, render_text->cursor_position()); |
1170 | 1430 |
1171 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1431 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1172 EXPECT_EQ(4U, render_text->cursor_position()); | 1432 EXPECT_EQ(4U, render_text->cursor_position()); |
1173 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1433 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1174 EXPECT_EQ(2U, render_text->cursor_position()); | 1434 EXPECT_EQ(2U, render_text->cursor_position()); |
1175 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1435 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1176 EXPECT_EQ(0U, render_text->cursor_position()); | 1436 EXPECT_EQ(0U, render_text->cursor_position()); |
1177 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1437 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1178 EXPECT_EQ(0U, render_text->cursor_position()); | 1438 EXPECT_EQ(0U, render_text->cursor_position()); |
1179 } | 1439 } |
1180 | 1440 |
1181 TEST_F(RenderTextTest, MoveCursorLeftRight_MeiryoUILigatures) { | 1441 TEST_F(RenderTextTest, MoveCursorLeftRight_MeiryoUILigatures) { |
1182 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1442 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1183 // Meiryo UI uses single-glyph ligatures for 'ff' and 'ffi', but each letter | 1443 // 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. | 1444 // (code point) has unique bounds, so mid-glyph cursoring should be possible. |
1185 render_text->SetFontList(FontList("Meiryo UI, 12px")); | 1445 render_text->SetFontList(FontList("Meiryo UI, 12px")); |
1186 render_text->SetText(WideToUTF16(L"ff ffi")); | 1446 render_text->SetText(WideToUTF16(L"ff ffi")); |
1187 EXPECT_EQ(0U, render_text->cursor_position()); | 1447 EXPECT_EQ(0U, render_text->cursor_position()); |
1188 for (size_t i = 0; i < render_text->text().length(); ++i) { | 1448 for (size_t i = 0; i < render_text->text().length(); ++i) { |
1189 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1449 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1190 EXPECT_EQ(i + 1, render_text->cursor_position()); | 1450 EXPECT_EQ(i + 1, render_text->cursor_position()); |
1191 } | 1451 } |
1192 EXPECT_EQ(6U, render_text->cursor_position()); | 1452 EXPECT_EQ(6U, render_text->cursor_position()); |
1193 } | 1453 } |
1194 | 1454 |
1195 TEST_F(RenderTextTest, GraphemePositions) { | 1455 TEST_F(RenderTextTest, GraphemePositions) { |
1196 // LTR 2-character grapheme, LTR abc, LTR 2-character grapheme. | 1456 // LTR 2-character grapheme, LTR abc, LTR 2-character grapheme. |
1197 const base::string16 kText1 = | 1457 const base::string16 kText1 = |
1198 WideToUTF16(L"\x0915\x093f" L"abc" L"\x0915\x093f"); | 1458 WideToUTF16(L"\x0915\x093f" L"abc" L"\x0915\x093f"); |
1199 | 1459 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1285 for (size_t i = 0; i < arraysize(cases); i++) { | 1545 for (size_t i = 0; i < arraysize(cases); i++) { |
1286 SCOPED_TRACE(base::StringPrintf("Testing cases[%" PRIuS "]", i)); | 1546 SCOPED_TRACE(base::StringPrintf("Testing cases[%" PRIuS "]", i)); |
1287 render_text->SetText(cases[i]); | 1547 render_text->SetText(cases[i]); |
1288 EXPECT_TRUE(render_text->IsValidLogicalIndex(1)); | 1548 EXPECT_TRUE(render_text->IsValidLogicalIndex(1)); |
1289 EXPECT_FALSE(render_text->IsValidCursorIndex(1)); | 1549 EXPECT_FALSE(render_text->IsValidCursorIndex(1)); |
1290 EXPECT_TRUE(render_text->SelectRange(Range(2, 1))); | 1550 EXPECT_TRUE(render_text->SelectRange(Range(2, 1))); |
1291 EXPECT_EQ(Range(2, 1), render_text->selection()); | 1551 EXPECT_EQ(Range(2, 1), render_text->selection()); |
1292 EXPECT_EQ(1U, render_text->cursor_position()); | 1552 EXPECT_EQ(1U, render_text->cursor_position()); |
1293 // Although selection bounds may be set within a multi-character grapheme, | 1553 // Although selection bounds may be set within a multi-character grapheme, |
1294 // cursor movement (e.g. via arrow key) should avoid those indices. | 1554 // cursor movement (e.g. via arrow key) should avoid those indices. |
1295 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1555 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1296 EXPECT_EQ(0U, render_text->cursor_position()); | 1556 EXPECT_EQ(0U, render_text->cursor_position()); |
1297 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1557 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1298 EXPECT_EQ(2U, render_text->cursor_position()); | 1558 EXPECT_EQ(2U, render_text->cursor_position()); |
1299 } | 1559 } |
1300 } | 1560 } |
1301 | 1561 |
1302 TEST_F(RenderTextTest, FindCursorPosition) { | 1562 TEST_F(RenderTextTest, FindCursorPosition) { |
1303 const wchar_t* kTestStrings[] = { kLtrRtl, kLtrRtlLtr, kRtlLtr, kRtlLtrRtl }; | 1563 const wchar_t* kTestStrings[] = { kLtrRtl, kLtrRtlLtr, kRtlLtr, kRtlLtrRtl }; |
1304 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1564 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1305 render_text->SetDisplayRect(Rect(0, 0, 100, 20)); | 1565 render_text->SetDisplayRect(Rect(0, 0, 100, 20)); |
1306 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { | 1566 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { |
1307 SCOPED_TRACE(base::StringPrintf("Testing case[%" PRIuS "]", i)); | 1567 SCOPED_TRACE(base::StringPrintf("Testing case[%" PRIuS "]", i)); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1389 EXPECT_EQ(render_text->selection_model(), expected_reversed); | 1649 EXPECT_EQ(render_text->selection_model(), expected_reversed); |
1390 } | 1650 } |
1391 } | 1651 } |
1392 | 1652 |
1393 EXPECT_EQ(was_rtl, base::i18n::IsRTL()); | 1653 EXPECT_EQ(was_rtl, base::i18n::IsRTL()); |
1394 } | 1654 } |
1395 | 1655 |
1396 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 | 1656 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 |
1397 #if !defined(OS_MACOSX) | 1657 #if !defined(OS_MACOSX) |
1398 TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) { | 1658 TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) { |
1399 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1659 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
tapted
2016/08/16 03:28:31
and here..
| |
1400 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); | 1660 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); |
1401 // Left arrow on select ranging (6, 4). | 1661 // Left arrow on select ranging (6, 4). |
1402 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 1662 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1403 EXPECT_EQ(Range(6), render_text->selection()); | 1663 EXPECT_EQ(Range(6), render_text->selection()); |
1404 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1664 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1405 EXPECT_EQ(Range(4), render_text->selection()); | 1665 EXPECT_EQ(Range(4), render_text->selection()); |
1406 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1666 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1407 EXPECT_EQ(Range(5), render_text->selection()); | 1667 EXPECT_EQ(Range(5), render_text->selection()); |
1408 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1668 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1409 EXPECT_EQ(Range(6), render_text->selection()); | 1669 EXPECT_EQ(Range(6), render_text->selection()); |
1410 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, true); | 1670 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, |
1671 gfx::SELECTION_DEFAULT); | |
1411 EXPECT_EQ(Range(6, 5), render_text->selection()); | 1672 EXPECT_EQ(Range(6, 5), render_text->selection()); |
1412 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, true); | 1673 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, |
1674 gfx::SELECTION_DEFAULT); | |
1413 EXPECT_EQ(Range(6, 4), render_text->selection()); | 1675 EXPECT_EQ(Range(6, 4), render_text->selection()); |
1414 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1676 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1415 EXPECT_EQ(Range(6), render_text->selection()); | 1677 EXPECT_EQ(Range(6), render_text->selection()); |
1416 | 1678 |
1417 // Right arrow on select ranging (4, 6). | 1679 // Right arrow on select ranging (4, 6). |
1418 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 1680 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1419 EXPECT_EQ(Range(0), render_text->selection()); | 1681 EXPECT_EQ(Range(0), render_text->selection()); |
1420 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1682 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1421 EXPECT_EQ(Range(1), render_text->selection()); | 1683 EXPECT_EQ(Range(1), render_text->selection()); |
1422 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1684 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1423 EXPECT_EQ(Range(2), render_text->selection()); | 1685 EXPECT_EQ(Range(2), render_text->selection()); |
1424 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1686 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1425 EXPECT_EQ(Range(3), render_text->selection()); | 1687 EXPECT_EQ(Range(3), render_text->selection()); |
1426 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1688 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1427 EXPECT_EQ(Range(5), render_text->selection()); | 1689 EXPECT_EQ(Range(5), render_text->selection()); |
1428 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1690 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1429 EXPECT_EQ(Range(4), render_text->selection()); | 1691 EXPECT_EQ(Range(4), render_text->selection()); |
1430 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, true); | 1692 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, gfx::SELECTION_DEFAULT); |
1431 EXPECT_EQ(Range(4, 5), render_text->selection()); | 1693 EXPECT_EQ(Range(4, 5), render_text->selection()); |
1432 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, true); | 1694 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, gfx::SELECTION_DEFAULT); |
1433 EXPECT_EQ(Range(4, 6), render_text->selection()); | 1695 EXPECT_EQ(Range(4, 6), render_text->selection()); |
1434 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1696 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1435 EXPECT_EQ(Range(4), render_text->selection()); | 1697 EXPECT_EQ(Range(4), render_text->selection()); |
1436 } | 1698 } |
1437 #endif // !defined(OS_MACOSX) | 1699 #endif // !defined(OS_MACOSX) |
1438 | 1700 |
1439 TEST_F(RenderTextTest, CenteredDisplayOffset) { | 1701 TEST_F(RenderTextTest, CenteredDisplayOffset) { |
1440 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1702 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1441 render_text->SetText(ASCIIToUTF16("abcdefghij")); | 1703 render_text->SetText(ASCIIToUTF16("abcdefghij")); |
1442 render_text->SetHorizontalAlignment(ALIGN_CENTER); | 1704 render_text->SetHorizontalAlignment(ALIGN_CENTER); |
1443 | 1705 |
1444 const int kEnlargement = 10; | 1706 const int kEnlargement = 10; |
(...skipping 28 matching lines...) Expand all Loading... | |
1473 EXPECT_EQ(display_rect.right(), | 1735 EXPECT_EQ(display_rect.right(), |
1474 render_text->GetUpdatedCursorBounds().right()); | 1736 render_text->GetUpdatedCursorBounds().right()); |
1475 #endif // !defined(OS_MACOSX) | 1737 #endif // !defined(OS_MACOSX) |
1476 } | 1738 } |
1477 | 1739 |
1478 void MoveLeftRightByWordVerifier(RenderText* render_text, | 1740 void MoveLeftRightByWordVerifier(RenderText* render_text, |
1479 const wchar_t* str) { | 1741 const wchar_t* str) { |
1480 render_text->SetText(WideToUTF16(str)); | 1742 render_text->SetText(WideToUTF16(str)); |
1481 | 1743 |
1482 // Test moving by word from left ro right. | 1744 // Test moving by word from left ro right. |
1483 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 1745 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1484 bool first_word = true; | 1746 bool first_word = true; |
1485 while (true) { | 1747 while (true) { |
1486 // First, test moving by word from a word break position, such as from | 1748 // First, test moving by word from a word break position, such as from |
1487 // "|abc def" to "abc| def". | 1749 // "|abc def" to "abc| def". |
1488 SelectionModel start = render_text->selection_model(); | 1750 SelectionModel start = render_text->selection_model(); |
1489 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1751 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1490 SelectionModel end = render_text->selection_model(); | 1752 SelectionModel end = render_text->selection_model(); |
1491 if (end == start) // reach the end. | 1753 if (end == start) // reach the end. |
1492 break; | 1754 break; |
1493 | 1755 |
1494 // For testing simplicity, each word is a 3-character word. | 1756 // For testing simplicity, each word is a 3-character word. |
1495 int num_of_character_moves = first_word ? 3 : 4; | 1757 int num_of_character_moves = first_word ? 3 : 4; |
1496 first_word = false; | 1758 first_word = false; |
1497 render_text->MoveCursorTo(start); | 1759 render_text->MoveCursorTo(start); |
1498 for (int j = 0; j < num_of_character_moves; ++j) | 1760 for (int j = 0; j < num_of_character_moves; ++j) |
1499 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1761 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, |
1762 gfx::SELECTION_NONE); | |
1500 EXPECT_EQ(end, render_text->selection_model()); | 1763 EXPECT_EQ(end, render_text->selection_model()); |
1501 | 1764 |
1502 // Then, test moving by word from positions inside the word, such as from | 1765 // 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". | 1766 // "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) { | 1767 for (int j = 1; j < num_of_character_moves; ++j) { |
1505 render_text->MoveCursorTo(start); | 1768 render_text->MoveCursorTo(start); |
1506 for (int k = 0; k < j; ++k) | 1769 for (int k = 0; k < j; ++k) |
1507 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1770 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, |
1508 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1771 gfx::SELECTION_NONE); |
1772 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); | |
1509 EXPECT_EQ(end, render_text->selection_model()); | 1773 EXPECT_EQ(end, render_text->selection_model()); |
1510 } | 1774 } |
1511 } | 1775 } |
1512 | 1776 |
1513 // Test moving by word from right to left. | 1777 // Test moving by word from right to left. |
1514 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 1778 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1515 first_word = true; | 1779 first_word = true; |
1516 while (true) { | 1780 while (true) { |
1517 SelectionModel start = render_text->selection_model(); | 1781 SelectionModel start = render_text->selection_model(); |
1518 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); | 1782 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1519 SelectionModel end = render_text->selection_model(); | 1783 SelectionModel end = render_text->selection_model(); |
1520 if (end == start) // reach the end. | 1784 if (end == start) // reach the end. |
1521 break; | 1785 break; |
1522 | 1786 |
1523 int num_of_character_moves = first_word ? 3 : 4; | 1787 int num_of_character_moves = first_word ? 3 : 4; |
1524 first_word = false; | 1788 first_word = false; |
1525 render_text->MoveCursorTo(start); | 1789 render_text->MoveCursorTo(start); |
1526 for (int j = 0; j < num_of_character_moves; ++j) | 1790 for (int j = 0; j < num_of_character_moves; ++j) |
1527 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1791 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, |
1792 gfx::SELECTION_NONE); | |
1528 EXPECT_EQ(end, render_text->selection_model()); | 1793 EXPECT_EQ(end, render_text->selection_model()); |
1529 | 1794 |
1530 for (int j = 1; j < num_of_character_moves; ++j) { | 1795 for (int j = 1; j < num_of_character_moves; ++j) { |
1531 render_text->MoveCursorTo(start); | 1796 render_text->MoveCursorTo(start); |
1532 for (int k = 0; k < j; ++k) | 1797 for (int k = 0; k < j; ++k) |
1533 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1798 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, |
1534 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); | 1799 gfx::SELECTION_NONE); |
1800 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); | |
1535 EXPECT_EQ(end, render_text->selection_model()); | 1801 EXPECT_EQ(end, render_text->selection_model()); |
1536 } | 1802 } |
1537 } | 1803 } |
1538 } | 1804 } |
1539 | 1805 |
1540 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 | 1806 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 |
1541 #if !defined(OS_MACOSX) | 1807 #if !defined(OS_MACOSX) |
1542 // TODO(msw): Make these work on Windows. | 1808 // TODO(msw): Make these work on Windows. |
1543 #if !defined(OS_WIN) | 1809 #if !defined(OS_WIN) |
1544 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText) { | 1810 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1577 } | 1843 } |
1578 | 1844 |
1579 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText_TestEndOfText) { | 1845 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText_TestEndOfText) { |
1580 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1846 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1581 | 1847 |
1582 render_text->SetText(WideToUTF16(L"ab\x05E1")); | 1848 render_text->SetText(WideToUTF16(L"ab\x05E1")); |
1583 // Moving the cursor by word from "abC|" to the left should return "|abC". | 1849 // 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 | 1850 // But since end of text is always treated as a word break, it returns |
1585 // position "ab|C". | 1851 // position "ab|C". |
1586 // TODO(xji): Need to make it work as expected. | 1852 // TODO(xji): Need to make it work as expected. |
1587 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 1853 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1588 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); | 1854 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1589 // EXPECT_EQ(SelectionModel(), render_text->selection_model()); | 1855 // EXPECT_EQ(SelectionModel(), render_text->selection_model()); |
1590 | 1856 |
1591 // Moving the cursor by word from "|abC" to the right returns "abC|". | 1857 // Moving the cursor by word from "|abC" to the right returns "abC|". |
1592 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 1858 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1593 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1859 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1594 EXPECT_EQ(SelectionModel(3, CURSOR_FORWARD), render_text->selection_model()); | 1860 EXPECT_EQ(SelectionModel(3, CURSOR_FORWARD), render_text->selection_model()); |
1595 | 1861 |
1596 render_text->SetText(WideToUTF16(L"\x05E1\x05E2" L"a")); | 1862 render_text->SetText(WideToUTF16(L"\x05E1\x05E2" L"a")); |
1597 // For logical text "BCa", moving the cursor by word from "aCB|" to the left | 1863 // For logical text "BCa", moving the cursor by word from "aCB|" to the left |
1598 // returns "|aCB". | 1864 // returns "|aCB". |
1599 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 1865 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1600 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); | 1866 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1601 EXPECT_EQ(SelectionModel(3, CURSOR_FORWARD), render_text->selection_model()); | 1867 EXPECT_EQ(SelectionModel(3, CURSOR_FORWARD), render_text->selection_model()); |
1602 | 1868 |
1603 // Moving the cursor by word from "|aCB" to the right should return "aCB|". | 1869 // 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 | 1870 // But since end of text is always treated as a word break, it returns |
1605 // position "a|CB". | 1871 // position "a|CB". |
1606 // TODO(xji): Need to make it work as expected. | 1872 // TODO(xji): Need to make it work as expected. |
1607 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 1873 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1608 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1874 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1609 // EXPECT_EQ(SelectionModel(), render_text->selection_model()); | 1875 // EXPECT_EQ(SelectionModel(), render_text->selection_model()); |
1610 } | 1876 } |
1611 | 1877 |
1612 TEST_F(RenderTextTest, MoveLeftRightByWordInTextWithMultiSpaces) { | 1878 TEST_F(RenderTextTest, MoveLeftRightByWordInTextWithMultiSpaces) { |
1613 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1879 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1614 render_text->SetText(WideToUTF16(L"abc def")); | 1880 render_text->SetText(WideToUTF16(L"abc def")); |
1615 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD)); | 1881 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD)); |
1616 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1882 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1617 EXPECT_EQ(11U, render_text->cursor_position()); | 1883 EXPECT_EQ(11U, render_text->cursor_position()); |
1618 | 1884 |
1619 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD)); | 1885 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD)); |
1620 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); | 1886 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1621 EXPECT_EQ(0U, render_text->cursor_position()); | 1887 EXPECT_EQ(0U, render_text->cursor_position()); |
1622 } | 1888 } |
1623 #endif // !defined(OS_WIN) | 1889 #endif // !defined(OS_WIN) |
1624 | 1890 |
1625 TEST_F(RenderTextTest, MoveLeftRightByWordInChineseText) { | 1891 TEST_F(RenderTextTest, MoveLeftRightByWordInChineseText) { |
1626 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1892 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1627 render_text->SetText(WideToUTF16(L"\x6211\x4EEC\x53BB\x516C\x56ED\x73A9")); | 1893 render_text->SetText(WideToUTF16(L"\x6211\x4EEC\x53BB\x516C\x56ED\x73A9")); |
1628 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 1894 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, gfx::SELECTION_NONE); |
1629 EXPECT_EQ(0U, render_text->cursor_position()); | 1895 EXPECT_EQ(0U, render_text->cursor_position()); |
1630 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1896 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1631 EXPECT_EQ(2U, render_text->cursor_position()); | 1897 EXPECT_EQ(2U, render_text->cursor_position()); |
1632 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1898 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1633 EXPECT_EQ(3U, render_text->cursor_position()); | 1899 EXPECT_EQ(3U, render_text->cursor_position()); |
1634 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1900 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1635 EXPECT_EQ(5U, render_text->cursor_position()); | 1901 EXPECT_EQ(5U, render_text->cursor_position()); |
1636 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1902 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1637 EXPECT_EQ(6U, render_text->cursor_position()); | 1903 EXPECT_EQ(6U, render_text->cursor_position()); |
1638 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1904 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, gfx::SELECTION_NONE); |
1639 EXPECT_EQ(6U, render_text->cursor_position()); | 1905 EXPECT_EQ(6U, render_text->cursor_position()); |
1640 } | 1906 } |
1641 #endif // !defined(OS_MACOSX) | 1907 #endif // !defined(OS_MACOSX) |
1642 | 1908 |
1643 TEST_F(RenderTextTest, StringSizeSanity) { | 1909 TEST_F(RenderTextTest, StringSizeSanity) { |
1644 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1910 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1645 render_text->SetText(UTF8ToUTF16("Hello World")); | 1911 render_text->SetText(UTF8ToUTF16("Hello World")); |
1646 const Size string_size = render_text->GetStringSize(); | 1912 const Size string_size = render_text->GetStringSize(); |
1647 EXPECT_GT(string_size.width(), 0); | 1913 EXPECT_GT(string_size.width(), 0); |
1648 EXPECT_GT(string_size.height(), 0); | 1914 EXPECT_GT(string_size.height(), 0); |
(...skipping 1782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3431 EXPECT_FALSE(backend.paint().isLCDRenderText()); | 3697 EXPECT_FALSE(backend.paint().isLCDRenderText()); |
3432 backend.GetHarfbuzzRunList()->runs()[0]->render_params.subpixel_rendering = | 3698 backend.GetHarfbuzzRunList()->runs()[0]->render_params.subpixel_rendering = |
3433 FontRenderParams::SUBPIXEL_RENDERING_RGB; | 3699 FontRenderParams::SUBPIXEL_RENDERING_RGB; |
3434 backend.DrawVisualText(); | 3700 backend.DrawVisualText(); |
3435 #endif | 3701 #endif |
3436 EXPECT_FALSE(backend.paint().isLCDRenderText()); | 3702 EXPECT_FALSE(backend.paint().isLCDRenderText()); |
3437 } | 3703 } |
3438 } | 3704 } |
3439 | 3705 |
3440 } // namespace gfx | 3706 } // namespace gfx |
OLD | NEW |