layout/forms/test/test_textarea_resize.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Test for Bug 477700</title>
     5   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6   <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
     7   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     8 </head>
     9 <body>
    10 <div id="content" style="display: none">
    11 </div>
    13 <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>
    15 <pre id="test">
    16 <script type="application/javascript">
    18 /** Test for textbox resizing **/
    19 SimpleTest.waitForExplicitFinish();
    20 addLoadEvent(function() SimpleTest.executeSoon(doTheTest));
    22 // -1 means use the default value which is 'both', then test explicitly
    23 // setting each possible value.
    24 var currentResize = -1;
    25 var currentBoxSizing = 0;
    26 var currentPointer = 0;
    27 var resizeTypes = [ "horizontal", "vertical", "none", "inherit", "both" ];
    28 var boxSizingTypes = [ "", "border-box", "padding-box" ];
    29 var pointerTypes = [ synthesizeMouse, synthesizeTouch]
    31 function doTheTest() {
    32   runTest(pointerTypes[currentPointer]);
    33 }
    35 function runTest(aPointerFunc) {
    36   var boxSizingText = " with box sizing " + (currentBoxSizing ? boxSizingTypes[currentBoxSizing] : "content-box");
    38   var textarea = $("textarea");
    39   var rect = textarea.getBoundingClientRect();
    40   var touch = aPointerFunc.name.match(/Touch/);
    41   // -1 means use the default value of resize, i.e. "both"
    42   var type = (currentResize == -1) ? "both" : resizeTypes[currentResize];
    43   // assume that the resizer is in the lower right corner
    45   aPointerFunc(textarea, rect.width - 10, rect.height - 10, { type: touch ? "touchstart" : "mousedown" });
    46   aPointerFunc(textarea, rect.width + 40, rect.height + 40, { type: touch ? "touchmove" : "mousemove" });
    48   var newrect = textarea.getBoundingClientRect();
    49   var hchange = (type == "both" || type == "horizontal");
    50   var vchange = (type == "both" || type == "vertical");
    52   is(Math.round(newrect.width), Math.round(rect.width + (hchange ? 50 : 0)),
    53      type + " width has increased" + boxSizingText + " using " + aPointerFunc.name);
    54   is(Math.round(newrect.height), Math.round(rect.height + (vchange ? 50 : 0)),
    55      type + " height has increased" + boxSizingText + " using " + aPointerFunc.name);
    57   aPointerFunc(textarea, rect.width - 20, rect.height - 20, { type: touch ? "touchmove" : "mousemove" });
    59   newrect = textarea.getBoundingClientRect();
    61   is(Math.round(newrect.width), Math.round(rect.width - (hchange ? 10 : 0)),
    62      type + " width has decreased" + boxSizingText + " using " + aPointerFunc.name);
    63   is(Math.round(newrect.height), Math.round(rect.height - (vchange ? 10 : 0)),
    64      type + " height has decreased" + boxSizingText + " using " + aPointerFunc.name);
    66   aPointerFunc(textarea, rect.width - 220, rect.height - 220, { type: touch ? "touchmove" : "mousemove" });
    68   newrect = textarea.getBoundingClientRect();
    69   ok(hchange ? newrect.width >= 15 : Math.round(newrect.width) == Math.round(rect.width),
    70      type + " width decreased below minimum" + boxSizingText + " using " + newrect.width);
    71   ok(vchange ? newrect.height >= 15 : Math.round(newrect.height) == Math.round(rect.height),
    72      type + " height decreased below minimum" + boxSizingText + " using " + aPointerFunc.name);
    74   aPointerFunc(textarea, rect.width - 8, rect.height - 8, { type: touch ? "touchend" : "mouseup" });
    76   textarea.style.width = "auto";
    77   textarea.style.height = "auto";
    79   if (currentBoxSizing++ <= boxSizingTypes.length) {
    80     textarea.style.MozBoxSizing = boxSizingTypes[currentBoxSizing];
    81     SimpleTest.executeSoon(doTheTest);
    82   } else {
    83     currentBoxSizing = 0;
    84     if (++currentResize < resizeTypes.length) {
    85       textarea.style.resize = resizeTypes[currentResize];
    86       SimpleTest.executeSoon(doTheTest);
    87     } else {
    88       currentResize = -1;
    89       textarea.style.resize = "";
    90       if (++currentPointer < pointerTypes.length) {
    91         SimpleTest.executeSoon(doTheTest);
    92       } else {
    93         SimpleTest.finish();
    94       }
    95     }
    96   }
    97 }
    99 </script>
   100 </pre>
   101 </body>
   102 </html>

mercurial