OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "modules/csspaint/PaintRenderingContext2D.h" |
| 6 |
| 7 #include "platform/graphics/ImageBuffer.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace blink { |
| 11 namespace { |
| 12 |
| 13 static const int s_width = 50; |
| 14 static const int s_height = 75; |
| 15 |
| 16 class PaintRenderingContext2DTest : public ::testing::Test { |
| 17 protected: |
| 18 void SetUp() override; |
| 19 |
| 20 RefPtrWillBePersistent<PaintRenderingContext2D> m_ctx; |
| 21 }; |
| 22 |
| 23 void PaintRenderingContext2DTest::SetUp() |
| 24 { |
| 25 m_ctx = PaintRenderingContext2D::create(ImageBuffer::create(IntSize(s_width,
s_height))); |
| 26 } |
| 27 |
| 28 void trySettingStrokeStyle(PaintRenderingContext2D* ctx, const String& expected,
const String& value) |
| 29 { |
| 30 StringOrCanvasGradientOrCanvasPattern result, arg, dummy; |
| 31 dummy.setString("red"); |
| 32 arg.setString(value); |
| 33 ctx->setStrokeStyle(dummy); |
| 34 ctx->setStrokeStyle(arg); |
| 35 ctx->strokeStyle(result); |
| 36 EXPECT_EQ(expected, result.getAsString()); |
| 37 } |
| 38 |
| 39 TEST_F(PaintRenderingContext2DTest, testParseColorOrCurrentColor) |
| 40 { |
| 41 trySettingStrokeStyle(m_ctx.get(), "#0000ff", "blue"); |
| 42 trySettingStrokeStyle(m_ctx.get(), "#000000", "currentColor"); |
| 43 } |
| 44 |
| 45 TEST_F(PaintRenderingContext2DTest, testWidthAndHeight) |
| 46 { |
| 47 EXPECT_EQ(s_width, m_ctx->width()); |
| 48 EXPECT_EQ(s_height, m_ctx->height()); |
| 49 } |
| 50 |
| 51 TEST_F(PaintRenderingContext2DTest, testBasicState) |
| 52 { |
| 53 const double shadowBlurBefore = 2; |
| 54 const double shadowBlurAfter = 3; |
| 55 |
| 56 const String lineJoinBefore = "bevel"; |
| 57 const String lineJoinAfter = "round"; |
| 58 |
| 59 m_ctx->setShadowBlur(shadowBlurBefore); |
| 60 m_ctx->setLineJoin(lineJoinBefore); |
| 61 EXPECT_EQ(shadowBlurBefore, m_ctx->shadowBlur()); |
| 62 EXPECT_EQ(lineJoinBefore, m_ctx->lineJoin()); |
| 63 |
| 64 m_ctx->save(); |
| 65 |
| 66 m_ctx->setShadowBlur(shadowBlurAfter); |
| 67 m_ctx->setLineJoin(lineJoinAfter); |
| 68 EXPECT_EQ(shadowBlurAfter, m_ctx->shadowBlur()); |
| 69 EXPECT_EQ(lineJoinAfter, m_ctx->lineJoin()); |
| 70 |
| 71 m_ctx->restore(); |
| 72 |
| 73 EXPECT_EQ(shadowBlurBefore, m_ctx->shadowBlur()); |
| 74 EXPECT_EQ(lineJoinBefore, m_ctx->lineJoin()); |
| 75 } |
| 76 |
| 77 } // namespace |
| 78 } // namespace blink |
OLD | NEW |