Commit b70aed12 authored by Eddy Mead's avatar Eddy Mead Committed by Commit Bot

[CSS Typed OM] Add extra tests for CSSScale

Found during testing:
- scale(sx) should be the same as scale(sx, sx)
spec here: https://drafts.csswg.org/css-transforms/#valdef-transform-scale

Bug: 545318
Change-Id: Icfb150ecc83e55b142d6d6ea21e00caf28b117ad
Reviewed-on: https://chromium-review.googlesource.com/554634
Commit-Queue: meade_UTC10 <meade@chromium.org>
Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487439}
parent 5566a0f4
......@@ -31,7 +31,10 @@ runInlineStylePropertyMapTests( {
new CSSTransformValue(
[new CSSTranslation(CSS.px(-10), CSS.px(-20), CSS.px(-30))]),
// Scales
// TODO(meade)
new CSSTransformValue([new CSSScale(1, 2.2)]),
new CSSTransformValue([new CSSScale(1, 2.2, 3)]),
new CSSTransformValue([new CSSScale(-1, -2.2)]),
new CSSTransformValue([new CSSScale(-1, -2.2, -3)]),
// Skews
new CSSTransformValue([new CSSSkew(CSS.deg(30), CSS.deg(0))]),
new CSSTransformValue([new CSSSkew(CSS.rad(10), CSS.deg(0))]),
......@@ -67,6 +70,10 @@ runInlineStylePropertyMapTests( {
'translateZ(30in)':
new CSSTransformValue(
[new CSSTranslation(CSS.px(0), CSS.px(0), CSS.in(30))]),
// Scales
'scale(4)': new CSSTransformValue([new CSSScale(4, 4)]),
'scaleX(2)': new CSSTransformValue([new CSSScale(2, 1)]),
'scaleY(3)': new CSSTransformValue([new CSSScale(1, 3)]),
// Skews
'skew(45deg)':
new CSSTransformValue([new CSSSkew(CSS.deg(45), CSS.deg(0))]),
......
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<div id="testElement"></div>
<script>
var EPSILON = 1e-6; // float epsilon
function validateTransformWithSingleScale(transform, x, y, z, cssText) {
assert_equals(transform.toString(), cssText);
// Shouldn't be base StyleValue as for unsupported values.
assert_equals(transform.constructor.name, CSSTransformValue.name);
var components = [...transform.values()];
assert_equals(components.length, 1);
assert_equals(components[0].constructor.name, CSSScale.name);
assert_equals(components[0].toString(), cssText);
assert_approx_equals(components[0].x, x, EPSILON);
assert_approx_equals(components[0].y, y, EPSILON);
assert_approx_equals(components[0].z, z, EPSILON);
}
test(function() {
testElement.style.transform = "scale(5)";
validateTransformWithSingleScale(
testElement.styleMap.get("transform"),
5, 1, 1,
"scale(5, 1)");
}, "Single argument rotation read from a StyleMap is correct");
test(function() {
testElement.style.transform = "scale(5, 4)";
validateTransformWithSingleScale(
testElement.styleMap.get("transform"),
5, 4, 1,
"scale(5, 4)");
}, "Two-argument rotation read from a StyleMap is correct");
test(function() {
testElement.style.transform = "scale3d(1, 2, 3)";
validateTransformWithSingleScale(
testElement.styleMap.get("transform"),
1, 2, 3,
"scale3d(1, 2, 3)");
}, "scale3d read from a StyleMap is correct");
test(function() {
testElement.style.transform = "scaleX(4.5)";
validateTransformWithSingleScale(
testElement.styleMap.get("transform"),
4.5, 1, 1,
"scale(4.5, 1)");
}, "scaleX read from a StyleMap works");
test(function() {
testElement.style.transform = "scaleY(8.1)";
validateTransformWithSingleScale(
testElement.styleMap.get("transform"),
1, 8.1, 1,
"scale(1, 8.1)");
}, "scaleY read from a StyleMap works");
test(function() {
testElement.style.transform = "scaleZ(1.6)";
validateTransformWithSingleScale(
testElement.styleMap.get("transform"),
1, 1, 1.6,
"scale3d(1, 1, 1.6)");
}, "scaleZ read from a StyleMap results in a scale3d");
test(function() {
testElement.styleMap.set(
'transform',
new CSSTransformValue([new CSSScale(1.2, 3.4)]));
assert_equals(testElement.style.transform, 'scale(1.2, 3.4)');
}, "Set a 2-argument CSSScale into a styleMap");
test(function() {
testElement.styleMap.set(
'transform',
new CSSTransformValue([new CSSScale(1.2, 3.4, 5.6)]));
assert_equals(testElement.style.transform, 'scale3d(1.2, 3.4, 5.6)');
}, "Set a 3-argument CSSScale into a styleMap");
</script>
......@@ -14,7 +14,7 @@ CSSScale* FromScale(const CSSFunctionValue& value) {
DCHECK(value.length() == 1U || value.length() == 2U);
double x = ToCSSPrimitiveValue(value.Item(0)).GetDoubleValue();
if (value.length() == 1U)
return CSSScale::Create(x, 1);
return CSSScale::Create(x, x);
double y = ToCSSPrimitiveValue(value.Item(1)).GetDoubleValue();
return CSSScale::Create(x, y);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment