Commit c858541b authored by meade's avatar meade Committed by Commit bot

Re-add re-named typed CSS OM tests.

They were deleted in https://codereview.chromium.org/1618523002 because apparently some filesystems get
confused by only changing the case of characters in the filename, so I'm re-adding them in this CL.

Review URL: https://codereview.chromium.org/1612893002

Cr-Commit-Position: refs/heads/master@{#370640}
parent 3aba6483
<!DOCTYPE html>
<script src='../resources/testharness.js'></script>
<script src='../resources/testharnessreport.js'></script>
<script>
test(function() {
assert_throws(null, function() { new CalcLength(); });
assert_throws(null, function() { new CalcLength({}); });
assert_throws(null, function() { new CalcLength({foo: 1}); });
}, 'Test that passing invalid arguments to CalcLength throws an exception.');
test(function() {
var calcLength1 = new CalcLength({px: 1, percent: 2.2});
var calcLength2 = new CalcLength({px: 3, percent: 4.3});
var result = calcLength1.add(calcLength2);
assert_not_equals(calcLength1, result);
assert_not_equals(calcLength2, result);
assert_true(result instanceof CalcLength);
assert_equals(result.px, 4);
assert_equals(result.percent, 6.5);
}, 'Test that adding two CalcLengths produces a new CalcLength with the correct value.');
test(function() {
var calcLength1 = new CalcLength({px: 1, percent: 2.2});
var calcLength2 = new CalcLength({px: 3, percent: 4.3});
var result = calcLength1.subtract(calcLength2);
assert_not_equals(calcLength1, result);
assert_not_equals(calcLength2, result);
assert_true(result instanceof CalcLength);
assert_equals(result.px, -2);
assert_approx_equals(result.percent, -2.1, 0.000001);
}, 'Test that subtracting two CalcLengths produces a new CalcLength with the correct values.');
test(function() {
var calcLength = new CalcLength({px: 1, percent: 5.2});
var result = calcLength.multiply(3);
assert_not_equals(calcLength, result);
assert_equals(result.px, 3);
assert_approx_equals(result.percent, 15.6, 0.000001);
}, 'Test that multiplying a CalcLength produces a new CalcLength with the correct values.');
test(function() {
var calcLength = new CalcLength({px: 3, percent: 15.6});
var result = calcLength.divide(3);
assert_not_equals(calcLength, result);
assert_equals(result.px, 1);
assert_equals(result.percent, 5.2);
}, 'Test that dividing a CalcLength produces a new CalcLength with the correct values.');
test(function() {
var values = [
{input: new CalcLength({px: 1}), cssString: 'calc(1px)'},
{input: new CalcLength({px: -1}), cssString: 'calc(-1px)'},
{input: new CalcLength({px: 1, percent: 15.6}), cssString: 'calc(1px + 15.6%)'},
{input: new CalcLength({px: 1, percent: -15.6}), cssString: 'calc(1px - 15.6%)'},
{input: new CalcLength({px: -1, percent: -15.6}), cssString: 'calc(-1px - 15.6%)'},
{input: new CalcLength({px: -1, percent: -15.6, vw: 5}), cssString: 'calc((-1px - 15.6%) + 5vw)'},
{input: new CalcLength({px: -1, percent: -15.6, vw: -5}), cssString: 'calc((-1px - 15.6%) - 5vw)'},
];
for (var i = 0; i < values.length; ++i) {
assert_equals(values[i].input.cssString, values[i].cssString);
}
}, 'Test that the CSS string method for a CalcLength produces the correct result');
</script>
<body>
</body>
<!DOCTYPE html>
<script src='../resources/testharness.js'></script>
<script src='../resources/testharnessreport.js'></script>
<script>
test(function() {
var result = LengthValue.fromValue(5, 'px');
assert_true(result instanceof SimpleLength);
assert_equals(result.value, 5);
assert_equals(result.type, 'px');
}, "Test that LengthValue's static fromValue method produces a SimpleLength.");
test(function() {
var result = LengthValue.fromDictionary({px: 1, percent: 2.5});
assert_true(result instanceof CalcLength);
assert_equals(result.px, 1);
assert_equals(result.percent, 2.5);
}, "Test that LengthValue's static fromDictionary method produces a CalcLength.");
</script>
<body>
</body>
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
var values = [
{input: new MatrixTransformComponent(0, 0, 0, 0, 0, 0), a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, is2DComponent: true},
{input: new MatrixTransformComponent(2, 4, 6, 8, 10, 12), a: 2, b: 4, c: 6, d: 8, e: 10, f: 12, is2DComponent: true},
{input: new MatrixTransformComponent(-2, -4, -6, -8, -10, -12), a: -2, b: -4, c: -6, d: -8, e: -10, f: -12, is2DComponent: true},
{input: new MatrixTransformComponent(1.1, -2.2, 3.3, -4.4, 5.5, 0.6), a: 1.1, b: -2.2, c: 3.3, d: -4.4, e: 5.5, f: 0.6, is2DComponent: true},
{input: new MatrixTransformComponent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), m11: 0, m12: 0, m13: 0, m14: 0,
m21: 0, m22: 0, m23: 0, m24: 0, m31: 0, m32: 0, m33: 0, m34: 0, m41: 0, m42: 0, m43: 0, m44: 0, is2DComponent: false},
{input: new MatrixTransformComponent(11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, 44), m11: 11, m12: 12, m13: 13, m14: 14,
m21: 21, m22: 22, m23: 23, m24: 24, m31: 31, m32: 32, m33: 33, m34: 34, m41: 41, m42: 42, m43: 43, m44: 44, is2DComponent: false},
{input: new MatrixTransformComponent(1.1, 1.2, -13, -1.4, 2, 0, -2, 4, 3.1, 3, 3, 3.4, -4.1, 42, 43, 4.4), m11: 1.1, m12: 1.2, m13: -13, m14: -1.4,
m21: 2, m22: 0, m23: -2, m24: 4, m31: 3.1, m32: 3, m33: 3, m34: 3.4, m41: -4.1, m42: 42, m43: 43, m44: 4.4, is2DComponent: false},
];
test(function() {
var attributeValues2D = ["a", "b", "c", "d", "e", "f"];
var attributeValues3D = ["m11", "m12", "m13", "m14", "m21", "m22", "m23", "m24", "m31", "m32", "m33", "m34", "m41", "m42", "m43", "m44"];
for (var i = 0; i < values.length; ++i) {
var attributeValues = values[i].is2DComponent ? attributeValues2D : attributeValues3D;
for (var j = 0; j < attributeValues.length; ++j) {
var attribute = attributeValues[j];
assert_equals(values[i].input[attribute], values[i][attribute]);
}
}
}, "Test that the (a, ... , f) and (m11, ... , m44) attributes for MatrixTransformComponent are correct.");
test(function() {
for (var i = 0; i < values.length; ++i) {
assert_equals(values[i].input.is2DComponent(), values[i].is2DComponent);
}
}, "Test that the is2DComponent values for MatrixTransformComponent is correct.");
test(function() {
assert_throws(null, function() { new MatrixTransformComponent(); });
assert_throws(null, function() { new MatrixTransformComponent(0); });
assert_throws(null, function() { new MatrixTransformComponent(0, 1, 2, 3, 4); });
assert_throws(null, function() { new MatrixTransformComponent(0, 1, 2, 3, 4, 5, 6); });
assert_throws(null, function() { new MatrixTransformComponent(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14); });
}, "Test that invalid MatrixTransformComponent constructor arity throws an error.");
</script>
<body>
</body>
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
var values = [
{input: new NumberValue(0), cssString: '0'},
{input: new NumberValue(1), cssString: '1'},
{input: new NumberValue(-2), cssString: '-2'},
{input: new NumberValue(3.4), cssString: '3.4'}
];
test(function() {
for (var i = 0; i < values.length; ++i) {
assert_equals(values[i].input.cssString, values[i].cssString);
}
}, "Test that the css string for NumberValue is correct.");
</script>
<body>
</body>
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
var values = [
{input: new ScaleTransformComponent(0, 0), x: 0, y: 0, z: 1, is2DComponent: true},
{input: new ScaleTransformComponent(1, 2), x: 1, y: 2, z: 1, is2DComponent: true},
{input: new ScaleTransformComponent(-2, -4), x: -2, y: -4, z: 1, is2DComponent: true},
{input: new ScaleTransformComponent(3.4, 2.7), x: 3.4, y: 2.7, z: 1, is2DComponent: true},
{input: new ScaleTransformComponent(0, 0, 0), x: 0, y: 0, z: 0, is2DComponent: false},
{input: new ScaleTransformComponent(1, 2, 3), x: 1, y: 2, z: 3, is2DComponent: false},
{input: new ScaleTransformComponent(3.5, -2.7, -2), x: 3.5, y: -2.7, z: -2, is2DComponent: false}
];
test(function() {
for (var i = 0; i < values.length; ++i) {
assert_equals(values[i].input.x, values[i].x);
assert_equals(values[i].input.y, values[i].y);
assert_equals(values[i].input.z, values[i].z);
}
}, "Test that the (x, y, z) values for ScaleTransformComponent are correct.");
test(function() {
for (var i = 0; i < values.length; ++i) {
assert_equals(values[i].input.is2DComponent(), values[i].is2DComponent);
}
}, "Test that the is2DComponent values for ScaleTransformComponent is correct.");
</script>
<body>
</body>
<!DOCTYPE html>
<script src='../resources/testharness.js'></script>
<script src='../resources/testharnessreport.js'></script>
<script>
test(function() {
var simpleLength1 = new SimpleLength(5.1, 'px');
var simpleLength2 = new SimpleLength(10, 'px');
var result = simpleLength1.add(simpleLength2);
assert_not_equals(simpleLength1, result);
assert_not_equals(simpleLength2, result);
assert_true(result instanceof SimpleLength);
assert_equals(result.value, 15.1);
assert_equals(result.type, 'px');
}, 'Test that adding SimpleLengths with the same unit produces a new SimpleLength with the correct value.');
test(function() {
var simpleLength1 = new SimpleLength(5.1, 'px');
var simpleLength2 = new SimpleLength(10, 'percent');
var result = simpleLength1.add(simpleLength2);
assert_true(result instanceof CalcLength);
assert_equals(result.px, 5.1);
assert_equals(result.percent, 10);
}, 'Test that adding SimpleLengths with different units produces a calc length with the correct values.');
test(function() {
var simpleLength1 = new SimpleLength(5.1, 'px');
var simpleLength2 = new SimpleLength(10, 'px');
var result = simpleLength1.subtract(simpleLength2);
assert_not_equals(simpleLength1, result);
assert_not_equals(simpleLength2, result);
assert_true(result instanceof SimpleLength);
assert_equals(result.value, -4.9);
assert_equals(result.type, 'px');
}, 'Test that subtracting SimpleLengths with the same unit produces a new SimpleLength with the correct value.');
test(function() {
var simpleLength1 = new SimpleLength(5.1, 'px');
var simpleLength2 = new SimpleLength(10, 'percent');
var result = simpleLength1.subtract(simpleLength2);
assert_true(result instanceof CalcLength);
assert_equals(result.px, 5.1);
assert_equals(result.percent, -10);
}, 'Test that subtracting SimpleLengths with different units produces a calc length with the correct values.');
test(function() {
var simpleLength = new SimpleLength(5.2, 'px');
var result = simpleLength.multiply(4);
assert_not_equals(simpleLength, result);
assert_true(result instanceof SimpleLength);
assert_approx_equals(result.value, 20.8, 0.00000001);
assert_equals(result.type, 'px');
}, 'Test that multiplying a SimpleLength produces a new SimpleLength with the correct value.');
test(function() {
var simpleLength = new SimpleLength(25, 'px');
var result = simpleLength.divide(2);
assert_not_equals(simpleLength, result);
assert_true(result instanceof SimpleLength);
assert_equals(result.value, 12.5);
assert_equals(result.type, 'px');
}, 'Test that dividing a SimpleLength produces a new SimpleLength with the correct value.');
test(function() {
var values = [
{input: new SimpleLength(1, 'px'), cssString: '1px' },
{input: new SimpleLength(2, 'percent'), cssString: '2%' },
{input: new SimpleLength(3, '%'), cssString: '3%' },
{input: new SimpleLength(4, 'em'), cssString: '4em' },
{input: new SimpleLength(5, 'ex'), cssString: '5ex' },
{input: new SimpleLength(6, 'ch'), cssString: '6ch' },
{input: new SimpleLength(7, 'rem'), cssString: '7rem' },
{input: new SimpleLength(8, 'vw'), cssString: '8vw' },
{input: new SimpleLength(9, 'vh'), cssString: '9vh' },
{input: new SimpleLength(10, 'vmin'), cssString: '10vmin' },
{input: new SimpleLength(11, 'vmax'), cssString: '11vmax' },
{input: new SimpleLength(12, 'cm'), cssString: '12cm' },
{input: new SimpleLength(13, 'mm'), cssString: '13mm' },
{input: new SimpleLength(14, 'in'), cssString: '14in' },
{input: new SimpleLength(15, 'pc'), cssString: '15pc' },
{input: new SimpleLength(16, 'pt'), cssString: '16pt' },
// Same again to double check that it's case insensitive.
{input: new SimpleLength(1, 'PX'), cssString: '1px' },
{input: new SimpleLength(2, 'PERCENT'), cssString: '2%' },
{input: new SimpleLength(3, '%'), cssString: '3%' },
{input: new SimpleLength(4, 'EM'), cssString: '4em' },
{input: new SimpleLength(5, 'EX'), cssString: '5ex' },
{input: new SimpleLength(6, 'CH'), cssString: '6ch' },
{input: new SimpleLength(7, 'REM'), cssString: '7rem' },
{input: new SimpleLength(8, 'VW'), cssString: '8vw' },
{input: new SimpleLength(9, 'VH'), cssString: '9vh' },
{input: new SimpleLength(10, 'VMIN'), cssString: '10vmin' },
{input: new SimpleLength(11, 'VMAX'), cssString: '11vmax' },
{input: new SimpleLength(12, 'CM'), cssString: '12cm' },
{input: new SimpleLength(13, 'MM'), cssString: '13mm' },
{input: new SimpleLength(14, 'IN'), cssString: '14in' },
{input: new SimpleLength(15, 'PC'), cssString: '15pc' },
{input: new SimpleLength(16, 'PT'), cssString: '16pt' },
];
for (var i = 0; i < values.length; ++i) {
assert_equals(values[i].input.cssString, values[i].cssString);
}
}, 'Test that the SimpleLength css string is generated correctly for each unit type.');
test(function() {
var values = [
{value: NaN, unit: 'px'},
{value: Infinity, unit: 'px'},
{value: -Infinity, unit: 'px'},
{value: 5, unit: 'puppies'}
];
for (var i = 0; i < values.length; ++i) {
assert_throws(null, function() { new SimpleLength(values[i].value, values[i].unit); });
}
}, 'Test that invalid input throws an exception.');
</script>
<body>
</body>
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
test(function() {
var transformValueObject = new TransformValue();
assert_true(transformValueObject instanceof TransformValue);
assert_true(transformValueObject instanceof StyleValue);
}, "A TransformValue object can be constructed");
</script>
<body>
</body>
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