summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/sub-pixel/table-rows-have-stable-height.html
blob: e56214736ec6e8cdb07cb99afebb40b7a12e223a (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html>
    <head>
        <style>
            body {
                margin: 5px;
            }
            table {
                border-collapse: collapse;
            }
            td {
                background: skyblue;
                border: 1px solid black;
            }
            #measure {
                position: absolute;
                top: -500px;
                visibility: hidden;
            }
        </style>
        <script src="../../resources/js-test.js"></script>
    </head>
    <body>
        <table id="main" cellspacing="0" border="0" cellpadding="0">
            <tr>
                <td>style.height</td>
                <td>rect.height</td>
                <td>rect.bottom - rect.top</td>
            </tr>
            <tr><td>a</td><td>b</td><td>c</td></tr>
            <tr><td>a</td><td>b</td><td>c</td></tr>
            <tr><td>a</td><td>b</td><td>c</td></tr>
            <tr><td>a</td><td>b</td><td>c</td></tr>
            <tr><td>a</td><td>b</td><td>c</td></tr>
            <tr><td>a</td><td>b</td><td>c</td></tr>
            <tr><td>a</td><td>b</td><td>c</td></tr>
            <tr><td>a</td><td>b</td><td>c</td></tr>
            <tr><td>a</td><td>b</td><td>c</td></tr>
        </table>
        <p>
            This tests whether table row heights are stable by measuring the
            height of a row, assigning that height to another row and then
            measuring it.
            For each row the numbers in the three cells should be the same.
        </p>
        <p>
            <a href="https://bugs.webkit.org/show_bug.cgi?id=88813">Bug 88813</a>
        </p>

        <table id="measure" cellspacing="0" border="0" cellpadding="0">
            <tr><td>Measurement</td><td>table</td><td>...</td></tr>
        </table>
        
        <script>
            var mainTable = document.getElementById('main');
            var measureTable = document.getElementById('measure');
            var rowHeights = [];

            function r(n) {
                return Math.round(n * 1000) / 1000;
            }

            function computeHeights()
            {
                rowHeights.length = 0;
                var rowElement = measureTable.tBodies[0].rows[0];
                for (var i = 0; i < mainTable.tBodies[0].rows.length; i++) {
                    // Set the size to a subpixel value, the exact value isn't
                    // important but each row should have a different height.
                    var height = r((20 + i) * 0.93 + i);
                    rowElement.style.height = height + 'px';
                    rect = rowElement.getBoundingClientRect();
                    rowHeights.push(rect.bottom - rect.top);
                }
            }
            

            function testHeights(zoom)
            {
                document.body.style.zoom = zoom;
                computeHeights();
                
                var rows = mainTable.tBodies[0].rows;
                for (var i = 0; i < rows.length; i++) {
                    var rowElement = rows[i];
                    rowElement.style.height = rowHeights[i] + 'px';
                    var rect = rowElement.getBoundingClientRect();
                    if (i) {
                        rowElement.cells[0].firstChild.nodeValue = r(rowHeights[i]);
                        rowElement.cells[1].firstChild.nodeValue = r(rect.height);
                        rowElement.cells[2].firstChild.nodeValue = r(rect.bottom - rect.top);
                    }
                }

                var failures = 0;
                for (var i = 0; i < rows.length; i++) {
                    var rect = rows[i].getBoundingClientRect();
                    if (r(rowHeights[i]) != r(rect.height)) {
                        testFailed('At ' + r(zoom * 100) + '% zoom getBoundingClientRect returned a height of ' + r(rect.height) + ', expected ' + r(rowHeights[i]) + '.');
                        failures++;
                    }
                    if (r(rowHeights[i]) != r(rect.bottom - rect.top)) {
                        testFailed('At ' + r(zoom * 100) + '% zoom getBoundingClientRect returned a rect with bottom - top of ' + (rect.bottom - rect.top) + ', expected ' + rowHeights[i] + '.');
                        failures++;
                    }
                }
                if (!failures)
                    testPassed('At ' + r(zoom * 100) + '% zoom all heights matched.');
        }

        testHeights(0.5);
        testHeights(0.75);
        testHeights(0.9);
        testHeights(1.1);
        testHeights(1.25);
        testHeights(1.33);
        testHeights(1.5);
        testHeights(1.75);
        testHeights(2);
        testHeights(1);

        if (window.testRunner)
            document.getElementById('main').style.display = 'none';
        </script>
  </body>
</html>