test_units_length.html (1608B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test for serialization and equivalence of length units</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 7 </head> 8 <body> 9 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a> 10 <p id="display"></p> 11 <div id="content" style="display: none"> 12 13 </div> 14 <pre id="test"> 15 <script type="application/javascript"> 16 17 /** Test for serialization and equivalence of length units */ 18 19 /** 20 * We test that for each of the following: 21 * + they reserialize to exactly what is given 22 * + if a mapping is provided, they compute to the same result as the mapping 23 */ 24 var tests = { 25 "1in": "72pt", 26 "20mm": "2cm", 27 "2.54cm": "1in", 28 "36pt": "0.5in", 29 "4pc": "48pt", 30 "1em": null, 31 "3ex": null, 32 "57px": null, 33 "5rem": null 34 }; 35 36 var p = document.getElementById("display"); 37 38 for (var test in tests) { 39 p.setAttribute("style", "margin-left: " + test); 40 is(p.style.getPropertyValue("margin-left"), test, 41 test + " serializes to exactly itself"); 42 var equiv = tests[test]; 43 if (equiv) { 44 var cm1 = getComputedStyle(p, "").marginLeft; 45 p.style.marginLeft = equiv; 46 var cm2 = getComputedStyle(p, "").marginLeft; 47 48 ok(Math.abs(parseFloat(cm1, 10) - parseFloat(cm2, 10)) <= 0.0001, test + " should compute to the same as " + equiv + ", modulo floating point math error"); 49 } 50 } 51 52 // Bug 393910 53 p.setAttribute("style", "margin-left: 0"); 54 is(p.style.getPropertyValue("margin-left"), "0px", 55 "0 serializes to 0px"); 56 57 </script> 58 </pre> 59 </body> 60 </html>