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 774fd04260f93bb709887cabef20a93e5e7be239..ecae332671d361ff90ffed2b56034cd3f7feddd0 100644 |
| --- a/ui/gfx/render_text_unittest.cc |
| +++ b/ui/gfx/render_text_unittest.cc |
| @@ -15,6 +15,7 @@ |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "ui/gfx/break_list.h" |
| #include "ui/gfx/canvas.h" |
| +#include "ui/gfx/color_utils.h" |
| #include "ui/gfx/font.h" |
| #include "ui/gfx/render_text_harfbuzz.h" |
| @@ -2379,29 +2380,40 @@ TEST_F(RenderTextTest, HarfBuzz_UniscribeFallback) { |
| // 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" }; |
| + const Size kCanvasSize(300, 50); |
| + const int kTestWidth = 10; |
| - skia::RefPtr<SkCanvas> sk_canvas = |
| - skia::AdoptRef(SkCanvas::NewRasterN32(300, 50)); |
| + skia::RefPtr<SkCanvas> sk_canvas = skia::AdoptRef( |
| + SkCanvas::NewRasterN32(kCanvasSize.width(), kCanvasSize.height())); |
| 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->SetDisplayRect(Rect(kCanvasSize)); |
| render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| render_text->SetColor(SK_ColorBLACK); |
| - for (size_t i = 0; i < arraysize(kTestStrings); ++i) { |
| + for (auto string : kTestStrings) { |
| sk_canvas->clear(SK_ColorWHITE); |
| - render_text->SetText(WideToUTF16(kTestStrings[i])); |
| + render_text->SetText(WideToUTF16(string)); |
| render_text->SetStyle(BOLD, true); |
| render_text->Draw(canvas.get()); |
| int width = render_text->GetStringSize().width(); |
| - ASSERT_LT(width, 300); |
| + ASSERT_GT(kCanvasSize.width() - kTestWidth, width); |
|
msw
2014/12/12 18:58:43
optional nit: this might be a bit clearer:
ASSER
ckocagil
2014/12/12 22:16:23
Done.
|
| 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]; |
| + |
| + for (int y = 0; y < kCanvasSize.height(); ++y) { |
| + for (int x = 0; x < kTestWidth; ++x) { |
|
msw
2014/12/12 18:58:43
optional nit: this might be a bit clearer:
for (
ckocagil
2014/12/12 22:16:23
Done.
|
| + const SkColor color = buffer[width + x + y * kCanvasSize.width()]; |
| + if (x == 0) { |
| + // Allow one column of anti-aliased pixels past the expected width. |
| + EXPECT_LT(230U, color_utils::GetLuminanceForColor(color)) |
| + << "String: " << string; |
| + continue; |
| + } |
| + EXPECT_EQ(SK_ColorWHITE, color) << "String: " << string; |
| + } |
| } |
| } |
| } |