summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/geometry/DOMQuad-002.html
blob: 5734be1f2938a2d4995c4b4b74ab9c7e5d807f59 (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
<!DOCTYPE html>
<html>
<head>
    <title>Geometry Interfaces: DOMQuad interface tests</title>
    <link rel="author" title="Hwanseung Lee" href="mailto:hs1217.lee@samsung.com" />
    <link rel="help" href="https://drafts.fxtf.org/geometry-1/#DOMQuad">
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
</head>
<body>
    <p>Test DOMQuad interface</p>
    <div id="log"></div>
    <script>

        function init() {
            var initial = {
                p1: { x: 0, y: 0, z: 0, w: 1 },
                p2: { x: 0, y: 0, z: 0, w: 1 },
                p3: { x: 0, y: 0, z: 0, w: 1 },
                p4: { x: 0, y: 0, z: 0, w: 1 }
            };
            return initial;
        }

        test(function() {
            checkDOMQuad(new DOMQuad(), init());
        },'test Constructor no args');

        test(function() {
            checkDOMQuad(new DOMQuad(new DOMPoint()), init());
        },'test Constructor with one init DOMPoint arg');

        test(function() {
            checkDOMQuad(new DOMQuad(new DOMPoint(), new DOMPoint()), init());
        },'test Constructor with two init DOMPoint args');

        test(function() {
            checkDOMQuad(new DOMQuad(new DOMPoint(), new DOMPoint(), new DOMPoint()), init());
        },'test Constructor with three init DOMPoint args');

        test(function() {
            checkDOMQuad(new DOMQuad(new DOMPoint(), new DOMPoint(), new DOMPoint(), new DOMPoint()), init());
        },'test Constructor with four init DOMPoint args');

        test(function() {
            var exp = init();
            exp.p1 = { x: 1, y: 2, z: 3, w: 4 };
            checkDOMQuad(new DOMQuad(new DOMPoint(1, 2, 3, 4)), exp);
        },'test Constructor with one DOMPoint arg');

        test(function() {
            var exp = init();
            exp.p1 = { x: 1, y: 2, z: 3, w: 4 };
            exp.p2 = { x: 5, y: 6, z: 7, w: 8 };
            checkDOMQuad(new DOMQuad(new DOMPoint(1, 2, 3, 4), new DOMPoint(5, 6, 7, 8)), exp);
        },'test Constructor with two DOMPoint args');

        test(function() {
            var exp = init();
            exp.p1 = { x: 1, y: 2, z: 3, w: 4 };
            exp.p2 = { x: 5, y: 6, z: 7, w: 8 };
            exp.p3 = { x: 9, y: 10, z: 11, w: 12 };
            checkDOMQuad(new DOMQuad(new DOMPoint(1, 2, 3, 4), new DOMPoint(5, 6, 7, 8), new DOMPoint(9, 10, 11, 12)), exp);
        },'test Constructor with three DOMPoint args');

        test(function() {
            var exp = init();
            exp.p1 = { x: 1, y: 2, z: 3, w: 4 };
            exp.p2 = { x: 5, y: 6, z: 7, w: 8 };
            exp.p3 = { x: 9, y: 10, z: 11, w: 12 };
            exp.p4 = { x: 13, y: 14, z: 15, w: 16 };
            checkDOMQuad(new DOMQuad(new DOMPoint(1, 2, 3, 4), new DOMPoint(5, 6, 7, 8), new DOMPoint(9, 10, 11, 12), new DOMPoint(13, 14, 15, 16)), exp);
        },'test Constructor with four DOMPoint args');

        test(function() {
            assert_throws_js(TypeError, function() { new DOMQuad(1, 2, 3, 4); });
        },'test Constructor with invaild integer args');

        test(function() {
            assert_throws_js(TypeError, function() { new DOMQuad("1", "2", "3", "4"); });
        },'test Constructor with invaild string args');

        test(function() {
            assert_throws_js(TypeError, function() { new DOMQuad({}, {}, {}, NaN); });
        },'test Constructor with NaN');

        test(function() {
            var domQuad = DOMQuad.fromRect(new DOMRect(10, 20, 100, 200));
            var expQuad = init();
            expQuad.p1 = { x: 10, y: 20, z: 0, w: 1 };
            expQuad.p2 = { x: 110, y: 20, z: 0, w: 1 };
            expQuad.p3 = { x: 110, y: 220, z: 0, w: 1 };
            expQuad.p4 = { x: 10, y: 220, z: 0, w: 1 };
            checkDOMQuad(domQuad, expQuad);
        },'test fromRect');

        test(function() {
            var domQuad = DOMQuad.fromRect(new DOMRect(-Infinity, -Infinity, Infinity, Infinity));
            var expQuad = init();
            expQuad.p1 = { x: -Infinity, y: -Infinity, z: 0, w: 1 };
            expQuad.p2 = { x: NaN, y: -Infinity, z: 0, w: 1 };
            expQuad.p3 = { x: NaN, y: NaN, z: 0, w: 1 };
            expQuad.p4 = { x: -Infinity, y: NaN, z: 0, w: 1 };
            checkDOMQuad(domQuad, expQuad);
        },'test fromRect with Infinity');

        test(function() {
            var domQuad = DOMQuad.fromQuad(
                new DOMQuad(
                    new DOMPoint(1, 2, 3, 4),
                    new DOMPoint(5, 6, 7, 8),
                    new DOMPoint(9, 10, 11, 12),
                    new DOMPoint(13, 14, 15, 16)));
            var exp = init();
            exp.p1 = { x: 1, y: 2, z: 3, w: 4 };
            exp.p2 = { x: 5, y: 6, z: 7, w: 8 };
            exp.p3 = { x: 9, y: 10, z: 11, w: 12 };
            exp.p4 = { x: 13, y: 14, z: 15, w: 16 };
            checkDOMQuad(domQuad, exp);
        },'test fromQuad');

        test(function() {
            var domQuad = new DOMQuad();
            domQuad.p1 = new DOMPoint(1, 2, 3, 4);
            domQuad.p2 = new DOMPoint(1, 2, 3, 4);
            domQuad.p3 = new DOMPoint(1, 2, 3, 4);
            domQuad.p4 = new DOMPoint(1, 2, 3, 4);
            checkDOMQuad(domQuad, init());
        },'test p1, p2, p3, p4 are readonly');

        test(function() {
            var domQuad = DOMQuad.fromQuad(
                new DOMQuad(
                    new DOMPoint(10, 20, 0, 1),
                    new DOMPoint(110, 20, 0, 1),
                    new DOMPoint(110, 220, 0, 1),
                    new DOMPoint(10, 220, 10, 1)));
            var expBound = new DOMRect(10, 20, 100, 200);
            checkDOMRect(domQuad.getBounds(), expBound);
        },'test getBounds');

        function checkDOMQuad(actual, exp) {
            assert_equals(actual.p1.x, exp.p1.x, "p1.x is not matched");
            assert_equals(actual.p1.y, exp.p1.y, "p1.y is not matched");
            assert_equals(actual.p1.z, exp.p1.z, "p1.z is not matched");
            assert_equals(actual.p1.w, exp.p1.w, "p1.w is not matched");
            assert_equals(actual.p2.x, exp.p2.x, "p2.x is not matched");
            assert_equals(actual.p2.y, exp.p2.y, "p2.y is not matched");
            assert_equals(actual.p2.z, exp.p2.z, "p2.z is not matched");
            assert_equals(actual.p2.w, exp.p2.w, "p2.w is not matched");
            assert_equals(actual.p3.x, exp.p3.x, "p3.x is not matched");
            assert_equals(actual.p3.y, exp.p3.y, "p3.y is not matched");
            assert_equals(actual.p3.z, exp.p3.z, "p3.z is not matched");
            assert_equals(actual.p3.w, exp.p3.w, "p3.w is not matched");
            assert_equals(actual.p4.x, exp.p4.x, "p4.x is not matched");
            assert_equals(actual.p4.y, exp.p4.y, "p4.y is not matched");
            assert_equals(actual.p4.z, exp.p4.z, "p4.z is not matched");
            assert_equals(actual.p4.w, exp.p4.w, "p4.w is not matched");
        }

        function checkDOMRect(actual, exp) {
            assert_equals(actual.x, exp.x, "x is not matched");
            assert_equals(actual.y, exp.y, "y is not matched");
            assert_equals(actual.width, exp.width, "width is not matched");
            assert_equals(actual.height, exp.height, "height is not matched");
            assert_equals(actual.top, exp.top, "top is not matched");
            assert_equals(actual.left, exp.left, "left is not matched");
            assert_equals(actual.bottom, exp.bottom, "bottom is not matched");
            assert_equals(actual.right, exp.right, "right is not matched");
        }
    </script>
</body>
</html>