summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/quirks-mode/percentage-height-calculation.html
blob: 7cadd8b0fafb58aec87af4927b938b20c9eafcd5 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!doctype html>
<html>
 <head>
  <title>The percentage height calculation quirk</title>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <style> iframe { width:20px; height:200px } </style>
 </head>
 <body>
  <div id=log></div>
  <iframe id=quirks></iframe>
  <iframe id=almost></iframe>
  <iframe id=standards></iframe>
  <img id="preload">
  <script>
    var png = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==";
    // Ensure png is loaded and cached before we run the tests. Otherwise
    // the tests that use it may run while it's not fully loaded and get <img>
    // fallback layout (i.e., not an image with a 1x1 intrinsic size).
    document.getElementById('preload').src = png;
    setup({explicit_done:true});

    var png = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==";
    var preload = new Image();
    preload.src = png;

    onload = function() {
        var html = "<style id=style></style>";
        var a_doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
        var s_doctype = '<!DOCTYPE HTML>';
        var q = document.getElementById('quirks').contentWindow;
        var a = document.getElementById('almost').contentWindow;
        var s = document.getElementById('standards').contentWindow;
        q.document.open();
        q.document.write(html);
        q.document.close();
        a.document.open();
        a.document.write(a_doctype + html);
        a.document.close();
        s.document.open();
        s.document.write(s_doctype + html);
        s.document.close();
        [q, a, s].forEach(function(win) {
            ['style', 'test'].forEach(function(id) {
                win.__proto__.__defineGetter__(id, function() { return win.document.getElementById(id); });
            });
        });

        var tests = [
        {style:'#test { height:100% }', body:'<div id=test></div>', q:184, s:0},
        {style:'#test { height:50% }', body:'<div id=test></div>', q:92, s:0},
        {style:'#test { height:25% }', body:'<div id=test></div>', q:46, s:0},
        {style:'#test { height:12.5% }', body:'<div id=test></div>', q:23, s:0},
        {style:'#test { height:100% }', body:'<div><div id=test></div></div>', q:184, s:0},
        {style:'', body:'<img id=test src="{png}" height=100%>', q:184, s:1},
        {style:'', body:'<img id=test src="{png}" height=100% border=10>', q:184, s:1},
        {style:'', body:'<table id=test height=100%><tr><td></table>', q:184, s:6},
        {style:'#foo { height:100px } #test { height:100% }', body:'<div id=foo><div><div id=test></div></div></div>', q:100, s:0},
        {style:'#foo { position:absolute } #test { height:100% }', body:'<div id=foo><div><div id=test></div></div></div>', q:0, s:0},
        {style:'#foo { position:relative } #test { height:100% }', body:'<div id=foo><div><div id=test></div></div></div>', q:184, s:0},
        {style:'#foo { height:100px } #test { height:100%; position:absolute }', body:'<div id=foo><div><div id=test></div></div></div>', q:200, s:200},
        {style:'#foo { height:100px } #test { height:100%; position:fixed }', body:'<div id=foo><div><div id=test></div></div></div>', q:200, s:200},
        {style:'#foo { height:100px } #test { height:100%; position:relative }', body:'<div id=foo><div><div id=test></div></div></div>', q:100, s:0},
        {style:'#foo { height:100px } #test { height:calc(100% + 1px) }', body:'<div id=foo><div id=test></div></div>', q:101, s:101},
        {style:'#foo { height:100px } #test { height:5px; height:calc(100% + 1px) }', body:'<div id=foo><div><div id=test></div></div></div>', q:0, s:0},
        {style:'html { display:inline } #test { height:100% }', body:'<div id=test></div>', q:184, s:0}, // display:inline on root has no effect
        {style:'html { margin:10px } body { display:inline } #test { height:100% }', body:'<div id=test></div>', q:200, s:0},
        {style:'body { margin:0 } #test { height:100% }', body:'<div id=test></div>', q:200, s:0},
        {style:'body { margin:0; padding:10px } #test { height:100% }', body:'<div id=test></div>', q:180, s:0},
        {style:'body { margin:0; border:10px solid } #test { height:100% }', body:'<div id=test></div>', q:180, s:0},
        {style:'html { margin:10px } #test { height:100% }', body:'<div id=test></div>', q:164, s:0},
        {style:'html { padding:10px } #test { height:100% }', body:'<div id=test></div>', q:164, s:0},
        {style:'html { border:10px solid } #test { height:100% }', body:'<div id=test></div>', q:164, s:0},
        {style:'html { position:absolute } #test { height:100% }', body:'<div id=test></div>', q:0, s:0},
        {style:'body { position:absolute } #test { height:100% }', body:'<div id=test></div>', q:0, s:0},
        {style:'html { height:100%; margin:10px } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
        {style:'html { height:100%; padding:10px } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
        {style:'html { height:100%; border:10px solid } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
        {style:'body { height:100%; margin:10px } #test { height:100% }', body:'<div id=test></div>', q:200, s:0},
        {style:'body { height:100%; padding:10px } #test { height:100% }', body:'<div id=test></div>', q:200, s:0},
        {style:'body { height:100%; border:10px solid } #test { height:100% }', body:'<div id=test></div>', q:200, s:0},
        {style:'html { position:absolute; height:100%; margin:10px } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
        {style:'html { position:absolute; height:100%; padding:10px } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
        {style:'html { position:absolute; height:100%; border:10px solid } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
        {style:'body { margin:99px 0 } #test { height:100% }', body:'<div id=test></div>', q:2, s:0},
        {style:'body { margin:110px 0 } #test { height:100% }', body:'<div id=test></div>', q:0, s:0},
        {style:'html, body { border:10px none } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
        {style:'html, body { border:10px hidden } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
        ];

        tests.forEach(function(t) {
            test(function() {
                // Hide scrollbars in all subdocuments so that a horizontal
                // scrollbar doesn't appear and upset our calculations.
                var style = t.style.replace(/\{png\}/g, png) + " html { overflow:hidden; }";
                var body = t.body.replace(/\{png\}/g, png);
                q.style.textContent = style;
                a.style.textContent = style;
                s.style.textContent = style;
                q.document.body.innerHTML = body;
                a.document.body.innerHTML = body;
                s.document.body.innerHTML = body;

                assert_equals(q.getComputedStyle(q.test).height,
                              t.q + 'px',
                              'quirks mode');
                assert_equals(a.getComputedStyle(a.test).height,
                              t.s + 'px',
                              'almost standards mode');
                assert_equals(s.getComputedStyle(s.test).height,
                              t.s + 'px',
                              'standards mode');
            }, document.title+', '+t.style+t.body);
        });

        var xml_tests = [
        {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><body><div id="test"/></body></html>', q:184, s:0},
        {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><body/><div id="test"/></html>', q:200, s:0},
        {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><span><body><div id="test"/></body></span></html>', q:200, s:0},
        {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><body><body><div id="test"/></body></body></html>', q:200, s:0},
        {input:'<html><head xmlns="{html}"><style>#test { height:100% }</style></head><body xmlns="{html}"><div id="test"/></body></html>', q:200, s:0},
        {input:'<div xmlns="{html}"><head><style>#test { height:100% }</style></head><body><div id="test"/></body></div>', q:200, s:0},
        {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><body xmlns=""><div xmlns="{html}" id="test"/></body></html>', q:200, s:0},
        {input:'<HTML xmlns="{html}"><head><style>#test { height:100% }</style></head><body><div id="test"/></body></HTML>', q:200, s:0},
        {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><BODY><div id="test"/></BODY></html>', q:200, s:0},
        ];

        var parser = new DOMParser();

        xml_tests.forEach(function(t) {
            test(function() {
                var input = t.input.replace(/\{html\}/g, 'http://www.w3.org/1999/xhtml')
                                   .replace(/\{png\}/g, png);
                var root = parser.parseFromString(input, 'text/xml').documentElement;
                q.document.replaceChild(root.cloneNode(true), q.document.documentElement);
                a.document.replaceChild(root.cloneNode(true), a.document.documentElement);
                s.document.replaceChild(root, s.document.documentElement);
                assert_equals(q.getComputedStyle(q.test).height,
                              t.q + 'px',
                              'quirks mode');
                assert_equals(a.getComputedStyle(a.test).height,
                              t.s + 'px',
                              'almost standards mode');
                assert_equals(s.getComputedStyle(s.test).height,
                              t.s + 'px',
                              'standards mode');
            }, document.title+', '+t.input);
        });

        done();
    }
  </script>
 </body>
</html>