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

Unified Diff: ui/gfx/render_text_unittest.cc

Issue 276123003: Add a unit tests for RenderText::FindCursorPosition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: EnsureLayout in RenderTextWin::GetGlyphBounds; cleanup. Created 6 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/gfx/render_text_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text_unittest.cc
diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc
index 9cf7bb69ac3efca5b4503d7baa462c11cc9075b8..30677c126585789cad9bebdb16951ddc2b375755 100644
--- a/ui/gfx/render_text_unittest.cc
+++ b/ui/gfx/render_text_unittest.cc
@@ -946,6 +946,22 @@ TEST_F(RenderTextTest, MidGraphemeSelectionBounds) {
}
}
+TEST_F(RenderTextTest, FindCursorPosition) {
+ const wchar_t* kTestStrings[] = { kLtrRtl, kLtrRtlLtr, kRtlLtr, kRtlLtrRtl };
+ scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
+ render_text->SetDisplayRect(Rect(0, 0, 100, 20));
+ for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
+ SCOPED_TRACE(base::StringPrintf("Testing case[%" PRIuS "]", i));
+ render_text->SetText(WideToUTF16(kTestStrings[i]));
+ for(size_t j = 0; j < render_text->text().length(); ++j) {
+ const Range range(render_text->GetGlyphBounds(j));
+ // Test a point just inside the leading edge of the glyph bounds.
+ int x = range.is_reversed() ? range.GetMax() - 1 : range.GetMin() + 1;
+ EXPECT_EQ(j, render_text->FindCursorPosition(Point(x, 0)).caret_pos());
+ }
+ }
+}
+
TEST_F(RenderTextTest, EdgeSelectionModels) {
// Simple Latin text.
const base::string16 kLatin = WideToUTF16(L"abc");
@@ -1751,11 +1767,7 @@ TEST_F(RenderTextTest, DisplayRectShowsCursorRTL) {
// Changing colors between or inside ligated glyphs should not break shaping.
TEST_F(RenderTextTest, SelectionKeepsLigatures) {
- const wchar_t* kTestStrings[] = {
- L"\x644\x623",
- L"\x633\x627"
- };
-
+ const wchar_t* kTestStrings[] = { L"\x644\x623", L"\x633\x627" };
scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
render_text->set_selection_color(SK_ColorRED);
Canvas canvas;
@@ -1765,8 +1777,7 @@ TEST_F(RenderTextTest, SelectionKeepsLigatures) {
const int expected_width = render_text->GetStringSize().width();
render_text->MoveCursorTo(SelectionModel(Range(0, 1), CURSOR_FORWARD));
EXPECT_EQ(expected_width, render_text->GetStringSize().width());
- // Draw the text. It shouldn't hit any DCHECKs or crash.
- // See http://crbug.com/214150
+ // Drawing the text should not DCHECK or crash; see http://crbug.com/262119
render_text->Draw(&canvas);
render_text->MoveCursorTo(SelectionModel(0, CURSOR_FORWARD));
}
« no previous file with comments | « no previous file | ui/gfx/render_text_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698