DOMQuad-002.html (7666B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Geometry Interfaces: DOMQuad interface tests</title> 5 <link rel="author" title="Hwanseung Lee" href="mailto:hs1217.lee@samsung.com" /> 6 <link rel="help" href="https://drafts.fxtf.org/geometry-1/#DOMQuad"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 </head> 10 <body> 11 <p>Test DOMQuad interface</p> 12 <div id="log"></div> 13 <script> 14 15 function init() { 16 var initial = { 17 p1: { x: 0, y: 0, z: 0, w: 1 }, 18 p2: { x: 0, y: 0, z: 0, w: 1 }, 19 p3: { x: 0, y: 0, z: 0, w: 1 }, 20 p4: { x: 0, y: 0, z: 0, w: 1 } 21 }; 22 return initial; 23 } 24 25 test(function() { 26 checkDOMQuad(new DOMQuad(), init()); 27 },'test Constructor no args'); 28 29 test(function() { 30 checkDOMQuad(new DOMQuad(new DOMPoint()), init()); 31 },'test Constructor with one init DOMPoint arg'); 32 33 test(function() { 34 checkDOMQuad(new DOMQuad(new DOMPoint(), new DOMPoint()), init()); 35 },'test Constructor with two init DOMPoint args'); 36 37 test(function() { 38 checkDOMQuad(new DOMQuad(new DOMPoint(), new DOMPoint(), new DOMPoint()), init()); 39 },'test Constructor with three init DOMPoint args'); 40 41 test(function() { 42 checkDOMQuad(new DOMQuad(new DOMPoint(), new DOMPoint(), new DOMPoint(), new DOMPoint()), init()); 43 },'test Constructor with four init DOMPoint args'); 44 45 test(function() { 46 var exp = init(); 47 exp.p1 = { x: 1, y: 2, z: 3, w: 4 }; 48 checkDOMQuad(new DOMQuad(new DOMPoint(1, 2, 3, 4)), exp); 49 },'test Constructor with one DOMPoint arg'); 50 51 test(function() { 52 var exp = init(); 53 exp.p1 = { x: 1, y: 2, z: 3, w: 4 }; 54 exp.p2 = { x: 5, y: 6, z: 7, w: 8 }; 55 checkDOMQuad(new DOMQuad(new DOMPoint(1, 2, 3, 4), new DOMPoint(5, 6, 7, 8)), exp); 56 },'test Constructor with two DOMPoint args'); 57 58 test(function() { 59 var exp = init(); 60 exp.p1 = { x: 1, y: 2, z: 3, w: 4 }; 61 exp.p2 = { x: 5, y: 6, z: 7, w: 8 }; 62 exp.p3 = { x: 9, y: 10, z: 11, w: 12 }; 63 checkDOMQuad(new DOMQuad(new DOMPoint(1, 2, 3, 4), new DOMPoint(5, 6, 7, 8), new DOMPoint(9, 10, 11, 12)), exp); 64 },'test Constructor with three DOMPoint args'); 65 66 test(function() { 67 var exp = init(); 68 exp.p1 = { x: 1, y: 2, z: 3, w: 4 }; 69 exp.p2 = { x: 5, y: 6, z: 7, w: 8 }; 70 exp.p3 = { x: 9, y: 10, z: 11, w: 12 }; 71 exp.p4 = { x: 13, y: 14, z: 15, w: 16 }; 72 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); 73 },'test Constructor with four DOMPoint args'); 74 75 test(function() { 76 assert_throws_js(TypeError, function() { new DOMQuad(1, 2, 3, 4); }); 77 },'test Constructor with invaild integer args'); 78 79 test(function() { 80 assert_throws_js(TypeError, function() { new DOMQuad("1", "2", "3", "4"); }); 81 },'test Constructor with invaild string args'); 82 83 test(function() { 84 assert_throws_js(TypeError, function() { new DOMQuad({}, {}, {}, NaN); }); 85 },'test Constructor with NaN'); 86 87 test(function() { 88 var domQuad = DOMQuad.fromRect(new DOMRect(10, 20, 100, 200)); 89 var expQuad = init(); 90 expQuad.p1 = { x: 10, y: 20, z: 0, w: 1 }; 91 expQuad.p2 = { x: 110, y: 20, z: 0, w: 1 }; 92 expQuad.p3 = { x: 110, y: 220, z: 0, w: 1 }; 93 expQuad.p4 = { x: 10, y: 220, z: 0, w: 1 }; 94 checkDOMQuad(domQuad, expQuad); 95 },'test fromRect'); 96 97 test(function() { 98 var domQuad = DOMQuad.fromRect(new DOMRect(-Infinity, -Infinity, Infinity, Infinity)); 99 var expQuad = init(); 100 expQuad.p1 = { x: -Infinity, y: -Infinity, z: 0, w: 1 }; 101 expQuad.p2 = { x: NaN, y: -Infinity, z: 0, w: 1 }; 102 expQuad.p3 = { x: NaN, y: NaN, z: 0, w: 1 }; 103 expQuad.p4 = { x: -Infinity, y: NaN, z: 0, w: 1 }; 104 checkDOMQuad(domQuad, expQuad); 105 },'test fromRect with Infinity'); 106 107 test(function() { 108 var domQuad = DOMQuad.fromQuad( 109 new DOMQuad( 110 new DOMPoint(1, 2, 3, 4), 111 new DOMPoint(5, 6, 7, 8), 112 new DOMPoint(9, 10, 11, 12), 113 new DOMPoint(13, 14, 15, 16))); 114 var exp = init(); 115 exp.p1 = { x: 1, y: 2, z: 3, w: 4 }; 116 exp.p2 = { x: 5, y: 6, z: 7, w: 8 }; 117 exp.p3 = { x: 9, y: 10, z: 11, w: 12 }; 118 exp.p4 = { x: 13, y: 14, z: 15, w: 16 }; 119 checkDOMQuad(domQuad, exp); 120 },'test fromQuad'); 121 122 test(function() { 123 var domQuad = new DOMQuad(); 124 domQuad.p1 = new DOMPoint(1, 2, 3, 4); 125 domQuad.p2 = new DOMPoint(1, 2, 3, 4); 126 domQuad.p3 = new DOMPoint(1, 2, 3, 4); 127 domQuad.p4 = new DOMPoint(1, 2, 3, 4); 128 checkDOMQuad(domQuad, init()); 129 },'test p1, p2, p3, p4 are readonly'); 130 131 test(function() { 132 var domQuad = DOMQuad.fromQuad( 133 new DOMQuad( 134 new DOMPoint(10, 20, 0, 1), 135 new DOMPoint(110, 20, 0, 1), 136 new DOMPoint(110, 220, 0, 1), 137 new DOMPoint(10, 220, 10, 1))); 138 var expBound = new DOMRect(10, 20, 100, 200); 139 checkDOMRect(domQuad.getBounds(), expBound); 140 },'test getBounds'); 141 142 function checkDOMQuad(actual, exp) { 143 assert_equals(actual.p1.x, exp.p1.x, "p1.x is not matched"); 144 assert_equals(actual.p1.y, exp.p1.y, "p1.y is not matched"); 145 assert_equals(actual.p1.z, exp.p1.z, "p1.z is not matched"); 146 assert_equals(actual.p1.w, exp.p1.w, "p1.w is not matched"); 147 assert_equals(actual.p2.x, exp.p2.x, "p2.x is not matched"); 148 assert_equals(actual.p2.y, exp.p2.y, "p2.y is not matched"); 149 assert_equals(actual.p2.z, exp.p2.z, "p2.z is not matched"); 150 assert_equals(actual.p2.w, exp.p2.w, "p2.w is not matched"); 151 assert_equals(actual.p3.x, exp.p3.x, "p3.x is not matched"); 152 assert_equals(actual.p3.y, exp.p3.y, "p3.y is not matched"); 153 assert_equals(actual.p3.z, exp.p3.z, "p3.z is not matched"); 154 assert_equals(actual.p3.w, exp.p3.w, "p3.w is not matched"); 155 assert_equals(actual.p4.x, exp.p4.x, "p4.x is not matched"); 156 assert_equals(actual.p4.y, exp.p4.y, "p4.y is not matched"); 157 assert_equals(actual.p4.z, exp.p4.z, "p4.z is not matched"); 158 assert_equals(actual.p4.w, exp.p4.w, "p4.w is not matched"); 159 } 160 161 function checkDOMRect(actual, exp) { 162 assert_equals(actual.x, exp.x, "x is not matched"); 163 assert_equals(actual.y, exp.y, "y is not matched"); 164 assert_equals(actual.width, exp.width, "width is not matched"); 165 assert_equals(actual.height, exp.height, "height is not matched"); 166 assert_equals(actual.top, exp.top, "top is not matched"); 167 assert_equals(actual.left, exp.left, "left is not matched"); 168 assert_equals(actual.bottom, exp.bottom, "bottom is not matched"); 169 assert_equals(actual.right, exp.right, "right is not matched"); 170 } 171 </script> 172 </body> 173 </html>