1
+ <!DOCTYPE html>
2
+ < html > < head >
3
+ < title > Geometry Interfaces: DOMPoint and DOMPointReadOnly interface tests</ title >
4
+ < link href ="mailto:hs1217.lee@samsung.com " rel ="author " title ="Hwanseung Lee ">
5
+ < link href ="https://drafts.fxtf.org/geometry-1/#DOMPoint " rel ="help ">
6
+ < script src ="/resources/testharness.js "> </ script >
7
+ < script src ="/resources/testharnessreport.js "> </ script >
8
+ </ head >
9
+ < body >
10
+ < p > Test DOMPoint and DOMPointReadOnly interfaces</ p >
11
+ < div id ="log "> </ div >
12
+ < script >
13
+ function getMatrixTransform ( matrix , point ) {
14
+ var x = point . x * matrix . m11 + point . y * matrix . m21 + point . z * matrix . m31 + point . w * matrix . m41 ;
15
+ var y = point . x * matrix . m12 + point . y * matrix . m22 + point . z * matrix . m32 + point . w * matrix . m42 ;
16
+ var w = point . x * matrix . m13 + point . y * matrix . m23 + point . z * matrix . m33 + point . w * matrix . m43 ;
17
+ var z = point . x * matrix . m14 + point . y * matrix . m24 + point . z * matrix . m34 + point . w * matrix . m44 ;
18
+ return new DOMPoint ( x , y , w , z )
19
+ }
20
+
21
+ test ( function ( ) {
22
+ checkDOMPoint ( new DOMPoint ( ) , { x :0 , y :0 , z :0 , w :1 } ) ;
23
+ } , 'test DOMPoint Constructor no args' ) ;
24
+ test ( function ( ) {
25
+ checkDOMPoint ( new DOMPoint ( 1 ) , { x :1 , y :0 , z :0 , w :1 } ) ;
26
+ } , 'test DOMPoint Constructor one args' ) ;
27
+ test ( function ( ) {
28
+ checkDOMPoint ( new DOMPoint ( 1 , 2 ) , { x :1 , y :2 , z :0 , w :1 } ) ;
29
+ } , 'test DOMPoint Constructor two args' ) ;
30
+ test ( function ( ) {
31
+ checkDOMPoint ( new DOMPoint ( 1 , 2 , 3 ) , { x :1 , y :2 , z :3 , w :1 } ) ;
32
+ } , 'test DOMPoint Constructor three args' ) ;
33
+ test ( function ( ) {
34
+ checkDOMPoint ( new DOMPoint ( 1 , 2 , 3 , 4 ) , { x :1 , y :2 , z :3 , w :4 } ) ;
35
+ } , 'test DOMPoint Constructor four args' ) ;
36
+ test ( function ( ) {
37
+ checkDOMPoint ( new DOMPoint ( 1 , 2 , 3 , 4 , 5 ) , { x :1 , y :2 , z :3 , w :4 } ) ;
38
+ } , 'test DOMPoint Constructor more then four args' ) ;
39
+ test ( function ( ) {
40
+ checkDOMPoint ( new DOMPoint ( 1 , undefined ) , { x :1 , y :0 , z :0 , w :1 } ) ;
41
+ } , 'test DOMPoint Constructor with undefined' ) ;
42
+ test ( function ( ) {
43
+ checkDOMPoint ( new DOMPoint ( "a" , "b" ) , { x :NaN , y :NaN , z :0 , w :1 } ) ;
44
+ } , 'test DOMPoint Constructor with string' ) ;
45
+ test ( function ( ) {
46
+ checkDOMPoint ( new DOMPoint ( { } ) , { x :NaN , y :0 , z :0 , w :1 } ) ;
47
+ } , 'test DOMPoint Constructor with empty object' ) ;
48
+ test ( function ( ) {
49
+ checkDOMPoint ( DOMPoint . fromPoint ( { } ) , { x :0 , y :0 , z :0 , w :1 } ) ;
50
+ } , 'test DOMPoint fromPoint with empty object' ) ;
51
+ test ( function ( ) {
52
+ checkDOMPoint ( DOMPoint . fromPoint ( { x :1 } ) , { x :1 , y :0 , z :0 , w :1 } ) ;
53
+ } , 'test DOMPoint fromPoint with x' ) ;
54
+ test ( function ( ) {
55
+ checkDOMPoint ( DOMPoint . fromPoint ( { x :1 , y :2 } ) , { x :1 , y :2 , z :0 , w :1 } ) ;
56
+ } , 'test DOMPoint fromPoint with x, y' ) ;
57
+ test ( function ( ) {
58
+ checkDOMPoint ( DOMPoint . fromPoint ( { x :1 , y :2 , z :3 } ) , { x :1 , y :2 , z :3 , w :1 } ) ;
59
+ } , 'test DOMPoint fromPoint with x, y, z' ) ;
60
+ test ( function ( ) {
61
+ checkDOMPoint ( DOMPoint . fromPoint ( { x :1 , y :2 , z :3 , w :4 } ) , { x :1 , y :2 , z :3 , w :4 } ) ;
62
+ } , 'test DOMPoint fromPoint with x, y, z, w' ) ;
63
+ test ( function ( ) {
64
+ checkDOMPoint ( DOMPoint . fromPoint ( { x :1 , y :2 , z :3 , w :4 , v :5 } ) , { x :1 , y :2 , z :3 , w :4 } ) ;
65
+ } , 'test DOMPoint fromPoint with x, y, z, w, v' ) ;
66
+ test ( function ( ) {
67
+ checkDOMPoint ( DOMPoint . fromPoint ( { x :1 , z :3 } ) , { x :1 , y :0 , z :3 , w :1 } ) ;
68
+ } , 'test DOMPoint fromPoint with x, z' ) ;
69
+ test ( function ( ) {
70
+ checkDOMPoint ( DOMPoint . fromPoint ( { x :1 , y : undefined , z :3 } ) , { x :1 , y :0 , z :3 , w :1 } ) ;
71
+ } , 'test DOMPoint fromPoint with undefined value' ) ;
72
+ test ( function ( ) {
73
+ var point = new DOMPoint ( 5 , 4 ) ;
74
+ var matrix = new DOMMatrix ( [ 2 , 0 , 0 , 2 , 10 , 10 ] ) ;
75
+ var result = point . matrixTransform ( matrix ) ;
76
+ var expected = getMatrixTransform ( matrix , point ) ;
77
+ checkDOMPoint ( result , expected ) ;
78
+ } , 'test DOMPoint matrixTransform' ) ;
79
+ test ( function ( ) {
80
+ var p = new DOMPoint ( 0 , 0 , 0 , 1 ) ;
81
+ p . x = undefined ;
82
+ p . y = undefined ;
83
+ p . z = undefined ;
84
+ p . w = undefined ;
85
+ checkDOMPoint ( p , { x :NaN , y :NaN , z :NaN , w :NaN } ) ;
86
+ } , 'test DOMPoint Attributes undefined' ) ;
87
+ test ( function ( ) {
88
+ var p = new DOMPoint ( 0 , 0 , 0 , 1 ) ;
89
+ p . x = NaN ;
90
+ p . y = Number . POSITIVE_INFINITY ;
91
+ p . z = Number . NEGATIVE_INFINITY ;
92
+ p . w = Infinity ;
93
+ checkDOMPoint ( p , { x :NaN , y :Infinity , z :- Infinity , w :Infinity } ) ;
94
+ } , 'test DOMPoint Attributes NaN Infinity' ) ;
95
+ test ( function ( ) {
96
+ checkDOMPoint ( new DOMPointReadOnly ( ) , { x :0 , y :0 , z :0 , w :1 } ) ;
97
+ } , 'test DOMPointReadOnly Constructor no args' ) ;
98
+ test ( function ( ) {
99
+ checkDOMPoint ( new DOMPointReadOnly ( 1 ) , { x :1 , y :0 , z :0 , w :1 } ) ;
100
+ } , 'test DOMPointReadOnly Constructor one args' ) ;
101
+ test ( function ( ) {
102
+ checkDOMPoint ( new DOMPointReadOnly ( 1 , 2 ) , { x :1 , y :2 , z :0 , w :1 } ) ;
103
+ } , 'test DOMPointReadOnly Constructor two args' ) ;
104
+ test ( function ( ) {
105
+ checkDOMPoint ( new DOMPointReadOnly ( 1 , 2 , 3 ) , { x :1 , y :2 , z :3 , w :1 } ) ;
106
+ } , 'test DOMPointReadOnly Constructor three args' ) ;
107
+ test ( function ( ) {
108
+ checkDOMPoint ( new DOMPointReadOnly ( 1 , 2 , 3 , 4 ) , { x :1 , y :2 , z :3 , w :4 } ) ;
109
+ } , 'test DOMPointReadOnly Constructor four args' ) ;
110
+ test ( function ( ) {
111
+ checkDOMPoint ( new DOMPointReadOnly ( 1 , 2 , 3 , 4 , 5 ) , { x :1 , y :2 , z :3 , w :4 } ) ;
112
+ } , 'test DOMPointReadOnly Constructor more then four args' ) ;
113
+ test ( function ( ) {
114
+ checkDOMPoint ( new DOMPointReadOnly ( 1 , undefined ) , { x :1 , y :0 , z :0 , w :1 } ) ;
115
+ } , 'test DOMPointReadOnly Constructor with undefined' ) ;
116
+ test ( function ( ) {
117
+ checkDOMPoint ( new DOMPointReadOnly ( "a" , "b" ) , { x :NaN , y :NaN , z :0 , w :1 } ) ;
118
+ } , 'test DOMPointReadOnly Constructor with string' ) ;
119
+ test ( function ( ) {
120
+ checkDOMPoint ( new DOMPointReadOnly ( { } ) , { x :NaN , y :0 , z :0 , w :1 } ) ;
121
+ } , 'test DOMPointReadOnly Constructor with object' ) ;
122
+ test ( function ( ) {
123
+ checkDOMPoint ( DOMPointReadOnly . fromPoint ( { } ) , { x :0 , y :0 , z :0 , w :1 } ) ;
124
+ } , 'test DOMPointReadOnly fromPoint with empty object' ) ;
125
+ test ( function ( ) {
126
+ checkDOMPoint ( DOMPointReadOnly . fromPoint ( { x :1 } ) , { x :1 , y :0 , z :0 , w :1 } ) ;
127
+ } , 'test DOMPointReadOnly fromPoint with x' ) ;
128
+ test ( function ( ) {
129
+ checkDOMPoint ( DOMPointReadOnly . fromPoint ( { x :1 , y :2 } ) , { x :1 , y :2 , z :0 , w :1 } ) ;
130
+ } , 'test DOMPointReadOnly fromPoint with x, y' ) ;
131
+ test ( function ( ) {
132
+ checkDOMPoint ( DOMPointReadOnly . fromPoint ( { x :1 , y :2 , z :3 } ) , { x :1 , y :2 , z :3 , w :1 } ) ;
133
+ } , 'test DOMPointReadOnly fromPoint with x, y, z' ) ;
134
+ test ( function ( ) {
135
+ checkDOMPoint ( DOMPointReadOnly . fromPoint ( { x :1 , y :2 , z :3 , w :4 } ) , { x :1 , y :2 , z :3 , w :4 } ) ;
136
+ } , 'test DOMPointReadOnly fromPoint with x, y, z, w' ) ;
137
+ test ( function ( ) {
138
+ checkDOMPoint ( DOMPointReadOnly . fromPoint ( { x :1 , y :2 , z :3 , w :4 , v :5 } ) , { x :1 , y :2 , z :3 , w :4 } ) ;
139
+ } , 'test DOMPointReadOnly fromPoint with x, y, z, w, v' ) ;
140
+ test ( function ( ) {
141
+ checkDOMPoint ( DOMPointReadOnly . fromPoint ( { x :1 , z :3 } ) , { x :1 , y :0 , z :3 , w :1 } ) ;
142
+ } , 'test DOMPointReadOnly fromPoint with x, z' ) ;
143
+ test ( function ( ) {
144
+ checkDOMPoint ( DOMPointReadOnly . fromPoint ( { x :1 , y : undefined , z :3 } ) , { x :1 , y :0 , z :3 , w :1 } ) ;
145
+ } , 'test DOMPointReadOnly fromPoint with undefined value' ) ;
146
+ test ( function ( ) {
147
+ var point = new DOMPointReadOnly ( 5 , 4 ) ;
148
+ var matrix = new DOMMatrix ( [ 2 , 0 , 0 , 2 , 10 , 10 ] ) ;
149
+ var result = point . matrixTransform ( matrix ) ;
150
+ var expected = getMatrixTransform ( matrix , point ) ;
151
+ checkDOMPoint ( result , expected ) ;
152
+ } , 'test DOMPointReadOnly matrixTransform' ) ;
153
+ test ( function ( ) {
154
+ var p = new DOMPointReadOnly ( 0 , 0 , 0 , 1 ) ;
155
+ p . x = undefined ;
156
+ p . y = undefined ;
157
+ p . z = undefined ;
158
+ p . w = undefined ;
159
+ checkDOMPoint ( p , { x :0 , y :0 , z :0 , w :1 } ) ;
160
+ } , 'test DOMPointReadOnly Attributes undefined' ) ;
161
+
162
+ function checkDOMPoint ( p , exp ) {
163
+ assert_equals ( p . x , exp . x , "x is not matched" ) ;
164
+ assert_equals ( p . y , exp . y , "y is not matched" ) ;
165
+ assert_equals ( p . z , exp . z , "z is not matched" ) ;
166
+ assert_equals ( p . w , exp . w , "w is not matched" ) ;
167
+ }
168
+ </ script >
169
+
170
+
171
+
172
+ </ body > </ html >
0 commit comments