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

Side by Side Diff: Source/core/rendering/TextPainterTest.cpp

Issue 738863002: Move TextPainter to core/paint/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/rendering/TextPainter.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/rendering/TextPainter.h"
7
8 #include "core/CSSPropertyNames.h"
9 #include "core/CSSValueKeywords.h"
10 #include "core/css/CSSPrimitiveValue.h"
11 #include "core/frame/Settings.h"
12 #include "core/rendering/RenderText.h"
13 #include "core/rendering/RenderingTestHelper.h"
14 #include "core/rendering/style/ShadowData.h"
15 #include "core/rendering/style/ShadowList.h"
16 #include <gtest/gtest.h>
17
18 namespace blink {
19 namespace {
20
21 class TextPainterTest : public RenderingTest {
22 public:
23 TextPainterTest() : m_renderText(nullptr) { }
24
25 protected:
26 RenderText* renderText() { return m_renderText; }
27
28 private:
29 virtual void SetUp() override
30 {
31 RenderingTest::SetUp();
32 setBodyInnerHTML("Hello world");
33 m_renderText = toRenderText(document().body()->firstChild()->renderer()) ;
34 ASSERT_TRUE(m_renderText);
35 ASSERT_EQ("Hello world", m_renderText->text());
36 }
37
38 RenderText* m_renderText;
39 };
40
41 TEST_F(TextPainterTest, TextPaintingStyle_Simple)
42 {
43 document().body()->setInlineStyleProperty(CSSPropertyColor, CSSValueBlue);
44 document().view()->updateLayoutAndStyleIfNeededRecursive();
45
46 TextPainter::Style textStyle = TextPainter::textPaintingStyle(
47 *renderText(), renderText()->style(), false /* forceBlackText */, false /* isPrinting */);
48 EXPECT_EQ(Color(0, 0, 255), textStyle.fillColor);
49 EXPECT_EQ(Color(0, 0, 255), textStyle.strokeColor);
50 EXPECT_EQ(Color(0, 0, 255), textStyle.emphasisMarkColor);
51 EXPECT_EQ(0, textStyle.strokeWidth);
52 EXPECT_EQ(nullptr, textStyle.shadow);
53 }
54
55 TEST_F(TextPainterTest, TextPaintingStyle_AllProperties)
56 {
57 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextFillColor, CS SValueRed);
58 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeColor, CSSValueLime);
59 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextEmphasisColor , CSSValueBlue);
60 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeWidth, 4, CSSPrimitiveValue::CSS_PX);
61 document().body()->setInlineStyleProperty(CSSPropertyTextShadow, "1px 2px 3p x yellow");
62 document().view()->updateLayoutAndStyleIfNeededRecursive();
63
64 TextPainter::Style textStyle = TextPainter::textPaintingStyle(
65 *renderText(), renderText()->style(), false /* forceBlackText */, false /* isPrinting */);
66 EXPECT_EQ(Color(255, 0, 0), textStyle.fillColor);
67 EXPECT_EQ(Color(0, 255, 0), textStyle.strokeColor);
68 EXPECT_EQ(Color(0, 0, 255), textStyle.emphasisMarkColor);
69 EXPECT_EQ(4, textStyle.strokeWidth);
70 ASSERT_NE(nullptr, textStyle.shadow);
71 EXPECT_EQ(1u, textStyle.shadow->shadows().size());
72 EXPECT_EQ(1, textStyle.shadow->shadows()[0].x());
73 EXPECT_EQ(2, textStyle.shadow->shadows()[0].y());
74 EXPECT_EQ(3, textStyle.shadow->shadows()[0].blur());
75 EXPECT_EQ(Color(255, 255, 0), textStyle.shadow->shadows()[0].color());
76 }
77
78 TEST_F(TextPainterTest, TextPaintingStyle_ForceBlackText)
79 {
80 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextFillColor, CS SValueRed);
81 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeColor, CSSValueLime);
82 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextEmphasisColor , CSSValueBlue);
83 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeWidth, 4, CSSPrimitiveValue::CSS_PX);
84 document().body()->setInlineStyleProperty(CSSPropertyTextShadow, "1px 2px 3p x yellow");
85 document().view()->updateLayoutAndStyleIfNeededRecursive();
86
87 TextPainter::Style textStyle = TextPainter::textPaintingStyle(
88 *renderText(), renderText()->style(), true /* forceBlackText */, false / * isPrinting */);
89 EXPECT_EQ(Color::black, textStyle.fillColor);
90 EXPECT_EQ(Color::black, textStyle.strokeColor);
91 EXPECT_EQ(Color::black, textStyle.emphasisMarkColor);
92 EXPECT_EQ(4, textStyle.strokeWidth);
93 EXPECT_EQ(nullptr, textStyle.shadow);
94 }
95
96 TEST_F(TextPainterTest, TextPaintingStyle_ForceBackgroundToWhite_NoAdjustmentNee ded)
97 {
98 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextFillColor, CS SValueRed);
99 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeColor, CSSValueLime);
100 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextEmphasisColor , CSSValueBlue);
101 document().body()->setInlineStyleProperty(CSSPropertyWebkitPrintColorAdjust, CSSValueEconomy);
102 document().settings()->setShouldPrintBackgrounds(false);
103 document().view()->updateLayoutAndStyleIfNeededRecursive();
104
105 TextPainter::Style textStyle = TextPainter::textPaintingStyle(
106 *renderText(), renderText()->style(), false /* forceBlackText */, true / * isPrinting */);
107 EXPECT_EQ(Color(255, 0, 0), textStyle.fillColor);
108 EXPECT_EQ(Color(0, 255, 0), textStyle.strokeColor);
109 EXPECT_EQ(Color(0, 0, 255), textStyle.emphasisMarkColor);
110 }
111
112 TEST_F(TextPainterTest, TextPaintingStyle_ForceBackgroundToWhite_Darkened)
113 {
114 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextFillColor, "r gb(255, 220, 220)");
115 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeColor, "rgb(220, 255, 220)");
116 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextEmphasisColor , "rgb(220, 220, 255)");
117 document().body()->setInlineStyleProperty(CSSPropertyWebkitPrintColorAdjust, CSSValueEconomy);
118 document().settings()->setShouldPrintBackgrounds(false);
119 document().view()->updateLayoutAndStyleIfNeededRecursive();
120
121 TextPainter::Style textStyle = TextPainter::textPaintingStyle(
122 *renderText(), renderText()->style(), false /* forceBlackText */, true / * isPrinting */);
123 EXPECT_EQ(Color(255, 220, 220).dark(), textStyle.fillColor);
124 EXPECT_EQ(Color(220, 255, 220).dark(), textStyle.strokeColor);
125 EXPECT_EQ(Color(220, 220, 255).dark(), textStyle.emphasisMarkColor);
126 }
127
128 } // namespace
129 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/rendering/TextPainter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698