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

Side by Side Diff: third_party/WebKit/Source/core/paint/TextPainterTest.cpp

Issue 1512803004: Use refs for GraphicsContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ScrollbarTheme
Patch Set: Created 5 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/paint/TextPainter.h" 6 #include "core/paint/TextPainter.h"
7 7
8 #include "core/CSSPropertyNames.h" 8 #include "core/CSSPropertyNames.h"
9 #include "core/CSSValueKeywords.h" 9 #include "core/CSSValueKeywords.h"
10 #include "core/css/CSSPrimitiveValue.h" 10 #include "core/css/CSSPrimitiveValue.h"
11 #include "core/frame/Settings.h" 11 #include "core/frame/Settings.h"
12 #include "core/layout/LayoutTestHelper.h" 12 #include "core/layout/LayoutTestHelper.h"
13 #include "core/layout/LayoutText.h" 13 #include "core/layout/LayoutText.h"
14 #include "core/paint/PaintInfo.h" 14 #include "core/paint/PaintInfo.h"
15 #include "core/style/ShadowData.h" 15 #include "core/style/ShadowData.h"
16 #include "core/style/ShadowList.h" 16 #include "core/style/ShadowList.h"
17 #include "platform/graphics/paint/PaintController.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace blink { 20 namespace blink {
20 namespace { 21 namespace {
21 22
22 class TextPainterTest : public RenderingTest { 23 class TextPainterTest : public RenderingTest {
23 public: 24 public:
24 TextPainterTest() : m_layoutText(nullptr) { } 25 TextPainterTest()
26 : m_layoutText(nullptr)
27 , m_paintController(PaintController::create())
28 , m_context(*m_paintController)
29 { }
25 30
26 protected: 31 protected:
27 LayoutText* layoutText() { return m_layoutText; } 32 LayoutText* layoutText() { return m_layoutText; }
28 33
34 PaintInfo createPaintInfo(bool usesTextAsClip, bool isPrinting)
35 {
36 return PaintInfo(m_context, IntRect(), usesTextAsClip ? PaintPhaseTextCl ip : PaintPhaseBlockBackground, isPrinting ? GlobalPaintPrinting : GlobalPaintNo rmalPhase, 0);
37 }
38
29 private: 39 private:
30 void SetUp() override 40 void SetUp() override
31 { 41 {
32 RenderingTest::SetUp(); 42 RenderingTest::SetUp();
33 setBodyInnerHTML("Hello world"); 43 setBodyInnerHTML("Hello world");
34 m_layoutText = toLayoutText(document().body()->firstChild()->layoutObjec t()); 44 m_layoutText = toLayoutText(document().body()->firstChild()->layoutObjec t());
35 ASSERT_TRUE(m_layoutText); 45 ASSERT_TRUE(m_layoutText);
36 ASSERT_EQ("Hello world", m_layoutText->text()); 46 ASSERT_EQ("Hello world", m_layoutText->text());
37 } 47 }
38 48
39 LayoutText* m_layoutText; 49 LayoutText* m_layoutText;
50 OwnPtr<PaintController> m_paintController;
51 GraphicsContext m_context;
40 }; 52 };
41 53
42 static PaintInfo createPaintInfo(bool usesTextAsClip, bool isPrinting)
43 {
44 return PaintInfo(nullptr, IntRect(), usesTextAsClip ? PaintPhaseTextClip : P aintPhaseBlockBackground, isPrinting ? GlobalPaintPrinting : GlobalPaintNormalPh ase, 0);
45 }
46
47 TEST_F(TextPainterTest, TextPaintingStyle_Simple) 54 TEST_F(TextPainterTest, TextPaintingStyle_Simple)
48 { 55 {
49 document().body()->setInlineStyleProperty(CSSPropertyColor, CSSValueBlue); 56 document().body()->setInlineStyleProperty(CSSPropertyColor, CSSValueBlue);
50 document().view()->updateAllLifecyclePhases(); 57 document().view()->updateAllLifecyclePhases();
51 58
52 TextPainter::Style textStyle = TextPainter::textPaintingStyle( 59 TextPainter::Style textStyle = TextPainter::textPaintingStyle(
53 *layoutText(), layoutText()->styleRef(), createPaintInfo(false /* usesTe xtAsClip */, false /* isPrinting */)); 60 *layoutText(), layoutText()->styleRef(), createPaintInfo(false /* usesTe xtAsClip */, false /* isPrinting */));
54 EXPECT_EQ(Color(0, 0, 255), textStyle.fillColor); 61 EXPECT_EQ(Color(0, 0, 255), textStyle.fillColor);
55 EXPECT_EQ(Color(0, 0, 255), textStyle.strokeColor); 62 EXPECT_EQ(Color(0, 0, 255), textStyle.strokeColor);
56 EXPECT_EQ(Color(0, 0, 255), textStyle.emphasisMarkColor); 63 EXPECT_EQ(Color(0, 0, 255), textStyle.emphasisMarkColor);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 135
129 TextPainter::Style textStyle = TextPainter::textPaintingStyle( 136 TextPainter::Style textStyle = TextPainter::textPaintingStyle(
130 *layoutText(), layoutText()->styleRef(), createPaintInfo(false /* usesTe xtAsClip */, true /* isPrinting */)); 137 *layoutText(), layoutText()->styleRef(), createPaintInfo(false /* usesTe xtAsClip */, true /* isPrinting */));
131 EXPECT_EQ(Color(255, 220, 220).dark(), textStyle.fillColor); 138 EXPECT_EQ(Color(255, 220, 220).dark(), textStyle.fillColor);
132 EXPECT_EQ(Color(220, 255, 220).dark(), textStyle.strokeColor); 139 EXPECT_EQ(Color(220, 255, 220).dark(), textStyle.strokeColor);
133 EXPECT_EQ(Color(220, 220, 255).dark(), textStyle.emphasisMarkColor); 140 EXPECT_EQ(Color(220, 220, 255).dark(), textStyle.emphasisMarkColor);
134 } 141 }
135 142
136 } // namespace 143 } // namespace
137 } // namespace blink 144 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/paint/TextPainter.cpp ('k') | third_party/WebKit/Source/core/paint/ThemePainter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698