DOMQuad-001.html (7566B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Geometry Interfaces: DOMQuad interface tests</title> 5 <link rel="author" title="Dirk Schulze" href="mailto:dschulze@adobe.com" /> 6 <link rel="help" href="https://www.w3.org/TR/geometry-1/#dom-domquad-domquad"> 7 <link rel="help" href="https://www.w3.org/TR/geometry-1/#dom-domquad-p1"> 8 <link rel="help" href="https://www.w3.org/TR/geometry-1/#dom-domquad-p2"> 9 <link rel="help" href="https://www.w3.org/TR/geometry-1/#dom-domquad-p3"> 10 <link rel="help" href="https://www.w3.org/TR/geometry-1/#dom-domquad-p4"> 11 <link rel="help" href="https://www.w3.org/TR/geometry-1/#DOMQuad"> 12 <script src="/resources/testharness.js"></script> 13 <script src="/resources/testharnessreport.js"></script> 14 </head> 15 <body> 16 <p>Test DOMQuad interface</p> 17 <div id="log"></div> 18 <script> 19 var initial = { 20 p1: { x: 0, y: 0, z: 0, w: 1 }, 21 p2: { x: 0, y: 0, z: 0, w: 1 }, 22 p3: { x: 0, y: 0, z: 0, w: 1 }, 23 p4: { x: 0, y: 0, z: 0, w: 1 }, 24 bounds: { x: 0, y: 0, width: 0, height: 0 } 25 }; 26 27 checkDOMQuad(function() { return new DOMQuad(); }, initial, 'testConstructor0'); 28 29 test(function() { 30 assert_throws_js(TypeError, function() { new DOMQuad(1); }); 31 },'testConstructor1'); 32 33 test(function() { 34 assert_throws_js(TypeError, function() { new DOMQuad(1, 2); }); 35 },'testConstructor2'); 36 37 test(function() { 38 assert_throws_js(TypeError, function() { new DOMQuad(1, 2, 3); }); 39 },'testConstructor3'); 40 41 test(function() { 42 assert_throws_js(TypeError, function() { new DOMQuad(1, 2, 3, 4); }); 43 },'testConstructor4'); 44 45 checkDOMQuad( 46 function() { return DOMQuad.fromRect(new DOMRect(10, 20, 100, 200)); }, 47 { p1: { x: 10, y: 20, z: 0, w: 1 }, 48 p2: { x: 110, y: 20, z: 0, w: 1 }, 49 p3: { x: 110, y: 220, z: 0, w: 1 }, 50 p4: { x: 10, y: 220, z: 0, w: 1 }, 51 bounds: { x: 10, y: 20, width: 100, height: 200 } }, 52 'fromRect() method on DOMQuad'); 53 54 checkDOMQuad( 55 function() { return DOMQuad.fromRect(new DOMRect(10, 20, -100, -200)) }, 56 { p1: { x: 10, y: 20, z: 0, w: 1 }, 57 p2: { x: -90, y: 20, z: 0, w: 1 }, 58 p3: { x: -90, y: -180, z: 0, w: 1 }, 59 p4: { x: 10, y: -180, z: 0, w: 1 }, 60 bounds: { x: -90, y: -180, width: 100, height: 200 } }, 61 'fromRect() method on DOMQuad with negatives'); 62 63 checkDOMQuad( 64 function() { return DOMQuad.fromRect(new DOMRect(-Infinity, -Infinity, Infinity, Infinity)) }, 65 { p1: { x: -Infinity, y: -Infinity, z: 0, w: 1 }, 66 p2: { x: NaN, y: -Infinity, z: 0, w: 1 }, 67 p3: { x: NaN, y: NaN, z: 0, w: 1 }, 68 p4: { x: -Infinity, y: NaN, z: 0, w: 1 }, 69 bounds: { x: NaN, y: NaN, width: NaN, height: NaN } }, 70 'fromRect() method on DOMQuad with Infinity'); 71 72 checkDOMQuad(function() { return new DOMQuad(new DOMRect()); }, initial, 'testConstructor8'); 73 74 checkDOMQuad(function() { return new DOMQuad({}); }, initial, 'testConstructor9'); 75 76 checkDOMQuad(function() { return new DOMQuad({}, {}); }, initial, 'testConstructor10'); 77 78 checkDOMQuad(function() { return new DOMQuad({}, {}, {}); }, initial, 'testConstructor11'); 79 80 checkDOMQuad(function() { return new DOMQuad({}, {}, {}, {}); }, initial, 'testConstructor12'); 81 82 checkDOMQuad(function() { return new DOMQuad(null, undefined, {}, {}); }, initial, 'testConstructor13'); 83 84 checkDOMQuad(function() { return new DOMQuad({}, {}, {}, {}, NaN); }, initial, 'testConstructor14'); 85 86 test(function() { 87 assert_throws_js(TypeError, function() { new DOMQuad({}, {}, {}, NaN); }); 88 },'testConstructor15'); 89 90 checkDOMQuad(function() { 91 return new DOMQuad({ y: 10 }, { x: 20 }, { z: 30 }, { x: 20, y: 10, z: 20, w: 10 }); 92 }, 93 { p1: { x: 0, y: 10, z: 0, w: 1 }, 94 p2: { x: 20, y: 0, z: 0, w: 1 }, 95 p3: { x: 0, y: 0, z: 30, w: 1 }, 96 p4: { x: 20, y: 10, z: 20, w: 10 }, 97 bounds: { x: 0, y: 0, width: 20, height: 10 } }, 98 'testConstructor16'); 99 100 checkDOMQuad(function() { 101 // p1 to p4 are readonly attributes. 102 var q = new DOMQuad({}, {}, {}, {}); 103 q.p1 = new DOMPoint(2, 2); 104 q.p2 = new DOMPoint(2, 2); 105 q.p3 = new DOMPoint(2, 2); 106 q.p4 = new DOMPoint(2, 2); 107 return q; 108 }, initial, 'p1Top4Attributes0'); 109 110 checkDOMQuad(function() { 111 var q = new DOMQuad({}, {}, {}, {}); 112 q.p1.x = 2; 113 q.p2.x = 2; 114 q.p3.x = 2; 115 q.p4.x = 2; 116 return q; 117 }, 118 { p1: { x: 2, y: 0, z: 0, w: 1 }, 119 p2: { x: 2, y: 0, z: 0, w: 1 }, 120 p3: { x: 2, y: 0, z: 0, w: 1 }, 121 p4: { x: 2, y: 0, z: 0, w: 1 }, 122 bounds: { x: 2, y: 0, width: 0, height: 0 } }, 123 'p1Top4Attributes1'); 124 125 function checkDOMQuad(createQuad, exp, name) { 126 test(function() { 127 var q = createQuad(); 128 assert_equals(q.p1.x, exp.p1.x, "Expected value for p1.x is " + exp.p1.x); 129 assert_equals(q.p1.y, exp.p1.y, "Expected value for p1.y is " + exp.p1.y); 130 assert_equals(q.p1.z, exp.p1.z, "Expected value for p1.z is " + exp.p1.z); 131 assert_equals(q.p1.w, exp.p1.w, "Expected value for p1.w is " + exp.p1.w); 132 assert_equals(q.p2.x, exp.p2.x, "Expected value for p2.x is " + exp.p2.x); 133 assert_equals(q.p2.y, exp.p2.y, "Expected value for p2.y is " + exp.p2.y); 134 assert_equals(q.p2.z, exp.p2.z, "Expected value for p2.z is " + exp.p2.z); 135 assert_equals(q.p2.w, exp.p2.w, "Expected value for p2.w is " + exp.p2.w); 136 assert_equals(q.p3.x, exp.p3.x, "Expected value for p3.x is " + exp.p3.x); 137 assert_equals(q.p3.y, exp.p3.y, "Expected value for p3.y is " + exp.p3.y); 138 assert_equals(q.p3.z, exp.p3.z, "Expected value for p3.z is " + exp.p3.z); 139 assert_equals(q.p3.w, exp.p3.w, "Expected value for p3.w is " + exp.p3.w); 140 assert_equals(q.p4.x, exp.p4.x, "Expected value for p4.x is " + exp.p4.x); 141 assert_equals(q.p4.y, exp.p4.y, "Expected value for p4.y is " + exp.p4.y); 142 assert_equals(q.p4.z, exp.p4.z, "Expected value for p4.z is " + exp.p4.z); 143 assert_equals(q.p4.w, exp.p4.w, "Expected value for p4.w is " + exp.p4.w); 144 }, name + ": points"); 145 146 test(function() { 147 var q = createQuad(); 148 assert_equals(q.getBounds().x, exp.bounds.x, "Expected value for getBounds().x is " + exp.bounds.x); 149 assert_equals(q.getBounds().y, exp.bounds.y, "Expected value for getBounds().y is " + exp.bounds.y); 150 assert_equals(q.getBounds().width, exp.bounds.width, "Expected value for getBounds().width is " + exp.bounds.width); 151 assert_equals(q.getBounds().height, exp.bounds.height, "Expected value for getBounds().height is " + exp.bounds.height); 152 }, name + ": bounds"); 153 } 154 </script> 155 </body> 156 </html>