summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/css/resolver/style_builder_test.cc
blob: 495229341d321fb5af3d9a391703cffb896b284b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/core/css/resolver/style_builder.h"
#include "third_party/blink/renderer/core/css/css_identifier_value.h"
#include "third_party/blink/renderer/core/css/css_inherited_value.h"
#include "third_party/blink/renderer/core/css/css_initial_value.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver_state.h"
#include "third_party/blink/renderer/core/html/html_element.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"

namespace blink {

class StyleBuilderTest : public PageTestBase {};

TEST_F(StyleBuilderTest, WritingModeChangeDirtiesFont) {
  const CSSProperty* properties[] = {
      &GetCSSPropertyWritingMode(),
      &GetCSSPropertyWebkitWritingMode(),
  };

  HeapVector<Member<const CSSValue>> values = {
      CSSInitialValue::Create(),
      CSSInheritedValue::Create(),
      CSSIdentifierValue::Create(CSSValueID::kHorizontalTb),
  };

  for (const CSSProperty* property : properties) {
    for (const CSSValue* value : values) {
      auto parent_style = ComputedStyle::Create();
      auto style = ComputedStyle::Create();
      // This test assumes that initial 'writing-mode' is not 'vertical-lr'.
      ASSERT_NE(WritingMode::kVerticalLr, style->GetWritingMode());
      style->SetWritingMode(WritingMode::kVerticalLr);

      StyleResolverState state(GetDocument(), *GetDocument().body(),
                               parent_style.get(), parent_style.get());
      state.SetStyle(style);

      ASSERT_FALSE(state.GetFontBuilder().FontDirty());
      StyleBuilder::ApplyProperty(*property, state, *value);
      EXPECT_TRUE(state.GetFontBuilder().FontDirty());
    }
  }
}

TEST_F(StyleBuilderTest, TextOrientationChangeDirtiesFont) {
  const CSSProperty* properties[] = {
      &GetCSSPropertyTextOrientation(),
      &GetCSSPropertyWebkitTextOrientation(),
  };

  HeapVector<Member<const CSSValue>> values = {
      CSSInitialValue::Create(),
      CSSInheritedValue::Create(),
      CSSIdentifierValue::Create(CSSValueID::kMixed),
  };

  for (const CSSProperty* property : properties) {
    for (const CSSValue* value : values) {
      auto parent_style = ComputedStyle::Create();
      auto style = ComputedStyle::Create();
      // This test assumes that initial 'text-orientation' is not 'upright'.
      ASSERT_NE(ETextOrientation::kUpright, style->GetTextOrientation());
      style->SetTextOrientation(ETextOrientation::kUpright);

      StyleResolverState state(GetDocument(), *GetDocument().body(),
                               parent_style.get(), parent_style.get());
      state.SetStyle(style);

      ASSERT_FALSE(state.GetFontBuilder().FontDirty());
      StyleBuilder::ApplyProperty(*property, state, *value);
      EXPECT_TRUE(state.GetFontBuilder().FontDirty());
    }
  }
}

TEST_F(StyleBuilderTest, HasExplicitInheritance) {
  auto parent_style = ComputedStyle::Create();
  auto style = ComputedStyle::Create();
  StyleResolverState state(GetDocument(), *GetDocument().body(),
                           parent_style.get(), parent_style.get());
  state.SetStyle(style);
  EXPECT_FALSE(style->HasExplicitInheritance());

  // Flag should not be set for properties which are inherited.
  StyleBuilder::ApplyProperty(GetCSSPropertyColor(), state,
                              *CSSInheritedValue::Create());
  EXPECT_FALSE(style->HasExplicitInheritance());

  StyleBuilder::ApplyProperty(GetCSSPropertyBackgroundColor(), state,
                              *CSSInheritedValue::Create());
  EXPECT_TRUE(style->HasExplicitInheritance());
}

}  // namespace blink