test_bug369370.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=369370
  5. -->
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  8. <title>Test for Bug 369370</title>
  9. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  10. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  11. </head>
  12. <body>
  13. <script type="text/javascript">
  14. /*
  15. * Test strategy:
  16. */
  17. function makeClickFor(x, y) {
  18. var event = kidDoc.createEvent("mouseevent");
  19. event.initMouseEvent("click",
  20. true, true, kidWin, 1, // bubbles, cancelable, view, single-click
  21. x, y, x, y, // screen X/Y, client X/Y
  22. false, false, false, false, // no key modifiers
  23. 0, null); // left click, not relatedTarget
  24. return event;
  25. }
  26. function childLoaded() {
  27. kidDoc = kidWin.document;
  28. ok(true, "Child window loaded");
  29. var elements = kidDoc.getElementsByTagName("img");
  30. is(elements.length, 1, "looking for imagedoc img");
  31. var img = elements[0];
  32. // Need to use innerWidth/innerHeight of the window
  33. // since the containing image is absolutely positioned,
  34. // causing clientHeight to be zero.
  35. is(kidWin.innerWidth, 400, "Checking doc width");
  36. is(kidWin.innerHeight, 300, "Checking doc height");
  37. // Image just loaded and is scaled to window size.
  38. is(img.width, 400, "image width");
  39. is(img.height, 300, "image height");
  40. is(kidDoc.body.scrollLeft, 0, "Checking scrollLeft");
  41. is(kidDoc.body.scrollTop, 0, "Checking scrollTop");
  42. // ========== test 1 ==========
  43. // Click in the upper left to zoom in
  44. var event = makeClickFor(25,25);
  45. img.dispatchEvent(event);
  46. ok(true, "----- click 1 -----");
  47. is(img.width, 800, "image width");
  48. is(img.height, 600, "image height");
  49. is(kidDoc.body.scrollLeft, 0, "Checking scrollLeft");
  50. is(kidDoc.body.scrollTop, 0, "Checking scrollTop");
  51. // ========== test 2 ==========
  52. // Click there again to zoom out
  53. event = makeClickFor(25,25);
  54. img.dispatchEvent(event);
  55. ok(true, "----- click 2 -----");
  56. is(img.width, 400, "image width");
  57. is(img.height, 300, "image height");
  58. is(kidDoc.body.scrollLeft, 0, "Checking scrollLeft");
  59. is(kidDoc.body.scrollTop, 0, "Checking scrollTop");
  60. // ========== test 3 ==========
  61. // Click in the lower right to zoom in
  62. event = makeClickFor(350, 250);
  63. img.dispatchEvent(event);
  64. ok(true, "----- click 3 -----");
  65. is(img.width, 800, "image width");
  66. is(img.height, 600, "image height");
  67. is(kidDoc.body.scrollLeft, 400, "Checking scrollLeft");
  68. is(kidDoc.body.scrollTop, 300, "Checking scrollTop");
  69. // ========== test 4 ==========
  70. // Click there again to zoom out
  71. event = makeClickFor(350, 250);
  72. img.dispatchEvent(event);
  73. ok(true, "----- click 4 -----");
  74. is(img.width, 400, "image width");
  75. is(img.height, 300, "image height");
  76. is(kidDoc.body.scrollLeft, 0, "Checking scrollLeft");
  77. is(kidDoc.body.scrollTop, 0, "Checking scrollTop");
  78. // ========== test 5 ==========
  79. // Click in the upper left to zoom in again
  80. event = makeClickFor(25, 25);
  81. img.dispatchEvent(event);
  82. ok(true, "----- click 5 -----");
  83. is(img.width, 800, "image width");
  84. is(img.height, 600, "image height");
  85. is(kidDoc.body.scrollLeft, 0, "Checking scrollLeft");
  86. is(kidDoc.body.scrollTop, 0, "Checking scrollTop");
  87. is(img.getBoundingClientRect().top, 0, "Image is in view vertically");
  88. // ========== test 6 ==========
  89. // Now try resizing the window so the image fits vertically.
  90. function test6() {
  91. kidWin.addEventListener("resize", function resizeListener() {
  92. kidWin.removeEventListener("resize", resizeListener);
  93. // Give the image document time to respond
  94. SimpleTest.executeSoon(function() {
  95. is(img.height, 600, "image height");
  96. is(img.getBoundingClientRect().top, 25, "Image is vertically centered");
  97. test7();
  98. });
  99. });
  100. var decorationSize = kidWin.outerHeight - kidWin.innerHeight;
  101. kidWin.resizeTo(400, 600 + 50 + decorationSize);
  102. }
  103. // ========== test 7 ==========
  104. // Now try resizing the window so the image no longer fits vertically.
  105. function test7() {
  106. kidWin.addEventListener("resize", function resizeListener() {
  107. kidWin.removeEventListener("resize", resizeListener);
  108. // Give the image document time to respond
  109. SimpleTest.executeSoon(function() {
  110. is(img.height, 600, "image height");
  111. is(img.getBoundingClientRect().top, 0, "Image is at top again");
  112. kidWin.close();
  113. SimpleTest.finish();
  114. });
  115. });
  116. var decorationSize = kidWin.outerHeight - kidWin.innerHeight;
  117. kidWin.resizeTo(400, 300 + decorationSize);
  118. }
  119. test6();
  120. }
  121. var kidWin;
  122. var kidDoc;
  123. SimpleTest.waitForExplicitFinish();
  124. SpecialPowers.pushPrefEnv({"set":[["browser.enable_automatic_image_resizing", true]]}, function() {
  125. kidWin = window.open("bug369370-popup.png", "bug369370", "width=400,height=300,scrollbars=no");
  126. // will init onload
  127. ok(kidWin, "opened child window");
  128. kidWin.onload = childLoaded;
  129. });
  130. </script>
  131. </body>
  132. </html>