margin-002.html (4537B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>margin</title> 6 <link rel="help" href="https://w3c.github.io/mathml-core/#layout-algorithms"> 7 <meta name="assert" content="Verify that margin is taken into account."> 8 <link rel="stylesheet" type="text/css" href="/fonts/ahem.css" /> 9 <style> 10 math { 11 font: 25px/1 Ahem; 12 } 13 </style> 14 <script src="/resources/testharness.js"></script> 15 <script src="/resources/testharnessreport.js"></script> 16 <script src="/mathml/support/feature-detection.js"></script> 17 <script src="/mathml/support/mathml-fragments.js"></script> 18 <script src="/mathml/support/box-comparison.js"></script> 19 <script src="/mathml/support/fonts.js"></script> 20 <script> 21 var epsilon = 2; 22 23 setup({ explicit_done: true }); 24 window.addEventListener("load", () => { loadAllFonts().then(runTests); }); 25 26 function runTests() { 27 28 for (tag in MathMLFragments) { 29 if (!FragmentHelper.isValidChildOfMrow(tag)) 30 continue; 31 32 var style = "margin-left: 30px; margin-right: 40px; margin-top: 50px; margin-bottom: 60px;"; 33 34 if (FragmentHelper.isEmpty(tag)) { 35 test(function() { 36 assert_true(MathMLFeatureDetection[`has_${tag}`](), `${tag} is supported`); 37 var s = compareSizeWithAndWithoutStyle(tag, style); 38 assert_approx_equals(s.width_delta, 30 + 40, epsilon, "left/right margin"); 39 assert_approx_equals(s.height_delta, 50 + 60, epsilon, "top/bottom margin"); 40 assert_approx_equals(s.element_width_delta, 0, epsilon, "element width"); 41 assert_approx_equals(s.element_height_delta, 0, epsilon, "element height"); 42 assert_approx_equals(s.preferred_width_delta, 30 + 40, epsilon, "preferred width"); 43 }, `Margin properties on ${tag}`); 44 continue; 45 } 46 47 test(function() { 48 assert_true(MathMLFeatureDetection[`has_${tag}`](), `${tag} is supported`); 49 var s = compareSpaceWithAndWithoutStyle(tag, style); 50 assert_approx_equals(s.left_delta, 30, epsilon, "left margin"); 51 assert_approx_equals(s.right_delta, 40, epsilon, "right margin"); 52 assert_approx_equals(s.top_delta, 50, epsilon, "top margin"); 53 assert_approx_equals(s.bottom_delta, 60, epsilon, "bottom margin"); 54 assert_approx_equals(s.element_width_delta, 0, epsilon, "element width"); 55 assert_approx_equals(s.element_height_delta, 0, epsilon, "element height"); 56 assert_approx_equals(s.preferred_width_delta, 30 + 40, epsilon, "preferred width"); 57 }, `Margin properties on ${tag}`); 58 59 test(function() { 60 assert_true(MathMLFeatureDetection[`has_${tag}`](), `${tag} is supported`); 61 var s = compareSpaceWithAndWithoutStyle(tag, style, null, "rtl"); 62 assert_approx_equals(s.left_delta, 30, epsilon, "left margin"); 63 assert_approx_equals(s.right_delta, 40, epsilon, "right margin"); 64 assert_approx_equals(s.top_delta, 50, epsilon, "top margin"); 65 assert_approx_equals(s.bottom_delta, 60, epsilon, "bottom margin"); 66 assert_approx_equals(s.element_width_delta, 0, epsilon, "element width"); 67 assert_approx_equals(s.element_height_delta, 0, epsilon, "element height"); 68 assert_approx_equals(s.preferred_width_delta, 30 + 40, epsilon, "preferred width"); 69 }, `Margin properties on ${tag} (rtl)`); 70 71 test(function() { 72 assert_true(MathMLFeatureDetection[`has_${tag}`](), `${tag} is supported`); 73 // Apply the same margin style on the parent mrow. 74 // The margins are not collapsed so they should be added twice. 75 var s = compareSpaceWithAndWithoutStyle(tag, style, style); 76 assert_approx_equals(s.left_delta, 30 * 2, epsilon, "left margin"); 77 assert_approx_equals(s.right_delta, 40 * 2, epsilon, "right margin"); 78 assert_approx_equals(s.top_delta, 50 * 2, epsilon, "top margin"); 79 assert_approx_equals(s.bottom_delta, 60 * 2, epsilon, "bottom margin"); 80 assert_approx_equals(s.element_width_delta, 0, epsilon, "element width"); 81 assert_approx_equals(s.element_height_delta, 0, epsilon, "element height"); 82 assert_approx_equals(s.preferred_width_delta, (30 + 40) * 2, epsilon, "preferred width"); 83 }, `Margin properties on ${tag} (no margin-collapsing)`); 84 } 85 86 done(); 87 } 88 </script> 89 </head> 90 <body> 91 <div id="log"></div> 92 </body> 93 </html>