test_bug332246.html 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <html>
  2. <!--
  3. https://bugzilla.mozilla.org/show_bug.cgi?id=332246
  4. -->
  5. <head>
  6. <title>Test for Bug 332246 - scrollIntoView(false) doesn't work correctly for inline elements that wrap at multiple lines</title>
  7. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  8. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  9. </head>
  10. <body>
  11. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=332246">Mozilla Bug 332246</a>
  12. <p id="display"></p>
  13. <div id="content">
  14. <div id="a1" style="height: 100px; width: 100px; overflow: hidden; outline:1px dotted black;">
  15. <div style="height: 100px"></div>
  16. <a id="a2" href="#" style="display:block; background:yellow; height:200px;">Top</a>
  17. <div style="height: 100px"></div>
  18. </div>
  19. <div id="b1" style="height: 100px; width: 100px; overflow: hidden; outline:1px dotted black;">
  20. <div style="height: 100px"></div>
  21. <div id="b2" href="#" style="border:10px solid black; background:yellow; height:200px;"></div>
  22. <div style="height: 100px"></div>
  23. </div>
  24. <br>
  25. <div id="c1" style="height: 100px; width: 100px; overflow: hidden; position: relative; outline:1px dotted black;">
  26. <div id="c2" style="border: 10px solid black; height: 200px; width: 50px; position: absolute; top: 100px;"></div>
  27. <div style="height: 100px"></div>
  28. </div>
  29. </div>
  30. <pre id="test">
  31. <script class="testbody" type="text/javascript">
  32. /** Test for Bug 332246 **/
  33. function isWithFuzz(itIs, itShouldBe, fuzz, description) {
  34. ok(Math.abs(itIs - itShouldBe) <= fuzz, `${description} - expected a value between ${itShouldBe - fuzz} and ${itShouldBe + fuzz}, got ${itIs}`);
  35. }
  36. var a1 = document.getElementById('a1');
  37. var a2 = document.getElementById('a2');
  38. isWithFuzz(a1.scrollHeight, 400, 1, "Wrong a1.scrollHeight");
  39. is(a1.offsetHeight, 100, "Wrong a1.offsetHeight");
  40. a2.scrollIntoView(true);
  41. is(a1.scrollTop, 100, "Wrong scrollTop value after a2.scrollIntoView(true)");
  42. a2.scrollIntoView(false);
  43. is(a1.scrollTop, 200, "Wrong scrollTop value after a2.scrollIntoView(false)");
  44. var b1 = document.getElementById('b1');
  45. var b2 = document.getElementById('b2');
  46. isWithFuzz(b1.scrollHeight, 420, 1, "Wrong b1.scrollHeight");
  47. is(b1.offsetHeight, 100, "Wrong b1.offsetHeight");
  48. b2.scrollIntoView(true);
  49. is(b1.scrollTop, 100, "Wrong scrollTop value after b2.scrollIntoView(true)");
  50. b2.scrollIntoView(false);
  51. is(b1.scrollTop, 220, "Wrong scrollTop value after b2.scrollIntoView(false)");
  52. var c1 = document.getElementById('c1');
  53. var c2 = document.getElementById('c2');
  54. isWithFuzz(c1.scrollHeight, 320, 1, "Wrong c1.scrollHeight");
  55. is(c1.offsetHeight, 100, "Wrong c1.offsetHeight");
  56. c2.scrollIntoView(true);
  57. is(c1.scrollTop, 100, "Wrong scrollTop value after c2.scrollIntoView(true)");
  58. c2.scrollIntoView(false);
  59. isWithFuzz(c1.scrollTop, 220, 1, "Wrong scrollTop value after c2.scrollIntoView(false)");
  60. </script>
  61. </pre>
  62. </body>
  63. </html>