Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Unified Diff: third_party/WebKit/LayoutTests/typedcssom/translationTransformComponent.html

Issue 1689573002: CSS Typed OM: asMatrix for TransformComponent with LengthValue types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@asMatrixMethod
Patch Set: Add in Translation and use exceptionState.hadException Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/typedcssom/translationTransformComponent.html
diff --git a/third_party/WebKit/LayoutTests/typedcssom/translationTransformComponent.html b/third_party/WebKit/LayoutTests/typedcssom/translationTransformComponent.html
index 7ae5f462c4b55a22b5ad6c9366f12bcb49fcd7e3..7a4ad3a9f119989aa78c8ab4be62275b00d39d4d 100644
--- a/third_party/WebKit/LayoutTests/typedcssom/translationTransformComponent.html
+++ b/third_party/WebKit/LayoutTests/typedcssom/translationTransformComponent.html
@@ -3,6 +3,7 @@
<script src="../resources/testharnessreport.js"></script>
<script>
+var EPSILON = 1e-6; // float epsilon
var simpleLength = new SimpleLength(0, "px");
var decimalLength = new SimpleLength(1.1, "px");
@@ -94,4 +95,47 @@ test(function() {
assert_throws(null, function() { new Translation(simpleLength); });
}, "Test that invalid number of arguments for Translation throws an exception.");
+function assert_matrix_equals(actual, expected) {
+ assert_equals(actual.is2DComponent(), expected.is2DComponent());
+ for (var attribute in expected) {
+ if (typeof expected[attribute] === "number") {
+ assert_approx_equals(actual[attribute], expected[attribute], EPSILON);
+ } else {
+ assert_equals(actual[attribute], expected[attribute]);
+ }
+ }
+}
+
+test(function() {
+ var coordinates = [
+ {x: 0, y: 0, z: 0},
+ {x: 1, y: 0, z: 0},
+ {x: 0, y: 1, z: 0},
+ {x: 0, y: 0, z: 1},
+ {x: 1, y: 2, z: 3},
+ {x: 1.1, y: 0, z: 3.3},
+ {x: -1, y: 2, z: -0.1}
+ ];
+
+ for (var i = 0; i < coordinates.length; ++i) {
+ var x = coordinates[i].x;
+ var y = coordinates[i].y;
+ var z = coordinates[i].z;
+
+ var lengthX = new SimpleLength(x, "px");
+ var lengthY = new SimpleLength(y, "px");
+ var lengthZ = new SimpleLength(z, "px");
+
+ // Test 2D translation matrix
+ var translation2D = new Translation(lengthX, lengthY);
+ var expectedMatrix2D = new Matrix(1, 0, 0, 1, x, y);
+ assert_matrix_equals(translation2D.asMatrix(), expectedMatrix2D);
+
+ // Test 3D translation matrix
+ var translation3D = new Translation(lengthX, lengthY, lengthZ);
+ var expectedMatrix3D = new Matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1);
+ assert_matrix_equals(translation3D.asMatrix(), expectedMatrix3D);
+ }
+}, "asMatrix for simple Translation instances constructs the correct matrix");
+
</script>

Powered by Google App Engine
This is Rietveld 408576698