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 6b13ee1aeab30577ee8fd6b3d52b3688070051f4..1338df85d2ecaf0d476ce82054a464a6353af040 100644 |
| --- a/ui/gfx/render_text_unittest.cc |
| +++ b/ui/gfx/render_text_unittest.cc |
| @@ -728,6 +728,62 @@ TEST_F(RenderTextTest, TruncatedText) { |
| } |
| } |
| +TEST_F(RenderTextTest, FontSize) { |
| + SCOPED_TRACE("FontSize"); |
| + scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| + const wchar_t* string = L"0gl1gl2gl3gl"; |
| + render_text->SetText(WideToUTF16(string)); |
| + const Size kCanvasSize(150, 55); |
| + const int kTestSize = 10; |
| + |
| + struct Tests { |
| + int a_size; |
| + int b_size; |
| + int c_size; |
| + BaselineStyle a_baseline; |
| + bool b_bold; |
| + SkColor c_color; |
| + } const kTests[] = { |
| + {18, 26, 0, NORMAL_BASELINE, false, SK_ColorBLACK}, |
| + {26, 18, 8, SUPERSCRIPT, true, SK_ColorLTGRAY}, |
| + {18, 26, 0, INFERIOR, false, SK_ColorRED}, |
| + {26, 18, 8, SUPERIOR, true, SK_ColorBLUE}, |
| + }; |
| + |
| + render_text->SetHorizontalAlignment(ALIGN_LEFT); |
| + render_text->SetVerticalAlignment(VALIGN_TOP); |
| + skia::RefPtr<SkSurface> surface = skia::AdoptRef( |
| + SkSurface::NewRasterN32Premul(kCanvasSize.width(), kCanvasSize.height())); |
| + scoped_ptr<Canvas> canvas( |
| + Canvas::CreateCanvasWithoutScaling(surface->getCanvas(), 1.0f)); |
| + Rect bounds = Rect(kTestSize, kTestSize, kCanvasSize.width() - kTestSize * 2, |
| + kCanvasSize.height() - kTestSize * 2); |
| + render_text->SetDisplayRect(bounds); |
| + render_text->set_clip_to_display_rect(false); |
| + const uint32* buffer = |
| + static_cast<const uint32*>(surface->peekPixels(nullptr, nullptr)); |
| + ASSERT_NE(nullptr, buffer); |
| + TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(), |
|
msw
2015/03/30 21:14:35
As in the vertical alignment CL, I hope that testi
|
| + kCanvasSize.height()); |
| + for (const auto& test : kTests) { |
| + surface->getCanvas()->clear(SK_ColorWHITE); |
| + render_text->ApplyFontSize(test.a_size, Range(0, 3)); |
| + render_text->ApplyFontSize(test.b_size, Range(3, 6)); |
| + render_text->ApplyFontSize(test.c_size, Range(6, 9)); |
| + render_text->ApplyBaselineStyle(test.a_baseline, Range(2, 3)); |
| + render_text->ApplyStyle(BOLD, test.b_bold, Range(4, 6)); |
| + render_text->ApplyColor(test.c_color, Range(7, 9)); |
| + const Size string_size = render_text->GetStringSize(); |
| + ASSERT_LE(string_size.width() + kTestSize * 2, kCanvasSize.width()); |
| + ASSERT_LE(string_size.height() + kTestSize * 2, kCanvasSize.height()); |
| + Rect expected_rect(kTestSize, kTestSize, string_size.width(), |
| + string_size.height()); |
| + render_text->Draw(canvas.get()); |
| + expected_rect.Inset(-1, -1); |
| + rect_buffer.EnsureSolidBorder(SK_ColorWHITE, expected_rect); |
| + } |
| +} |
| + |
| TEST_F(RenderTextTest, TruncatedObscuredText) { |
| scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| render_text->set_truncate_length(3); |
| @@ -2738,7 +2794,6 @@ TEST_F(RenderTextTest, VerticalAlignment) { |
| for (const auto& test : kTests) { |
| SCOPED_TRACE(base::StringPrintf("VerticalAlignement H %i, V %i", |
| test.horizontal, test.vertical)); |
| - |
| surface->getCanvas()->clear(SK_ColorWHITE); |
| render_text->SetHorizontalAlignment(test.horizontal); |
| render_text->SetVerticalAlignment(test.vertical); |