summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/geometry/DOMPoint-002.html
blob: 96276d86f5aada1873cc96416cc189a417e22ce4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!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>