CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text) { initLengthArray(lengthArray); RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::create(); propertySet->setProperty(CSSPropertyLeft, text); toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).get())->accumulateLengthArray(lengthArray); return lengthArray; }
TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnits) { CSSLengthArray actual, expectation; initLengthArray(expectation); OwnPtr<InterpolableList> list = createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10); toCSSPrimitiveValue(interpolableValueToLength(list.get(), ValueRangeAll).get())->accumulateLengthArray(expectation); EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(10%% + 10ex + 10ch + 10vh + 10vmax)"))); }
CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text) { CSSPrimitiveValue::CSSLengthTypeArray lengthTypeArray; initLengthArray(lengthArray); RefPtrWillBeRawPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::create(HTMLQuirksMode); propertySet->setProperty(CSSPropertyLeft, text); toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).get())->accumulateLengthArray(lengthArray); return lengthArray; }
TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValues) { CSSLengthArray expectation, actual; initLengthArray(expectation); OwnPtr<InterpolableList> result = InterpolableList::create(2); result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); result->set(1, createInterpolableLength(1, 1, 1, 1, 0, 1, 0, 1, 1, 1)); toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get())->accumulateLengthArray(expectation); setLengthArray(actual, "calc(0px + 10% + 0em + 10ex + 10ch + 10vh + 0vmin + 10vmax)"); EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual); }
static void verifyCSSCalc(String text, double value, bool valid, unsigned fontSize, unsigned viewportWidth, unsigned viewportHeight) { CSSLengthArray lengthArray; initLengthArray(lengthArray); RawPtr<CSSValue> cssValue = CSSParser::parseSingleValue(CSSPropertyLeft, text); CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(cssValue.get()); if (primitiveValue) primitiveValue->accumulateLengthArray(lengthArray); else ASSERT_EQ(valid, false); float length = lengthArray.at(CSSPrimitiveValue::UnitTypePixels); length += lengthArray.at(CSSPrimitiveValue::UnitTypeFontSize) * fontSize; length += lengthArray.at(CSSPrimitiveValue::UnitTypeViewportWidth) * viewportWidth / 100.0; length += lengthArray.at(CSSPrimitiveValue::UnitTypeViewportHeight) * viewportHeight / 100.0; ASSERT_EQ(value, length); }