OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <html> |
| 3 <head> |
| 4 <title>The percentage height calculation quirk</title> |
| 5 <script src="../../../resources/testharness.js"></script> |
| 6 <script src="../../../resources/testharnessreport.js"></script> |
| 7 <style> iframe { width:20px; height:200px } </style> |
| 8 </head> |
| 9 <body> |
| 10 <div id=log></div> |
| 11 <iframe id=quirks></iframe> |
| 12 <iframe id=almost></iframe> |
| 13 <iframe id=standards></iframe> |
| 14 <img id="preload"> |
| 15 <script> |
| 16 var png = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcS
JAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg=="; |
| 17 // Ensure png is loaded and cached before we run the tests. Otherwise |
| 18 // the tests that use it may run while it's not fully loaded and get <img> |
| 19 // fallback layout (i.e., not an image with a 1x1 intrinsic size). |
| 20 document.getElementById('preload').src = png; |
| 21 setup({explicit_done:true}); |
| 22 |
| 23 var png = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcS
JAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg=="; |
| 24 var preload = new Image(); |
| 25 preload.src = png; |
| 26 |
| 27 onload = function() { |
| 28 var html = "<style id=style></style>"; |
| 29 var a_doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transition
al//EN" "http://www.w3.org/TR/html4/loose.dtd">'; |
| 30 var s_doctype = '<!DOCTYPE HTML>'; |
| 31 var q = document.getElementById('quirks').contentWindow; |
| 32 var a = document.getElementById('almost').contentWindow; |
| 33 var s = document.getElementById('standards').contentWindow; |
| 34 q.document.open(); |
| 35 q.document.write(html); |
| 36 q.document.close(); |
| 37 a.document.open(); |
| 38 a.document.write(a_doctype + html); |
| 39 a.document.close(); |
| 40 s.document.open(); |
| 41 s.document.write(s_doctype + html); |
| 42 s.document.close(); |
| 43 [q, a, s].forEach(function(win) { |
| 44 ['style', 'test'].forEach(function(id) { |
| 45 win.__proto__.__defineGetter__(id, function() { return win.docum
ent.getElementById(id); }); |
| 46 }); |
| 47 }); |
| 48 |
| 49 var tests = [ |
| 50 {style:'#test { height:100% }', body:'<div id=test></div>', q:184, s:0}, |
| 51 {style:'#test { height:50% }', body:'<div id=test></div>', q:92, s:0}, |
| 52 {style:'#test { height:25% }', body:'<div id=test></div>', q:46, s:0}, |
| 53 {style:'#test { height:12.5% }', body:'<div id=test></div>', q:23, s:0}, |
| 54 {style:'#test { height:100% }', body:'<div><div id=test></div></div>', q
:184, s:0}, |
| 55 {style:'', body:'<img id=test src="{png}" height=100%>', q:184, s:1}, |
| 56 {style:'', body:'<img id=test src="{png}" height=100% border=10>', q:184
, s:1}, |
| 57 {style:'', body:'<table id=test height=100%><tr><td></table>', q:184, s:
6}, |
| 58 {style:'#foo { height:100px } #test { height:100% }', body:'<div id=foo>
<div><div id=test></div></div></div>', q:100, s:0}, |
| 59 {style:'#foo { position:absolute } #test { height:100% }', body:'<div id
=foo><div><div id=test></div></div></div>', q:0, s:0}, |
| 60 {style:'#foo { position:relative } #test { height:100% }', body:'<div id
=foo><div><div id=test></div></div></div>', q:184, s:0}, |
| 61 {style:'#foo { height:100px } #test { height:100%; position:absolute }',
body:'<div id=foo><div><div id=test></div></div></div>', q:200, s:200}, |
| 62 {style:'#foo { height:100px } #test { height:100%; position:fixed }', bo
dy:'<div id=foo><div><div id=test></div></div></div>', q:200, s:200}, |
| 63 {style:'#foo { height:100px } #test { height:100%; position:relative }',
body:'<div id=foo><div><div id=test></div></div></div>', q:100, s:0}, |
| 64 {style:'#foo { height:100px } #test { height:calc(100% + 1px) }', body:'
<div id=foo><div id=test></div></div>', q:101, s:101}, |
| 65 {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}, |
| 66 {style:'html { display:inline } #test { height:100% }', body:'<div id=te
st></div>', q:184, s:0}, // display:inline on root has no effect |
| 67 {style:'html { margin:10px } body { display:inline } #test { height:100%
}', body:'<div id=test></div>', q:200, s:0}, |
| 68 {style:'body { margin:0 } #test { height:100% }', body:'<div id=test></d
iv>', q:200, s:0}, |
| 69 {style:'body { margin:0; padding:10px } #test { height:100% }', body:'<d
iv id=test></div>', q:180, s:0}, |
| 70 {style:'body { margin:0; border:10px solid } #test { height:100% }', bod
y:'<div id=test></div>', q:180, s:0}, |
| 71 {style:'html { margin:10px } #test { height:100% }', body:'<div id=test>
</div>', q:164, s:0}, |
| 72 {style:'html { padding:10px } #test { height:100% }', body:'<div id=test
></div>', q:164, s:0}, |
| 73 {style:'html { border:10px solid } #test { height:100% }', body:'<div id
=test></div>', q:164, s:0}, |
| 74 {style:'html { position:absolute } #test { height:100% }', body:'<div id
=test></div>', q:0, s:0}, |
| 75 {style:'body { position:absolute } #test { height:100% }', body:'<div id
=test></div>', q:0, s:0}, |
| 76 {style:'html { height:100%; margin:10px } #test { height:100% }', body:'
<div id=test></div>', q:184, s:0}, |
| 77 {style:'html { height:100%; padding:10px } #test { height:100% }', body:
'<div id=test></div>', q:184, s:0}, |
| 78 {style:'html { height:100%; border:10px solid } #test { height:100% }',
body:'<div id=test></div>', q:184, s:0}, |
| 79 {style:'body { height:100%; margin:10px } #test { height:100% }', body:'
<div id=test></div>', q:200, s:0}, |
| 80 {style:'body { height:100%; padding:10px } #test { height:100% }', body:
'<div id=test></div>', q:200, s:0}, |
| 81 {style:'body { height:100%; border:10px solid } #test { height:100% }',
body:'<div id=test></div>', q:200, s:0}, |
| 82 {style:'html { position:absolute; height:100%; margin:10px } #test { hei
ght:100% }', body:'<div id=test></div>', q:184, s:0}, |
| 83 {style:'html { position:absolute; height:100%; padding:10px } #test { he
ight:100% }', body:'<div id=test></div>', q:184, s:0}, |
| 84 {style:'html { position:absolute; height:100%; border:10px solid } #test
{ height:100% }', body:'<div id=test></div>', q:184, s:0}, |
| 85 {style:'body { margin:99px 0 } #test { height:100% }', body:'<div id=tes
t></div>', q:2, s:0}, |
| 86 {style:'body { margin:110px 0 } #test { height:100% }', body:'<div id=te
st></div>', q:0, s:0}, |
| 87 {style:'html, body { border:10px none } #test { height:100% }', body:'<d
iv id=test></div>', q:184, s:0}, |
| 88 {style:'html, body { border:10px hidden } #test { height:100% }', body:'
<div id=test></div>', q:184, s:0}, |
| 89 ]; |
| 90 |
| 91 tests.forEach(function(t) { |
| 92 test(function() { |
| 93 // Hide scrollbars in all subdocuments so that a horizontal |
| 94 // scrollbar doesn't appear and upset our calculations. |
| 95 var style = t.style.replace(/\{png\}/g, png) + " html { overflow
:hidden; }"; |
| 96 var body = t.body.replace(/\{png\}/g, png); |
| 97 q.style.textContent = style; |
| 98 a.style.textContent = style; |
| 99 s.style.textContent = style; |
| 100 q.document.body.innerHTML = body; |
| 101 a.document.body.innerHTML = body; |
| 102 s.document.body.innerHTML = body; |
| 103 |
| 104 assert_equals(q.getComputedStyle(q.test).height, |
| 105 t.q + 'px', |
| 106 'quirks mode'); |
| 107 assert_equals(a.getComputedStyle(a.test).height, |
| 108 t.s + 'px', |
| 109 'almost standards mode'); |
| 110 assert_equals(s.getComputedStyle(s.test).height, |
| 111 t.s + 'px', |
| 112 'standards mode'); |
| 113 }, document.title+', '+t.style+t.body); |
| 114 }); |
| 115 |
| 116 var xml_tests = [ |
| 117 {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style><
/head><body><div id="test"/></body></html>', q:184, s:0}, |
| 118 {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style><
/head><body/><div id="test"/></html>', q:200, s:0}, |
| 119 {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style><
/head><span><body><div id="test"/></body></span></html>', q:200, s:0}, |
| 120 {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style><
/head><body><body><div id="test"/></body></body></html>', q:200, s:0}, |
| 121 {input:'<html><head xmlns="{html}"><style>#test { height:100% }</style><
/head><body xmlns="{html}"><div id="test"/></body></html>', q:200, s:0}, |
| 122 {input:'<div xmlns="{html}"><head><style>#test { height:100% }</style></
head><body><div id="test"/></body></div>', q:200, s:0}, |
| 123 {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style><
/head><body xmlns=""><div xmlns="{html}" id="test"/></body></html>', q:200, s:0}
, |
| 124 {input:'<HTML xmlns="{html}"><head><style>#test { height:100% }</style><
/head><body><div id="test"/></body></HTML>', q:200, s:0}, |
| 125 {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style><
/head><BODY><div id="test"/></BODY></html>', q:200, s:0}, |
| 126 ]; |
| 127 |
| 128 var parser = new DOMParser(); |
| 129 |
| 130 xml_tests.forEach(function(t) { |
| 131 test(function() { |
| 132 var input = t.input.replace(/\{html\}/g, 'http://www.w3.org/1999
/xhtml') |
| 133 .replace(/\{png\}/g, png); |
| 134 var root = parser.parseFromString(input, 'text/xml').documentEle
ment; |
| 135 q.document.replaceChild(root.cloneNode(true), q.document.documen
tElement); |
| 136 a.document.replaceChild(root.cloneNode(true), a.document.documen
tElement); |
| 137 s.document.replaceChild(root, s.document.documentElement); |
| 138 assert_equals(q.getComputedStyle(q.test).height, |
| 139 t.q + 'px', |
| 140 'quirks mode'); |
| 141 assert_equals(a.getComputedStyle(a.test).height, |
| 142 t.s + 'px', |
| 143 'almost standards mode'); |
| 144 assert_equals(s.getComputedStyle(s.test).height, |
| 145 t.s + 'px', |
| 146 'standards mode'); |
| 147 }, document.title+', '+t.input); |
| 148 }); |
| 149 |
| 150 done(); |
| 151 } |
| 152 </script> |
| 153 </body> |
| 154 </html> |
OLD | NEW |