| <!DOCTYPE html> | |
| <html><head> | |
| <title>Geometry Interfaces: DOMPoint and DOMPointReadOnly interface tests</title> | |
| <link href="mailto:hs1217.lee@samsung.com" rel="author" title="Hwanseung Lee"> | |
| <link href="https://drafts.fxtf.org/geometry-1/#DOMPoint" rel="help"> | |
| <script src="/resources/testharness.js"></script> | |
| <script src="/resources/testharnessreport.js"></script> | |
| </head> | |
| <body> | |
| <p>Test DOMPoint and DOMPointReadOnly interfaces</p> | |
| <div id="log"></div> | |
| <script> | |
| function getMatrixTransform(matrix, point) { | |
| var x = point.x * matrix.m11 + point.y * matrix.m21 + point.z * matrix.m31 + point.w * matrix.m41; | |
| var y = point.x * matrix.m12 + point.y * matrix.m22 + point.z * matrix.m32 + point.w * matrix.m42; | |
| var w = point.x * matrix.m13 + point.y * matrix.m23 + point.z * matrix.m33 + point.w * matrix.m43; | |
| var z = point.x * matrix.m14 + point.y * matrix.m24 + point.z * matrix.m34 + point.w * matrix.m44; | |
| return new DOMPoint(x, y, w, z) | |
| } | |
| test(function() { | |
| checkDOMPoint(new DOMPoint(), {x:0, y:0, z:0, w:1}); | |
| },'test DOMPoint Constructor no args'); | |
| test(function() { | |
| checkDOMPoint(new DOMPoint(1), {x:1, y:0, z:0, w:1}); | |
| },'test DOMPoint Constructor one args'); | |
| test(function() { | |
| checkDOMPoint(new DOMPoint(1, 2), {x:1, y:2, z:0, w:1}); | |
| },'test DOMPoint Constructor two args'); | |
| test(function() { | |
| checkDOMPoint(new DOMPoint(1, 2, 3), {x:1, y:2, z:3, w:1}); | |
| },'test DOMPoint Constructor three args'); | |
| test(function() { | |
| checkDOMPoint(new DOMPoint(1, 2, 3, 4), {x:1, y:2, z:3, w:4}); | |
| },'test DOMPoint Constructor four args'); | |
| test(function() { | |
| checkDOMPoint(new DOMPoint(1, 2, 3, 4, 5), {x:1, y:2, z:3, w:4}); | |
| },'test DOMPoint Constructor more then four args'); | |
| test(function() { | |
| checkDOMPoint(new DOMPoint(1, undefined), {x:1, y:0, z:0, w:1}); | |
| },'test DOMPoint Constructor with undefined'); | |
| test(function() { | |
| checkDOMPoint(new DOMPoint("a", "b"), {x:NaN, y:NaN, z:0, w:1}); | |
| },'test DOMPoint Constructor with string'); | |
| test(function() { | |
| checkDOMPoint(new DOMPoint({}), {x:NaN, y:0, z:0, w:1}); | |
| },'test DOMPoint Constructor with empty object'); | |
| test(function() { | |
| checkDOMPoint(DOMPoint.fromPoint({}), {x:0, y:0, z:0, w:1}); | |
| },'test DOMPoint fromPoint with empty object'); | |
| test(function() { | |
| checkDOMPoint(DOMPoint.fromPoint({x:1}), {x:1, y:0, z:0, w:1}); | |
| },'test DOMPoint fromPoint with x'); | |
| test(function() { | |
| checkDOMPoint(DOMPoint.fromPoint({x:1, y:2}), {x:1, y:2, z:0, w:1}); | |
| },'test DOMPoint fromPoint with x, y'); | |
| test(function() { | |
| checkDOMPoint(DOMPoint.fromPoint({x:1, y:2, z:3}), {x:1, y:2, z:3, w:1}); | |
| },'test DOMPoint fromPoint with x, y, z'); | |
| test(function() { | |
| checkDOMPoint(DOMPoint.fromPoint({x:1, y:2, z:3, w:4}), {x:1, y:2, z:3, w:4}); | |
| },'test DOMPoint fromPoint with x, y, z, w'); | |
| test(function() { | |
| checkDOMPoint(DOMPoint.fromPoint({x:1, y:2, z:3, w:4, v:5}), {x:1, y:2, z:3, w:4}); | |
| },'test DOMPoint fromPoint with x, y, z, w, v'); | |
| test(function() { | |
| checkDOMPoint(DOMPoint.fromPoint({x:1, z:3}), {x:1, y:0, z:3, w:1}); | |
| },'test DOMPoint fromPoint with x, z'); | |
| test(function() { | |
| checkDOMPoint(DOMPoint.fromPoint({x:1, y: undefined, z:3}), {x:1, y:0, z:3, w:1}); | |
| },'test DOMPoint fromPoint with undefined value'); | |
| test(function() { | |
| var point = new DOMPoint(5, 4); | |
| var matrix = new DOMMatrix([2, 0, 0, 2, 10, 10]); | |
| var result = point.matrixTransform(matrix); | |
| var expected = getMatrixTransform(matrix, point); | |
| checkDOMPoint(result, expected); | |
| },'test DOMPoint matrixTransform'); | |
| test(function() { | |
| var point = new DOMPoint(42, 84); | |
| assert_throws_js(TypeError, function() { | |
| point.matrixTransform({ is2D: true, m33: 1.0000001 }); | |
| }); | |
| },'test DOMPoint matrixTransform with inconsistent input'); | |
| test(function() { | |
| var p = new DOMPoint(0, 0, 0, 1); | |
| p.x = undefined; | |
| p.y = undefined; | |
| p.z = undefined; | |
| p.w = undefined; | |
| checkDOMPoint(p, {x:NaN, y:NaN, z:NaN, w:NaN}); | |
| },'test DOMPoint Attributes undefined'); | |
| test(function() { | |
| var p = new DOMPoint(0, 0, 0, 1); | |
| p.x = NaN; | |
| p.y = Number.POSITIVE_INFINITY; | |
| p.z = Number.NEGATIVE_INFINITY; | |
| p.w = Infinity; | |
| checkDOMPoint(p, {x:NaN, y:Infinity, z:-Infinity, w:Infinity}); | |
| },'test DOMPoint Attributes NaN Infinity'); | |
| test(function() { | |
| checkDOMPoint(new DOMPointReadOnly(), {x:0, y:0, z:0, w:1}); | |
| },'test DOMPointReadOnly Constructor no args'); | |
| test(function() { | |
| checkDOMPoint(new DOMPointReadOnly(1), {x:1, y:0, z:0, w:1}); | |
| },'test DOMPointReadOnly Constructor one args'); | |
| test(function() { | |
| checkDOMPoint(new DOMPointReadOnly(1, 2), {x:1, y:2, z:0, w:1}); | |
| },'test DOMPointReadOnly Constructor two args'); | |
| test(function() { | |
| checkDOMPoint(new DOMPointReadOnly(1, 2, 3), {x:1, y:2, z:3, w:1}); | |
| },'test DOMPointReadOnly Constructor three args'); | |
| test(function() { | |
| checkDOMPoint(new DOMPointReadOnly(1, 2, 3, 4), {x:1, y:2, z:3, w:4}); | |
| },'test DOMPointReadOnly Constructor four args'); | |
| test(function() { | |
| checkDOMPoint(new DOMPointReadOnly(1, 2, 3, 4, 5), {x:1, y:2, z:3, w:4}); | |
| },'test DOMPointReadOnly Constructor more then four args'); | |
| test(function() { | |
| checkDOMPoint(new DOMPointReadOnly(1, undefined), {x:1, y:0, z:0, w:1}); | |
| },'test DOMPointReadOnly Constructor with undefined'); | |
| test(function() { | |
| checkDOMPoint(new DOMPointReadOnly("a", "b"), {x:NaN, y:NaN, z:0, w:1}); | |
| },'test DOMPointReadOnly Constructor with string'); | |
| test(function() { | |
| checkDOMPoint(new DOMPointReadOnly({}), {x:NaN, y:0, z:0, w:1}); | |
| },'test DOMPointReadOnly Constructor with object'); | |
| test(function() { | |
| checkDOMPoint(DOMPointReadOnly.fromPoint({}), {x:0, y:0, z:0, w:1}); | |
| },'test DOMPointReadOnly fromPoint with empty object'); | |
| test(function() { | |
| checkDOMPoint(DOMPointReadOnly.fromPoint({x:1}), {x:1, y:0, z:0, w:1}); | |
| },'test DOMPointReadOnly fromPoint with x'); | |
| test(function() { | |
| checkDOMPoint(DOMPointReadOnly.fromPoint({x:1, y:2}), {x:1, y:2, z:0, w:1}); | |
| },'test DOMPointReadOnly fromPoint with x, y'); | |
| test(function() { | |
| checkDOMPoint(DOMPointReadOnly.fromPoint({x:1, y:2, z:3}), {x:1, y:2, z:3, w:1}); | |
| },'test DOMPointReadOnly fromPoint with x, y, z'); | |
| test(function() { | |
| checkDOMPoint(DOMPointReadOnly.fromPoint({x:1, y:2, z:3, w:4}), {x:1, y:2, z:3, w:4}); | |
| },'test DOMPointReadOnly fromPoint with x, y, z, w'); | |
| test(function() { | |
| checkDOMPoint(DOMPointReadOnly.fromPoint({x:1, y:2, z:3, w:4, v:5}), {x:1, y:2, z:3, w:4}); | |
| },'test DOMPointReadOnly fromPoint with x, y, z, w, v'); | |
| test(function() { | |
| checkDOMPoint(DOMPointReadOnly.fromPoint({x:1, z:3}), {x:1, y:0, z:3, w:1}); | |
| },'test DOMPointReadOnly fromPoint with x, z'); | |
| test(function() { | |
| checkDOMPoint(DOMPointReadOnly.fromPoint({x:1, y: undefined, z:3}), {x:1, y:0, z:3, w:1}); | |
| },'test DOMPointReadOnly fromPoint with undefined value'); | |
| test(function() { | |
| var point = new DOMPointReadOnly(5, 4); | |
| var matrix = new DOMMatrix([1, 2, 3, 4, 5, 6]); | |
| var result = point.matrixTransform(matrix); | |
| var expected = getMatrixTransform(matrix, point); | |
| checkDOMPoint(result, expected); | |
| },'test DOMPointReadOnly matrixTransform'); | |
| test(function() { | |
| var p = new DOMPointReadOnly(0, 0, 0, 1); | |
| p.x = undefined; | |
| p.y = undefined; | |
| p.z = undefined; | |
| p.w = undefined; | |
| checkDOMPoint(p, {x:0, y:0, z:0, w:1}); | |
| },'test DOMPointReadOnly Attributes undefined'); | |
| function checkDOMPoint(p, exp) { | |
| assert_equals(p.x, exp.x, "x is not matched"); | |
| assert_equals(p.y, exp.y, "y is not matched"); | |
| assert_equals(p.z, exp.z, "z is not matched"); | |
| assert_equals(p.w, exp.w, "w is not matched"); | |
| } | |
| </script> | |
| </body></html> |