1 // Copyright 2020 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/style_builder.h"
6 #include "third_party/blink/renderer/core/css/css_identifier_value.h"
7 #include "third_party/blink/renderer/core/css/css_inherited_value.h"
8 #include "third_party/blink/renderer/core/css/css_initial_value.h"
9 #include "third_party/blink/renderer/core/css/resolver/style_resolver_state.h"
10 #include "third_party/blink/renderer/core/css/scoped_css_value.h"
11 #include "third_party/blink/renderer/core/html/html_element.h"
12 #include "third_party/blink/renderer/core/style/computed_style.h"
13 #include "third_party/blink/renderer/core/testing/page_test_base.h"
14 #include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
15
16 namespace blink {
17
18 class StyleBuilderTest : public PageTestBase {};
19
TEST_F(StyleBuilderTest,WritingModeChangeDirtiesFont)20 TEST_F(StyleBuilderTest, WritingModeChangeDirtiesFont) {
21 const CSSProperty* properties[] = {
22 &GetCSSPropertyWritingMode(),
23 &GetCSSPropertyWebkitWritingMode(),
24 };
25
26 HeapVector<Member<const CSSValue>> values = {
27 CSSInitialValue::Create(),
28 CSSInheritedValue::Create(),
29 CSSIdentifierValue::Create(CSSValueID::kHorizontalTb),
30 };
31
32 for (const CSSProperty* property : properties) {
33 for (const CSSValue* value : values) {
34 auto parent_style = ComputedStyle::Create();
35 auto style = ComputedStyle::Create();
36 // This test assumes that initial 'writing-mode' is not 'vertical-lr'.
37 ASSERT_NE(WritingMode::kVerticalLr, style->GetWritingMode());
38 style->SetWritingMode(WritingMode::kVerticalLr);
39
40 StyleResolverState state(GetDocument(), *GetDocument().body(),
41 parent_style.get(), parent_style.get());
42 state.SetStyle(style);
43
44 ASSERT_FALSE(state.GetFontBuilder().FontDirty());
45 StyleBuilder::ApplyProperty(*property, state,
46 ScopedCSSValue(*value, &GetDocument()));
47 EXPECT_TRUE(state.GetFontBuilder().FontDirty());
48 }
49 }
50 }
51
TEST_F(StyleBuilderTest,TextOrientationChangeDirtiesFont)52 TEST_F(StyleBuilderTest, TextOrientationChangeDirtiesFont) {
53 const CSSProperty* properties[] = {
54 &GetCSSPropertyTextOrientation(),
55 &GetCSSPropertyWebkitTextOrientation(),
56 };
57
58 HeapVector<Member<const CSSValue>> values = {
59 CSSInitialValue::Create(),
60 CSSInheritedValue::Create(),
61 CSSIdentifierValue::Create(CSSValueID::kMixed),
62 };
63
64 for (const CSSProperty* property : properties) {
65 for (const CSSValue* value : values) {
66 auto parent_style = ComputedStyle::Create();
67 auto style = ComputedStyle::Create();
68 // This test assumes that initial 'text-orientation' is not 'upright'.
69 ASSERT_NE(ETextOrientation::kUpright, style->GetTextOrientation());
70 style->SetTextOrientation(ETextOrientation::kUpright);
71
72 StyleResolverState state(GetDocument(), *GetDocument().body(),
73 parent_style.get(), parent_style.get());
74 state.SetStyle(style);
75
76 ASSERT_FALSE(state.GetFontBuilder().FontDirty());
77 StyleBuilder::ApplyProperty(*property, state,
78 ScopedCSSValue(*value, &GetDocument()));
79 EXPECT_TRUE(state.GetFontBuilder().FontDirty());
80 }
81 }
82 }
83
TEST_F(StyleBuilderTest,HasExplicitInheritance)84 TEST_F(StyleBuilderTest, HasExplicitInheritance) {
85 auto parent_style = ComputedStyle::Create();
86 auto style = ComputedStyle::Create();
87 StyleResolverState state(GetDocument(), *GetDocument().body(),
88 parent_style.get(), parent_style.get());
89 state.SetStyle(style);
90 EXPECT_FALSE(style->HasExplicitInheritance());
91
92 ScopedCSSValue inherited(*CSSInheritedValue::Create(), &GetDocument());
93
94 // Flag should not be set for properties which are inherited.
95 StyleBuilder::ApplyProperty(GetCSSPropertyColor(), state, inherited);
96 EXPECT_FALSE(style->HasExplicitInheritance());
97
98 StyleBuilder::ApplyProperty(GetCSSPropertyBackgroundColor(), state,
99 inherited);
100 EXPECT_TRUE(style->HasExplicitInheritance());
101 }
102
103 } // namespace blink
104