| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "core/css/CSSPrimitiveValue.h" | 34 #include "core/css/CSSPrimitiveValue.h" |
| 35 #include "core/rendering/style/RenderStyle.h" | 35 #include "core/rendering/style/RenderStyle.h" |
| 36 #include "core/rendering/style/StyleInheritedData.h" | 36 #include "core/rendering/style/StyleInheritedData.h" |
| 37 | 37 |
| 38 #include <gtest/gtest.h> | 38 #include <gtest/gtest.h> |
| 39 | 39 |
| 40 using namespace WebCore; | 40 using namespace WebCore; |
| 41 | 41 |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 void testExpression(PassRefPtr<CSSCalcExpressionNode> expression, const RenderSt
yle* style) |
| 45 { |
| 46 EXPECT_TRUE( |
| 47 expression->equals( |
| 48 *CSSCalcValue::createExpressionNode( |
| 49 expression->toCalcValue(style, style, style->effectiveZoom()).ge
t(), |
| 50 style).get())); |
| 51 } |
| 52 |
| 44 TEST(CSSCalculationValue, CreateExpressionNodeFromLength) | 53 TEST(CSSCalculationValue, CreateExpressionNodeFromLength) |
| 45 { | 54 { |
| 46 RefPtr<RenderStyle> style = RenderStyle::create(); | 55 RefPtr<RenderStyle> style = RenderStyle::create(); |
| 47 RefPtr<CSSCalcExpressionNode> expected; | 56 RefPtr<CSSCalcExpressionNode> expected; |
| 48 RefPtr<CSSCalcExpressionNode> actual; | 57 RefPtr<CSSCalcExpressionNode> actual; |
| 49 | 58 |
| 50 expected = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(10,
CSSPrimitiveValue::CSS_PX), true); | 59 expected = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(10,
CSSPrimitiveValue::CSS_PX), true); |
| 51 actual = CSSCalcValue::createExpressionNode(Length(10, WebCore::Fixed), styl
e.get()); | 60 actual = CSSCalcValue::createExpressionNode(Length(10, WebCore::Fixed), styl
e.get()); |
| 52 EXPECT_TRUE(actual->equals(*expected.get())); | 61 EXPECT_TRUE(actual->equals(*expected.get())); |
| 53 | 62 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 CalcMultiply), | 99 CalcMultiply), |
| 91 CalcAdd); | 100 CalcAdd); |
| 92 actual = CSSCalcValue::createExpressionNode( | 101 actual = CSSCalcValue::createExpressionNode( |
| 93 Length(CalculationValue::create( | 102 Length(CalculationValue::create( |
| 94 adoptPtr(new CalcExpressionBlendLength(Length(50, WebCore::Fixed), L
ength(60, WebCore::Fixed), 0.75)), | 103 adoptPtr(new CalcExpressionBlendLength(Length(50, WebCore::Fixed), L
ength(60, WebCore::Fixed), 0.75)), |
| 95 CalculationRangeAll)), | 104 CalculationRangeAll)), |
| 96 style.get()); | 105 style.get()); |
| 97 EXPECT_TRUE(actual->equals(*expected.get())); | 106 EXPECT_TRUE(actual->equals(*expected.get())); |
| 98 } | 107 } |
| 99 | 108 |
| 109 TEST(CSSCalculationValue, CreateExpressionNodeFromLengthFromExpressionNode) |
| 110 { |
| 111 RefPtr<CSSCalcExpressionNode> expression; |
| 112 RefPtr<RenderStyle> style = RenderStyle::createDefaultStyle(); |
| 113 style->setEffectiveZoom(5); |
| 114 |
| 115 testExpression( |
| 116 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(10, CSSPrim
itiveValue::CSS_PX), true), |
| 117 style.get()); |
| 118 |
| 119 testExpression( |
| 120 CSSCalcValue::createExpressionNode( |
| 121 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(10, CSS
PrimitiveValue::CSS_PX), true), |
| 122 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(20, CSS
PrimitiveValue::CSS_PX), true), |
| 123 CalcAdd), |
| 124 style.get()); |
| 125 |
| 126 testExpression( |
| 127 CSSCalcValue::createExpressionNode( |
| 128 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(30, CSS
PrimitiveValue::CSS_PX), true), |
| 129 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(40, CSS
PrimitiveValue::CSS_NUMBER), true), |
| 130 CalcMultiply), |
| 131 style.get()); |
| 132 |
| 133 testExpression( |
| 134 CSSCalcValue::createExpressionNode( |
| 135 CSSCalcValue::createExpressionNode( |
| 136 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(50,
CSSPrimitiveValue::CSS_PX), true), |
| 137 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(0.2
5, CSSPrimitiveValue::CSS_NUMBER), false), |
| 138 CalcMultiply), |
| 139 CSSCalcValue::createExpressionNode( |
| 140 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(60,
CSSPrimitiveValue::CSS_PX), true), |
| 141 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(0.7
5, CSSPrimitiveValue::CSS_NUMBER), false), |
| 142 CalcMultiply), |
| 143 CalcAdd), |
| 144 style.get()); |
| 100 } | 145 } |
| 146 |
| 147 } |
| OLD | NEW |