tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

calc-size-flex-basis-on-column.html (4085B)


      1 <!DOCTYPE html>
      2 <title>calc-size() on flex-basis</title>
      3 <link rel="help" href="https://drafts.csswg.org/css-values-5/#calc-size">
      4 <link rel="help" href="https://drafts.csswg.org/css-flexbox/#flex-basis-property">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <link rel="stylesheet" href="/fonts/ahem.css">
      8 <style>
      9  #container {
     10    display: flex;
     11    flex-direction: column;
     12    font-family: 'Ahem';
     13    font-size: 20px;
     14    height: 200px;
     15  }
     16  #target {
     17    height: 50px;
     18    flex-grow: 0;
     19    flex-shrink: 0;
     20  }
     21 </style>
     22 
     23 <div id="container">
     24  <!--
     25    Given the contents of #target (and the Ahem font), intrinsic height is 1ch or 20px
     26  -->
     27  <div id="target">hello</div>
     28 </div>
     29 
     30 <script>
     31 
     32 setup({explicit_done: true});
     33 document.fonts.ready.then(()=> {
     34  let basic_tests = [
     35    /* I think flex layout rules require expectations be >= 20px */
     36    { value: "274px", expected: "274px" },
     37    { value: "min-content", expected: "20px" },
     38    { value: "fit-content", expected: "20px" },
     39    { value: "max-content", expected: "20px" },
     40    { value: "content", expected: "20px" },
     41    { value: "auto", expected: "50px" },
     42    { value: "calc-size(any, 357px)", expected: "357px" },
     43    { value: "calc-size(any, 220%)", expected: "440px" },
     44    { value: "calc-size(max-content, 350%)", expected: "700px" },
     45    { value: "calc-size(fit-content, 172px)", expected: "172px" },
     46    { value: "calc-size(37px, 193px)", expected: "193px" },
     47    { value: "calc-size(83px, size * 3)", expected: "249px" },
     48    { value: "calc-size(min-content, size / 0.25)", expected: "80px" },
     49    { value: "calc-size(max-content, size * 5.2)", expected: "104px" },
     50    { value: "calc-size(fit-content, size / 4 + 60px)", expected: "65px" },
     51    { value: "calc-size(stretch, size * 2 - 10%)", expected: "380px" },
     52    { value: "calc-size(30px, 15em)", expected: "300px" },
     53    { value: "calc-size(calc-size(any, 30px), 15em)", expected: "300px" },
     54    { value: "calc-size(calc-size(2in, 30px), 15em)", expected: "300px" },
     55    { value: "calc-size(calc-size(min-content, 30px), 15em)", expected: "300px" },
     56    { value: "calc-size(calc-size(min-content, size), size * 3)", expected: "60px" },
     57    { value: "calc-size(auto, size)", expected: "50px" },
     58    { value: "calc-size(auto, size * 1.6 + 23px)", expected: "103px" },
     59    { value: "calc-size(content, size)", expected: "20px" },
     60    { value: "calc-size(content, size * 1.6 + 23px)", expected: "55px" },
     61    { value: "auto", height_value: "auto", expected: "20px" },
     62    { value: "calc-size(auto, size * 3)", height_value: "auto", expected: "60px" },
     63    { value: "auto", height_value: "calc-size(auto, size * 7)", expected: "140px" },
     64    { value: "calc-size(auto, size * 7)", height_value: "calc-size(auto, size * 3)", expected: "420px" },
     65    { value: "auto", height_value: "calc-size(max-content, size + 12px)", expected: "32px" },
     66    { value: "calc-size(auto, size + 4px)", height_value: "calc-size(fit-content, size + 12px)", expected: "36px" },
     67    { value: "372px", height_value: "calc-size(fit-content, size + 12px)", expected: "372px" },
     68    { value: "calc-size(content, size * 7)", height_value: "321px", expected: "140px" },
     69  ];
     70  const container = document.getElementById("container");
     71  const target = document.getElementById("target");
     72  const target_cs = getComputedStyle(target);
     73  for (const obj of basic_tests) {
     74    test((t) => {
     75      target.style.removeProperty("flex-basis");
     76      target.style.flexBasis = obj.value;
     77      assert_not_equals(target.style.flexBasis, "", "flex-basis value is accepted");
     78 
     79      target.style.removeProperty("height");
     80      if ("height_value" in obj) {
     81        target.style.height = obj.height_value;
     82        assert_not_equals(target.style.height, "", "height value is accepted");
     83      }
     84 
     85      assert_equals(target_cs.height, obj.expected, "resulting height is correct");
     86    }, `resolved value for height resulting from flex-basis: ${obj.value}${obj.height_value ? ` and height: ${obj.height_value}` : ""}`);
     87  }
     88 
     89  done();
     90 });
     91 
     92 </script>