layout/forms/test/test_textarea_resize.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/forms/test/test_textarea_resize.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,102 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test for Bug 477700</title>
     1.8 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.11 +</head>
    1.12 +<body>
    1.13 +<div id="content" style="display: none">
    1.14 +</div>
    1.15 +
    1.16 +<textarea id="textarea" style="-moz-appearance: none; border: 2px solid black; padding: 3px; box-sizing: border-box; min-width: 15px; min-height: 15px;">Text</textarea>
    1.17 +
    1.18 +<pre id="test">
    1.19 +<script type="application/javascript">
    1.20 +
    1.21 +/** Test for textbox resizing **/
    1.22 +SimpleTest.waitForExplicitFinish();
    1.23 +addLoadEvent(function() SimpleTest.executeSoon(doTheTest));
    1.24 +
    1.25 +// -1 means use the default value which is 'both', then test explicitly
    1.26 +// setting each possible value.
    1.27 +var currentResize = -1;
    1.28 +var currentBoxSizing = 0;
    1.29 +var currentPointer = 0;
    1.30 +var resizeTypes = [ "horizontal", "vertical", "none", "inherit", "both" ];
    1.31 +var boxSizingTypes = [ "", "border-box", "padding-box" ];
    1.32 +var pointerTypes = [ synthesizeMouse, synthesizeTouch]
    1.33 +
    1.34 +function doTheTest() {
    1.35 +  runTest(pointerTypes[currentPointer]);
    1.36 +}
    1.37 +
    1.38 +function runTest(aPointerFunc) {
    1.39 +  var boxSizingText = " with box sizing " + (currentBoxSizing ? boxSizingTypes[currentBoxSizing] : "content-box");
    1.40 +
    1.41 +  var textarea = $("textarea");
    1.42 +  var rect = textarea.getBoundingClientRect();
    1.43 +  var touch = aPointerFunc.name.match(/Touch/);
    1.44 +  // -1 means use the default value of resize, i.e. "both"
    1.45 +  var type = (currentResize == -1) ? "both" : resizeTypes[currentResize];
    1.46 +  // assume that the resizer is in the lower right corner
    1.47 +
    1.48 +  aPointerFunc(textarea, rect.width - 10, rect.height - 10, { type: touch ? "touchstart" : "mousedown" });
    1.49 +  aPointerFunc(textarea, rect.width + 40, rect.height + 40, { type: touch ? "touchmove" : "mousemove" });
    1.50 +
    1.51 +  var newrect = textarea.getBoundingClientRect();
    1.52 +  var hchange = (type == "both" || type == "horizontal");
    1.53 +  var vchange = (type == "both" || type == "vertical");
    1.54 +
    1.55 +  is(Math.round(newrect.width), Math.round(rect.width + (hchange ? 50 : 0)),
    1.56 +     type + " width has increased" + boxSizingText + " using " + aPointerFunc.name);
    1.57 +  is(Math.round(newrect.height), Math.round(rect.height + (vchange ? 50 : 0)),
    1.58 +     type + " height has increased" + boxSizingText + " using " + aPointerFunc.name);
    1.59 +
    1.60 +  aPointerFunc(textarea, rect.width - 20, rect.height - 20, { type: touch ? "touchmove" : "mousemove" });
    1.61 +
    1.62 +  newrect = textarea.getBoundingClientRect();
    1.63 +
    1.64 +  is(Math.round(newrect.width), Math.round(rect.width - (hchange ? 10 : 0)),
    1.65 +     type + " width has decreased" + boxSizingText + " using " + aPointerFunc.name);
    1.66 +  is(Math.round(newrect.height), Math.round(rect.height - (vchange ? 10 : 0)),
    1.67 +     type + " height has decreased" + boxSizingText + " using " + aPointerFunc.name);
    1.68 +
    1.69 +  aPointerFunc(textarea, rect.width - 220, rect.height - 220, { type: touch ? "touchmove" : "mousemove" });
    1.70 +
    1.71 +  newrect = textarea.getBoundingClientRect();
    1.72 +  ok(hchange ? newrect.width >= 15 : Math.round(newrect.width) == Math.round(rect.width),
    1.73 +     type + " width decreased below minimum" + boxSizingText + " using " + newrect.width);
    1.74 +  ok(vchange ? newrect.height >= 15 : Math.round(newrect.height) == Math.round(rect.height),
    1.75 +     type + " height decreased below minimum" + boxSizingText + " using " + aPointerFunc.name);
    1.76 +
    1.77 +  aPointerFunc(textarea, rect.width - 8, rect.height - 8, { type: touch ? "touchend" : "mouseup" });
    1.78 +
    1.79 +  textarea.style.width = "auto";
    1.80 +  textarea.style.height = "auto";
    1.81 +
    1.82 +  if (currentBoxSizing++ <= boxSizingTypes.length) {
    1.83 +    textarea.style.MozBoxSizing = boxSizingTypes[currentBoxSizing];
    1.84 +    SimpleTest.executeSoon(doTheTest);
    1.85 +  } else {
    1.86 +    currentBoxSizing = 0;
    1.87 +    if (++currentResize < resizeTypes.length) {
    1.88 +      textarea.style.resize = resizeTypes[currentResize];
    1.89 +      SimpleTest.executeSoon(doTheTest);
    1.90 +    } else {
    1.91 +      currentResize = -1;
    1.92 +      textarea.style.resize = "";
    1.93 +      if (++currentPointer < pointerTypes.length) {
    1.94 +        SimpleTest.executeSoon(doTheTest);
    1.95 +      } else {
    1.96 +        SimpleTest.finish();
    1.97 +      }
    1.98 +    }
    1.99 +  }
   1.100 +}
   1.101 +
   1.102 +</script>
   1.103 +</pre>
   1.104 +</body>
   1.105 +</html>

mercurial