<!DOCTYPE html>
<html lang=en>
<meta charset="utf-8">
<title>CSS Grid Layout Test: Change fit-content() argument</title>
<link rel="author" title="Manuel Rego Casasnovas" href="mailto:rego@igalia.com">
<link rel="help" href="https://drafts.csswg.org/css-grid-1/#track-sizing">
<meta name="assert" content="This test checks that grid-template-{rows|columns} with fit-content() tracks recomputes the tracks when the fit-content() argument is modified.">
<meta name="flags" content="ahem">
<link rel="stylesheet" href="/css/support/grid.css">
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
<style>
.grid {
  width: fit-content;
  position: relative;
  justify-content: start;
  align-content: start;
  font: 25px/1 Ahem;
}

.verticalLR {
  writing-mode: vertical-lr;
}
</style>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/check-layout-th.js"></script>
<script>
setup({ explicit_done: true });
function setGridTemplate(id, gridTemplateRows, gridTemplateColumns)
{
  var gridElement = document.getElementById(id);
  gridElement.style.gridTemplateRows = gridTemplateRows;
  gridElement.style.gridTemplateColumns = gridTemplateColumns;
}

function testGridItemDefinitions(gridItemData)
{
  var item = document.getElementById(gridItemData.id);
  item.setAttribute("data-expected-width", gridItemData.width);
  item.setAttribute("data-expected-height", gridItemData.height);
  item.setAttribute("data-offset-x", gridItemData.x);
  item.setAttribute("data-offset-y", gridItemData.y);

  checkLayout(".grid", false);
}

function testChangingGridDefinitions()
{
  // Test changing the argument of fit-content() tracks.
  setGridTemplate("grid1", "none", "fit-content(100px)");
  testGridItemDefinitions({"id": "item1", "width": "100", "height": "100", "x": "0", "y": "0" });

  setGridTemplate("grid1", "none", "fit-content(150px)");
  testGridItemDefinitions({"id": "item1", "width": "150", "height": "75", "x": "0", "y": "0" });

  setGridTemplate("grid2", "fit-content(100px)", "none");
  testGridItemDefinitions({"id": "item2", "width": "100", "height": "100", "x": "0", "y": "0" });

  setGridTemplate("grid2", "fit-content(150px)", "none");
  testGridItemDefinitions({"id": "item2", "width": "75", "height": "150", "x": "0", "y": "0" });

  done();
}
</script>

<body onload="document.fonts.ready.then(() => { testChangingGridDefinitions(); })">
<div id="grid1" class="grid">
  <div id="item1" class="autoRowAutoColumn">XXXX XXX XX X X</div>
</div>

<div id="grid2" class="grid">
  <div id="item2" class="autoRowAutoColumn verticalLR">XXXX XXX XX X X</div>
</div>
</body>
