Chromium Code Reviews| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 EXPECT_EQ(expectedPercent, value.percent); | 62 EXPECT_EQ(expectedPercent, value.percent); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void initLengthArray(CSSLengthArray& lengthArray) | 65 void initLengthArray(CSSLengthArray& lengthArray) |
| 66 { | 66 { |
| 67 lengthArray.resize(CSSPrimitiveValue::LengthUnitTypeCount); | 67 lengthArray.resize(CSSPrimitiveValue::LengthUnitTypeCount); |
| 68 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) | 68 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) |
| 69 lengthArray.at(i) = 0; | 69 lengthArray.at(i) = 0; |
| 70 } | 70 } |
| 71 | 71 |
| 72 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text) | 72 void initLengthTypeArray(CSSLengthTypeArray& lengthTypeArray) |
| 73 { | |
| 74 lengthTypeArray.resize(CSSPrimitiveValue::LengthUnitTypeCount); | |
| 75 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) | |
| 76 lengthTypeArray.clear(i); | |
| 77 } | |
| 78 | |
| 79 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, CSSLengthTypeArray& lengthTypeArray, String text) | |
| 73 { | 80 { |
| 74 initLengthArray(lengthArray); | 81 initLengthArray(lengthArray); |
| 82 initLengthTypeArray(lengthTypeArray); | |
| 75 RefPtrWillBeRawPtr<MutableStylePropertySet> propertySet = MutableStyleProper tySet::create(); | 83 RefPtrWillBeRawPtr<MutableStylePropertySet> propertySet = MutableStyleProper tySet::create(); |
| 76 propertySet->setProperty(CSSPropertyLeft, text); | 84 propertySet->setProperty(CSSPropertyLeft, text); |
| 77 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).get()) ->accumulateLengthArray(lengthArray); | 85 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).get()) ->accumulateLengthArray(lengthArray, lengthTypeArray); |
| 78 return lengthArray; | 86 return lengthArray; |
| 79 } | 87 } |
| 80 | 88 |
| 81 bool lengthArraysEqual(CSSLengthArray& a, CSSLengthArray& b) | 89 bool lengthArraysEqual(CSSLengthArray& a, CSSLengthArray& b) |
| 82 { | 90 { |
| 83 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) { | 91 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) { |
| 84 if (a.at(i) != b.at(i)) | 92 if (a.at(i) != b.at(i)) |
| 85 return false; | 93 return false; |
| 86 } | 94 } |
| 87 return true; | 95 return true; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 lengthD = lengthA; | 172 lengthD = lengthA; |
| 165 EXPECT_EQ(calc->refCount(), 5); | 173 EXPECT_EQ(calc->refCount(), 5); |
| 166 | 174 |
| 167 lengthD = Length(); | 175 lengthD = Length(); |
| 168 EXPECT_EQ(calc->refCount(), 4); | 176 EXPECT_EQ(calc->refCount(), 4); |
| 169 } | 177 } |
| 170 | 178 |
| 171 TEST(CSSCalculationValue, AddToLengthUnitValues) | 179 TEST(CSSCalculationValue, AddToLengthUnitValues) |
| 172 { | 180 { |
| 173 CSSLengthArray expectation, actual; | 181 CSSLengthArray expectation, actual; |
| 182 CSSLengthTypeArray expectedType, actualType; | |
| 174 initLengthArray(expectation); | 183 initLengthArray(expectation); |
| 175 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "0"))); | 184 initLengthTypeArray(expectedType); |
|
samli
2014/12/22 03:38:04
Not actually used. Remove once you add the extra a
evemj (not active)
2014/12/22 06:09:05
Done.
| |
| 185 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, actualType , "0"))); | |
| 176 | 186 |
| 177 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 10; | 187 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 10; |
| 178 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "10px"))); | 188 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, actualType , "10px"))); |
| 179 | 189 |
| 180 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 0; | 190 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 0; |
| 181 expectation.at(CSSPrimitiveValue::UnitTypePercentage) = 20; | 191 expectation.at(CSSPrimitiveValue::UnitTypePercentage) = 20; |
| 182 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "20%"))); | 192 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, actualType , "20%"))); |
| 183 | 193 |
| 184 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 30; | 194 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 30; |
| 185 expectation.at(CSSPrimitiveValue::UnitTypePercentage) = -40; | 195 expectation.at(CSSPrimitiveValue::UnitTypePercentage) = -40; |
| 186 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(30px - 40%)"))); | 196 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, actualType , "calc(30px - 40%)"))); |
| 187 | 197 |
| 188 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 90; | 198 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 90; |
| 189 expectation.at(CSSPrimitiveValue::UnitTypePercentage) = 10; | 199 expectation.at(CSSPrimitiveValue::UnitTypePercentage) = 10; |
| 190 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(1in + 10% - 6px)"))); | 200 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, actualType , "calc(1in + 10% - 6px)"))); |
| 191 | 201 |
| 192 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 15; | 202 expectation.at(CSSPrimitiveValue::UnitTypePixels) = 15; |
| 193 expectation.at(CSSPrimitiveValue::UnitTypeFontSize) = 20; | 203 expectation.at(CSSPrimitiveValue::UnitTypeFontSize) = 20; |
| 194 expectation.at(CSSPrimitiveValue::UnitTypePercentage) = -40; | 204 expectation.at(CSSPrimitiveValue::UnitTypePercentage) = -40; |
| 195 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc((1 * 2) * (5px + 20em / 2) - 80% / (3 - 1) + 5px)"))); | 205 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, actualType , "calc((1 * 2) * (5px + 20em / 2) - 80% / (3 - 1) + 5px)"))); |
| 196 } | 206 } |
| 197 | 207 |
| 198 } | 208 } |
| OLD | NEW |