<!DOCTYPE html>
<html>
<title>CSS Grid Layout Test: Auto repeat tracks, grid-template-columns and flexible lengths.</title>
<link rel="author" title="Julien Chaffraix" href="mailto:jchaffraix@chromium.org">
<link rel="help" href="https://drafts.csswg.org/css-grid-1/#track-sizes">
<link rel="help" href="https://drafts.csswg.org/css-grid-1/#fr-unit">
<link rel="help" href="https://bugs.chromium.org/p/chromium/issues/detail?id=235258">
<link rel="stylesheet" href="/fonts/ahem.css">
<link rel="stylesheet" href="/css/support/grid.css">
<meta name="assert" content="Test that resolving auto tracks on grid items using <flex> values with grid-template-columns works properly." />

<style>
.gridFlexContent {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 50px;
}
.gridMaxFlexContent {
    grid-template-columns: minmax(30px, 2fr);
    grid-template-rows: 50px;
}
.gridTwoMaxFlexContent {
    grid-template-columns: minmax(10px, 1fr) minmax(10px, 2fr);
    grid-template-rows: 50px;
}
.gridTwoDoubleMaxFlexContent {
    grid-template-columns: minmax(10px, 0.5fr) minmax(10px, 2fr);
    grid-template-rows: 50px;
}
.gridIgnoreSecondGridItem {
    grid-template-columns: minmax(300px, 3fr) minmax(150px, 1fr);
    grid-template-rows: 50px;
}
.gridRespectBaseSize {
    grid-template-columns: minmax(75px, 1fr) minmax(0px, 2fr);
    grid-template-rows: 50px;
}
.gridRespectProportions {
    grid-template-columns: minmax(0px, .25fr) minmax(0px, .5fr) minmax(0px, 2fr);
    grid-template-rows: 50px;
}
.gridRespectBaseSizeProportions {
    grid-template-columns: minmax(50px, .25fr) minmax(0px, .5fr) minmax(0px, 1fr);
    grid-template-rows: 50px;
}
.gridRespectBaseSizeBeforeProportions {
    grid-template-columns: minmax(50px, .25fr) minmax(0px, .5fr) minmax(0px, 1fr);
    grid-template-rows: 50px;
}
.firstRowThirdColumn {
    background-color: yellow;
    grid-column: 3;
    grid-row: 1;
}
</style>

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/check-layout-th.js"></script>
<script type="text/javascript">
  setup({ explicit_done: true });
</script>

<body onload="document.fonts.ready.then(() => { checkLayout('.grid'); })">

<div class="constrainedContainer" style="position: relative">
    <div class="grid gridFlexContent">
        <div class="sizedToGridArea firstRowFirstColumn" data-offset-x="0" data-offset-y="0" data-expected-width="30" data-expected-height="50">XXX</div>
        <div class="sizedToGridArea firstRowSecondColumn" data-offset-x="30" data-offset-y="0" data-expected-width="50" data-expected-height="50">XXXXX</div>
    </div>
</div>

<div class="constrainedContainer">
    <div class="grid gridMaxFlexContent">
        <div class="sizedToGridArea firstRowFirstColumn" data-expected-width="30" data-expected-height="50"></div>
    </div>
</div>

<!-- Allow the extra logical space distribution to occur. -->
<div style="width: 40px; height: 10px">
    <div class="grid gridMaxFlexContent">
        <div class="sizedToGridArea firstRowFirstColumn" data-expected-width="40" data-expected-height="50"></div>
    </div>
</div>

<div style="width: 100px; height: 10px;">
    <div class="grid gridMaxFlexContent">
        <div class="sizedToGridArea firstRowFirstColumn" data-expected-width="100" data-expected-height="50"></div>
    </div>
</div>


<div class="constrainedContainer">
    <div class="grid gridTwoMaxFlexContent">
        <div class="sizedToGridArea firstRowFirstColumn" data-expected-width="10" data-expected-height="50"></div>
        <div class="sizedToGridArea firstRowSecondColumn" data-expected-width="10" data-expected-height="50"></div>
    </div>
</div>

<!-- Allow the extra logical space distribution to occur. -->
<div style="width: 60px; height: 10px">
    <div class="grid gridTwoMaxFlexContent">
        <div class="sizedToGridArea firstRowFirstColumn" data-expected-width="20" data-expected-height="50"></div>
        <div class="sizedToGridArea firstRowSecondColumn" data-expected-width="40" data-expected-height="50"></div>
    </div>
</div>

<div style="width: 120px; height: 10px;">
    <div class="grid gridTwoMaxFlexContent">
        <div class="sizedToGridArea firstRowFirstColumn" data-expected-width="40" data-expected-height="50"></div>
        <div class="sizedToGridArea firstRowSecondColumn" data-expected-width="80" data-expected-height="50"></div>
    </div>
</div>


<div class="constrainedContainer">
    <div class="grid gridTwoDoubleMaxFlexContent">
        <div class="sizedToGridArea firstRowFirstColumn" data-expected-width="10" data-expected-height="50"></div>
        <div class="sizedToGridArea firstRowSecondColumn" data-expected-width="10" data-expected-height="50"></div>
    </div>
</div>

<!-- Allow the extra logical space distribution to occur. -->
<div style="width: 60px; height: 10px">
    <div class="grid gridTwoDoubleMaxFlexContent">
        <div class="sizedToGridArea firstRowFirstColumn" data-expected-width="12" data-expected-height="50"></div>
        <div class="sizedToGridArea firstRowSecondColumn" data-expected-width="48" data-expected-height="50"></div>
    </div>
</div>

<div style="width: 120px; height: 10px;">
    <div class="grid gridTwoDoubleMaxFlexContent">
        <div class="sizedToGridArea firstRowFirstColumn" data-expected-width="24" data-expected-height="50"></div>
        <div class="sizedToGridArea firstRowSecondColumn" data-expected-width="96" data-expected-height="50"></div>
    </div>
</div>


<!-- Custom test for a corner case. -->
<div style="width: 570px; height: 10px;">
    <div class="grid gridIgnoreSecondGridItem">
        <div class="sizedToGridArea firstRowFirstColumn" data-expected-width="420" data-expected-height="50"></div>
        <div class="sizedToGridArea firstRowSecondColumn" data-expected-width="150" data-expected-height="50"></div>
    </div>
</div>

<!-- Flex track length must be at least its baseSize. -->
<div style="width: 100px; height: 10px;">
    <div class="grid gridRespectBaseSize">
        <div class="sizedToGridArea firstRowFirstColumn" data-expected-width="75" data-expected-height="50"></div>
        <div class="sizedToGridArea firstRowSecondColumn" data-expected-width="25" data-expected-height="50"></div>
    </div>
</div>

<!-- Flex track lengths must be proportional to their flex factors.. -->
<div style="width: 275px; height: 10px;">
    <div class="grid gridRespectProportions">
        <div class="sizedToGridArea firstRowFirstColumn" data-expected-width="25" data-expected-height="50"></div>
        <div class="sizedToGridArea firstRowSecondColumn" data-expected-width="50" data-expected-height="50"></div>
        <div class="sizedToGridArea firstRowThirdColumn" data-expected-width="200" data-expected-height="50"></div>
    </div>
</div>

<!-- Flex track lengths must be proportional but still respecting their base sizes. -->
<div style="width: 350px; height: 10px;">
    <div class="grid gridRespectBaseSizeProportions">
        <div class="sizedToGridArea firstRowFirstColumn" data-expected-width="50" data-expected-height="50"></div>
        <div class="sizedToGridArea firstRowSecondColumn" data-expected-width="100" data-expected-height="50"></div>
        <div class="sizedToGridArea firstRowThirdColumn" data-expected-width="200" data-expected-height="50"></div>
    </div>
</div>

<!-- Not enough space to respect proportions, because minTrackBreadh it's a harder requirement -->
<div style="width: 275px; height: 10px;">
    <div class="grid gridRespectBaseSizeBeforeProportions">
        <div class="sizedToGridArea firstRowFirstColumn" data-expected-width="50" data-expected-height="50"></div>
        <div class="sizedToGridArea firstRowSecondColumn" data-expected-width="75" data-expected-height="50"></div>
        <div class="sizedToGridArea firstRowThirdColumn" data-expected-width="150" data-expected-height="50"></div>
    </div>
</div>

</body>
</html>
