summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/blink/renderer/core/animation/property_handle_test.cc
blob: 5348c19d696eb1b122f2ac807ec29d400dc83ce1 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright 2015 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/animation/property_handle.h"

#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/svg_names.h"

namespace blink {

using svg_names::kAmplitudeAttr;
using svg_names::kExponentAttr;

class PropertyHandleTest : public testing::Test {};

TEST_F(PropertyHandleTest, Equality) {
  AtomicString name_a = "--a";
  AtomicString name_b = "--b";

  EXPECT_TRUE(PropertyHandle(GetCSSPropertyOpacity()) ==
              PropertyHandle(GetCSSPropertyOpacity()));
  EXPECT_FALSE(PropertyHandle(GetCSSPropertyOpacity()) !=
               PropertyHandle(GetCSSPropertyOpacity()));
  EXPECT_FALSE(PropertyHandle(GetCSSPropertyOpacity()) ==
               PropertyHandle(GetCSSPropertyTransform()));
  EXPECT_TRUE(PropertyHandle(GetCSSPropertyOpacity()) !=
              PropertyHandle(GetCSSPropertyTransform()));
  EXPECT_FALSE(PropertyHandle(GetCSSPropertyOpacity()) ==
               PropertyHandle(name_a));
  EXPECT_TRUE(PropertyHandle(GetCSSPropertyOpacity()) !=
              PropertyHandle(name_a));
  EXPECT_FALSE(PropertyHandle(GetCSSPropertyOpacity()) ==
               PropertyHandle(kAmplitudeAttr));
  EXPECT_TRUE(PropertyHandle(GetCSSPropertyOpacity()) !=
              PropertyHandle(kAmplitudeAttr));

  EXPECT_FALSE(PropertyHandle(name_a) ==
               PropertyHandle(GetCSSPropertyOpacity()));
  EXPECT_TRUE(PropertyHandle(name_a) !=
              PropertyHandle(GetCSSPropertyOpacity()));
  EXPECT_FALSE(PropertyHandle(name_a) ==
               PropertyHandle(GetCSSPropertyTransform()));
  EXPECT_TRUE(PropertyHandle(name_a) !=
              PropertyHandle(GetCSSPropertyTransform()));
  EXPECT_TRUE(PropertyHandle(name_a) == PropertyHandle(name_a));
  EXPECT_FALSE(PropertyHandle(name_a) != PropertyHandle(name_a));
  EXPECT_FALSE(PropertyHandle(name_a) == PropertyHandle(name_b));
  EXPECT_TRUE(PropertyHandle(name_a) != PropertyHandle(name_b));
  EXPECT_FALSE(PropertyHandle(name_a) == PropertyHandle(kAmplitudeAttr));
  EXPECT_TRUE(PropertyHandle(name_a) != PropertyHandle(kAmplitudeAttr));

  EXPECT_FALSE(PropertyHandle(kAmplitudeAttr) ==
               PropertyHandle(GetCSSPropertyOpacity()));
  EXPECT_TRUE(PropertyHandle(kAmplitudeAttr) !=
              PropertyHandle(GetCSSPropertyOpacity()));
  EXPECT_FALSE(PropertyHandle(kAmplitudeAttr) == PropertyHandle(name_a));
  EXPECT_TRUE(PropertyHandle(kAmplitudeAttr) != PropertyHandle(name_a));
  EXPECT_TRUE(PropertyHandle(kAmplitudeAttr) == PropertyHandle(kAmplitudeAttr));
  EXPECT_FALSE(PropertyHandle(kAmplitudeAttr) !=
               PropertyHandle(kAmplitudeAttr));
  EXPECT_FALSE(PropertyHandle(kAmplitudeAttr) == PropertyHandle(kExponentAttr));
  EXPECT_TRUE(PropertyHandle(kAmplitudeAttr) != PropertyHandle(kExponentAttr));
}

TEST_F(PropertyHandleTest, Hash) {
  AtomicString name_a = "--a";
  AtomicString name_b = "--b";

  EXPECT_TRUE(PropertyHandle(GetCSSPropertyOpacity()).GetHash() ==
              PropertyHandle(GetCSSPropertyOpacity()).GetHash());
  EXPECT_FALSE(PropertyHandle(GetCSSPropertyOpacity()).GetHash() ==
               PropertyHandle(name_a).GetHash());
  EXPECT_FALSE(PropertyHandle(GetCSSPropertyOpacity()).GetHash() ==
               PropertyHandle(GetCSSPropertyTransform()).GetHash());
  EXPECT_FALSE(PropertyHandle(GetCSSPropertyOpacity()).GetHash() ==
               PropertyHandle(kAmplitudeAttr).GetHash());

  EXPECT_FALSE(PropertyHandle(name_a).GetHash() ==
               PropertyHandle(GetCSSPropertyOpacity()).GetHash());
  EXPECT_TRUE(PropertyHandle(name_a).GetHash() ==
              PropertyHandle(name_a).GetHash());
  EXPECT_FALSE(PropertyHandle(name_a).GetHash() ==
               PropertyHandle(name_b).GetHash());
  EXPECT_FALSE(PropertyHandle(name_a).GetHash() ==
               PropertyHandle(kExponentAttr).GetHash());

  EXPECT_FALSE(PropertyHandle(kAmplitudeAttr).GetHash() ==
               PropertyHandle(GetCSSPropertyOpacity()).GetHash());
  EXPECT_FALSE(PropertyHandle(kAmplitudeAttr).GetHash() ==
               PropertyHandle(name_a).GetHash());
  EXPECT_TRUE(PropertyHandle(kAmplitudeAttr).GetHash() ==
              PropertyHandle(kAmplitudeAttr).GetHash());
  EXPECT_FALSE(PropertyHandle(kAmplitudeAttr).GetHash() ==
               PropertyHandle(kExponentAttr).GetHash());
}

TEST_F(PropertyHandleTest, Accessors) {
  AtomicString name = "--x";

  EXPECT_TRUE(PropertyHandle(GetCSSPropertyOpacity()).IsCSSProperty());
  EXPECT_TRUE(PropertyHandle(name).IsCSSProperty());
  EXPECT_FALSE(PropertyHandle(kAmplitudeAttr).IsCSSProperty());

  EXPECT_FALSE(PropertyHandle(GetCSSPropertyOpacity()).IsSVGAttribute());
  EXPECT_FALSE(PropertyHandle(name).IsSVGAttribute());
  EXPECT_TRUE(PropertyHandle(kAmplitudeAttr).IsSVGAttribute());

  EXPECT_FALSE(PropertyHandle(GetCSSPropertyOpacity()).IsCSSCustomProperty());
  EXPECT_TRUE(PropertyHandle(name).IsCSSCustomProperty());
  EXPECT_FALSE(PropertyHandle(kAmplitudeAttr).IsCSSCustomProperty());

  EXPECT_EQ(
      CSSPropertyID::kOpacity,
      PropertyHandle(GetCSSPropertyOpacity()).GetCSSProperty().PropertyID());
  EXPECT_EQ(CSSPropertyID::kVariable,
            PropertyHandle(name).GetCSSProperty().PropertyID());
  EXPECT_EQ(name, PropertyHandle(name).CustomPropertyName());
  EXPECT_EQ(kAmplitudeAttr, PropertyHandle(kAmplitudeAttr).SvgAttribute());

  EXPECT_EQ(name, PropertyHandle(name).GetCSSPropertyName().ToAtomicString());
  EXPECT_EQ(CSSPropertyID::kOpacity,
            PropertyHandle(GetCSSPropertyOpacity()).GetCSSPropertyName().Id());
  EXPECT_EQ(
      CSSPropertyID::kColor,
      PropertyHandle(GetCSSPropertyColor(), true).GetCSSPropertyName().Id());
}

}  // namespace blink