| 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/css/parser/SizesCalcParser.h" | 6 #include "core/css/parser/SizesCalcParser.h" |
| 7 | 7 |
| 8 #include "core/css/CSSPrimitiveValue.h" | 8 #include "core/css/CSSPrimitiveValue.h" |
| 9 #include "core/css/MediaValuesCached.h" | 9 #include "core/css/MediaValuesCached.h" |
| 10 #include "core/css/StylePropertySet.h" | 10 #include "core/css/StylePropertySet.h" |
| 11 #include "core/css/parser/MediaQueryTokenizer.h" | 11 #include "core/css/parser/MediaQueryTokenizer.h" |
| 12 | 12 |
| 13 #include <gtest/gtest.h> | 13 #include <gtest/gtest.h> |
| 14 | 14 |
| 15 namespace WebCore { | 15 namespace WebCore { |
| 16 | 16 |
| 17 struct TestCase { | 17 struct TestCase { |
| 18 const char* input; | 18 const char* input; |
| 19 const unsigned output; | 19 const unsigned output; |
| 20 const bool valid; | 20 const bool valid; |
| 21 const bool dontRunInCSSCalc; | 21 const bool dontRunInCSSCalc; |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 static void initLengthArray(CSSLengthArray& lengthArray) | |
| 25 { | |
| 26 lengthArray.resize(CSSPrimitiveValue::LengthUnitTypeCount); | |
| 27 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) | |
| 28 lengthArray.at(i) = 0; | |
| 29 } | |
| 30 | |
| 31 static void verifyCSSCalc(String text, double value, bool valid, unsigned fontSi
ze, unsigned viewportWidth, unsigned viewportHeight) | 24 static void verifyCSSCalc(String text, double value, bool valid, unsigned fontSi
ze, unsigned viewportWidth, unsigned viewportHeight) |
| 32 { | 25 { |
| 33 CSSLengthArray lengthArray; | 26 CSSLengthArray lengthArray; |
| 34 initLengthArray(lengthArray); | 27 CSSPrimitiveValue::zeroLengthArray(lengthArray); |
| 35 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::creat
e(); | 28 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::creat
e(); |
| 36 propertySet->setProperty(CSSPropertyLeft, text); | 29 propertySet->setProperty(CSSPropertyLeft, text); |
| 37 RefPtrWillBeRawPtr<CSSValue> cssValue = propertySet->getPropertyCSSValue(CSS
PropertyLeft); | 30 RefPtrWillBeRawPtr<CSSValue> cssValue = propertySet->getPropertyCSSValue(CSS
PropertyLeft); |
| 38 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(cssValue.get()); | 31 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(cssValue.get()); |
| 39 if (primitiveValue) | 32 if (primitiveValue) |
| 40 primitiveValue->accumulateLengthArray(lengthArray); | 33 primitiveValue->accumulateLengthArray(lengthArray); |
| 41 else | 34 else |
| 42 ASSERT_EQ(valid, false); | 35 ASSERT_EQ(valid, false); |
| 43 int length = lengthArray.at(CSSPrimitiveValue::UnitTypePixels); | 36 int length = lengthArray.at(CSSPrimitiveValue::UnitTypePixels); |
| 44 length += lengthArray.at(CSSPrimitiveValue::UnitTypeFontSize) * fontSize; | 37 length += lengthArray.at(CSSPrimitiveValue::UnitTypeFontSize) * fontSize; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 } | 120 } |
| 128 | 121 |
| 129 for (unsigned i = 0; testCases[i].input; ++i) { | 122 for (unsigned i = 0; testCases[i].input; ++i) { |
| 130 if (testCases[i].dontRunInCSSCalc) | 123 if (testCases[i].dontRunInCSSCalc) |
| 131 continue; | 124 continue; |
| 132 verifyCSSCalc(testCases[i].input, testCases[i].output, testCases[i].vali
d, data.defaultFontSize, data.viewportWidth, data.viewportHeight); | 125 verifyCSSCalc(testCases[i].input, testCases[i].output, testCases[i].vali
d, data.defaultFontSize, data.viewportWidth, data.viewportHeight); |
| 133 } | 126 } |
| 134 } | 127 } |
| 135 | 128 |
| 136 } // namespace | 129 } // namespace |
| OLD | NEW |