test_bbox.xhtml (3038B)
1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=449327 5 --> 6 <head> 7 <title>Test for getBBox</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 </head> 11 <body> 12 13 <p id="display"></p> 14 <div id="content" style="display: none"></div> 15 16 <iframe id="svg" src="bbox-helper.svg"></iframe> 17 18 <pre id="test"> 19 <script class="testbody" type="application/javascript">//<![CDATA[ 20 21 SimpleTest.waitForExplicitFinish(); 22 23 function run() { 24 var doc = $("svg").contentDocument; 25 26 function isFuzzy(a, b, error, name) { 27 ok(!(Math.abs(a - b) > error), 28 name + " - got " + a + ", expected " + b + " (within " + error + ")"); 29 } 30 31 function getBBox(id) { 32 return doc.getElementById(id).getBBox(); 33 } 34 function checkBBox(id, x, y, width, height, error) { 35 var bbox = getBBox(id); 36 isFuzzy(bbox.x, x, error, id + ".getBBox().x"); 37 isFuzzy(bbox.y, y, error, id + ".getBBox().y"); 38 isFuzzy(bbox.width, width, error, id + ".getBBox().width"); 39 isFuzzy(bbox.height, height, error, id + ".getBBox().height"); 40 } 41 function compareBBox(id1, id2) { 42 var bbox1 = getBBox(id1); 43 var bbox2 = getBBox(id2); 44 is(bbox1.x, bbox2.x, id1 + ".getBBox().x"); 45 is(bbox1.y, bbox2.y, id1 + ".getBBox().y"); 46 isFuzzy(bbox1.width, bbox2.width, 0.0002, id1 + ".getBBox().width"); 47 is(bbox1.height, bbox2.height, id1 + ".getBBox().height"); 48 } 49 function compareBBoxFuzzy(id1, id2, err) { 50 var bbox1 = getBBox(id1); 51 var bbox2 = getBBox(id2); 52 isfuzzy(bbox1.x, bbox2.x, err, id1 + ".getBBox().x"); 53 isfuzzy(bbox1.y, bbox2.y, err, id1 + ".getBBox().y"); 54 isfuzzy(bbox1.width, bbox2.width, err, id1 + ".getBBox().width"); 55 isfuzzy(bbox1.height, bbox2.height, err, id1 + ".getBBox().height"); 56 } 57 function compareBBoxHeight(id1, id2) { 58 var bbox1 = getBBox(id1); 59 var bbox2 = getBBox(id2); 60 is(bbox1.height, bbox2.height, id1 + ".getBBox().height"); 61 } 62 function compareBBoxWidthWithScaleFuzzy(id1, id2, scaleOfId2, err) { 63 var bbox1 = getBBox(id1); 64 var bbox2 = getBBox(id2); 65 isfuzzy(bbox1.width, bbox2.width * scaleOfId2, err, id1 + ".getBBox().width"); 66 } 67 68 checkBBox("fO", 10, 10, 100, 100, 0.0); 69 checkBBox("i", 10, 10, 100, 100, 0.0); 70 compareBBoxHeight("a", "b"); 71 compareBBoxHeight("a", "y"); 72 compareBBox("b", "tspantext1"); 73 compareBBoxFuzzy("tspantext1", "tspan1", 5); 74 compareBBoxHeight("tspantext2", "tspan2"); 75 compareBBoxWidthWithScaleFuzzy("tspantext2", "tspan2", 2, 5); 76 compareBBoxHeight("text", "lrmText"); 77 checkBBox("v", 95, 45, 10, 155, 0.001); 78 checkBBox("h", 195, 45, 105, 55, 0.001); 79 checkBBox("e", 95, 95, 10, 10, 0.001); 80 checkBBox("none", 0, 0, 10, 10, 0.001); 81 checkBBox("use_v", 195, 145, 10, 155, 0.001); 82 checkBBox("use_h", 295, 145, 105, 55, 0.001); 83 checkBBox("use_e", 195, 195, 10, 10, 0.001); 84 SimpleTest.finish(); 85 } 86 87 window.addEventListener("load", run); 88 89 //]]></script> 90 </pre> 91 </body> 92 </html>