1 // Copyright 2017 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 "third_party/blink/renderer/core/css/resolver/font_style_resolver.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/blink/renderer/core/css/parser/css_parser.h"
9 #include "third_party/blink/renderer/platform/heap/heap.h"
10
11 namespace blink {
12
TEST(FontStyleResolverTest,Simple)13 TEST(FontStyleResolverTest, Simple) {
14 auto* style =
15 MakeGarbageCollected<MutableCSSPropertyValueSet>(kHTMLStandardMode);
16 CSSParser::ParseValue(style, CSSPropertyID::kFont, "15px Ahem", true);
17
18 FontDescription desc = FontStyleResolver::ComputeFont(*style, nullptr);
19
20 EXPECT_EQ(desc.SpecifiedSize(), 15);
21 EXPECT_EQ(desc.ComputedSize(), 15);
22 EXPECT_EQ(desc.Family().Family(), "Ahem");
23 }
24
TEST(FontStyleResolverTest,InvalidSize)25 TEST(FontStyleResolverTest, InvalidSize) {
26 auto* style =
27 MakeGarbageCollected<MutableCSSPropertyValueSet>(kHTMLStandardMode);
28 CSSParser::ParseValue(style, CSSPropertyID::kFont, "-1px Ahem", true);
29
30 FontDescription desc = FontStyleResolver::ComputeFont(*style, nullptr);
31
32 EXPECT_EQ(desc.Family().Family(), nullptr);
33 EXPECT_EQ(desc.SpecifiedSize(), 0);
34 EXPECT_EQ(desc.ComputedSize(), 0);
35 }
36
TEST(FontStyleResolverTest,InvalidWeight)37 TEST(FontStyleResolverTest, InvalidWeight) {
38 auto* style =
39 MakeGarbageCollected<MutableCSSPropertyValueSet>(kHTMLStandardMode);
40 CSSParser::ParseValue(style, CSSPropertyID::kFont, "wrong 1px Ahem", true);
41
42 FontDescription desc = FontStyleResolver::ComputeFont(*style, nullptr);
43
44 EXPECT_EQ(desc.Family().Family(), nullptr);
45 EXPECT_EQ(desc.SpecifiedSize(), 0);
46 EXPECT_EQ(desc.ComputedSize(), 0);
47 }
48
TEST(FontStyleResolverTest,InvalidEverything)49 TEST(FontStyleResolverTest, InvalidEverything) {
50 auto* style =
51 MakeGarbageCollected<MutableCSSPropertyValueSet>(kHTMLStandardMode);
52 CSSParser::ParseValue(style, CSSPropertyID::kFont,
53 "wrong wrong wrong 1px Ahem", true);
54
55 FontDescription desc = FontStyleResolver::ComputeFont(*style, nullptr);
56
57 EXPECT_EQ(desc.Family().Family(), nullptr);
58 EXPECT_EQ(desc.SpecifiedSize(), 0);
59 EXPECT_EQ(desc.ComputedSize(), 0);
60 }
61
TEST(FontStyleResolverTest,RelativeSize)62 TEST(FontStyleResolverTest, RelativeSize) {
63 auto* style =
64 MakeGarbageCollected<MutableCSSPropertyValueSet>(kHTMLStandardMode);
65 CSSParser::ParseValue(style, CSSPropertyID::kFont, "italic 2ex Ahem", true);
66
67 FontDescription desc = FontStyleResolver::ComputeFont(*style, nullptr);
68
69 EXPECT_EQ(desc.Family().Family(), "Ahem");
70 EXPECT_EQ(desc.SpecifiedSize(), 10);
71 EXPECT_EQ(desc.ComputedSize(), 10);
72 }
73
74 } // namespace blink
75