Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: Source/core/css/CSSCalculationValueTest.cpp

Issue 273683005: Web Animations API: Deferred computation of interpolated values (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add missing test file Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/css/CSSPrimitiveValue.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 namespace { 55 namespace {
56 56
57 void testAccumulatePixelsAndPercent(const CSSToLengthConversionData& conversionD ata, PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> expression, float expectedPix els, float expectedPercent) 57 void testAccumulatePixelsAndPercent(const CSSToLengthConversionData& conversionD ata, PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> expression, float expectedPix els, float expectedPercent)
58 { 58 {
59 PixelsAndPercent value(0, 0); 59 PixelsAndPercent value(0, 0);
60 expression->accumulatePixelsAndPercent(conversionData, value); 60 expression->accumulatePixelsAndPercent(conversionData, value);
61 EXPECT_EQ(expectedPixels, value.pixels); 61 EXPECT_EQ(expectedPixels, value.pixels);
62 EXPECT_EQ(expectedPercent, value.percent); 62 EXPECT_EQ(expectedPercent, value.percent);
63 } 63 }
64 64
65 void initLengthArray(CSSLengthArray& lengthArray)
66 {
67 lengthArray.resize(CSSPrimitiveValue::LengthUnitTypeCount);
68 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i)
69 lengthArray.at(i) = 0;
70 }
71
72 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text) 65 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text)
73 { 66 {
74 initLengthArray(lengthArray); 67 CSSPrimitiveValue::zeroLengthArray(lengthArray);
75 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::creat e(); 68 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::creat e();
76 propertySet->setProperty(CSSPropertyLeft, text); 69 propertySet->setProperty(CSSPropertyLeft, text);
77 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).get()) ->accumulateLengthArray(lengthArray); 70 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).get()) ->accumulateLengthArray(lengthArray);
78 return lengthArray; 71 return lengthArray;
79 } 72 }
80 73
81 bool lengthArraysEqual(CSSLengthArray& a, CSSLengthArray& b) 74 bool lengthArraysEqual(CSSLengthArray& a, CSSLengthArray& b)
82 { 75 {
83 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) { 76 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) {
84 if (a.at(i) != b.at(i)) 77 if (a.at(i) != b.at(i))
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 lengthD = lengthA; 157 lengthD = lengthA;
165 EXPECT_EQ(calc->refCount(), 5); 158 EXPECT_EQ(calc->refCount(), 5);
166 159
167 lengthD = Length(); 160 lengthD = Length();
168 EXPECT_EQ(calc->refCount(), 4); 161 EXPECT_EQ(calc->refCount(), 4);
169 } 162 }
170 163
171 TEST(CSSCalculationValue, AddToLengthUnitValues) 164 TEST(CSSCalculationValue, AddToLengthUnitValues)
172 { 165 {
173 CSSLengthArray expectation, actual; 166 CSSLengthArray expectation, actual;
174 initLengthArray(expectation); 167 CSSPrimitiveValue::zeroLengthArray(expectation);
175 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "0"))); 168 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "0")));
176 169
177 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 10; 170 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 10;
178 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "10px"))); 171 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "10px")));
179 172
180 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 0; 173 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 0;
181 expectation.at(CSSPrimitiveValue::UnitTypePercentage) = 20; 174 expectation.at(CSSPrimitiveValue::UnitTypePercentage) = 20;
182 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "20%%"))); 175 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "20%%")));
183 176
184 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 30; 177 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 30;
185 expectation.at(CSSPrimitiveValue::UnitTypePercentage) = -40; 178 expectation.at(CSSPrimitiveValue::UnitTypePercentage) = -40;
186 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(30px - 40%%)"))); 179 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(30px - 40%%)")));
187 180
188 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 90; 181 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 90;
189 expectation.at(CSSPrimitiveValue::UnitTypePercentage) = 10; 182 expectation.at(CSSPrimitiveValue::UnitTypePercentage) = 10;
190 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(1in + 10%% - 6px)"))); 183 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(1in + 10%% - 6px)")));
191 184
192 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 15; 185 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 15;
193 expectation.at(CSSPrimitiveValue::UnitTypeFontSize) = 20; 186 expectation.at(CSSPrimitiveValue::UnitTypeFontSize) = 20;
194 expectation.at(CSSPrimitiveValue::UnitTypePercentage) = -40; 187 expectation.at(CSSPrimitiveValue::UnitTypePercentage) = -40;
195 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc((1 * 2) * (5px + 20em / 2) - 80%% / (3 - 1) + 5px)"))); 188 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc((1 * 2) * (5px + 20em / 2) - 80%% / (3 - 1) + 5px)")));
196 } 189 }
197 190
198 } 191 }
OLDNEW
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/css/CSSPrimitiveValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698