summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/geometry/DOMQuad-001.html
blob: 6fa765bbabce7c07111855acbe06ba45bd1343d9 (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
<!DOCTYPE html>
<html>
<head>
    <title>Geometry Interfaces: DOMQuad interface tests</title>
    <link rel="author" title="Dirk Schulze" href="mailto:dschulze@adobe.com" />
    <link rel="help" href="https://www.w3.org/TR/geometry-1/#dom-domquad-domquad">
    <link rel="help" href="https://www.w3.org/TR/geometry-1/#dom-domquad-p1">
    <link rel="help" href="https://www.w3.org/TR/geometry-1/#dom-domquad-p2">
    <link rel="help" href="https://www.w3.org/TR/geometry-1/#dom-domquad-p3">
    <link rel="help" href="https://www.w3.org/TR/geometry-1/#dom-domquad-p4">
    <link rel="help" href="https://www.w3.org/TR/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>
        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 },
            bounds: { x: 0, y: 0, width: 0, height: 0 }
        };

        checkDOMQuad(function() { return new DOMQuad(); }, initial, 'testConstructor0');

        test(function() {
            assert_throws_js(TypeError, function() { new DOMQuad(1); });
        },'testConstructor1');

        test(function() {
            assert_throws_js(TypeError, function() { new DOMQuad(1, 2); });
        },'testConstructor2');

        test(function() {
            assert_throws_js(TypeError, function() { new DOMQuad(1, 2, 3); });
        },'testConstructor3');

        test(function() {
            assert_throws_js(TypeError, function() { new DOMQuad(1, 2, 3, 4); });
        },'testConstructor4');

        checkDOMQuad(
                function() { return DOMQuad.fromRect(new DOMRect(10, 20, 100, 200)); },
                {   p1: { x: 10, y: 20, z: 0, w: 1 },
                    p2: { x: 110, y: 20, z: 0, w: 1 },
                    p3: { x: 110, y: 220, z: 0, w: 1 },
                    p4: { x: 10, y: 220, z: 0, w: 1 },
                    bounds: { x: 10, y: 20, width: 100, height: 200 } },
                'fromRect() method on DOMQuad');

        checkDOMQuad(
                function() { return DOMQuad.fromRect(new DOMRect(10, 20, -100, -200)) },
                {   p1: { x: 10, y: 20, z: 0, w: 1 },
                    p2: { x: -90, y: 20, z: 0, w: 1 },
                    p3: { x: -90, y: -180, z: 0, w: 1 },
                    p4: { x: 10, y: -180, z: 0, w: 1 },
                    bounds: { x: -90, y: -180, width: 100, height: 200 } },
                'fromRect() method on DOMQuad with negatives');

        checkDOMQuad(
                function() { return DOMQuad.fromRect(new DOMRect(-Infinity, -Infinity, Infinity, Infinity)) },
                {   p1: { x: -Infinity, y: -Infinity, z: 0, w: 1 },
                    p2: { x: NaN, y: -Infinity, z: 0, w: 1 },
                    p3: { x: NaN, y: NaN, z: 0, w: 1 },
                    p4: { x: -Infinity, y: NaN, z: 0, w: 1 },
                    bounds: { x: NaN, y: NaN, width: NaN, height: NaN } },
                'fromRect() method on DOMQuad with Infinity');

        checkDOMQuad(function() { return new DOMQuad(new DOMRect()); }, initial, 'testConstructor8');

        checkDOMQuad(function() { return new DOMQuad({}); }, initial, 'testConstructor9');

        checkDOMQuad(function() { return new DOMQuad({}, {}); }, initial, 'testConstructor10');

        checkDOMQuad(function() { return new DOMQuad({}, {}, {}); }, initial, 'testConstructor11');

        checkDOMQuad(function() { return new DOMQuad({}, {}, {}, {}); }, initial, 'testConstructor12');

        checkDOMQuad(function() { return new DOMQuad(null, undefined, {}, {}); }, initial, 'testConstructor13');

        checkDOMQuad(function() { return new DOMQuad({}, {}, {}, {}, NaN); }, initial, 'testConstructor14');

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

        checkDOMQuad(function() {
            return new DOMQuad({ y: 10 }, { x: 20 }, { z: 30 }, { x: 20, y: 10, z: 20, w: 10 });
        },
        {   p1: { x: 0, y: 10, z: 0, w: 1 },
            p2: { x: 20, y: 0, z: 0, w: 1 },
            p3: { x: 0, y: 0, z: 30, w: 1 },
            p4: { x: 20, y: 10, z: 20, w: 10 },
            bounds: { x: 0, y: 0, width: 20, height: 10 } },
        'testConstructor16');

        checkDOMQuad(function() {
            // p1 to p4 are readonly attributes.
            var q = new DOMQuad({}, {}, {}, {});
            q.p1 = new DOMPoint(2, 2);
            q.p2 = new DOMPoint(2, 2);
            q.p3 = new DOMPoint(2, 2);
            q.p4 = new DOMPoint(2, 2);
            return q;
        }, initial, 'p1Top4Attributes0');

        checkDOMQuad(function() {
            var q = new DOMQuad({}, {}, {}, {});
            q.p1.x = 2;
            q.p2.x = 2;
            q.p3.x = 2;
            q.p4.x = 2;
            return q;
        },
        {   p1: { x: 2, y: 0, z: 0, w: 1 },
            p2: { x: 2, y: 0, z: 0, w: 1 },
            p3: { x: 2, y: 0, z: 0, w: 1 },
            p4: { x: 2, y: 0, z: 0, w: 1 },
            bounds: { x: 2, y: 0, width: 0, height: 0 } },
        'p1Top4Attributes1');

        function checkDOMQuad(createQuad, exp, name) {
            test(function() {
                var q = createQuad();
                assert_equals(q.p1.x, exp.p1.x, "Expected value for p1.x is " + exp.p1.x);
                assert_equals(q.p1.y, exp.p1.y, "Expected value for p1.y is " + exp.p1.y);
                assert_equals(q.p1.z, exp.p1.z, "Expected value for p1.z is " + exp.p1.z);
                assert_equals(q.p1.w, exp.p1.w, "Expected value for p1.w is " + exp.p1.w);
                assert_equals(q.p2.x, exp.p2.x, "Expected value for p2.x is " + exp.p2.x);
                assert_equals(q.p2.y, exp.p2.y, "Expected value for p2.y is " + exp.p2.y);
                assert_equals(q.p2.z, exp.p2.z, "Expected value for p2.z is " + exp.p2.z);
                assert_equals(q.p2.w, exp.p2.w, "Expected value for p2.w is " + exp.p2.w);
                assert_equals(q.p3.x, exp.p3.x, "Expected value for p3.x is " + exp.p3.x);
                assert_equals(q.p3.y, exp.p3.y, "Expected value for p3.y is " + exp.p3.y);
                assert_equals(q.p3.z, exp.p3.z, "Expected value for p3.z is " + exp.p3.z);
                assert_equals(q.p3.w, exp.p3.w, "Expected value for p3.w is " + exp.p3.w);
                assert_equals(q.p4.x, exp.p4.x, "Expected value for p4.x is " + exp.p4.x);
                assert_equals(q.p4.y, exp.p4.y, "Expected value for p4.y is " + exp.p4.y);
                assert_equals(q.p4.z, exp.p4.z, "Expected value for p4.z is " + exp.p4.z);
                assert_equals(q.p4.w, exp.p4.w, "Expected value for p4.w is " + exp.p4.w);
            }, name + ": points");

            test(function() {
                var q = createQuad();
                assert_equals(q.getBounds().x, exp.bounds.x, "Expected value for getBounds().x is " + exp.bounds.x);
                assert_equals(q.getBounds().y, exp.bounds.y, "Expected value for getBounds().y is " + exp.bounds.y);
                assert_equals(q.getBounds().width, exp.bounds.width, "Expected value for getBounds().width is " + exp.bounds.width);
                assert_equals(q.getBounds().height, exp.bounds.height, "Expected value for getBounds().height is " + exp.bounds.height);
            }, name + ": bounds");
        }
    </script>
</body>
</html>