Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=640321
5 -->
6 <head>
7 <title>Test for Bug 640321</title>
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=640321">Mozilla Bug 640321</a>
14 <p id="display"></p>
15 <div id="content" contenteditable style="text-align: center">
16 <img src="green.png">
17 </div>
18 <div id="clickaway" style="width: 10px; height: 10px"></div>
19 <pre id="test">
20 <script type="application/javascript">
22 /** Test for Bug 640321 **/
23 SimpleTest.waitForExplicitFinish();
24 SimpleTest.waitForFocus(function() {
25 var img = document.querySelector("img");
27 function cancel(e) { e.stopPropagation(); }
28 var content = document.getElementById("content");
29 content.addEventListener("mousedown", cancel, false);
30 content.addEventListener("mousemove", cancel, false);
31 content.addEventListener("mouseup", cancel, false);
33 /**
34 * This function is a generic resizer test.
35 * We have 8 resizers that we'd like to test, and each can be moved in 8 different directions.
36 * In specifying baseX, W can be considered to be the width of the image, and for baseY, H
37 * can be considered to be the height of the image. deltaX and deltaY are regular pixel values
38 * which can be positive or negative.
39 */
40 const W = 1;
41 const H = 1;
42 function testResizer(baseX, baseY, deltaX, deltaY, expectedDeltaX, expectedDeltaY) {
43 ok(true, "testResizer(" + [baseX, baseY, deltaX, deltaY, expectedDeltaX, expectedDeltaY].join(", ") + ")");
45 // Reset the dimensions of the image
46 img.style.width = "100px";
47 img.style.height = "100px";
48 var rect = img.getBoundingClientRect();
49 is(rect.width, 100, "Sanity check the length");
50 is(rect.height, 100, "Sanity check the height");
52 // Click on the image to show the resizers
53 synthesizeMouseAtCenter(img, {});
55 // Determine which resizer we're dealing with
56 var basePosX = rect.width * baseX;
57 var basePosY = rect.height * baseY;
59 // Click on the correct resizer
60 synthesizeMouse(img, basePosX, basePosY, {type: "mousedown"});
61 // Drag it delta pixels to the right and bottom (or maybe left and top!)
62 synthesizeMouse(img, basePosX + deltaX, basePosY + deltaY, {type: "mousemove"});
63 // Release the mouse button
64 synthesizeMouse(img, basePosX + deltaX, basePosY + deltaY, {type: "mouseup"});
65 // Move the mouse delta more pixels to the same direction to make sure that the
66 // resize operation has stopped.
67 synthesizeMouse(img, basePosX + deltaX * 2, basePosY + deltaY * 2, {type: "mousemove"});
68 // Click outside of the image to hide the resizers
69 synthesizeMouseAtCenter(document.getElementById("clickaway"), {});
71 // Get the new dimensions for the image
72 var newRect = img.getBoundingClientRect();
73 is(newRect.width, rect.width + expectedDeltaX, "The width should be increased by " + expectedDeltaX + " pixels");
74 is(newRect.height, rect.height + expectedDeltaY, "The height should be increased by " + expectedDeltaY + "pixels");
75 }
77 function runTests(preserveRatio) {
78 // Account for changes in the resizing behavior when we're trying to preserve
79 // the aspect ration.
80 // ignoredGrowth means we don't change the size of a dimension because otherwise
81 // the aspect ratio would change undesirably.
82 // needlessGrowth means that we change the size of a dimension perpendecular to
83 // the mouse movement axis in order to preserve the aspect ratio.
84 // reversedGrowth means that we change the size of a dimension in the opposite
85 // direction to the mouse movement in order to maintain the aspect ratio.
86 const ignoredGrowth = preserveRatio ? 0 : 1;
87 const needlessGrowth = preserveRatio ? 1 : 0;
88 const reversedGrowth = preserveRatio ? -1 : 1;
90 SpecialPowers.setBoolPref("editor.resizing.preserve_ratio", preserveRatio);
92 // top resizer
93 testResizer(W/2, 0, -10, -10, 0, 10);
94 testResizer(W/2, 0, -10, 0, 0, 0);
95 testResizer(W/2, 0, -10, 10, 0, -10);
96 testResizer(W/2, 0, 0, -10, 0, 10);
97 testResizer(W/2, 0, 0, 0, 0, 0);
98 testResizer(W/2, 0, 0, 10, 0, -10);
99 testResizer(W/2, 0, 10, -10, 0, 10);
100 testResizer(W/2, 0, 10, 0, 0, 0);
101 testResizer(W/2, 0, 10, 10, 0, -10);
103 // top right resizer
104 testResizer( W, 0, -10, -10, -10 * reversedGrowth, 10);
105 testResizer( W, 0, -10, 0, -10 * ignoredGrowth, 0);
106 testResizer( W, 0, -10, 10, -10, -10);
107 testResizer( W, 0, 0, -10, 10 * needlessGrowth, 10);
108 testResizer( W, 0, 0, 0, 0, 0);
109 testResizer( W, 0, 0, 10, 0, -10 * ignoredGrowth);
110 testResizer( W, 0, 10, -10, 10, 10);
111 testResizer( W, 0, 10, 0, 10, 10 * needlessGrowth);
112 testResizer( W, 0, 10, 10, 10, -10 * reversedGrowth);
114 // right resizer
115 testResizer( W, H/2, -10, -10, -10, 0);
116 testResizer( W, H/2, -10, 0, -10, 0);
117 testResizer( W, H/2, -10, 10, -10, 0);
118 testResizer( W, H/2, 0, -10, 0, 0);
119 testResizer( W, H/2, 0, 0, 0, 0);
120 testResizer( W, H/2, 0, 10, 0, 0);
121 testResizer( W, H/2, 10, -10, 10, 0);
122 testResizer( W, H/2, 10, 0, 10, 0);
123 testResizer( W, H/2, 10, 10, 10, 0);
125 // bottom right resizer
126 testResizer( W, H, -10, -10, -10, -10);
127 testResizer( W, H, -10, 0, -10 * ignoredGrowth, 0);
128 testResizer( W, H, -10, 10, -10 * reversedGrowth, 10);
129 testResizer( W, H, 0, -10, 0, -10 * ignoredGrowth);
130 testResizer( W, H, 0, 0, 0, 0);
131 testResizer( W, H, 0, 10, 10 * needlessGrowth, 10);
132 testResizer( W, H, 10, -10, 10, -10 * reversedGrowth);
133 testResizer( W, H, 10, 0, 10, 10 * needlessGrowth);
134 testResizer( W, H, 10, 10, 10, 10);
136 // bottom resizer
137 testResizer(W/2, H, -10, -10, 0, -10);
138 testResizer(W/2, H, -10, 0, 0, 0);
139 testResizer(W/2, H, -10, 10, 0, 10);
140 testResizer(W/2, H, 0, -10, 0, -10);
141 testResizer(W/2, H, 0, 0, 0, 0);
142 testResizer(W/2, H, 0, 10, 0, 10);
143 testResizer(W/2, H, 10, -10, 0, -10);
144 testResizer(W/2, H, 10, 0, 0, 0);
145 testResizer(W/2, H, 10, 10, 0, 10);
147 // bottom left resizer
148 testResizer( 0, H, -10, -10, 10, -10 * reversedGrowth);
149 testResizer( 0, H, -10, 0, 10, 10 * needlessGrowth);
150 testResizer( 0, H, -10, 10, 10, 10);
151 testResizer( 0, H, 0, -10, 0, -10 * ignoredGrowth);
152 testResizer( 0, H, 0, 0, 0, 0);
153 testResizer( 0, H, 0, 10, 10 * needlessGrowth, 10);
154 testResizer( 0, H, 10, -10, -10, -10);
155 testResizer( 0, H, 10, 0, -10 * ignoredGrowth, 0);
156 testResizer( 0, H, 10, 10, -10 * reversedGrowth, 10);
158 // left resizer
159 testResizer( 0, H/2, -10, -10, 10, 0);
160 testResizer( 0, H/2, -10, 0, 10, 0);
161 testResizer( 0, H/2, -10, 10, 10, 0);
162 testResizer( 0, H/2, 0, -10, 0, 0);
163 testResizer( 0, H/2, 0, 0, 0, 0);
164 testResizer( 0, H/2, 0, 10, 0, 0);
165 testResizer( 0, H/2, 10, -10, -10, 0);
166 testResizer( 0, H/2, 10, 0, -10, 0);
167 testResizer( 0, H/2, 10, 10, -10, 0);
169 // top left resizer
170 testResizer( 0, 0, -10, -10, 10, 10);
171 testResizer( 0, 0, -10, 0, 10, 10 * needlessGrowth);
172 testResizer( 0, 0, -10, 10, 10, -10 * reversedGrowth);
173 testResizer( 0, 0, 0, -10, 10 * needlessGrowth, 10);
174 testResizer( 0, 0, 0, 0, 0, 0);
175 testResizer( 0, 0, 0, 10, 0, -10 * ignoredGrowth);
176 testResizer( 0, 0, 10, -10, -10 * reversedGrowth, 10);
177 testResizer( 0, 0, 10, 0, -10 * ignoredGrowth, 0);
178 testResizer( 0, 0, 10, 10, -10, -10);
180 SpecialPowers.clearUserPref("editor.resizing.preserve_ratio");
181 }
183 runTests(false);
184 runTests(true);
186 SimpleTest.finish();
187 });
189 </script>
190 </pre>
191 </body>
192 </html>