DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (b6057e17f856)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
<!DOCTYPE html>
<html>
<head>
  <meta charset=utf-8>
  <title>Test serialization of CSS Grid shorthand properties</title>
  <link rel="author" title="Simon Sapin" href="mailto:simon.sapin@exyr.org">
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <link rel='stylesheet' href='/resources/testharness.css'>
</head>
<body>

<script>

var initial_values = {
    gridTemplateAreas: "none",
    gridTemplateColumns: "none",
    gridTemplateRows: "none",
    gridAutoFlow: "row",
    gridAutoColumns: "auto",
    gridAutoRows: "auto",
};

// For various specified values of the grid-template subproperties,
// test the serialization of the shorthand.
var grid_template_test_cases = [
    {
        gridTemplateRows: "100px",
        shorthand: "none / 100px",
    },
    {
        gridTemplateColumns: "40px",
        shorthand: "40px / none",
    },
    {
        gridTemplateColumns: "40px",
        gridTemplateRows: "subgrid",
        shorthand: "40px / subgrid",
    },
    {
        gridTemplateColumns: "(foo) 40px (bar)",
        gridTemplateRows: "(baz) 100px (fizz)",
        shorthand: "(foo) 40px (bar) / (baz) 100px (fizz)",
    },
    {
        gridTemplateAreas: "\"a\"",
        gridTemplateRows: "20px",
        shorthand: "\"a\" 20px",
    },
    {
        gridTemplateAreas: "\"a\"",
        gridTemplateRows: "(foo) 20px (bar)",
        shorthand: "(foo) \"a\" 20px (bar)",
    },
    // Combinations of longhands that make the shorthand non-serializable:
    {
        gridTemplateAreas: "\"a\"",
        gridTemplateRows: "20px 100px",
        shorthand: "",
    },
    {
        gridTemplateAreas: "\"a\" \"b\"",
        gridTemplateRows: "20px",
        shorthand: "",
    },
    {
        gridTemplateAreas: "\"a\"",
        gridTemplateRows: "subgrid",
        shorthand: "",
    },
    {
        gridTemplateAreas: "\"a\"",
        gridTemplateRows: "subgrid (foo)",
        shorthand: "",
    },
    {
        gridTemplateAreas: "\"a\"",
        gridTemplateRows: "20px",
        gridTemplateColumns: "subgrid",
        shorthand: "",
    },
];

grid_test_cases = grid_template_test_cases.concat([
    {
        gridAutoFlow: "row",
        shorthand: "row auto / auto",
    },
    {
        gridAutoColumns: "40px",
        shorthand: "row 40px / auto",
    },
    {
        gridAutoFlow: "column dense",
        gridAutoColumns: "minmax(min-content, max-content)",
        shorthand: "column dense minmax(min-content, max-content) / auto",
    },
    {
        gridAutoFlow: "row dense",
        gridAutoRows: "minmax(min-content, 2fr)",
        shorthand: "row dense auto / minmax(min-content, 2fr)",
    },
    {
        gridAutoFlow: "row",
        gridAutoColumns: "40px",
        gridAutoRows: "100px",
        shorthand: "row 40px / 100px",
    },
]);

function run_tests(test_cases, shorthand, subproperties) {
    test_cases.forEach(function(test_case) {
        test(function() {
            var element = document.createElement('div');
            document.body.appendChild(element);
            subproperties.forEach(function(longhand) {
                element.style[longhand] = test_case[longhand] ||
                                          initial_values[longhand];
            });
            assert_equals(element.style[shorthand], test_case.shorthand);
        }, "test shorthand serialization " + JSON.stringify(test_case));
    });
}

run_tests(grid_template_test_cases, "gridTemplate", [
    "gridTemplateAreas", "gridTemplateColumns", "gridTemplateRows"]);

run_tests(grid_test_cases, "grid", [
    "gridTemplateAreas", "gridTemplateColumns", "gridTemplateRows",
    "gridAutoFlow", "gridAutoColumns", "gridAutoRows"]);

</script>
</body>
</html>