| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "config.h" | 5 #include "config.h" | 
| 6 #include "core/layout/style/SVGLayoutStyle.h" | 6 #include "core/layout/style/SVGLayoutStyle.h" | 
| 7 | 7 | 
| 8 #include "core/svg/SVGLength.h" |  | 
| 9 |  | 
| 10 #include <gtest/gtest.h> | 8 #include <gtest/gtest.h> | 
| 11 | 9 | 
| 12 using namespace blink; | 10 using namespace blink; | 
| 13 | 11 | 
| 14 namespace { | 12 namespace { | 
| 15 | 13 | 
| 16 // Ensures RefPtrWillBePersistent values are compared by their values, not by po
    inters. |  | 
| 17 #define TEST_STYLE_REFPTRWILLBEPERSISTENT_VALUE_NO_DIFF(type, fieldName) \ |  | 
| 18     { \ |  | 
| 19         RefPtr<SVGLayoutStyle> svg1 = SVGLayoutStyle::create(); \ |  | 
| 20         RefPtr<SVGLayoutStyle> svg2 = SVGLayoutStyle::create(); \ |  | 
| 21         RefPtrWillBePersistent<type> value1 = type::create(); \ |  | 
| 22         RefPtrWillBePersistent<type> value2 = value1->clone(); \ |  | 
| 23         svg1->set##fieldName(value1); \ |  | 
| 24         svg2->set##fieldName(value2); \ |  | 
| 25         EXPECT_FALSE(svg1->diff(svg2.get()).hasDifference()); \ |  | 
| 26     } |  | 
| 27 |  | 
| 28 // Ensures RefPtr values are compared by their values, not by pointers. | 14 // Ensures RefPtr values are compared by their values, not by pointers. | 
| 29 #define TEST_STYLE_REFPTR_VALUE_NO_DIFF(type, fieldName) \ | 15 #define TEST_STYLE_REFPTR_VALUE_NO_DIFF(type, fieldName) \ | 
| 30     { \ | 16     { \ | 
| 31         RefPtr<SVGLayoutStyle> svg1 = SVGLayoutStyle::create(); \ | 17         RefPtr<SVGLayoutStyle> svg1 = SVGLayoutStyle::create(); \ | 
| 32         RefPtr<SVGLayoutStyle> svg2 = SVGLayoutStyle::create(); \ | 18         RefPtr<SVGLayoutStyle> svg2 = SVGLayoutStyle::create(); \ | 
| 33         RefPtr<type> value1 = type::create(); \ | 19         RefPtr<type> value1 = type::create(); \ | 
| 34         RefPtr<type> value2 = value1->copy(); \ | 20         RefPtr<type> value2 = value1->copy(); \ | 
| 35         svg1->set##fieldName(value1); \ | 21         svg1->set##fieldName(value1); \ | 
| 36         svg2->set##fieldName(value2); \ | 22         svg2->set##fieldName(value2); \ | 
| 37         EXPECT_FALSE(svg1->diff(svg2.get()).hasDifference()); \ | 23         EXPECT_FALSE(svg1->diff(svg2.get()).hasDifference()); \ | 
| 38     } | 24     } | 
| 39 | 25 | 
| 40 // This is not very useful for fields directly stored by values, because they ca
    n only be | 26 // This is not very useful for fields directly stored by values, because they ca
    n only be | 
| 41 // compared by values. This macro mainly ensures that we update the comparisons 
    and tests | 27 // compared by values. This macro mainly ensures that we update the comparisons 
    and tests | 
| 42 // when we change some field to RefPtr in the future. | 28 // when we change some field to RefPtr in the future. | 
| 43 #define TEST_STYLE_VALUE_NO_DIFF(type, fieldName) \ | 29 #define TEST_STYLE_VALUE_NO_DIFF(type, fieldName) \ | 
| 44     { \ | 30     { \ | 
| 45         RefPtr<SVGLayoutStyle> svg1 = SVGLayoutStyle::create(); \ | 31         RefPtr<SVGLayoutStyle> svg1 = SVGLayoutStyle::create(); \ | 
| 46         RefPtr<SVGLayoutStyle> svg2 = SVGLayoutStyle::create(); \ | 32         RefPtr<SVGLayoutStyle> svg2 = SVGLayoutStyle::create(); \ | 
| 47         svg1->set##fieldName(SVGLayoutStyle::initial##fieldName()); \ | 33         svg1->set##fieldName(SVGLayoutStyle::initial##fieldName()); \ | 
| 48         svg2->set##fieldName(SVGLayoutStyle::initial##fieldName()); \ | 34         svg2->set##fieldName(SVGLayoutStyle::initial##fieldName()); \ | 
| 49         EXPECT_FALSE(svg1->diff(svg2.get()).hasDifference()); \ | 35         EXPECT_FALSE(svg1->diff(svg2.get()).hasDifference()); \ | 
| 50     } | 36     } | 
| 51 | 37 | 
| 52 TEST(SVGLayoutStyleTest, StrokeStyleShouldCompareValue) | 38 TEST(SVGLayoutStyleTest, StrokeStyleShouldCompareValue) | 
| 53 { | 39 { | 
| 54     TEST_STYLE_VALUE_NO_DIFF(float, StrokeOpacity); | 40     TEST_STYLE_VALUE_NO_DIFF(float, StrokeOpacity); | 
| 55     TEST_STYLE_VALUE_NO_DIFF(float, StrokeMiterLimit); | 41     TEST_STYLE_VALUE_NO_DIFF(float, StrokeMiterLimit); | 
| 56     TEST_STYLE_REFPTRWILLBEPERSISTENT_VALUE_NO_DIFF(SVGLength, StrokeWidth); | 42     TEST_STYLE_VALUE_NO_DIFF(UnzoomedLength, StrokeWidth); | 
| 57     TEST_STYLE_VALUE_NO_DIFF(Length, StrokeDashOffset); | 43     TEST_STYLE_VALUE_NO_DIFF(Length, StrokeDashOffset); | 
| 58     TEST_STYLE_REFPTR_VALUE_NO_DIFF(SVGDashArray, StrokeDashArray); | 44     TEST_STYLE_REFPTR_VALUE_NO_DIFF(SVGDashArray, StrokeDashArray); | 
| 59 | 45 | 
| 60     { | 46     { | 
| 61         RefPtr<SVGLayoutStyle> svg1 = SVGLayoutStyle::create(); | 47         RefPtr<SVGLayoutStyle> svg1 = SVGLayoutStyle::create(); | 
| 62         RefPtr<SVGLayoutStyle> svg2 = SVGLayoutStyle::create(); | 48         RefPtr<SVGLayoutStyle> svg2 = SVGLayoutStyle::create(); | 
| 63         svg1->setStrokePaint(SVGLayoutStyle::initialStrokePaintType(), SVGLayout
    Style::initialStrokePaintColor(), SVGLayoutStyle::initialStrokePaintUri(), true,
     false); | 49         svg1->setStrokePaint(SVGLayoutStyle::initialStrokePaintType(), SVGLayout
    Style::initialStrokePaintColor(), SVGLayoutStyle::initialStrokePaintUri(), true,
     false); | 
| 64         svg2->setStrokePaint(SVGLayoutStyle::initialStrokePaintType(), SVGLayout
    Style::initialStrokePaintColor(), SVGLayoutStyle::initialStrokePaintUri(), true,
     false); | 50         svg2->setStrokePaint(SVGLayoutStyle::initialStrokePaintType(), SVGLayout
    Style::initialStrokePaintColor(), SVGLayoutStyle::initialStrokePaintUri(), true,
     false); | 
| 65         EXPECT_FALSE(svg1->diff(svg2.get()).hasDifference()); | 51         EXPECT_FALSE(svg1->diff(svg2.get()).hasDifference()); | 
| 66     } | 52     } | 
| 67     { | 53     { | 
| 68         RefPtr<SVGLayoutStyle> svg1 = SVGLayoutStyle::create(); | 54         RefPtr<SVGLayoutStyle> svg1 = SVGLayoutStyle::create(); | 
| 69         RefPtr<SVGLayoutStyle> svg2 = SVGLayoutStyle::create(); | 55         RefPtr<SVGLayoutStyle> svg2 = SVGLayoutStyle::create(); | 
| 70         svg1->setStrokePaint(SVGLayoutStyle::initialStrokePaintType(), SVGLayout
    Style::initialStrokePaintColor(), SVGLayoutStyle::initialStrokePaintUri(), false
    , true); | 56         svg1->setStrokePaint(SVGLayoutStyle::initialStrokePaintType(), SVGLayout
    Style::initialStrokePaintColor(), SVGLayoutStyle::initialStrokePaintUri(), false
    , true); | 
| 71         svg2->setStrokePaint(SVGLayoutStyle::initialStrokePaintType(), SVGLayout
    Style::initialStrokePaintColor(), SVGLayoutStyle::initialStrokePaintUri(), false
    , true); | 57         svg2->setStrokePaint(SVGLayoutStyle::initialStrokePaintType(), SVGLayout
    Style::initialStrokePaintColor(), SVGLayoutStyle::initialStrokePaintUri(), false
    , true); | 
| 72         EXPECT_FALSE(svg1->diff(svg2.get()).hasDifference()); | 58         EXPECT_FALSE(svg1->diff(svg2.get()).hasDifference()); | 
| 73     } | 59     } | 
| 74 } | 60 } | 
| 75 | 61 | 
| 76 TEST(SVGLayoutStyleTest, MiscStyleShouldCompareValue) | 62 TEST(SVGLayoutStyleTest, MiscStyleShouldCompareValue) | 
| 77 { | 63 { | 
| 78     TEST_STYLE_VALUE_NO_DIFF(Color, FloodColor); | 64     TEST_STYLE_VALUE_NO_DIFF(Color, FloodColor); | 
| 79     TEST_STYLE_VALUE_NO_DIFF(float, FloodOpacity); | 65     TEST_STYLE_VALUE_NO_DIFF(float, FloodOpacity); | 
| 80     TEST_STYLE_VALUE_NO_DIFF(Color, LightingColor); | 66     TEST_STYLE_VALUE_NO_DIFF(Color, LightingColor); | 
| 81     TEST_STYLE_VALUE_NO_DIFF(Length, BaselineShiftValue); | 67     TEST_STYLE_VALUE_NO_DIFF(Length, BaselineShiftValue); | 
| 82 } | 68 } | 
| 83 | 69 | 
| 84 } | 70 } | 
| OLD | NEW | 
|---|