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

Unified Diff: ui/gfx/render_text_unittest.cc

Issue 378723003: RenderText: Allow setting display offset explicitly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added test Created 6 years, 5 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
« ui/gfx/render_text.cc ('K') | « ui/gfx/render_text.cc ('k') | no next file » | 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 4686066f088953085ff1df8d5e7bb381efa47866..3cd3b98e75e0eea0e30a426aeb57a2aefdd21ce2 100644
--- a/ui/gfx/render_text_unittest.cc
+++ b/ui/gfx/render_text_unittest.cc
@@ -1040,7 +1040,7 @@ TEST_F(RenderTextTest, SelectAll) {
EXPECT_EQ(was_rtl, base::i18n::IsRTL());
}
- TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) {
+TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) {
scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2"));
// Left arrow on select ranging (6, 4).
@@ -1488,6 +1488,80 @@ TEST_F(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL) {
SetRTL(was_rtl);
}
+TEST_F(RenderTextTest, SetDisplayOffset) {
+ scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
+ render_text->SetText(ASCIIToUTF16("abcdefg"));
+ render_text->SetFontList(FontList("Arial, 13px"));
+
+ const Size font_size(render_text->GetContentWidth(),
+ render_text->font_list().GetHeight());
+ const int kEnlargement = 10;
+
+ // Set display width |kEnlargement| pixels greater than content width and test
+ // different possible situations. In this case the only possible display
+ // offset is zero.
+ Rect display_rect(font_size);
+ display_rect.Inset(0, 0, -kEnlargement, 0);
+ render_text->SetDisplayRect(display_rect);
+
+ struct {
+ HorizontalAlignment alignment;
+ int offset;
+ } small_content_cases[] = {
+ { ALIGN_LEFT, -kEnlargement },
+ { ALIGN_LEFT, 0 },
+ { ALIGN_LEFT, kEnlargement },
+ { ALIGN_RIGHT, -kEnlargement },
+ { ALIGN_RIGHT, 0 },
+ { ALIGN_RIGHT, kEnlargement },
+ { ALIGN_CENTER, -kEnlargement },
+ { ALIGN_CENTER, 0 },
+ { ALIGN_CENTER, kEnlargement },
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(small_content_cases); i++) {
+ render_text->SetHorizontalAlignment(small_content_cases[i].alignment);
+ render_text->SetDisplayOffset(small_content_cases[i].offset);
+ EXPECT_EQ(0, render_text->GetUpdatedDisplayOffset().x());
+ }
+
+ // Set display width |kEnlargement| pixels less than content width and test
+ // different possible situations.
+ display_rect = Rect(font_size);
+ display_rect.Inset(0, 0, kEnlargement, 0);
+ render_text->SetDisplayRect(display_rect);
+
+ struct {
+ HorizontalAlignment alignment;
+ int offset;
+ int expected_offset;
+ } large_content_cases[] = {
+ // When text is left-aligned, display offset can be in range
+ // [-kEnlargement, 0].
+ { ALIGN_LEFT, -2 * kEnlargement, -kEnlargement },
+ { ALIGN_LEFT, -kEnlargement / 2, -kEnlargement / 2 },
+ { ALIGN_LEFT, kEnlargement, 0 },
+ // When text is right-aligned, display offset can be in range
+ // [0, kEnlargement].
+ { ALIGN_RIGHT, -kEnlargement, 0 },
+ { ALIGN_RIGHT, kEnlargement / 2, kEnlargement / 2 },
+ { ALIGN_RIGHT, 2 * kEnlargement, kEnlargement },
+ // When text is center-aligned, display offset can be in range
+ // [-kEnlargement / 2, kEnlargement / 2].
+ { ALIGN_CENTER, -kEnlargement, -kEnlargement / 2 },
+ { ALIGN_CENTER, -kEnlargement / 4, -kEnlargement / 4 },
+ { ALIGN_CENTER, kEnlargement / 4, kEnlargement / 4 },
+ { ALIGN_CENTER, kEnlargement, kEnlargement / 2 },
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(large_content_cases); i++) {
+ render_text->SetHorizontalAlignment(large_content_cases[i].alignment);
+ render_text->SetDisplayOffset(large_content_cases[i].offset);
+ EXPECT_EQ(large_content_cases[i].expected_offset,
+ render_text->GetUpdatedDisplayOffset().x());
+ }
+}
+
TEST_F(RenderTextTest, SameFontForParentheses) {
struct {
const base::char16 left_char;
« ui/gfx/render_text.cc ('K') | « ui/gfx/render_text.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698