PageRenderTime 54ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/quirks-mode/percentage-height-calculation.html

https://github.com/asankah/web-platform-tests
HTML | 142 lines | 135 code | 7 blank | 0 comment | 0 complexity | 3e0321c1c6f203d4eec31c02494a12ff MD5 | raw file
Possible License(s): BSD-3-Clause
  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. <script>
  15. setup({explicit_done:true});
  16. var html = "<style id=style></style>";
  17. var png = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==";
  18. var a_doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
  19. var s_doctype = '<!DOCTYPE HTML>';
  20. var q = document.getElementById('quirks').contentWindow;
  21. var a = document.getElementById('almost').contentWindow;
  22. var s = document.getElementById('standards').contentWindow;
  23. q.document.open();
  24. q.document.write(html);
  25. q.document.close();
  26. a.document.open();
  27. a.document.write(a_doctype + html);
  28. a.document.close();
  29. s.document.open();
  30. s.document.write(s_doctype + html);
  31. s.document.close();
  32. onload = function() {
  33. [q, a, s].forEach(function(win) {
  34. ['style', 'test'].forEach(function(id) {
  35. win.__proto__.__defineGetter__(id, function() { return win.document.getElementById(id); });
  36. });
  37. });
  38. var tests = [
  39. {style:'#test { height:100% }', body:'<div id=test></div>', q:184, s:0},
  40. {style:'#test { height:50% }', body:'<div id=test></div>', q:92, s:0},
  41. {style:'#test { height:25% }', body:'<div id=test></div>', q:46, s:0},
  42. {style:'#test { height:12.5% }', body:'<div id=test></div>', q:23, s:0},
  43. {style:'#test { height:100% }', body:'<div><div id=test></div></div>', q:184, s:0},
  44. {style:'', body:'<img id=test src="{png}" height=100%>', q:184, s:1},
  45. {style:'', body:'<img id=test src="{png}" height=100% border=10>', q:184, s:1},
  46. {style:'', body:'<table id=test height=100%><tr><td></table>', q:184, s:6},
  47. {style:'#foo { height:100px } #test { height:100% }', body:'<div id=foo><div><div id=test></div></div></div>', q:100, s:0},
  48. {style:'#foo { position:absolute } #test { height:100% }', body:'<div id=foo><div><div id=test></div></div></div>', q:0, s:0},
  49. {style:'#foo { position:relative } #test { height:100% }', body:'<div id=foo><div><div id=test></div></div></div>', q:184, s:0},
  50. {style:'#foo { height:100px } #test { height:100%; position:absolute }', body:'<div id=foo><div><div id=test></div></div></div>', q:200, s:200},
  51. {style:'#foo { height:100px } #test { height:100%; position:fixed }', body:'<div id=foo><div><div id=test></div></div></div>', q:200, s:200},
  52. {style:'#foo { height:100px } #test { height:100%; position:relative }', body:'<div id=foo><div><div id=test></div></div></div>', q:100, s:0},
  53. {style:'#foo { height:100px } #test { height:calc(100% + 1px) }', body:'<div id=foo><div id=test></div></div>', q:101, s:101},
  54. {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},
  55. {style:'html { display:inline } #test { height:100% }', body:'<div id=test></div>', q:184, s:0}, // display:inline on root has no effect
  56. {style:'html { margin:10px } body { display:inline } #test { height:100% }', body:'<div id=test></div>', q:200, s:0},
  57. {style:'body { margin:0 } #test { height:100% }', body:'<div id=test></div>', q:200, s:0},
  58. {style:'body { margin:0; padding:10px } #test { height:100% }', body:'<div id=test></div>', q:180, s:0},
  59. {style:'body { margin:0; border:10px solid } #test { height:100% }', body:'<div id=test></div>', q:180, s:0},
  60. {style:'html { margin:10px } #test { height:100% }', body:'<div id=test></div>', q:164, s:0},
  61. {style:'html { padding:10px } #test { height:100% }', body:'<div id=test></div>', q:164, s:0},
  62. {style:'html { border:10px solid } #test { height:100% }', body:'<div id=test></div>', q:164, s:0},
  63. {style:'html { position:absolute } #test { height:100% }', body:'<div id=test></div>', q:0, s:0},
  64. {style:'body { position:absolute } #test { height:100% }', body:'<div id=test></div>', q:0, s:0},
  65. {style:'html { height:100%; margin:10px } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
  66. {style:'html { height:100%; padding:10px } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
  67. {style:'html { height:100%; border:10px solid } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
  68. {style:'body { height:100%; margin:10px } #test { height:100% }', body:'<div id=test></div>', q:200, s:0},
  69. {style:'body { height:100%; padding:10px } #test { height:100% }', body:'<div id=test></div>', q:200, s:0},
  70. {style:'body { height:100%; border:10px solid } #test { height:100% }', body:'<div id=test></div>', q:200, s:0},
  71. {style:'html { position:absolute; height:100%; margin:10px } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
  72. {style:'html { position:absolute; height:100%; padding:10px } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
  73. {style:'html { position:absolute; height:100%; border:10px solid } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
  74. {style:'body { margin:99px 0 } #test { height:100% }', body:'<div id=test></div>', q:2, s:0},
  75. {style:'body { margin:110px 0 } #test { height:100% }', body:'<div id=test></div>', q:0, s:0},
  76. {style:'html, body { border:10px none } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
  77. {style:'html, body { border:10px hidden } #test { height:100% }', body:'<div id=test></div>', q:184, s:0},
  78. ];
  79. tests.forEach(function(t) {
  80. test(function() {
  81. var style = t.style.replace(/\{png\}/g, png);
  82. var body = t.body.replace(/\{png\}/g, png);
  83. q.style.textContent = style;
  84. a.style.textContent = style;
  85. s.style.textContent = style;
  86. q.document.body.innerHTML = body;
  87. a.document.body.innerHTML = body;
  88. s.document.body.innerHTML = body;
  89. assert_equals(q.getComputedStyle(q.test).height,
  90. t.q + 'px',
  91. 'quirks mode');
  92. assert_equals(a.getComputedStyle(a.test).height,
  93. t.s + 'px',
  94. 'almost standards mode');
  95. assert_equals(s.getComputedStyle(s.test).height,
  96. t.s + 'px',
  97. 'standards mode');
  98. }, document.title+', '+t.style+t.body);
  99. });
  100. var xml_tests = [
  101. {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><body><div id="test"/></body></html>', q:184, s:0},
  102. {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><body/><div id="test"/></html>', q:200, s:0},
  103. {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><span><body><div id="test"/></body></span></html>', q:200, s:0},
  104. {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><body><body><div id="test"/></body></body></html>', q:200, s:0},
  105. {input:'<html><head xmlns="{html}"><style>#test { height:100% }</style></head><body xmlns="{html}"><div id="test"/></body></html>', q:200, s:0},
  106. {input:'<div xmlns="{html}"><head><style>#test { height:100% }</style></head><body><div id="test"/></body></div>', q:200, s:0},
  107. {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><body xmlns=""><div xmlns="{html}" id="test"/></body></html>', q:200, s:0},
  108. {input:'<HTML xmlns="{html}"><head><style>#test { height:100% }</style></head><body><div id="test"/></body></HTML>', q:200, s:0},
  109. {input:'<html xmlns="{html}"><head><style>#test { height:100% }</style></head><BODY><div id="test"/></BODY></html>', q:200, s:0},
  110. ];
  111. var parser = new DOMParser();
  112. xml_tests.forEach(function(t) {
  113. test(function() {
  114. var input = t.input.replace(/\{html\}/g, 'http://www.w3.org/1999/xhtml')
  115. .replace(/\{png\}/g, png);
  116. var root = parser.parseFromString(input, 'text/xml').documentElement;
  117. q.document.replaceChild(root.cloneNode(true), q.document.documentElement);
  118. a.document.replaceChild(root.cloneNode(true), a.document.documentElement);
  119. s.document.replaceChild(root, s.document.documentElement);
  120. assert_equals(q.getComputedStyle(q.test).height,
  121. t.q + 'px',
  122. 'quirks mode');
  123. assert_equals(a.getComputedStyle(a.test).height,
  124. t.s + 'px',
  125. 'almost standards mode');
  126. assert_equals(s.getComputedStyle(s.test).height,
  127. t.s + 'px',
  128. 'standards mode');
  129. }, document.title+', '+t.input);
  130. });
  131. done();
  132. }
  133. </script>
  134. </body>
  135. </html>