blob: d6c056f1c6deae0f66524db16ebd04d3d9dd00df [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
var simpleLength = new CSSSimpleLength(0, "px");
var decimalLength = new CSSSimpleLength(1.1, "px");
var negativeLength = new CSSSimpleLength(-2.2, "em");
var calcLengthPx = new CSSCalcLength({px: 1});
var calcLength = new CSSCalcLength({px: 1, em: -2.2});
var simplePercent = new CSSSimpleLength(10, "percent");
var calcPercent = new CSSCalcLength({px: 1, percent: 2.2});
var values = [
// 2D CSSTranslation Transform Components
{input: new CSSTranslation(simpleLength, simpleLength),
x: simpleLength, y: simpleLength, is2DComponent: true},
{input: new CSSTranslation(decimalLength, negativeLength),
x: decimalLength, y: negativeLength, is2DComponent: true},
{input: new CSSTranslation(negativeLength, calcLengthPx),
x: negativeLength, y: calcLengthPx, is2DComponent: true},
{input: new CSSTranslation(calcLengthPx, negativeLength),
x: calcLengthPx, y: negativeLength, is2DComponent: true},
{input: new CSSTranslation(calcLengthPx, calcLength),
x: calcLengthPx, y: calcLength, is2DComponent: true},
{input: new CSSTranslation(simplePercent, simpleLength),
x: simplePercent, y: simpleLength, is2DComponent: true},
{input: new CSSTranslation(calcLengthPx, simplePercent),
x: calcLengthPx, y: simplePercent, is2DComponent: true},
{input: new CSSTranslation(calcPercent, calcLength),
x: calcPercent, y: calcLength, is2DComponent: true},
{input: new CSSTranslation(simplePercent, calcPercent),
x: simplePercent, y: calcPercent, is2DComponent: true},
// 3D CSSTranslation Transform Components
{input: new CSSTranslation(simpleLength, simpleLength, simpleLength),
x: simpleLength, y: simpleLength, z: simpleLength, is2DComponent: false},
{input: new CSSTranslation(simpleLength, decimalLength, negativeLength),
x: simpleLength, y: decimalLength, z: negativeLength, is2DComponent: false},
{input: new CSSTranslation(simpleLength, simpleLength, calcLengthPx),
x: simpleLength, y: simpleLength, z: calcLengthPx, is2DComponent: false},
{input: new CSSTranslation(calcLengthPx, calcLength, calcLength),
x: calcLengthPx, y: calcLength, z: calcLength, is2DComponent: false},
{input: new CSSTranslation(simplePercent, decimalLength, simpleLength),
x: simplePercent, y: decimalLength, z: simpleLength, is2DComponent: false},
{input: new CSSTranslation(simpleLength, calcPercent, decimalLength),
x: simpleLength, y: calcPercent, z: decimalLength, is2DComponent: false},
{input: new CSSTranslation(calcPercent, simplePercent, calcLength),
x: calcPercent, y: simplePercent, z: calcLength, is2DComponent: false}
];
function expectedCssString(obj) {
var cssString = obj.is2DComponent ? "translate(" : "translate3d(";
cssString += obj.x.cssString + ", " + obj.y.cssString;
if (!obj.is2DComponent)
cssString += ", " + obj.z.cssString;
cssString += ")";
return cssString;
}
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);
if (values[i].is2DComponent)
assert_equals(values[i].input.z, null);
else
assert_equals(values[i].input.z, values[i].z);
}
}, "Test that the (x, y, z) values for CSSTranslation 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 CSSTranslation is correct.");
test(function() {
for (var i = 0; i < values.length; ++i) {
assert_equals(values[i].input.cssString, expectedCssString(values[i]));
}
}, "Test that cssString values for CSSTranslation is correct.");
test(function() {
assert_throws(null, function() { new CSSTranslation(simpleLength, simpleLength, simplePercent); });
assert_throws(null, function() { new CSSTranslation(simpleLength, simpleLength, calcPercent); });
assert_throws(null, function() { new CSSTranslation(simplePercent, simplePercent, simplePercent); });
}, "Test that CSSTranslation constructor throws when z component contains percent.");
test(function() {
assert_throws(null, function() { new CSSTranslation(); });
assert_throws(null, function() { new CSSTranslation(simpleLength); });
}, "Test that invalid number of arguments for CSSTranslation throws an exception.");
</script>