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 "third_party/blink/renderer/core/style/svg_computed_style.h"
6
7 #include "third_party/blink/renderer/core/style/style_difference.h"
8
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace blink {
12
13 // Ensures RefPtr values are compared by their values, not by pointers.
14 #define TEST_STYLE_REFCOUNTED_VALUE_NO_DIFF(type, fieldName) \
15 { \
16 scoped_refptr<SVGComputedStyle> svg1 = SVGComputedStyle::Create(); \
17 scoped_refptr<SVGComputedStyle> svg2 = SVGComputedStyle::Create(); \
18 scoped_refptr<type> value1 = base::MakeRefCounted<type>(); \
19 scoped_refptr<type> value2 = base::MakeRefCounted<type>(value1->data); \
20 svg1->Set##fieldName(value1); \
21 svg2->Set##fieldName(value2); \
22 EXPECT_FALSE(svg1->Diff(*svg2).HasDifference()); \
23 }
24
25 // This is not very useful for fields directly stored by values, because they
26 // can only be compared by values. This macro mainly ensures that we update the
27 // comparisons and tests when we change some field to RefPtr in the future.
28 #define TEST_STYLE_VALUE_NO_DIFF(type, fieldName) \
29 { \
30 scoped_refptr<SVGComputedStyle> svg1 = SVGComputedStyle::Create(); \
31 scoped_refptr<SVGComputedStyle> svg2 = SVGComputedStyle::Create(); \
32 svg1->Set##fieldName(SVGComputedStyle::Initial##fieldName()); \
33 svg2->Set##fieldName(SVGComputedStyle::Initial##fieldName()); \
34 EXPECT_FALSE(svg1->Diff(*svg2).HasDifference()); \
35 }
36
TEST(SVGComputedStyleTest,StrokeStyleShouldCompareValue)37 TEST(SVGComputedStyleTest, StrokeStyleShouldCompareValue) {
38 TEST_STYLE_VALUE_NO_DIFF(float, StrokeOpacity);
39 TEST_STYLE_VALUE_NO_DIFF(float, StrokeMiterLimit);
40 TEST_STYLE_VALUE_NO_DIFF(UnzoomedLength, StrokeWidth);
41 TEST_STYLE_VALUE_NO_DIFF(Length, StrokeDashOffset);
42 TEST_STYLE_REFCOUNTED_VALUE_NO_DIFF(SVGDashArray, StrokeDashArray);
43
44 TEST_STYLE_VALUE_NO_DIFF(SVGPaint, StrokePaint);
45 {
46 scoped_refptr<SVGComputedStyle> svg1 = SVGComputedStyle::Create();
47 scoped_refptr<SVGComputedStyle> svg2 = SVGComputedStyle::Create();
48 svg1->SetInternalVisitedStrokePaint(SVGComputedStyle::InitialStrokePaint());
49 svg2->SetInternalVisitedStrokePaint(SVGComputedStyle::InitialStrokePaint());
50 EXPECT_FALSE(svg1->Diff(*svg2).HasDifference());
51 }
52 }
53
TEST(SVGComputedStyleTest,MiscStyleShouldCompareValue)54 TEST(SVGComputedStyleTest, MiscStyleShouldCompareValue) {
55 TEST_STYLE_VALUE_NO_DIFF(Color, FloodColor);
56 TEST_STYLE_VALUE_NO_DIFF(float, FloodOpacity);
57 TEST_STYLE_VALUE_NO_DIFF(Color, LightingColor);
58 TEST_STYLE_VALUE_NO_DIFF(Length, BaselineShiftValue);
59 }
60
61 } // namespace blink
62