dom/events/test/test_dragstart.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.

michael@0 1 <html>
michael@0 2 <head>
michael@0 3 <title>Tests for the dragstart event</title>
michael@0 4 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
michael@0 5 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 7
michael@0 8 <!--
michael@0 9 This test checks the dragstart event and the DataTransfer object
michael@0 10 -->
michael@0 11
michael@0 12 <script>
michael@0 13
michael@0 14 SimpleTest.waitForExplicitFinish();
michael@0 15
michael@0 16 var gDragInfo;
michael@0 17 var gDataTransfer = null;
michael@0 18 var gExtraDragTests = 0;
michael@0 19
michael@0 20 function runTests()
michael@0 21 {
michael@0 22 // first, create a selection and try dragging it
michael@0 23 var draggable = $("draggable");
michael@0 24 window.getSelection().selectAllChildren(draggable);
michael@0 25 synthesizeMouse(draggable, 6, 6, { type: "mousedown" });
michael@0 26 synthesizeMouse(draggable, 14, 14, { type: "mousemove" });
michael@0 27 // drags are asynchronous on Linux, so this extra event is needed to make
michael@0 28 // sure the drag gets processed
michael@0 29 synthesizeMouse(draggable, 15, 15, { type: "mousemove" });
michael@0 30 }
michael@0 31
michael@0 32 function afterDragTests()
michael@0 33 {
michael@0 34 // the dragstart should have occurred due to moving the mouse. gDataTransfer
michael@0 35 // caches the dataTransfer that was used, however it should now be empty and
michael@0 36 // be read only.
michael@0 37 ok(gDataTransfer instanceof DataTransfer, "DataTransfer after dragstart event");
michael@0 38 checkTypes(gDataTransfer, [], 0, "after dragstart event");
michael@0 39
michael@0 40 expectError(function() gDataTransfer.setData("text/plain", "Some Text"),
michael@0 41 "NoModificationAllowedError", "setData when read only");
michael@0 42 expectError(function() gDataTransfer.clearData("text/plain"),
michael@0 43 "NoModificationAllowedError", "clearData when read only");
michael@0 44 expectError(function() gDataTransfer.mozSetDataAt("text/plain", "Some Text", 0),
michael@0 45 "NoModificationAllowedError", "setDataAt when read only");
michael@0 46 expectError(function() gDataTransfer.mozClearDataAt("text/plain", 0),
michael@0 47 "NoModificationAllowedError", "clearDataAt when read only");
michael@0 48 expectError(function() gDataTransfer.setDragImage(draggable, 10, 10),
michael@0 49 "NoModificationAllowedError", "setDragImage when read only");
michael@0 50 expectError(function() gDataTransfer.addElement(draggable),
michael@0 51 "NoModificationAllowedError", "addElement when read only");
michael@0 52
michael@0 53 var evt = document.createEvent("dragevent");
michael@0 54 ok(evt instanceof DragEvent, "synthetic dragevent class")
michael@0 55 ok(evt instanceof MouseEvent, "synthetic event inherits from MouseEvent")
michael@0 56 evt.initDragEvent("dragstart", true, true, window, 1, 40, 35, 20, 15,
michael@0 57 false, true, false, false, 0, null, null);
michael@0 58 $("synthetic").dispatchEvent(evt);
michael@0 59
michael@0 60 var evt = document.createEvent("dragevents");
michael@0 61 ok(evt instanceof DragEvent, "synthetic dragevents class")
michael@0 62 evt.initDragEvent("dragover", true, true, window, 0, 40, 35, 20, 15,
michael@0 63 true, false, true, true, 2, document.documentElement, null);
michael@0 64 $("synthetic2").dispatchEvent(evt);
michael@0 65
michael@0 66 // next, dragging links and images
michael@0 67 sendMouseEventsForDrag("link");
michael@0 68 sendMouseEventsForDrag("image");
michael@0 69
michael@0 70 // disable testing input dragging for now, as it doesn't seem to be testable
michael@0 71 // draggable = $("input");
michael@0 72 // draggable.setSelectionRange(0, 4);
michael@0 73 // synthesizeMouse(draggable, 8, 8, { type: "mousedown" });
michael@0 74 // synthesizeMouse(draggable, 15, 15, { type: "mousemove" });
michael@0 75 // sendMouseEventsForDrag("input");
michael@0 76
michael@0 77 // next, check if the draggable attribute can be used to adjust the drag target
michael@0 78 gDragInfo = { target: $("dragtrue"), testid: "draggable true node" };
michael@0 79 sendMouseEventsForDrag("dragtrue");
michael@0 80 gDragInfo = { target: $("dragtrue"), testid: "draggable true child" };
michael@0 81 sendMouseEventsForDrag("spantrue");
michael@0 82 gDragInfo = { target: $("dragfalse").firstChild, testid: "draggable false node" };
michael@0 83 sendMouseEventsForDrag("dragfalse");
michael@0 84 gDragInfo = { target: $("spanfalse").firstChild, testid: "draggable false child" };
michael@0 85 sendMouseEventsForDrag("spanfalse");
michael@0 86
michael@0 87 synthesizeMouse(draggable, 12, 12, { type: "mouseup" });
michael@0 88 if (gExtraDragTests == 4)
michael@0 89 SimpleTest.finish();
michael@0 90 }
michael@0 91
michael@0 92 function sendMouseEventsForDrag(nodeid)
michael@0 93 {
michael@0 94 var draggable = $(nodeid);
michael@0 95 synthesizeMouse(draggable, 3, 3, { type: "mousedown" });
michael@0 96 synthesizeMouse(draggable, 10, 10, { type: "mousemove" });
michael@0 97 synthesizeMouse(draggable, 12, 12, { type: "mousemove" });
michael@0 98 }
michael@0 99
michael@0 100 function doDragStartSelection(event)
michael@0 101 {
michael@0 102 is(event.type, "dragstart", "dragstart event type");
michael@0 103 is(event.target, $("draggable").firstChild, "dragstart event target");
michael@0 104 is(event.bubbles, true, "dragstart event bubbles");
michael@0 105 is(event.cancelable, true, "dragstart event cancelable");
michael@0 106
michael@0 107 is(event.clientX, 14, "dragstart clientX");
michael@0 108 is(event.clientY, 14, "dragstart clientY");
michael@0 109 ok(event.screenX > 0, "dragstart screenX");
michael@0 110 ok(event.screenY > 0, "dragstart screenY");
michael@0 111 is(event.layerX, 14, "dragstart layerX");
michael@0 112 is(event.layerY, 14, "dragstart layerY");
michael@0 113 is(event.pageX, 14, "dragstart pageX");
michael@0 114 is(event.pageY, 14, "dragstart pageY");
michael@0 115
michael@0 116 var dt = event.dataTransfer;
michael@0 117 ok(dt instanceof DataTransfer, "dataTransfer is DataTransfer");
michael@0 118 gDataTransfer = dt;
michael@0 119
michael@0 120 var types = dt.types;
michael@0 121 is(types instanceof DOMStringList, true, "initial types is a DOMStringList");
michael@0 122 checkTypes(dt, ["text/_moz_htmlcontext", "text/_moz_htmlinfo", "text/html", "text/plain"], 0, "initial selection");
michael@0 123
michael@0 124 is(dt.getData("text/plain"), "This is a draggable bit of text.", "initial selection text/plain");
michael@0 125 is(dt.getData("text/html"), "<div id=\"draggable\" ondragstart=\"doDragStartSelection(event)\">This is a <em>draggable</em> bit of text.</div>",
michael@0 126 "initial selection text/html");
michael@0 127
michael@0 128 // text/unicode and Text are available for compatibility. They retrieve the
michael@0 129 // text/plain data
michael@0 130 is(dt.getData("text/unicode"), "This is a draggable bit of text.", "initial selection text/unicode");
michael@0 131 is(dt.getData("Text"), "This is a draggable bit of text.", "initial selection Text");
michael@0 132 is(dt.getData("TEXT"), "This is a draggable bit of text.", "initial selection TEXT");
michael@0 133 is(dt.getData("text/UNICODE"), "This is a draggable bit of text.", "initial selection text/UNICODE");
michael@0 134
michael@0 135 is(dt.mozItemCount, 1, "initial selection item count");
michael@0 136
michael@0 137 dt.clearData("text/plain");
michael@0 138 dt.clearData("text/html");
michael@0 139 dt.clearData("text/_moz_htmlinfo");
michael@0 140 dt.clearData("text/_moz_htmlcontext");
michael@0 141
michael@0 142 test_DataTransfer(dt);
michael@0 143 setTimeout(afterDragTests, 0);
michael@0 144 }
michael@0 145
michael@0 146 function test_DataTransfer(dt)
michael@0 147 {
michael@0 148 is(dt.mozItemCount, 0, "empty itemCount");
michael@0 149
michael@0 150 var types = dt.types;
michael@0 151 is(types instanceof DOMStringList, true, "empty types is a DOMStringList");
michael@0 152 checkTypes(dt, [], 0, "empty");
michael@0 153 is(dt.getData("text/plain"), "", "empty data is empty");
michael@0 154
michael@0 155 // calling setDataAt requires an index that is 0 <= index <= dt.itemCount
michael@0 156 expectError(function() dt.mozSetDataAt("text/plain", "Some Text", 1),
michael@0 157 "IndexSizeError", "setDataAt index too high");
michael@0 158
michael@0 159 is(dt.mozUserCancelled, false, "userCancelled");
michael@0 160
michael@0 161 // because an exception occurred, the data should not have been added
michael@0 162 is(dt.mozItemCount, 0, "empty setDataAt index too high itemCount");
michael@0 163 dt.getData("text/plain", "", "empty setDataAt index too high getData");
michael@0 164
michael@0 165 // if the type is '', do nothing, or return ''
michael@0 166 dt.setData("", "Invalid Type");
michael@0 167 is(dt.types.length, 0, "invalid type setData");
michael@0 168 is(dt.getData(""), "", "invalid type getData"),
michael@0 169 dt.mozSetDataAt("", "Invalid Type", 0);
michael@0 170 is(dt.types.length, 0, "invalid type setDataAt");
michael@0 171 is(dt.mozGetDataAt("", 0), null, "invalid type getDataAt"),
michael@0 172
michael@0 173 // similar with clearDataAt and getDataAt
michael@0 174 expectError(function() dt.mozGetDataAt("text/plain", 1),
michael@0 175 "IndexSizeError", "getDataAt index too high");
michael@0 176 expectError(function() dt.mozClearDataAt("text/plain", 1),
michael@0 177 "IndexSizeError", "clearDataAt index too high");
michael@0 178
michael@0 179 dt.setData("text/plain", "Sample Text");
michael@0 180 is(dt.mozItemCount, 1, "added plaintext itemCount");
michael@0 181 checkOneDataItem(dt, ["text/plain"], ["Sample Text"], 0, "added plaintext");
michael@0 182
michael@0 183 // after all those exceptions, the data should still be the same
michael@0 184 checkOneDataItem(dt, ["text/plain"], ["Sample Text"], 0, "added plaintext after exception");
michael@0 185
michael@0 186 // modifying the data associated with the format should give it the new value
michael@0 187 dt.setData("text/plain", "Modified Text");
michael@0 188 is(dt.mozItemCount, 1, "modified plaintext itemCount");
michael@0 189 checkOneDataItem(dt, ["text/plain"], ["Modified Text"], 0, "modified plaintext");
michael@0 190
michael@0 191 dt.setData("text/html", "<strong>Modified Text</strong>");
michael@0 192 is(dt.mozItemCount, 1, "modified html itemCount");
michael@0 193 checkOneDataItem(dt, ["text/plain", "text/html"],
michael@0 194 ["Modified Text", "<strong>Modified Text</strong>"],
michael@0 195 0, "modified html");
michael@0 196
michael@0 197 // modifying data for a type that already exists should adjust it in place,
michael@0 198 // not reinsert it at the beginning
michael@0 199 dt.setData("text/plain", "New Text");
michael@0 200 is(dt.mozItemCount, 1, "modified text again itemCount");
michael@0 201 checkOneDataItem(dt, ["text/plain", "text/html"],
michael@0 202 ["New Text", "<strong>Modified Text</strong>"],
michael@0 203 0, "modified text again");
michael@0 204
michael@0 205 var draggable = $("draggable");
michael@0 206 dt.setData("application/-moz-node", draggable);
michael@0 207 checkOneDataItem(dt, ["text/plain", "text/html", "application/-moz-node"],
michael@0 208 ["New Text", "<strong>Modified Text</strong>", draggable],
michael@0 209 0, "added node");
michael@0 210
michael@0 211 dt.clearData(""); // null means clear all
michael@0 212 is(dt.mozItemCount, 0, "itemCount after clearData empty string");
michael@0 213 checkTypes(dt, [], 0, "empty after clearData empty string");
michael@0 214
michael@0 215 dt.setData("text/plain", 22);
michael@0 216 dt.setData("text/html", 5.6);
michael@0 217 dt.setData("text/xml", 5.6);
michael@0 218 checkTypes(dt, ["text/plain", "text/html", "text/xml"], ["22", "5.6", ""], 0, "add numeric and empty data");
michael@0 219
michael@0 220 dt.clearData(); // no argument means clear all
michael@0 221 is(dt.mozItemCount, 0, "itemCount after clearData no argument");
michael@0 222 checkTypes(dt, [], 0, "empty after clearData no argument");
michael@0 223
michael@0 224 // check 'Text' type which should convert into text/plain
michael@0 225 dt.setData("Text", "Sample Text");
michael@0 226 checkOneDataItem(dt, ["text/plain"], ["Sample Text"], 0, "set Text");
michael@0 227 is(dt.getData("Text"), "Sample Text", "getData Text");
michael@0 228 is(dt.mozGetDataAt("Text", 0), "Sample Text", "getDataAt Text");
michael@0 229 dt.setData("text/plain", "More Text");
michael@0 230 checkOneDataItem(dt, ["text/plain"], ["More Text"], 0, "set text/plain after set Text");
michael@0 231
michael@0 232 dt.mozClearDataAt("", 0); // null means clear all
michael@0 233 is(dt.mozItemCount, 0, "itemCount after clearDataAt empty string");
michael@0 234 checkTypes(dt, [], 0, "empty after clearDataAt empty string");
michael@0 235
michael@0 236 // check text/uri-list type
michael@0 237 dt.setData("text/uri-list", "http://www.mozilla.org");
michael@0 238 checkURL(dt, "http://www.mozilla.org", "http://www.mozilla.org", 0, "set text/uri-list");
michael@0 239
michael@0 240 // check URL type which should add text/uri-list data
michael@0 241 dt.setData("URL", "ftp://ftp.example.com");
michael@0 242 checkURL(dt, "ftp://ftp.example.com", "ftp://ftp.example.com", 0, "set URL");
michael@0 243 checkTypes(dt, ["text/uri-list"], ["ftp://ftp.example.com"], "url types");
michael@0 244
michael@0 245 // clearing text/uri-list data
michael@0 246 dt.clearData("text/uri-list");
michael@0 247 is(dt.mozItemCount, 0, "itemCount after clear url-list");
michael@0 248 is(dt.getData("text/uri-list"), "", "text/uri-list after clear url-list");
michael@0 249 is(dt.getData("URL"), "", "URL after clear url-list");
michael@0 250
michael@0 251 // check text/uri-list parsing
michael@0 252 dt.setData("text/uri-list", "#http://www.mozilla.org\nhttp://www.xulplanet.com\nhttp://www.example.com");
michael@0 253 checkURL(dt, "http://www.xulplanet.com",
michael@0 254 "#http://www.mozilla.org\nhttp://www.xulplanet.com\nhttp://www.example.com",
michael@0 255 0, "uri-list 3 lines");
michael@0 256
michael@0 257 dt.setData("text/uri-list", "#http://www.mozilla.org");
michael@0 258 is(dt.getData("URL"), "", "uri-list commented");
michael@0 259 dt.setData("text/uri-list", "#http://www.mozilla.org\n");
michael@0 260 is(dt.getData("URL"), "", "uri-list commented with newline");
michael@0 261
michael@0 262 // check that clearing the URL type also clears the text/uri-list type
michael@0 263 dt.clearData("URL");
michael@0 264 is(dt.getData("text/uri-list"), "", "clear URL");
michael@0 265
michael@0 266 dt.setData("text/uri-list", "#http://www.mozilla.org\n\n\n\n\n");
michael@0 267 is(dt.getData("URL"), "", "uri-list with blank lines");
michael@0 268 dt.setData("text/uri-list", "");
michael@0 269 is(dt.getData("URL"), "", "empty uri-list");
michael@0 270 dt.setData("text/uri-list", "#http://www.mozilla.org\n#Sample\nhttp://www.xulplanet.com \r\n");
michael@0 271 is(dt.getData("URL"), "http://www.xulplanet.com", "uri-list mix");
michael@0 272 dt.setData("text/uri-list", "\nhttp://www.mozilla.org");
michael@0 273 is(dt.getData("URL"), "", "empty line to start uri-list");
michael@0 274 dt.setData("text/uri-list", " http://www.mozilla.org#anchor ");
michael@0 275 is(dt.getData("URL"), "http://www.mozilla.org#anchor", "uri-list with spaces and hash");
michael@0 276
michael@0 277 // ensure that setDataAt works the same way
michael@0 278 dt.mozSetDataAt("text/uri-list", "#http://www.mozilla.org\n#Sample\nhttp://www.xulplanet.com \r\n", 0);
michael@0 279 checkURL(dt, "http://www.xulplanet.com",
michael@0 280 "#http://www.mozilla.org\n#Sample\nhttp://www.xulplanet.com \r\n",
michael@0 281 0, "uri-list mix setDataAt");
michael@0 282
michael@0 283 // now test adding multiple items to be dragged using the setDataAt method
michael@0 284 dt.clearData();
michael@0 285 dt.mozSetDataAt("text/plain", "First Item", 0);
michael@0 286 dt.mozSetDataAt("text/plain", "Second Item", 1);
michael@0 287 expectError(function() dt.mozSetDataAt("text/plain", "Some Text", 3),
michael@0 288 "IndexSizeError", "setDataAt index too high with two items");
michael@0 289 is(dt.mozItemCount, 2, "setDataAt item itemCount");
michael@0 290 checkOneDataItem(dt, ["text/plain"], ["First Item"], 0, "setDataAt item at index 0");
michael@0 291 checkOneDataItem(dt, ["text/plain"], ["Second Item"], 1, "setDataAt item at index 1");
michael@0 292
michael@0 293 dt.mozSetDataAt("text/html", "<em>First Item</em>", 0);
michael@0 294 dt.mozSetDataAt("text/html", "<em>Second Item</em>", 1);
michael@0 295 is(dt.mozItemCount, 2, "setDataAt two types item itemCount");
michael@0 296 checkOneDataItem(dt, ["text/plain", "text/html"],
michael@0 297 ["First Item", "<em>First Item</em>"], 0, "setDataAt two types item at index 0");
michael@0 298 checkOneDataItem(dt, ["text/plain", "text/html"],
michael@0 299 ["Second Item", "<em>Second Item</em>"], 1, "setDataAt two types item at index 1");
michael@0 300
michael@0 301 dt.mozSetDataAt("text/html", "<em>Changed First Item</em>", 0);
michael@0 302 dt.mozSetDataAt("text/plain", "Changed Second Item", 1);
michael@0 303 is(dt.mozItemCount, 2, "changed with setDataAt item itemCount");
michael@0 304 checkOneDataItem(dt, ["text/plain", "text/html"],
michael@0 305 ["First Item", "<em>Changed First Item</em>"], 0, "changed with setDataAt item at index 0");
michael@0 306 checkOneDataItem(dt, ["text/plain", "text/html"],
michael@0 307 ["Changed Second Item", "<em>Second Item</em>"], 1, "changed with setDataAt item at index 1");
michael@0 308
michael@0 309 dt.setData("text/html", "Changed with setData");
michael@0 310 is(dt.mozItemCount, 2, "changed with setData");
michael@0 311 checkOneDataItem(dt, ["text/plain", "text/html"],
michael@0 312 ["First Item", "Changed with setData"], 0, "changed with setData item at index 0");
michael@0 313 checkOneDataItem(dt, ["text/plain", "text/html"],
michael@0 314 ["Changed Second Item", "<em>Second Item</em>"], 1, "changed with setData item at index 1");
michael@0 315
michael@0 316 dt.mozSetDataAt("application/-moz-node", draggable, 2);
michael@0 317 is(dt.mozItemCount, 3, "setDataAt node itemCount");
michael@0 318 checkOneDataItem(dt, ["application/-moz-node"], [draggable], 2, "setDataAt node item at index 2");
michael@0 319
michael@0 320 dt.mozClearDataAt("text/html", 1);
michael@0 321 is(dt.mozItemCount, 3, "clearDataAt itemCount");
michael@0 322 checkOneDataItem(dt, ["text/plain", "text/html"],
michael@0 323 ["First Item", "Changed with setData"], 0, "clearDataAt item at index 0");
michael@0 324 checkOneDataItem(dt, ["text/plain"], ["Changed Second Item"], 1, "clearDataAt item at index 1");
michael@0 325
michael@0 326 dt.mozClearDataAt("text/plain", 1);
michael@0 327 is(dt.mozItemCount, 2, "clearDataAt last type itemCount");
michael@0 328 checkOneDataItem(dt, ["text/plain", "text/html"],
michael@0 329 ["First Item", "Changed with setData"], 0, "clearDataAt last type at index 0");
michael@0 330 checkOneDataItem(dt, ["application/-moz-node"], [draggable], 1, "clearDataAt last type item at index 2");
michael@0 331 expectError(function() dt.mozGetDataAt("text/plain", 2),
michael@0 332 "IndexSizeError", "getDataAt after item removed index too high");
michael@0 333
michael@0 334 dt.mozSetDataAt("text/unknown", "Unknown type", 2);
michael@0 335 dt.mozSetDataAt("text/unknown", "Unknown type", 1);
michael@0 336 is(dt.mozItemCount, 3, "add unknown type");
michael@0 337 checkOneDataItem(dt, ["application/-moz-node", "text/unknown"],
michael@0 338 [draggable, "Unknown type"], 1, "add unknown type item at index 1");
michael@0 339 checkOneDataItem(dt, ["text/unknown"], ["Unknown type"], 2, "add unknown type item at index 2");
michael@0 340
michael@0 341 dt.mozClearDataAt("", 1);
michael@0 342 is(dt.mozItemCount, 2, "clearDataAt empty string");
michael@0 343 checkOneDataItem(dt, ["text/plain", "text/html"],
michael@0 344 ["First Item", "Changed with setData"], 0, "clearDataAt empty string item at index 0");
michael@0 345 checkOneDataItem(dt, ["text/unknown"],
michael@0 346 ["Unknown type"], 1, "clearDataAt empty string item at index 1");
michael@0 347
michael@0 348 // passing a format that doesn't exist to clearData or clearDataAt should just
michael@0 349 // do nothing
michael@0 350 dt.clearData("text/something");
michael@0 351 dt.mozClearDataAt("text/something", 1);
michael@0 352 is(dt.mozItemCount, 2, "clearData type that does not exist");
michael@0 353 checkOneDataItem(dt, ["text/plain", "text/html"],
michael@0 354 ["First Item", "Changed with setData"], 0, "clearData type that does not exist item at index 0");
michael@0 355 checkOneDataItem(dt, ["text/unknown"],
michael@0 356 ["Unknown type"], 1, "clearData type that does not exist item at index 1");
michael@0 357
michael@0 358 expectError(function() dt.mozClearDataAt("text/plain", 3),
michael@0 359 "IndexSizeError", "clearData index too high with two items");
michael@0 360
michael@0 361 // ensure that clearData() removes all data associated with the first item
michael@0 362 dt.clearData();
michael@0 363 is(dt.mozItemCount, 1, "clearData no argument with multiple items itemCount");
michael@0 364 checkOneDataItem(dt, ["text/unknown"],
michael@0 365 ["Unknown type"], 0, "clearData no argument with multiple items item at index 1");
michael@0 366
michael@0 367 // remove tha remaining data
michael@0 368 dt.mozClearDataAt("", 0);
michael@0 369 is(dt.mozItemCount, 0, "all data cleared");
michael@0 370
michael@0 371 // now check the effectAllowed and dropEffect properties
michael@0 372 is(dt.dropEffect, "none", "initial dropEffect");
michael@0 373 is(dt.effectAllowed, "uninitialized", "initial effectAllowed");
michael@0 374
michael@0 375 ["copy", "none", "link", "", "other", "copyMove", "all", "uninitialized", "move"].forEach(
michael@0 376 function (i) {
michael@0 377 dt.dropEffect = i;
michael@0 378 is(dt.dropEffect, i == "" || i == "other" || i == "copyMove" ||
michael@0 379 i == "all" || i == "uninitialized" ? "link" : i,
michael@0 380 "dropEffect set to " + i);
michael@0 381 is(dt.effectAllowed, "uninitialized", "effectAllowed not modified by dropEffect set to " + i);
michael@0 382 }
michael@0 383 );
michael@0 384
michael@0 385 ["move", "copy", "link", "", "other", "moveCopy", "copyMove",
michael@0 386 "linkMove", "copyLink", "all", "uninitialized", "none"].forEach(
michael@0 387 function (i) {
michael@0 388 dt.effectAllowed = i;
michael@0 389 is(dt.dropEffect, "move", "dropEffect not modified by effectAllowed set to " + i);
michael@0 390 is(dt.effectAllowed, i == "" || i == "other" || i == "moveCopy" ? "link" : i,
michael@0 391 "effectAllowed set to " + i);
michael@0 392 }
michael@0 393 );
michael@0 394 }
michael@0 395
michael@0 396 function doDragStartLink(event)
michael@0 397 {
michael@0 398 var dt = event.dataTransfer;
michael@0 399 checkTypes(dt, ["text/x-moz-url", "text/x-moz-url-data", "text/x-moz-url-desc", "text/uri-list",
michael@0 400 "text/_moz_htmlcontext", "text/_moz_htmlinfo", "text/html", "text/plain"], 0, "initial link");
michael@0 401
michael@0 402 is(dt.mozItemCount, 1, "initial link item count");
michael@0 403 is(dt.getData("text/uri-list"), "http://www.mozilla.org/", "link text/uri-list");
michael@0 404 is(dt.getData("text/plain"), "http://www.mozilla.org/", "link text/plain");
michael@0 405
michael@0 406 event.preventDefault();
michael@0 407
michael@0 408 gExtraDragTests++;
michael@0 409 }
michael@0 410
michael@0 411 function doDragStartImage(event)
michael@0 412 {
michael@0 413 var dataurl = $("image").src;
michael@0 414
michael@0 415 var dt = event.dataTransfer;
michael@0 416 checkTypes(dt, ["text/x-moz-url", "text/x-moz-url-data", "text/x-moz-url-desc", "text/uri-list",
michael@0 417 "text/_moz_htmlcontext", "text/_moz_htmlinfo", "text/html", "text/plain"], 0, "initial image");
michael@0 418
michael@0 419 is(dt.mozItemCount, 1, "initial image item count");
michael@0 420 is(dt.getData("text/uri-list"), dataurl, "image text/uri-list");
michael@0 421 is(dt.getData("text/plain"), dataurl, "image text/plain");
michael@0 422
michael@0 423 event.preventDefault();
michael@0 424
michael@0 425 gExtraDragTests++;
michael@0 426 }
michael@0 427
michael@0 428 function doDragStartInput(event)
michael@0 429 {
michael@0 430 var dt = event.dataTransfer;
michael@0 431 checkTypes(dt, ["text/plain"], 0, "initial input");
michael@0 432
michael@0 433 is(dt.mozItemCount, 1, "initial input item count");
michael@0 434 // is(dt.getData("text/plain"), "Text", "input text/plain");
michael@0 435
michael@0 436 // event.preventDefault();
michael@0 437 }
michael@0 438
michael@0 439 function doDragStartSynthetic(event)
michael@0 440 {
michael@0 441 is(event.type, "dragstart", "synthetic dragstart event type");
michael@0 442
michael@0 443 var dt = event.dataTransfer;
michael@0 444 todo(dt instanceof DataTransfer, "synthetic dragstart dataTransfer is DataTransfer");
michael@0 445 // Uncomment next line once the todo instanceof above is fixed.
michael@0 446 // checkTypes(dt, [], 0, "synthetic dragstart");
michael@0 447
michael@0 448 is(event.detail, 1, "synthetic dragstart detail");
michael@0 449 is(event.screenX, 40, "synthetic dragstart screenX");
michael@0 450 is(event.screenY, 35, "synthetic dragstart screenY");
michael@0 451 is(event.clientX, 20, "synthetic dragstart clientX");
michael@0 452 is(event.clientY, 15, "synthetic dragstart clientY");
michael@0 453 is(event.ctrlKey, false, "synthetic dragstart ctrlKey");
michael@0 454 is(event.altKey, true, "synthetic dragstart altKey");
michael@0 455 is(event.shiftKey, false, "synthetic dragstart shiftKey");
michael@0 456 is(event.metaKey, false, "synthetic dragstart metaKey");
michael@0 457 is(event.button, 0, "synthetic dragstart button ");
michael@0 458 is(event.relatedTarget, null, "synthetic dragstart relatedTarget");
michael@0 459
michael@0 460 // Uncomment next two lines once the todo instanceof above is fixed.
michael@0 461 // dt.setData("text/plain", "Text");
michael@0 462 // is(dt.getData("text/plain"), "Text", "synthetic dragstart data is set after adding");
michael@0 463 }
michael@0 464
michael@0 465 function doDragOverSynthetic(event)
michael@0 466 {
michael@0 467 is(event.type, "dragover", "synthetic dragover event type");
michael@0 468
michael@0 469 var dt = event.dataTransfer;
michael@0 470 todo(dt instanceof DataTransfer, "synthetic dragover dataTransfer is DataTransfer");
michael@0 471 // Uncomment next line once the todo instanceof above is fixed.
michael@0 472 // checkTypes(dt, [], 0, "synthetic dragover");
michael@0 473
michael@0 474 is(event.detail, 0, "synthetic dragover detail");
michael@0 475 is(event.screenX, 40, "synthetic dragover screenX");
michael@0 476 is(event.screenY, 35, "synthetic dragover screenY");
michael@0 477 is(event.clientX, 20, "synthetic dragover clientX");
michael@0 478 is(event.clientY, 15, "synthetic dragover clientY");
michael@0 479 is(event.ctrlKey, true, "synthetic dragover ctrlKey");
michael@0 480 is(event.altKey, false, "synthetic dragover altKey");
michael@0 481 is(event.shiftKey, true, "synthetic dragover shiftKey");
michael@0 482 is(event.metaKey, true, "synthetic dragover metaKey");
michael@0 483 is(event.button, 2, "synthetic dragover button");
michael@0 484 is(event.relatedTarget, document.documentElement, "synthetic dragover relatedTarget");
michael@0 485
michael@0 486 // Uncomment next two lines once the todo instanceof above is fixed.
michael@0 487 // dt.setData("text/plain", "Text");
michael@0 488 // is(dt.getData("text/plain"), "Text", "synthetic dragover data is set after adding");
michael@0 489 }
michael@0 490
michael@0 491 function onDragStartDraggable(event)
michael@0 492 {
michael@0 493 var dt = event.dataTransfer;
michael@0 494 ok(dt.mozItemCount == 0 && dt.types.length == 0 && event.originalTarget == gDragInfo.target, gDragInfo.testid);
michael@0 495
michael@0 496 gExtraDragTests++;
michael@0 497 }
michael@0 498
michael@0 499 function checkOneDataItem(dt, expectedtypes, expecteddata, index, testid)
michael@0 500 {
michael@0 501 checkTypes(dt, expectedtypes, index, testid);
michael@0 502 for (var f = 0; f < expectedtypes.length; f++) {
michael@0 503 if (index == 0)
michael@0 504 is(dt.getData(expectedtypes[f]), expecteddata[f], testid + " getData " + expectedtypes[f]);
michael@0 505 is(dt.mozGetDataAt(expectedtypes[f], index), expecteddata[f] ? expecteddata[f] : null,
michael@0 506 testid + " getDataAt " + expectedtypes[f]);
michael@0 507 }
michael@0 508 }
michael@0 509
michael@0 510 function checkTypes(dt, expectedtypes, index, testid)
michael@0 511 {
michael@0 512 if (index == 0) {
michael@0 513 var types = dt.types;
michael@0 514 is(types.length, expectedtypes.length, testid + " types length");
michael@0 515 for (var f = 0; f < expectedtypes.length; f++) {
michael@0 516 is(types[f], expectedtypes[f], testid + " " + types[f] + " check");
michael@0 517 }
michael@0 518 }
michael@0 519
michael@0 520 types = dt.mozTypesAt(index);
michael@0 521 is(types.length, expectedtypes.length, testid + " typesAt length");
michael@0 522 for (var f = 0; f < expectedtypes.length; f++) {
michael@0 523 is(types[f], expectedtypes[f], testid + " " + types[f] + " at " + index + " check");
michael@0 524 }
michael@0 525 }
michael@0 526
michael@0 527 function checkURL(dt, url, fullurllist, index, testid)
michael@0 528 {
michael@0 529 is(dt.getData("text/uri-list"), fullurllist, testid + " text/uri-list");
michael@0 530 is(dt.getData("URL"), url, testid + " URL");
michael@0 531 is(dt.mozGetDataAt("text/uri-list", 0), fullurllist, testid + " text/uri-list");
michael@0 532 is(dt.mozGetDataAt("URL", 0), fullurllist, testid + " URL");
michael@0 533 }
michael@0 534
michael@0 535 function expectError(fn, eid, testid)
michael@0 536 {
michael@0 537 var error = "";
michael@0 538 try {
michael@0 539 fn();
michael@0 540 } catch (ex) {
michael@0 541 error = ex.name;
michael@0 542 }
michael@0 543 is(error, eid, testid + " causes exception " + eid);
michael@0 544 }
michael@0 545
michael@0 546 </script>
michael@0 547
michael@0 548 </head>
michael@0 549
michael@0 550 <body style="height: 300px; overflow: auto;" onload="setTimeout(runTests, 0)">
michael@0 551
michael@0 552 <div id="draggable" ondragstart="doDragStartSelection(event)">This is a <em>draggable</em> bit of text.</div>
michael@0 553
michael@0 554 <fieldset>
michael@0 555 <a id="link" href="http://www.mozilla.org/" ondragstart="doDragStartLink(event)">mozilla.org</a>
michael@0 556 </fieldset>
michael@0 557
michael@0 558 <label>
michael@0 559 <img id="image" src="data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%18%00%00%00%18%02%03%00%00%00%9D%19%D5k%00%00%00%04gAMA%00%00%B1%8F%0B%FCa%05%00%00%00%0CPLTE%FF%FF%FF%FF%FF%FF%F7%DC%13%00%00%00%03%80%01X%00%00%00%01tRNS%08N%3DPT%00%00%00%01bKGD%00%88%05%1DH%00%00%00%09pHYs%00%00%0B%11%00%00%0B%11%01%7Fd_%91%00%00%00%07tIME%07%D2%05%0C%14%0C%0D%D8%3F%1FQ%00%00%00%5CIDATx%9C%7D%8E%CB%09%C0%20%10D%07r%B7%20%2F%E9wV0%15h%EA%D9%12D4%BB%C1x%CC%5C%1E%0C%CC%07%C0%9C0%9Dd7()%C0A%D3%8D%E0%B8%10%1DiCHM%D0%AC%D2d%C3M%F1%B4%E7%FF%10%0BY%AC%25%93%CD%CBF%B5%B2%C0%3Alh%CD%AE%13%DF%A5%F7%E0%03byW%09A%B4%F3%E2%00%00%00%00IEND%AEB%60%82"
michael@0 560 ondragstart="doDragStartImage(event)">
michael@0 561 </label>
michael@0 562
michael@0 563 <input id="input" value="Text in a box" ondragstart="doDragStartInput(event)">
michael@0 564
michael@0 565 <div ondragstart="onDragStartDraggable(event)">
michael@0 566 <div id="dragtrue" draggable="true">
michael@0 567 This is a <span id="spantrue">draggable</span> area.
michael@0 568 </div>
michael@0 569 <div id="dragfalse" draggable="false">
michael@0 570 This is a <span id="spanfalse">non-draggable</span> area.
michael@0 571 </div>
michael@0 572 </div>
michael@0 573
michael@0 574 <!--iframe src="http://www.mozilla.org" width="400" height="400"></iframe-->
michael@0 575
michael@0 576 <div id="synthetic" ondragstart="doDragStartSynthetic(event)">Synthetic Event Dispatch</div>
michael@0 577 <div id="synthetic2" ondragover="doDragOverSynthetic(event)">Synthetic Event Dispatch</div>
michael@0 578
michael@0 579 </body>
michael@0 580 </html>

mercurial