dom/tests/mochitest/bugs/test_sizetocontent_clamp.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/bugs/test_sizetocontent_clamp.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,75 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=764240
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for Bug 764240</title>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.14 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.15 +</head>
    1.16 +<body>
    1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=764240">Mozilla Bug 764240</a>
    1.18 +<p id="display"></p>
    1.19 +<div id="content">
    1.20 +  <button onclick="test();">run test</button>
    1.21 +</div>
    1.22 +<pre id="test">
    1.23 +<script type="application/javascript">
    1.24 +
    1.25 +/** Test for Bug 764240 **/
    1.26 +
    1.27 +SimpleTest.waitForExplicitFinish();
    1.28 +
    1.29 +// Error margin allowed for the window's size. Windows has varying minimum
    1.30 +// sizes depending on the os due to outer window chrome. Unix is given 5
    1.31 +// pixels to protect against minor variances.
    1.32 +var epsilon =  navigator.platform.indexOf("Win") == -1 ? 5 : 20;
    1.33 +
    1.34 +// Windows 8 has a minimum 122 pixel inner window width due to
    1.35 +// outer window chrome.
    1.36 +var isWin8 = (navigator.userAgent.indexOf("Windows NT 6.2") != -1);
    1.37 +
    1.38 +var innerWidthMin = (isWin8 ? 120 : 100);
    1.39 +var innerWidthMax = (isWin8 ? 125 : 100);
    1.40 +
    1.41 +function test() {
    1.42 +  var w = window.open('data:text/html,null', null, 'width=300,height=300');
    1.43 +  var nbResize = 0;
    1.44 +
    1.45 +  SimpleTest.waitForFocus(function() {
    1.46 +    w.onresize = function() {
    1.47 +      nbResize++;
    1.48 +
    1.49 +      if (nbResize == 1) {
    1.50 +        return;
    1.51 +      }
    1.52 +
    1.53 +      ok(w.innerWidth + epsilon >= innerWidthMin && w.innerWidth - epsilon <= innerWidthMax,
    1.54 +         "innerWidth should be between " + innerWidthMin + " and " + innerWidthMax);
    1.55 +      ok(w.innerHeight + epsilon >= 100 && w.innerHeight - epsilon <= 100,
    1.56 +         "innerHeight should be around 100");
    1.57 +
    1.58 +      // It's not clear why 2 events are coming...
    1.59 +      is(nbResize, 2, "We should get 2 events.");
    1.60 +
    1.61 +      w.close();
    1.62 +
    1.63 +      SimpleTest.waitForFocus(function() {
    1.64 +        SimpleTest.finish();
    1.65 +      });
    1.66 +    };
    1.67 +    w.sizeToContent();
    1.68 +  }, w);
    1.69 +}
    1.70 +
    1.71 +SimpleTest.waitForFocus(function() {
    1.72 +  synthesizeMouseAtCenter(document.getElementsByTagName('button')[0], {});
    1.73 +});
    1.74 +
    1.75 +</script>
    1.76 +</pre>
    1.77 +</body>
    1.78 +</html>

mercurial