1<!DOCTYPE html>
2<html>
3<head>
4 <title>Geometry Interfaces: DOMPoint and DOMPointReadOnly interface tests.</title>
5 <link rel="author" title="Dirk Schulze" href="mailto:dschulze@adobe.com" />
6 <link rel="help" href="http://www.w3.org/TR/geometry-1/#DOMPoint">
7 <link rel="help" href="http://dev.w3.org/fxtf/geometry/#dictdef-dompointinit">
8 <link rel="help" href="http://www.w3.org/TR/geometry-1/#dom-dompoint-dompoint">
9 <link rel="help" href="http://www.w3.org/TR/geometry-1/#dom-dompointreadonly-dompoint-x">
10 <link rel="help" href="http://www.w3.org/TR/geometry-1/#dom-dompointreadonly-dompoint-y">
11 <link rel="help" href="http://www.w3.org/TR/geometry-1/#dom-dompointreadonly-dompoint-z">
12 <link rel="help" href="http://www.w3.org/TR/geometry-1/#dom-dompointreadonly-dompoint-w">
13 <script src="../resources/testharness.js"></script>
14 <script src="../resources/testharnessreport.js"></script>
15</head>
16<body>
17 <p>Test DOMPoint and DOMPointReadOnly interfaces</p>
18 <div id="log"></div>
19 <script>
20 test(function() {
21 checkDOMPoint(new DOMPoint(), {x:0, y:0, z:0, w:1});
22 },'testConstructor0');
23 test(function() {
24 checkDOMPoint(new DOMPoint(1), {x:1, y:0, z:0, w:1})
25 },'testConstructor1');
26 test(function() {
27 checkDOMPoint(new DOMPoint(1, 2), {x:1, y:2, z:0, w:1});
28 },'testConstructor2');
29 test(function() {
30 checkDOMPoint(new DOMPoint(1, 2, 3), {x:1, y:2, z:3, w:1});
31 },'testConstructor3');
32 test(function() {
33 checkDOMPoint(new DOMPoint(1, 2, 3, 4), {x:1, y:2, z:3, w:4});
34 },'testConstructor4');
35 test(function() {
36 checkDOMPoint(new DOMPoint(1, 2, 3, 4, 5), {x:1, y:2, z:3, w:4});
37 },'testConstructor5');
38 test(function() {
39 checkDOMPoint(DOMPoint.fromPoint({}), {x:0, y:0, z:0, w:1});
40 },'testConstructorDOMPointInit0');
41 test(function() {
42 checkDOMPoint(DOMPoint.fromPoint({x:1}), {x:1, y:0, z:0, w:1});
43 },'testConstructorDOMPointInit1');
44 test(function() {
45 checkDOMPoint(DOMPoint.fromPoint({x:1, y:2}), {x:1, y:2, z:0, w:1});
46 },'testConstructorDOMPointInit2');
47 test(function() {
48 checkDOMPoint(DOMPoint.fromPoint({x:1, y:2, z:3}), {x:1, y:2, z:3, w:1});
49 },'testConstructorDOMPointInit3');
50 test(function() {
51 checkDOMPoint(DOMPoint.fromPoint({x:1, y:2, z:3, w:4}), {x:1, y:2, z:3, w:4});
52 },'testConstructorDOMPointInit4');
53 test(function() {
54 checkDOMPoint(DOMPoint.fromPoint({x:1, y:2, z:3, w:4, v:5}), {x:1, y:2, z:3, w:4});
55 },'testConstructorDOMPointInit5');
56 test(function() {
57 checkDOMPoint(DOMPoint.fromPoint({x:1, z:3}), {x:1, y:0, z:3, w:1});
58 },'testConstructorDOMPointInit2irregular');
59 test(function() {
60 checkDOMPoint(DOMPoint.fromPoint({x:1, y: undefined, z:3}), {x:1, y:0, z:3, w:1});
61 },'testConstructorDOMPointInit2undefined');
62 test(function() {
63 checkDOMPoint(new DOMPointReadOnly(), {x:0, y:0, z:0, w:1});
64 },'testReadonlyConstructor1');
65 test(function() {
66 checkDOMPoint(new DOMPoint(1, NaN), {x:1, y:NaN, z:0, w:1});
67 },'testConstructor2NaN');
68 test(function() {
69 checkDOMPoint(new DOMPoint(1, Number.POSITIVE_INFINITY), {x:1, y:Infinity, z:0, w:1});
70 },'testConstructor2Infinity');
71 test(function() {
72 var p = DOMPoint.fromPoint({});
73 assert_true(p instanceof DOMPoint);
74 },'testFromPointReturnType');
75 test(function() {
76 var p = DOMPointReadOnly.fromPoint({});
77 assert_true(p instanceof DOMPointReadOnly);
78 },'testFromPointReadOnlyReturnType');
79 test(function() {
80 var p = new DOMPointReadOnly();
81 p.x = 1;
82 p.y = Math.PI;
83 p.z = 3.2;
84 p.w = 4;
85 checkDOMPoint(p, {x:0, y:0, z:0, w:1});
86 },'testReadonlyAttributes');
87 test(function() {
88 var p = new DOMPoint();
89 p.x = 1;
90 p.y = Math.PI;
91 p.z = 3.2;
92 p.w = 4;
93 checkDOMPoint(p, {x:1, y:Math.PI, z:3.2, w:4});
94 },'testAttributes');
95 test(function() {
96 var p = new DOMPoint(0, 0, 0, 1);
97 p.x = undefined;
98 p.y = undefined;
99 p.z = undefined;
100 p.w = undefined;
101 checkDOMPoint(p, {x:NaN, y:NaN, z:NaN, w:NaN});
102 },'testAttributesUndefined');
103 test(function() {
104 var p = new DOMPoint(0, 0, 0, 1);
105 p.x = NaN;
106 p.y = Number.POSITIVE_INFINITY;
107 p.z = Number.NEGATIVE_INFINITY;
108 p.w = Infinity;
109 checkDOMPoint(p, {x:NaN, y:Infinity, z:-Infinity, w:Infinity});
110 },'testAttributesNaNInfinity');
111 test(function() {
112 var p = DOMPoint.fromPoint({x:1, y:3.1415927, z:3.2, w:4});
113 assert_equals(JSON.stringify(p.toJSON()), "{\"x\":1,\"y\":3.1415927,\"z\":3.2,\"w\":4}");
114 },'testSerializer');
115 test(function() {
116 var p = DOMPointReadOnly.fromPoint({x:1, y:3.1415927, z:3.2, w:4});
117 assert_equals(JSON.stringify(p.toJSON()), "{\"x\":1,\"y\":3.1415927,\"z\":3.2,\"w\":4}");
118 },'testReadonlySerializer');
119
120 function checkDOMPoint(p, exp) {
121 assert_equals(p.x, exp.x, "Expected value for x is " + exp.x);
122 assert_equals(p.y, exp.y, "Expected value for y is " + exp.y);
123 assert_equals(p.z, exp.z, "Expected value for z is " + exp.z);
124 assert_equals(p.w, exp.w, "Expected value for w is " + exp.w);
125 }
126 </script>
127</body>
128</html>