test_window_open_position_constraint.html 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Test for Bug 978847</title>
  5. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  6. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  7. </head>
  8. <body>
  9. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=978847">Mozilla Bug 978847</a>
  10. <p id="display"></p>
  11. </div>
  12. <pre id="test">
  13. <script class="testbody" type="text/javascript">
  14. SimpleTest.waitForExplicitFinish();
  15. SimpleTest.waitForFocus(function() {
  16. var x;
  17. var y;
  18. // window should be constrained to the screen rect,
  19. // which we assume is less than 10000px square
  20. var w1 = window.open("about:blank", "", "left=16000,top=16000,width=100,height=100");
  21. SimpleTest.waitForFocus(function() {
  22. ok(w1.screenX < 10000 && w1.screenY < 10000,
  23. "window should not be opened off-screen: got location " +
  24. w1.screenX + "," + w1.screenY);
  25. x = w1.screenX;
  26. y = w1.screenY;
  27. w1.close();
  28. // larger window dimensions should result in a shift of the constrained location
  29. var w2 = window.open("about:blank", "", "left=16000,top=16000,width=150,height=150");
  30. SimpleTest.waitForFocus(function() {
  31. ok(w2.screenX == x - 50 && w2.screenY == y - 50,
  32. "constrained window position did not depend on size as expected: got " +
  33. w2.screenX + "," + w2.screenY + ", expected " + (x - 50) + "," + (y - 50));
  34. w2.close();
  35. // now try with coordinates that are close to MAXINT,
  36. // so adding width/height risks 32-bit integer overflow
  37. var w3 = window.open("about:blank", "", "left=2147483600,top=2147483600,width=100,height=100");
  38. SimpleTest.waitForFocus(function() {
  39. ok(w3.screenX < 10000 && w3.screenY < 10000,
  40. "window should not be opened off-screen: got location " +
  41. w3.screenX + "," + w3.screenY);
  42. w3.close();
  43. SimpleTest.finish();
  44. }, w3, true);
  45. }, w2, true);
  46. }, w1, true);
  47. }, window, false);
  48. </script>
  49. </pre>
  50. </body>
  51. </html>