Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: ui/gfx/render_text_unittest.cc

Issue 8819001: Revert 113075 (requested by asvitkine) (requested by asvitkine) (requested by asvitkine) (request... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/render_text_linux.cc ('k') | ui/gfx/render_text_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 EXPECT_EQ(4U, render_text->GetCursorPosition()); 536 EXPECT_EQ(4U, render_text->GetCursorPosition());
537 render_text->MoveCursorLeft(CHARACTER_BREAK, false); 537 render_text->MoveCursorLeft(CHARACTER_BREAK, false);
538 EXPECT_EQ(2U, render_text->GetCursorPosition()); 538 EXPECT_EQ(2U, render_text->GetCursorPosition());
539 render_text->MoveCursorLeft(CHARACTER_BREAK, false); 539 render_text->MoveCursorLeft(CHARACTER_BREAK, false);
540 EXPECT_EQ(0U, render_text->GetCursorPosition()); 540 EXPECT_EQ(0U, render_text->GetCursorPosition());
541 render_text->MoveCursorLeft(CHARACTER_BREAK, false); 541 render_text->MoveCursorLeft(CHARACTER_BREAK, false);
542 EXPECT_EQ(0U, render_text->GetCursorPosition()); 542 EXPECT_EQ(0U, render_text->GetCursorPosition());
543 } 543 }
544 #endif 544 #endif
545 545
546 TEST_F(RenderTextTest, GraphemePositions) {
547 // LTR 2-character grapheme, LTR abc, LTR 2-character grapheme.
548 const string16 kText1 = WideToUTF16(L"\x0915\x093f"L"abc"L"\x0915\x093f");
549
550 // LTR ab, LTR 2-character grapheme, LTR cd.
551 const string16 kText2 = WideToUTF16(L"ab"L"\x0915\x093f"L"cd");
552
553 struct {
554 string16 text;
555 size_t index;
556 size_t expected_previous;
557 size_t expected_next;
558 } cases[] = {
559 { string16(), 0, 0, 0 },
560 { string16(), 1, 0, 0 },
561 { string16(), 50, 0, 0 },
562 { kText1, 0, 0, 2 },
563 { kText1, 1, 0, 2 },
564 { kText1, 2, 0, 3 },
565 { kText1, 3, 2, 4 },
566 { kText1, 4, 3, 5 },
567 { kText1, 5, 4, 7 },
568 { kText1, 6, 5, 7 },
569 { kText1, 7, 5, 7 },
570 { kText1, 8, 7, 7 },
571 { kText1, 50, 7, 7 },
572 { kText2, 0, 0, 1 },
573 { kText2, 1, 0, 2 },
574 { kText2, 2, 1, 4 },
575 { kText2, 3, 2, 4 },
576 { kText2, 4, 2, 5 },
577 { kText2, 5, 4, 6 },
578 { kText2, 6, 5, 6 },
579 { kText2, 7, 6, 6 },
580 { kText2, 50, 6, 6 },
581 };
582
583 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
584 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
585 render_text->SetText(cases[i].text);
586
587 size_t next = render_text->GetIndexOfNextGrapheme(cases[i].index);
588 EXPECT_EQ(cases[i].expected_next, next);
589 EXPECT_TRUE(render_text->IsCursorablePosition(next));
590
591 size_t previous = render_text->GetIndexOfPreviousGrapheme(cases[i].index);
592 EXPECT_EQ(cases[i].expected_previous, previous);
593 EXPECT_TRUE(render_text->IsCursorablePosition(previous));
594 }
595 }
596
597 TEST_F(RenderTextTest, SelectionModels) {
598 // Simple Latin text.
599 const string16 kLatin = WideToUTF16(L"abc");
600 // LTR 2-character grapheme.
601 const string16 kLTRGrapheme = WideToUTF16(L"\x0915\x093f");
602 // LTR 2-character grapheme, LTR a, LTR 2-character grapheme.
603 const string16 kHindiLatin = WideToUTF16(L"\x0915\x093f"L"a"L"\x0915\x093f");
604 // RTL 2-character grapheme.
605 const string16 kRTLGrapheme = WideToUTF16(L"\x05e0\x05b8");
606 // RTL 2-character grapheme, LTR a, RTL 2-character grapheme.
607 const string16 kHebrewLatin = WideToUTF16(L"\x05e0\x05b8"L"a"L"\x05e0\x05b8");
608
609 struct {
610 string16 text;
611 size_t expected_left_end_caret;
612 SelectionModel::CaretPlacement expected_left_end_placement;
613 size_t expected_right_end_caret;
614 SelectionModel::CaretPlacement expected_right_end_placement;
615 } cases[] = {
616 { string16(), 0, SelectionModel::LEADING, 0, SelectionModel::LEADING },
617 { kLatin, 0, SelectionModel::LEADING, 2, SelectionModel::TRAILING },
618 { kLTRGrapheme, 0, SelectionModel::LEADING, 0, SelectionModel::TRAILING },
619 { kHindiLatin, 0, SelectionModel::LEADING, 3, SelectionModel::TRAILING },
620 { kRTLGrapheme, 0, SelectionModel::TRAILING, 0, SelectionModel::LEADING },
621 #if defined(OS_LINUX)
622 // On Linux, the whole string is displayed RTL, rather than individual runs.
623 { kHebrewLatin, 3, SelectionModel::TRAILING, 0, SelectionModel::LEADING },
624 #else
625 { kHebrewLatin, 0, SelectionModel::TRAILING, 3, SelectionModel::LEADING },
626 #endif
627 };
628
629 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
630 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
631 render_text->SetText(cases[i].text);
632
633 SelectionModel model = render_text->LeftEndSelectionModel();
634 EXPECT_EQ(cases[i].expected_left_end_caret, model.caret_pos());
635 EXPECT_TRUE(render_text->IsCursorablePosition(model.caret_pos()));
636 EXPECT_EQ(cases[i].expected_left_end_placement, model.caret_placement());
637
638 model = render_text->RightEndSelectionModel();
639 EXPECT_EQ(cases[i].expected_right_end_caret, model.caret_pos());
640 EXPECT_TRUE(render_text->IsCursorablePosition(model.caret_pos()));
641 EXPECT_EQ(cases[i].expected_right_end_placement, model.caret_placement());
642 }
643 }
644
645 TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) { 546 TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) {
646 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 547 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
647 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); 548 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2"));
648 // Left arrow on select ranging (6, 4). 549 // Left arrow on select ranging (6, 4).
649 render_text->MoveCursorRight(LINE_BREAK, false); 550 render_text->MoveCursorRight(LINE_BREAK, false);
650 EXPECT_EQ(6U, render_text->GetCursorPosition()); 551 EXPECT_EQ(6U, render_text->GetCursorPosition());
651 render_text->MoveCursorLeft(CHARACTER_BREAK, false); 552 render_text->MoveCursorLeft(CHARACTER_BREAK, false);
652 EXPECT_EQ(4U, render_text->GetCursorPosition()); 553 EXPECT_EQ(4U, render_text->GetCursorPosition());
653 render_text->MoveCursorLeft(CHARACTER_BREAK, false); 554 render_text->MoveCursorLeft(CHARACTER_BREAK, false);
654 EXPECT_EQ(5U, render_text->GetCursorPosition()); 555 EXPECT_EQ(5U, render_text->GetCursorPosition());
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 EXPECT_EQ(5U, render_text->GetCursorPosition()); 746 EXPECT_EQ(5U, render_text->GetCursorPosition());
846 render_text->MoveCursorRight(WORD_BREAK, false); 747 render_text->MoveCursorRight(WORD_BREAK, false);
847 EXPECT_EQ(6U, render_text->GetCursorPosition()); 748 EXPECT_EQ(6U, render_text->GetCursorPosition());
848 render_text->MoveCursorRight(WORD_BREAK, false); 749 render_text->MoveCursorRight(WORD_BREAK, false);
849 EXPECT_EQ(6U, render_text->GetCursorPosition()); 750 EXPECT_EQ(6U, render_text->GetCursorPosition());
850 } 751 }
851 752
852 #endif 753 #endif
853 754
854 } // namespace gfx 755 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text_linux.cc ('k') | ui/gfx/render_text_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698