| Index: ui/gfx/render_text_unittest.cc
|
| diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc
|
| index 859689b5febce093495cea438fc1b3a3dd0d523d..42976a5c0e00433754831bd0537910b7b6de751f 100644
|
| --- a/ui/gfx/render_text_unittest.cc
|
| +++ b/ui/gfx/render_text_unittest.cc
|
| @@ -2373,4 +2373,35 @@ TEST_F(RenderTextTest, HarfBuzz_UniscribeFallback) {
|
| }
|
| #endif // defined(OS_WIN)
|
|
|
| +// Ensure that the width reported by RenderText is sufficient for drawing. Draws
|
| +// to a canvas and checks whether any pixel beyond the width is colored.
|
| +TEST_F(RenderTextTest, TextDoesntClip) {
|
| + const wchar_t* kTestStrings[] = { L"Save", L"Remove", L"TEST", L"W", L"WWW" };
|
| +
|
| + skia::RefPtr<SkCanvas> sk_canvas =
|
| + skia::AdoptRef(SkCanvas::NewRasterN32(300, 50));
|
| + scoped_ptr<Canvas> canvas(
|
| + Canvas::CreateCanvasWithoutScaling(sk_canvas.get(), 1.0f));
|
| + scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
|
| + render_text->SetDisplayRect(Rect(300, 50));
|
| + render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT);
|
| + render_text->SetColor(SK_ColorBLACK);
|
| +
|
| + for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
|
| + sk_canvas->clear(SK_ColorWHITE);
|
| + render_text->SetText(WideToUTF16(kTestStrings[i]));
|
| + render_text->SetStyle(BOLD, true);
|
| + render_text->Draw(canvas.get());
|
| + int width = render_text->GetStringSize().width();
|
| + ASSERT_LT(width, 300);
|
| + const uint32* buffer = static_cast<const uint32*>(
|
| + sk_canvas->peekPixels(NULL, NULL));
|
| + ASSERT_NE(nullptr, buffer);
|
| + for (int y = 0; y < 50; ++y) {
|
| + EXPECT_EQ(SK_ColorWHITE, buffer[width + y * 300])
|
| + << "String: " << kTestStrings[i];
|
| + }
|
| + }
|
| +}
|
| +
|
| } // namespace gfx
|
|
|