<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Edge cases for minsize and maxsize</title>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
<link rel="help" href="https://w3c.github.io/mathml-core/#dictionary-based-attributes">
<meta name="assert" content="Verify edge cases for minsize and maxsize .">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mathml/support/fonts.js"></script>
<style>
  math {
      font: 25px/1 Ahem;
  }
  @font-face {
      font-family: operators;
      src: url("/fonts/math/operators.woff"); /* AxisHeight == 0 */
  }
  mo {
      font-family: operators;
  }
</style>
<script>
  setup({ explicit_done: true });
  window.addEventListener("load", () => { loadAllFonts().then(runTests); });

  function runTests() {
      var epsilon = 1;
      var emToPx = 25;
      test(function() {
          assert_approx_equals(document.getElementById("negative_minsize").getBoundingClientRect().height, 5 * emToPx, epsilon);
      }, `minsize < 0 is treated as 0`);

      test(function() {
          assert_approx_equals(document.getElementById("maxsize_less_than_minsize").getBoundingClientRect().height, 7 * emToPx, epsilon);
      }, `maxsize < minsize is treated as maxsize = minsize`);

      test(function() {
          assert_less_than(document.getElementById("minsize_less_than_negative_maxsize").getBoundingClientRect().height, 2 * emToPx);
      }, `minsize < maxsize < 0 is treated as maxsize = minsize = 0`);

      test(function() {
          assert_approx_equals(document.getElementById("zero_target_size_with_minsize").getBoundingClientRect().height, 2 * emToPx, epsilon);
          assert_approx_equals(document.getElementById("zero_target_size_with_minsize").getBoundingClientRect().bottom - document.getElementById("zero_target_size_with_minsize_math_axis").getBoundingClientRect().bottom, emToPx, epsilon);
      }, `target size = 0 is treated as Tascent = Tdescent = minsize/2`);

      test(function() {
          assert_approx_equals(document.getElementById("percent_minsize").getBoundingClientRect().height, 12 * emToPx, epsilon, "percent minsize");
          assert_approx_equals(document.getElementById("percent_maxsize").getBoundingClientRect().height, 3 * emToPx, epsilon, "percent maxsize");
      }, `minsize/maxsize percentages are relative to the target size`);

      test(function() {
          // These tests are not really strong:
          // - The smallest glyph for this stretchy operator is a 1em square so
          //   it can't go under a minsize of 1em anyway.
          // - The maxsize is theorically infinite, this only tests that a large
          //   value of 300em is clamped.
          assert_approx_equals(document.getElementById("default_minsize").getBoundingClientRect().height, 1 * emToPx, epsilon, "default minsize is 1em");
          assert_approx_equals(document.getElementById("default_maxsize").getBoundingClientRect().height, 300 * emToPx, epsilon, "default maxsize is infinity");
      }, `default minsize/maxsize percentages`);

      done();
  }
</script>
</head>
<body>
  <div id="log"></div>
  <p>
    <math>
      <mrow>
        <mspace width="1em" height="5em" style="background: blue"/>
        <mo id="negative_minsize" minsize="-10em" stretchy="true" symmetric="false">⥯</mo>
        <mn><!-- not space like --></mn>
      </mrow>
    </math>
  </p>
  <p>
    <math>
      <mrow>
        <mspace width="1em" height="5em" style="background: blue"/>
        <mo id="maxsize_less_than_minsize" minsize="7em" maxsize="2em" stretchy="true" symmetric="false">⥯</mo>
        <mn><!-- not space like --></mn>
      </mrow>
    </math>
  </p>
  <p>
    <math>
      <mrow>
        <mspace width="1em" height="5em" style="background: blue"/>
        <mo id="minsize_less_than_negative_maxsize" minsize="-2em" maxsize="-1em" stretchy="true" symmetric="false">⥯</mo>
        <mn><!-- not space like --></mn>
      </mrow>
    </math>
  </p>
  <p>
    <math>
      <mrow>
        <mspace id="zero_target_size_with_minsize_math_axis" width="1em" height="0em" style="background: blue"/>
        <mo id="zero_target_size_with_minsize" minsize="2em" stretchy="true" symmetric="true">⥯</mo>
        <mn><!-- not space like --></mn>
      </mrow>
    </math>
  </p>
  <p>
    <math>
      <mrow>
        <mspace width="1em" height="6em" style="background: blue"/>
        <mo id="percent_minsize" minsize="200%" stretchy="true" symmetric="false">⥯</mo>
        <mn><!-- not space like --></mn>
      </mrow>
    </math>
  </p>
  <p>
    <math>
      <mrow>
        <mspace width="1em" height="6em" style="background: blue"/>
        <mo id="percent_maxsize" maxsize="50%" stretchy="true" symmetric="false">⥯</mo>
        <mn><!-- not space like --></mn>
      </mrow>
    </math>
  </p>
  <p>
    <math>
      <mrow>
        <mspace width="1em" height=".5em" style="background: blue"/>
        <mo id="default_minsize" stretchy="true" symmetric="false">⥯</mo>
        <mn><!-- not space like --></mn>
      </mrow>
    </math>
  </p>
  <p>
    <math>
      <mrow>
        <mspace width="1em" height="300em" style="background: blue"/>
        <mo id="default_maxsize" stretchy="true" symmetric="false">⥯</mo>
        <mn><!-- not space like --></mn>
      </mrow>
    </math>
  </p>

</body>
</html>
