test_bug1132427.html 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Test for scrolling selection into view</title>
  5. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  6. <script type="text/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
  7. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  8. </head>
  9. <body>
  10. <pre id="test">
  11. <script class="testbody" type="text/javascript">
  12. // We open a window which contains two copies of the same gif. One at a scaled size, one at the
  13. // natural image size. We rely on the bug only showing up in the scaled image. The gif has three
  14. // frames and a delay of 100ms. The first is all white. The second has a very small update area
  15. // in the upper left, it changes the pixels to slightly off white. The third changes all the
  16. // pixels to blue. When the bug appears we only update the upper left pixels when looping around
  17. // from the last frame to the first frame. We compare a middle pixel of the two images to make
  18. // sure that they are the same at 100ms for a second. If the bug appears then the middle pixel
  19. // on the scaled image will always be blue and so should not match the middle pixel on the
  20. // unscaled image which should be white two thirds of the time. If the timers fire at bad times
  21. // and only fire when both frames are displaying blue we won't be able to detect this bug and the
  22. // test will pass without testing anything important, but that's not a big deal. That should be
  23. // rare enough, and the next time the test is run will should do proper testing.
  24. SimpleTest.requestFlakyTimeout("Pre-existing timeouts when converting from mochitest-chrome");
  25. SimpleTest.waitForExplicitFinish();
  26. addLoadEvent(openWindow);
  27. var win = null;
  28. function openWindow() {
  29. win = window.open("bug1132427.html",
  30. "", "scrollbars=yes,toolbar,menubar,width=600,height=800");
  31. win.focus();
  32. }
  33. function doTest() {
  34. setTimeout(continueTest, 1000);
  35. }
  36. function checkPixel(canvas, context, x1, y1, x2, y2) {
  37. var pix = context.getImageData(0, 0, canvas.width, canvas.height).data;
  38. for (var i = 0; i < 4; i++) {
  39. is(pix[4 * (y1 * canvas.width + x1) + i], pix[4 * (y2 * canvas.width + x2) + i], "pixels should match");
  40. }
  41. }
  42. var iterationsLeft = 10;
  43. function continueTest() {
  44. // we need to drawWindow the chrome window so we can get a dump of the retained widget layers
  45. // if we have to repaint to fulfill this drawWindow request then it will be impossible to
  46. // observe the bug
  47. var chromewin = SpecialPowers.wrap(win).QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
  48. .getInterface(SpecialPowers.Ci.nsIWebNavigation)
  49. .QueryInterface(SpecialPowers.Ci.nsIDocShellTreeItem)
  50. .rootTreeItem
  51. .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
  52. .getInterface(SpecialPowers.Ci.nsIDOMWindow);
  53. var el = window.document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
  54. el.width = chromewin.innerWidth;
  55. el.height = chromewin.innerHeight;
  56. var ctx = el.getContext("2d");
  57. // pass the correct flags so we don't have to flush the retained layers
  58. SpecialPowers.wrap(ctx).drawWindow(chromewin, 0, 0, chromewin.innerWidth, chromewin.innerHeight, "rgba(0,0,0,0)",
  59. ctx.DRAWWINDOW_USE_WIDGET_LAYERS | ctx.DRAWWINDOW_DRAW_VIEW | ctx.DRAWWINDOW_DRAW_CARET);
  60. var leftbox = win.document.getElementById("left").getBoundingClientRect();
  61. var rightbox = win.document.getElementById("right").getBoundingClientRect();
  62. // this is actually chrome on left and right, but in practice we have none so it doesn't matter
  63. var chromeleft = win.outerWidth - win.innerWidth;
  64. // this is actually chrome on top and bottom, but bottom chrome is usually small to none and we have
  65. // 100px to spare in hitting the middle of the image elements (they are 200x200)
  66. var chrometop = win.outerHeight - win.innerHeight;
  67. // compare the middle of the two image elements
  68. checkPixel(el, ctx, chromeleft + leftbox.left + Math.floor(leftbox.width/2), chrometop + leftbox.top + Math.floor(leftbox.height/2),
  69. chromeleft + rightbox.left + Math.floor(rightbox.width/2), chrometop + rightbox.top + Math.floor(rightbox.height/2));
  70. iterationsLeft--;
  71. if (iterationsLeft > 0) {
  72. // now test 100ms later, we should have the next frame of the gif then
  73. setTimeout(continueTest, 100);
  74. } else {
  75. win.close();
  76. SimpleTest.finish();
  77. }
  78. }
  79. </script>
  80. </pre>
  81. </body>
  82. </html>