| <!DOCTYPE html> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| |
| <script> |
| var EPSILON = 1e-6; // float epsilon |
| var values = [ |
| {input: new CSSSkew(0, 0), ax: 0, ay: 0, cssText: "skew(0, 0)"}, |
| {input: new CSSSkew(1, 2), ax: 1, ay: 2, cssText: "skew(1, 2)"}, |
| {input: new CSSSkew(-2, -4), ax: -2, ay: -4, cssText: "skew(-2, -4)"}, |
| {input: new CSSSkew(3.4, 2.7), ax: 3.4, ay: 2.7, cssText: "skew(3.4, 2.7)"} |
| ]; |
| |
| test(function() { |
| for (var i = 0; i < values.length; ++i) { |
| assert_equals(values[i].input.ax, values[i].ax); |
| assert_equals(values[i].input.ay, values[i].ay); |
| } |
| }, "Test that the (ax, ay) values for CSSSkew are correct."); |
| |
| test(function() { |
| for (var i = 0; i < values.length; ++i) { |
| assert_true(values[i].input.is2D()); |
| } |
| }, "Test that the is2D values for CSSSkew is correct."); |
| |
| test(function() { |
| for (var i = 0; i < values.length; ++i) { |
| assert_equals(values[i].input.cssText, values[i].cssText); |
| } |
| }, "Test that the cssText for CSSSkew is correct."); |
| |
| test(function() { |
| assert_throws(null, function() { new CSSSkew(); }); |
| assert_throws(null, function() { new CSSSkew(1); }); |
| }, "Test that invalid number of arguments for CSSSkew throws an exception."); |
| |
| function tanDegrees(degrees) { |
| var radians = degrees * Math.PI / 180; |
| return Math.tan(radians); |
| } |
| |
| test(function() { |
| for (var i = 0; i < values.length; ++i) { |
| var input = values[i].input; |
| var inputAsMatrix = input.asMatrix(); |
| assert_true(inputAsMatrix.is2D()); |
| var tanAx = tanDegrees(input.ax); |
| var tanAy = tanDegrees(input.ay); |
| var expectedMatrix = new CSSMatrixTransformComponent(1, tanAy, tanAx, 1, 0, 0); |
| for (var attribute in expectedMatrix) { |
| if (typeof expectedMatrix[attribute] === "number") { |
| assert_approx_equals(inputAsMatrix[attribute], expectedMatrix[attribute], EPSILON); |
| } else { |
| assert_equals(inputAsMatrix[attribute], expectedMatrix[attribute]); |
| } |
| } |
| } |
| }, "Test that asMatrix is constructed correctly for CSSSkew."); |
| |
| </script> |