editor/libeditor/html/tests/test_bug640321.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/editor/libeditor/html/tests/test_bug640321.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,192 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=640321
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 640321</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=640321">Mozilla Bug 640321</a>
    1.17 +<p id="display"></p>
    1.18 +<div id="content" contenteditable style="text-align: center">
    1.19 +  <img src="green.png">
    1.20 +</div>
    1.21 +<div id="clickaway" style="width: 10px; height: 10px"></div>
    1.22 +<pre id="test">
    1.23 +<script type="application/javascript">
    1.24 +
    1.25 +/** Test for Bug 640321 **/
    1.26 +SimpleTest.waitForExplicitFinish();
    1.27 +SimpleTest.waitForFocus(function() {
    1.28 +  var img = document.querySelector("img");
    1.29 +
    1.30 +  function cancel(e) { e.stopPropagation(); }
    1.31 +  var content = document.getElementById("content");
    1.32 +  content.addEventListener("mousedown", cancel, false);
    1.33 +  content.addEventListener("mousemove", cancel, false);
    1.34 +  content.addEventListener("mouseup", cancel, false);
    1.35 +
    1.36 +  /**
    1.37 +   * This function is a generic resizer test.
    1.38 +   * We have 8 resizers that we'd like to test, and each can be moved in 8 different directions.
    1.39 +   * In specifying baseX, W can be considered to be the width of the image, and for baseY, H
    1.40 +   * can be considered to be the height of the image. deltaX and deltaY are regular pixel values
    1.41 +   * which can be positive or negative.
    1.42 +   */
    1.43 +  const W = 1;
    1.44 +  const H = 1;
    1.45 +  function testResizer(baseX, baseY, deltaX, deltaY, expectedDeltaX, expectedDeltaY) {
    1.46 +    ok(true, "testResizer(" + [baseX, baseY, deltaX, deltaY, expectedDeltaX, expectedDeltaY].join(", ") + ")");
    1.47 +
    1.48 +    // Reset the dimensions of the image
    1.49 +    img.style.width = "100px";
    1.50 +    img.style.height = "100px";
    1.51 +    var rect = img.getBoundingClientRect();
    1.52 +    is(rect.width, 100, "Sanity check the length");
    1.53 +    is(rect.height, 100, "Sanity check the height");
    1.54 +
    1.55 +    // Click on the image to show the resizers
    1.56 +    synthesizeMouseAtCenter(img, {});
    1.57 +
    1.58 +    // Determine which resizer we're dealing with
    1.59 +    var basePosX = rect.width * baseX;
    1.60 +    var basePosY = rect.height * baseY;
    1.61 +
    1.62 +    // Click on the correct resizer
    1.63 +    synthesizeMouse(img, basePosX, basePosY, {type: "mousedown"});
    1.64 +    // Drag it delta pixels to the right and bottom (or maybe left and top!)
    1.65 +    synthesizeMouse(img, basePosX + deltaX, basePosY + deltaY, {type: "mousemove"});
    1.66 +    // Release the mouse button
    1.67 +    synthesizeMouse(img, basePosX + deltaX, basePosY + deltaY, {type: "mouseup"});
    1.68 +    // Move the mouse delta more pixels to the same direction to make sure that the
    1.69 +    // resize operation has stopped.
    1.70 +    synthesizeMouse(img, basePosX + deltaX * 2, basePosY + deltaY * 2, {type: "mousemove"});
    1.71 +    // Click outside of the image to hide the resizers
    1.72 +    synthesizeMouseAtCenter(document.getElementById("clickaway"), {});
    1.73 +
    1.74 +    // Get the new dimensions for the image
    1.75 +    var newRect = img.getBoundingClientRect();
    1.76 +    is(newRect.width, rect.width + expectedDeltaX, "The width should be increased by " + expectedDeltaX + " pixels");
    1.77 +    is(newRect.height, rect.height + expectedDeltaY, "The height should be increased by " + expectedDeltaY + "pixels");
    1.78 +  }
    1.79 +
    1.80 +  function runTests(preserveRatio) {
    1.81 +    // Account for changes in the resizing behavior when we're trying to preserve
    1.82 +    // the aspect ration.
    1.83 +    // ignoredGrowth means we don't change the size of a dimension because otherwise
    1.84 +    // the aspect ratio would change undesirably.
    1.85 +    // needlessGrowth means that we change the size of a dimension perpendecular to
    1.86 +    // the mouse movement axis in order to preserve the aspect ratio.
    1.87 +    // reversedGrowth means that we change the size of a dimension in the opposite
    1.88 +    // direction to the mouse movement in order to maintain the aspect ratio.
    1.89 +    const ignoredGrowth = preserveRatio ? 0 : 1;
    1.90 +    const needlessGrowth = preserveRatio ? 1 : 0;
    1.91 +    const reversedGrowth = preserveRatio ? -1 : 1;
    1.92 +
    1.93 +    SpecialPowers.setBoolPref("editor.resizing.preserve_ratio", preserveRatio);
    1.94 +
    1.95 +    // top resizer
    1.96 +    testResizer(W/2,   0, -10, -10,   0,  10);
    1.97 +    testResizer(W/2,   0, -10,   0,   0,   0);
    1.98 +    testResizer(W/2,   0, -10,  10,   0, -10);
    1.99 +    testResizer(W/2,   0,   0, -10,   0,  10);
   1.100 +    testResizer(W/2,   0,   0,   0,   0,   0);
   1.101 +    testResizer(W/2,   0,   0,  10,   0, -10);
   1.102 +    testResizer(W/2,   0,  10, -10,   0,  10);
   1.103 +    testResizer(W/2,   0,  10,   0,   0,   0);
   1.104 +    testResizer(W/2,   0,  10,  10,   0, -10);
   1.105 +
   1.106 +    // top right resizer
   1.107 +    testResizer(  W,   0, -10, -10, -10 * reversedGrowth, 10);
   1.108 +    testResizer(  W,   0, -10,   0, -10 * ignoredGrowth,   0);
   1.109 +    testResizer(  W,   0, -10,  10, -10, -10);
   1.110 +    testResizer(  W,   0,   0, -10,  10 * needlessGrowth,  10);
   1.111 +    testResizer(  W,   0,   0,   0,   0,   0);
   1.112 +    testResizer(  W,   0,   0,  10,   0, -10 * ignoredGrowth);
   1.113 +    testResizer(  W,   0,  10, -10,  10,  10);
   1.114 +    testResizer(  W,   0,  10,   0,  10,  10 * needlessGrowth);
   1.115 +    testResizer(  W,   0,  10,  10,  10, -10 * reversedGrowth);
   1.116 +
   1.117 +    // right resizer
   1.118 +    testResizer(  W, H/2, -10, -10, -10,   0);
   1.119 +    testResizer(  W, H/2, -10,   0, -10,   0);
   1.120 +    testResizer(  W, H/2, -10,  10, -10,   0);
   1.121 +    testResizer(  W, H/2,   0, -10,   0,   0);
   1.122 +    testResizer(  W, H/2,   0,   0,   0,   0);
   1.123 +    testResizer(  W, H/2,   0,  10,   0,   0);
   1.124 +    testResizer(  W, H/2,  10, -10,  10,   0);
   1.125 +    testResizer(  W, H/2,  10,   0,  10,   0);
   1.126 +    testResizer(  W, H/2,  10,  10,  10,   0);
   1.127 +
   1.128 +    // bottom right resizer
   1.129 +    testResizer(  W,   H, -10, -10, -10, -10);
   1.130 +    testResizer(  W,   H, -10,   0, -10 * ignoredGrowth,   0);
   1.131 +    testResizer(  W,   H, -10,  10, -10 * reversedGrowth,  10);
   1.132 +    testResizer(  W,   H,   0, -10,   0, -10 * ignoredGrowth);
   1.133 +    testResizer(  W,   H,   0,   0,   0,   0);
   1.134 +    testResizer(  W,   H,   0,  10,  10 * needlessGrowth,  10);
   1.135 +    testResizer(  W,   H,  10, -10,  10, -10 * reversedGrowth);
   1.136 +    testResizer(  W,   H,  10,   0,  10,  10 * needlessGrowth);
   1.137 +    testResizer(  W,   H,  10,  10,  10,  10);
   1.138 +
   1.139 +    // bottom resizer
   1.140 +    testResizer(W/2,   H, -10, -10,   0, -10);
   1.141 +    testResizer(W/2,   H, -10,   0,   0,   0);
   1.142 +    testResizer(W/2,   H, -10,  10,   0,  10);
   1.143 +    testResizer(W/2,   H,   0, -10,   0, -10);
   1.144 +    testResizer(W/2,   H,   0,   0,   0,   0);
   1.145 +    testResizer(W/2,   H,   0,  10,   0,  10);
   1.146 +    testResizer(W/2,   H,  10, -10,   0, -10);
   1.147 +    testResizer(W/2,   H,  10,   0,   0,   0);
   1.148 +    testResizer(W/2,   H,  10,  10,   0,  10);
   1.149 +
   1.150 +    // bottom left resizer
   1.151 +    testResizer(  0,   H, -10, -10,  10, -10 * reversedGrowth);
   1.152 +    testResizer(  0,   H, -10,   0,  10,  10 * needlessGrowth);
   1.153 +    testResizer(  0,   H, -10,  10,  10,  10);
   1.154 +    testResizer(  0,   H,   0, -10,   0, -10 * ignoredGrowth);
   1.155 +    testResizer(  0,   H,   0,   0,   0,   0);
   1.156 +    testResizer(  0,   H,   0,  10,  10 * needlessGrowth,  10);
   1.157 +    testResizer(  0,   H,  10, -10, -10, -10);
   1.158 +    testResizer(  0,   H,  10,   0, -10 * ignoredGrowth,   0);
   1.159 +    testResizer(  0,   H,  10,  10, -10 * reversedGrowth,  10);
   1.160 +
   1.161 +    // left resizer
   1.162 +    testResizer(  0, H/2, -10, -10,  10,   0);
   1.163 +    testResizer(  0, H/2, -10,   0,  10,   0);
   1.164 +    testResizer(  0, H/2, -10,  10,  10,   0);
   1.165 +    testResizer(  0, H/2,   0, -10,   0,   0);
   1.166 +    testResizer(  0, H/2,   0,   0,   0,   0);
   1.167 +    testResizer(  0, H/2,   0,  10,   0,   0);
   1.168 +    testResizer(  0, H/2,  10, -10, -10,   0);
   1.169 +    testResizer(  0, H/2,  10,   0, -10,   0);
   1.170 +    testResizer(  0, H/2,  10,  10, -10,   0);
   1.171 +
   1.172 +    // top left resizer
   1.173 +    testResizer(  0,   0, -10, -10,  10,  10);
   1.174 +    testResizer(  0,   0, -10,   0,  10,  10 * needlessGrowth);
   1.175 +    testResizer(  0,   0, -10,  10,  10, -10 * reversedGrowth);
   1.176 +    testResizer(  0,   0,   0, -10,  10 * needlessGrowth,  10);
   1.177 +    testResizer(  0,   0,   0,   0,   0,   0);
   1.178 +    testResizer(  0,   0,   0,  10,   0, -10 * ignoredGrowth);
   1.179 +    testResizer(  0,   0,  10, -10, -10 * reversedGrowth,  10);
   1.180 +    testResizer(  0,   0,  10,   0, -10 * ignoredGrowth,   0);
   1.181 +    testResizer(  0,   0,  10,  10, -10, -10);
   1.182 +
   1.183 +    SpecialPowers.clearUserPref("editor.resizing.preserve_ratio");
   1.184 +  }
   1.185 +
   1.186 +  runTests(false);
   1.187 +  runTests(true);
   1.188 +
   1.189 +  SimpleTest.finish();
   1.190 +});
   1.191 +
   1.192 +</script>
   1.193 +</pre>
   1.194 +</body>
   1.195 +</html>

mercurial