summaryrefslogtreecommitdiffstats
path: root/dom/grid/test/chrome/test_grid_lines.html
blob: c8fa8b685063ea827b51eb1fd054dd7736f2c3c8 (plain)
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<style>
body {
  margin: 40px;
}
.wrapper {
  display: grid;
  width: 400px;
  grid-gap: 10px;
  grid-template-columns: 50px [first first] repeat(3, [divider] 100px) [last last last last];
  grid-template-rows: [top1 top2] repeat(1, [top2 top2] 50px) [bot];
  background-color: #f00;
}
.box {
  background-color: #444;
  color: #fff;
}
</style>

<script>
"use strict";

SimpleTest.waitForExplicitFinish();

function runTests() {
  var wrapper = document.getElementById("wrapper");
  var grid = wrapper.getGridFragments()[0];

  // test property existence
  isnot(typeof(grid.cols.lines), "undefined", "Grid.cols.lines property exists.");

  if (typeof(grid.cols.lines) != "undefined") {
    // test column line count
    is(grid.cols.lines.length, 5,
      "Grid.cols.lines property has length that matches grid-template-columns."
    );

    if (grid.cols.lines.length == 5) {
      // test column line position
      is(grid.cols.lines[1].start, 50, "Grid column line 2 position is as expected.");

      // test column line width
      is(grid.cols.lines[1].breadth, 10, "Grid column line 2 width is as expected.");

      // test column line numbers, positive and negative
      is(grid.cols.lines[3].number, 4, "Grid column line 4 positive number is as expected.");
      is(grid.cols.lines[3].negativeNumber, -2, "Grid column line 4 negative number is as expected.");

      // test column line names
      is(grid.cols.lines[0].names.length, 0, "Grid column line 1 has no names.");

      is(grid.cols.lines[1].names.length, 2, "Grid column line 2 has 2 names.");
      is(grid.cols.lines[1].names + "", "first,divider", "Grid column line 2 has the names 'first,divider'.");

      is(grid.cols.lines[4].names.length, 1, "Grid column line 5 has 1 name.");
      is(grid.cols.lines[4].names + "", "last", "Grid column line 5 has the name 'last'.");
    }
  }

  // test property existence
  isnot(typeof(grid.rows.lines), "undefined", "Grid.rows.lines property exists.");

  if (typeof(grid.rows.lines) != "undefined") {
    // test column line count
    is(grid.rows.lines.length, 3,
      "Grid.rows.lines property has length that matches grid-template-rows."
    );

    if (grid.rows.lines.length == 3) {
      // test row line names
      is(grid.rows.lines[0].names.length, 2, "Grid row line 1 has 2 names.");
      is(grid.rows.lines[0].names + "", "top1,top2", "Grid row line 1 has the names 'top1,top2'.");

      is(grid.rows.lines[1].names.length, 1, "Grid row line 2 has 1 name.");
      is(grid.rows.lines[1].names + "", "bot", "Grid row line 2 has the name 'bot'.");

      is(grid.rows.lines[2].names.length, 0, "Grid row line 3 has no names.");
    }
  }

  SimpleTest.finish();
}
</script>
</head>
<body onLoad="runTests();">

  <div id="wrapper" class="wrapper">
    <div id="boxA" class="box a">A</div>
    <div id="boxB" class="box b">B</div>
    <div id="boxC" class="box c">C</div>
    <div class="box d">D</div>
    <div class="box e">E</div>
    <div class="box f">F</div>
    <div class="box g">G</div>
    <div class="box h">H</div>
  </div>

</body>
</html>