editor/libeditor/html/tests/test_bug640321.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial