Chromium Code Reviews| Index: ui/gfx/render_text_unittest.cc |
| diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc |
| index 3cd3b98e75e0eea0e30a426aeb57a2aefdd21ce2..31519351d8de245f83b54a86521ea3a786fd34bc 100644 |
| --- a/ui/gfx/render_text_unittest.cc |
| +++ b/ui/gfx/render_text_unittest.cc |
| @@ -1562,6 +1562,44 @@ TEST_F(RenderTextTest, SetDisplayOffset) { |
| } |
| } |
| +TEST_F(RenderTextTest, DisplayOffsetForCenteredTextChangingAtEnds) { |
| + scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| + render_text->SetText(ASCIIToUTF16("abcdefghij")); |
| + render_text->SetFontList(FontList("Arial, 13px")); |
|
msw
2014/07/16 21:55:54
nit: can you avoid setting the font?
mohsen
2014/07/16 23:36:21
Sure, Done. That was what I saw other tests do.
|
| + render_text->SetHorizontalAlignment(ALIGN_CENTER); |
| + |
| + const Size display_size(render_text->GetContentWidth() / 2, |
| + render_text->font_list().GetHeight()); |
| + render_text->SetDisplayRect(Rect(display_size)); |
| + |
| + // Move cursor to the beginning of text and check the offset. |
|
msw
2014/07/16 21:55:54
nit: "Move the cursor" here and at line 1588.
mohsen
2014/07/16 23:36:21
Done.
|
| + render_text->SetCursorPosition(0); |
| + int expected_offset = |
|
msw
2014/07/16 21:55:54
nit: inline the |expected_offset| calculations int
mohsen
2014/07/16 23:36:21
Done.
|
| + (render_text->GetContentWidth() - display_size.width()) / 2; |
| + EXPECT_EQ(expected_offset, render_text->GetUpdatedDisplayOffset().x()); |
|
msw
2014/07/16 21:55:54
Hmm, is there a better way of verifying the intend
mohsen
2014/07/16 23:36:21
The intended outcome is that no extra space should
msw
2014/07/16 23:51:59
I think glyph bounds would be good indicator and e
|
| + |
| + // Make text shorter (by removing a character), put the cursor at the |
|
msw
2014/07/16 21:55:54
nit: "Make the text" here and at line 1594.
mohsen
2014/07/16 23:36:21
Done.
|
| + // beginning, and check the offset. |
| + render_text->SetText(render_text->text().substr(1)); |
| + render_text->SetCursorPosition(0); |
| + expected_offset = (render_text->GetContentWidth() - display_size.width()) / 2; |
| + EXPECT_EQ(expected_offset, render_text->GetUpdatedDisplayOffset().x()); |
| + |
| + // Move cursor to the end of text and check the offset. |
| + render_text->SetCursorPosition(render_text->text().length()); |
| + expected_offset = |
| + (display_size.width() - render_text->GetContentWidth() - 1) / 2; |
| + EXPECT_EQ(expected_offset, render_text->GetUpdatedDisplayOffset().x()); |
| + |
| + // Make text shorter (by removing a character), put cursor at the end, and |
|
msw
2014/07/16 21:55:54
Instead of setting the text and cursor (which comp
mohsen
2014/07/16 23:36:21
Done, it's cleaner and more to the point of the te
|
| + // check the offset. |
| + render_text->SetText(render_text->text().substr(1)); |
| + render_text->SetCursorPosition(render_text->text().length()); |
| + expected_offset = |
| + (display_size.width() - render_text->GetContentWidth() - 1) / 2; |
| + EXPECT_EQ(expected_offset, render_text->GetUpdatedDisplayOffset().x()); |
| +} |
| + |
| TEST_F(RenderTextTest, SameFontForParentheses) { |
| struct { |
| const base::char16 left_char; |