2 * Copyright (c) 2013, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "core/css/CSSCalculationValue.h"
34 #include "core/css/CSSPrimitiveValue.h"
35 #include "core/css/CSSToLengthConversionData.h"
36 #include "core/rendering/style/RenderStyle.h"
37 #include "core/rendering/style/StyleInheritedData.h"
39 #include <gtest/gtest.h>
41 using namespace WebCore;
45 void testExpression(PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> expression, const RenderStyle* style)
49 *CSSCalcValue::createExpressionNode(
50 expression->toCalcValue(CSSToLengthConversionData(style, style, 0)).get(),
51 style->effectiveZoom()).get()));
54 TEST(CSSCalculationValue, CreateExpressionNodeFromLength)
56 RefPtr<RenderStyle> style = RenderStyle::create();
57 RefPtrWillBeRawPtr<CSSCalcExpressionNode> expected = nullptr;
58 RefPtrWillBeRawPtr<CSSCalcExpressionNode> actual = nullptr;
60 expected = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX), true);
61 actual = CSSCalcValue::createExpressionNode(Length(10, WebCore::Fixed), style->effectiveZoom());
62 EXPECT_TRUE(actual->equals(*expected.get()));
64 expected = CSSCalcValue::createExpressionNode(
65 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX), true),
66 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(20, CSSPrimitiveValue::CSS_PX), true),
68 actual = CSSCalcValue::createExpressionNode(
69 Length(CalculationValue::create(
70 adoptPtr(new CalcExpressionBinaryOperation(
71 adoptPtr(new CalcExpressionLength(Length(10, WebCore::Fixed))),
72 adoptPtr(new CalcExpressionLength(Length(20, WebCore::Fixed))),
75 style->effectiveZoom());
76 EXPECT_TRUE(actual->equals(*expected.get()));
78 expected = CSSCalcValue::createExpressionNode(
79 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PX), true),
80 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(40, CSSPrimitiveValue::CSS_NUMBER), true),
82 actual = CSSCalcValue::createExpressionNode(
83 Length(CalculationValue::create(
84 adoptPtr(new CalcExpressionBinaryOperation(
85 adoptPtr(new CalcExpressionLength(Length(30, WebCore::Fixed))),
86 adoptPtr(new CalcExpressionNumber(40)),
89 style->effectiveZoom());
90 EXPECT_TRUE(actual->equals(*expected.get()));
92 expected = CSSCalcValue::createExpressionNode(
93 CSSCalcValue::createExpressionNode(
94 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(50, CSSPrimitiveValue::CSS_PX), true),
95 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(0.25, CSSPrimitiveValue::CSS_NUMBER), false),
97 CSSCalcValue::createExpressionNode(
98 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(60, CSSPrimitiveValue::CSS_PX), true),
99 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(0.75, CSSPrimitiveValue::CSS_NUMBER), false),
102 actual = CSSCalcValue::createExpressionNode(
103 Length(CalculationValue::create(
104 adoptPtr(new CalcExpressionBlendLength(Length(50, WebCore::Fixed), Length(60, WebCore::Fixed), 0.75)),
106 style->effectiveZoom());
107 EXPECT_TRUE(actual->equals(*expected.get()));
110 TEST(CSSCalculationValue, CreateExpressionNodeFromLengthFromExpressionNode)
112 RefPtr<RenderStyle> style = RenderStyle::createDefaultStyle();
113 style->setEffectiveZoom(5);
116 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX), true),
120 CSSCalcValue::createExpressionNode(
121 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX), true),
122 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(20, CSSPrimitiveValue::CSS_PX), true),
127 CSSCalcValue::createExpressionNode(
128 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PX), true),
129 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(40, CSSPrimitiveValue::CSS_NUMBER), true),
134 CSSCalcValue::createExpressionNode(
135 CSSCalcValue::createExpressionNode(
136 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(50, CSSPrimitiveValue::CSS_PX), true),
137 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(0.25, CSSPrimitiveValue::CSS_NUMBER), false),
139 CSSCalcValue::createExpressionNode(
140 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(60, CSSPrimitiveValue::CSS_PX), true),
141 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(0.75, CSSPrimitiveValue::CSS_NUMBER), false),