layout/forms/test/test_textarea_resize.html
author Malini Das <mdas@mozilla.com>
Fri, 12 Aug 2011 12:21:44 -0400
changeset 74315 1188456710819d4606e74396be333ead9fe63261
parent 47226 c1bb84d2470d84f19a9dbf39aff505d1107dfe5f
child 100780 377f1998ca05ff2fa91381b8791a38e58462f0da
permissions -rw-r--r--
Bug 367393 - Add a packed MochiKit that contains only SimpleTest dependencies- plain tests 2/2. r=jmaher, a=test-only

<!DOCTYPE HTML>
<html>
<head>
  <title>Test for Bug 477700</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<div id="content" style="display: none">
</div>

<textarea id="textarea" style="-moz-appearance: none; border: 2px solid black; padding: 3px; -moz-box-sizing: border-box;">Text</textarea>

<pre id="test">
<script type="application/javascript">

/** Test for textbox resizing **/
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() SimpleTest.executeSoon(doTheTest));

// First, test the default value which is 'both', then test explicitly
// setting each possible value.
var currentResize = "both";
var currentBoxSizing = 0;
var resizeTypes = [ "horizontal", "vertical", "none", "inherit", "both" ];
var boxSizingTypes = [ "", "border-box", "padding-box" ];

function doTheTest() {
  var boxSizingText = " with box sizing " + (currentBoxSizing ? boxSizingTypes[currentBoxSizing] : "content-box");

  var textarea = $("textarea");
  var rect = textarea.getBoundingClientRect();
  // assume that the resizer is in the lower right corner

  synthesizeMouse(textarea, rect.width - 10, rect.height - 10, { type:"mousedown" });
  synthesizeMouse(textarea, rect.width + 40, rect.height + 40, { type:"mousemove" });

  var newrect = textarea.getBoundingClientRect();
  var hchange = (currentResize == "both" || currentResize == "horizontal");
  var vchange = (currentResize == "both" || currentResize == "vertical");

  is(Math.round(newrect.width), Math.round(rect.width + (hchange ? 50 : 0)),
     currentResize + " width has increased" + boxSizingText);
  is(Math.round(newrect.height), Math.round(rect.height + (vchange ? 50 : 0)),
     currentResize + " height has increased" + boxSizingText);

  synthesizeMouse(textarea, rect.width - 20, rect.height - 20, { type:"mousemove" });

  newrect = textarea.getBoundingClientRect();

  is(Math.round(newrect.width), Math.round(rect.width - (hchange ? 10 : 0)),
     currentResize + " width has decreased" + boxSizingText);
  is(Math.round(newrect.height), Math.round(rect.height - (vchange ? 10 : 0)),
     currentResize + " height has decreased" + boxSizingText);

  synthesizeMouse(textarea, rect.width - 220, rect.height - 220, { type:"mousemove" });

  newrect = textarea.getBoundingClientRect();
  ok(hchange ? newrect.width >= 15 : Math.round(newrect.width) == Math.round(rect.width),
     currentResize + " width decreased below minimum" + boxSizingText);
  ok(vchange ? newrect.height >= 15 : Math.round(newrect.height) == Math.round(rect.height),
     currentResize + " height decreased below minimum" + boxSizingText);

  synthesizeMouse(textarea, rect.width - 8, rect.height - 8, { type:"mouseup" });

  textarea.style.width = "auto";
  textarea.style.height = "auto";

  if (currentBoxSizing++ <= boxSizingTypes.length) {
    textarea.style.MozBoxSizing = boxSizingTypes[currentBoxSizing];
    SimpleTest.executeSoon(doTheTest);
  }
  else {
    currentBoxSizing = 0;
    currentResize = resizeTypes.shift();
    if (currentResize) {
      textarea.style.resize = currentResize;
      SimpleTest.executeSoon(doTheTest);
    }
    else {
      SimpleTest.finish();
    }
  }
}

</script>
</pre>
</body>
</html>