dom/events/test/test_dragstart.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/test/test_dragstart.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,580 @@
     1.4 +<html>
     1.5 +<head>
     1.6 +  <title>Tests for the dragstart event</title>
     1.7 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
     1.8 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>      
     1.9 +  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>      
    1.10 +
    1.11 +<!--
    1.12 + This test checks the dragstart event and the DataTransfer object
    1.13 +  -->
    1.14 + 
    1.15 +<script>
    1.16 +
    1.17 +SimpleTest.waitForExplicitFinish();
    1.18 +
    1.19 +var gDragInfo;
    1.20 +var gDataTransfer = null;
    1.21 +var gExtraDragTests = 0;
    1.22 +
    1.23 +function runTests()
    1.24 +{
    1.25 +  // first, create a selection and try dragging it
    1.26 +  var draggable = $("draggable");
    1.27 +  window.getSelection().selectAllChildren(draggable);
    1.28 +  synthesizeMouse(draggable, 6, 6, { type: "mousedown" });
    1.29 +  synthesizeMouse(draggable, 14, 14, { type: "mousemove" });
    1.30 +  // drags are asynchronous on Linux, so this extra event is needed to make
    1.31 +  // sure the drag gets processed
    1.32 +  synthesizeMouse(draggable, 15, 15, { type: "mousemove" });
    1.33 +}
    1.34 +
    1.35 +function afterDragTests()
    1.36 +{
    1.37 +  // the dragstart should have occurred due to moving the mouse. gDataTransfer
    1.38 +  // caches the dataTransfer that was used, however it should now be empty and
    1.39 +  // be read only.
    1.40 +  ok(gDataTransfer instanceof DataTransfer, "DataTransfer after dragstart event");
    1.41 +  checkTypes(gDataTransfer, [], 0, "after dragstart event");
    1.42 +
    1.43 +  expectError(function() gDataTransfer.setData("text/plain", "Some Text"),
    1.44 +              "NoModificationAllowedError", "setData when read only");
    1.45 +  expectError(function() gDataTransfer.clearData("text/plain"),
    1.46 +              "NoModificationAllowedError", "clearData when read only");
    1.47 +  expectError(function() gDataTransfer.mozSetDataAt("text/plain", "Some Text", 0),
    1.48 +              "NoModificationAllowedError", "setDataAt when read only");
    1.49 +  expectError(function() gDataTransfer.mozClearDataAt("text/plain", 0),
    1.50 +              "NoModificationAllowedError", "clearDataAt when read only");
    1.51 +  expectError(function() gDataTransfer.setDragImage(draggable, 10, 10),
    1.52 +              "NoModificationAllowedError", "setDragImage when read only");
    1.53 +  expectError(function() gDataTransfer.addElement(draggable),
    1.54 +              "NoModificationAllowedError", "addElement when read only");
    1.55 +
    1.56 +  var evt = document.createEvent("dragevent");
    1.57 +  ok(evt instanceof DragEvent, "synthetic dragevent class")
    1.58 +  ok(evt instanceof MouseEvent, "synthetic event inherits from MouseEvent")
    1.59 +  evt.initDragEvent("dragstart", true, true, window, 1, 40, 35, 20, 15,
    1.60 +                    false, true, false, false, 0, null, null);
    1.61 +  $("synthetic").dispatchEvent(evt);
    1.62 +
    1.63 +  var evt = document.createEvent("dragevents");
    1.64 +  ok(evt instanceof DragEvent, "synthetic dragevents class")
    1.65 +  evt.initDragEvent("dragover", true, true, window, 0, 40, 35, 20, 15,
    1.66 +                    true, false, true, true, 2, document.documentElement, null);
    1.67 +  $("synthetic2").dispatchEvent(evt);
    1.68 +
    1.69 +  // next, dragging links and images
    1.70 +  sendMouseEventsForDrag("link");
    1.71 +  sendMouseEventsForDrag("image");
    1.72 +
    1.73 +//  disable testing input dragging for now, as it doesn't seem to be testable 
    1.74 +//  draggable = $("input");
    1.75 +//  draggable.setSelectionRange(0, 4);
    1.76 +//  synthesizeMouse(draggable, 8, 8, { type: "mousedown" });
    1.77 +//  synthesizeMouse(draggable, 15, 15, { type: "mousemove" });
    1.78 +//  sendMouseEventsForDrag("input");
    1.79 +
    1.80 +  // next, check if the draggable attribute can be used to adjust the drag target
    1.81 +  gDragInfo = { target: $("dragtrue"), testid: "draggable true node" };
    1.82 +  sendMouseEventsForDrag("dragtrue");
    1.83 +  gDragInfo = { target: $("dragtrue"), testid: "draggable true child" };
    1.84 +  sendMouseEventsForDrag("spantrue");
    1.85 +  gDragInfo = { target: $("dragfalse").firstChild, testid: "draggable false node" };
    1.86 +  sendMouseEventsForDrag("dragfalse");
    1.87 +  gDragInfo = { target: $("spanfalse").firstChild, testid: "draggable false child" };
    1.88 +  sendMouseEventsForDrag("spanfalse");
    1.89 +
    1.90 +  synthesizeMouse(draggable, 12, 12, { type: "mouseup" });
    1.91 +  if (gExtraDragTests == 4)
    1.92 +    SimpleTest.finish();
    1.93 +}
    1.94 +
    1.95 +function sendMouseEventsForDrag(nodeid)
    1.96 +{
    1.97 +  var draggable = $(nodeid);
    1.98 +  synthesizeMouse(draggable, 3, 3, { type: "mousedown" });
    1.99 +  synthesizeMouse(draggable, 10, 10, { type: "mousemove" });
   1.100 +  synthesizeMouse(draggable, 12, 12, { type: "mousemove" });
   1.101 +}
   1.102 +
   1.103 +function doDragStartSelection(event)
   1.104 +{
   1.105 +  is(event.type, "dragstart", "dragstart event type");
   1.106 +  is(event.target, $("draggable").firstChild, "dragstart event target");
   1.107 +  is(event.bubbles, true, "dragstart event bubbles");
   1.108 +  is(event.cancelable, true, "dragstart event cancelable");
   1.109 +
   1.110 +  is(event.clientX, 14, "dragstart clientX");
   1.111 +  is(event.clientY, 14, "dragstart clientY");
   1.112 +  ok(event.screenX > 0, "dragstart screenX");
   1.113 +  ok(event.screenY > 0, "dragstart screenY");
   1.114 +  is(event.layerX, 14, "dragstart layerX");
   1.115 +  is(event.layerY, 14, "dragstart layerY");
   1.116 +  is(event.pageX, 14, "dragstart pageX");
   1.117 +  is(event.pageY, 14, "dragstart pageY");
   1.118 +
   1.119 +  var dt = event.dataTransfer;
   1.120 +  ok(dt instanceof DataTransfer, "dataTransfer is DataTransfer");
   1.121 +  gDataTransfer = dt;
   1.122 +
   1.123 +  var types = dt.types;
   1.124 +  is(types instanceof DOMStringList, true, "initial types is a DOMStringList");
   1.125 +  checkTypes(dt, ["text/_moz_htmlcontext", "text/_moz_htmlinfo", "text/html", "text/plain"], 0, "initial selection");
   1.126 +
   1.127 +  is(dt.getData("text/plain"), "This is a draggable bit of text.", "initial selection text/plain");
   1.128 +  is(dt.getData("text/html"), "<div id=\"draggable\" ondragstart=\"doDragStartSelection(event)\">This is a <em>draggable</em> bit of text.</div>",
   1.129 +     "initial selection text/html");
   1.130 +
   1.131 +  // text/unicode and Text are available for compatibility. They retrieve the
   1.132 +  // text/plain data
   1.133 +  is(dt.getData("text/unicode"), "This is a draggable bit of text.", "initial selection text/unicode");
   1.134 +  is(dt.getData("Text"), "This is a draggable bit of text.", "initial selection Text");
   1.135 +  is(dt.getData("TEXT"), "This is a draggable bit of text.", "initial selection TEXT");
   1.136 +  is(dt.getData("text/UNICODE"), "This is a draggable bit of text.", "initial selection text/UNICODE"); 
   1.137 +
   1.138 +  is(dt.mozItemCount, 1, "initial selection item count");
   1.139 +
   1.140 +  dt.clearData("text/plain");
   1.141 +  dt.clearData("text/html");
   1.142 +  dt.clearData("text/_moz_htmlinfo");
   1.143 +  dt.clearData("text/_moz_htmlcontext");
   1.144 +
   1.145 +  test_DataTransfer(dt);
   1.146 +  setTimeout(afterDragTests, 0);
   1.147 +}
   1.148 +
   1.149 +function test_DataTransfer(dt)
   1.150 +{
   1.151 +  is(dt.mozItemCount, 0, "empty itemCount");
   1.152 +
   1.153 +  var types = dt.types;
   1.154 +  is(types instanceof DOMStringList, true, "empty types is a DOMStringList");
   1.155 +  checkTypes(dt, [], 0, "empty");
   1.156 +  is(dt.getData("text/plain"), "", "empty data is empty");
   1.157 +
   1.158 +  // calling setDataAt requires an index that is 0 <= index <= dt.itemCount
   1.159 +  expectError(function() dt.mozSetDataAt("text/plain", "Some Text", 1),
   1.160 +              "IndexSizeError", "setDataAt index too high");
   1.161 +
   1.162 +  is(dt.mozUserCancelled, false, "userCancelled");
   1.163 +
   1.164 +  // because an exception occurred, the data should not have been added
   1.165 +  is(dt.mozItemCount, 0, "empty setDataAt index too high itemCount");
   1.166 +  dt.getData("text/plain", "", "empty setDataAt index too high getData");
   1.167 +
   1.168 +  // if the type is '', do nothing, or return ''
   1.169 +  dt.setData("", "Invalid Type");
   1.170 +  is(dt.types.length, 0, "invalid type setData");
   1.171 +  is(dt.getData(""), "", "invalid type getData"),
   1.172 +  dt.mozSetDataAt("", "Invalid Type", 0);
   1.173 +  is(dt.types.length, 0, "invalid type setDataAt");
   1.174 +  is(dt.mozGetDataAt("", 0), null, "invalid type getDataAt"),
   1.175 +
   1.176 +  // similar with clearDataAt and getDataAt
   1.177 +  expectError(function() dt.mozGetDataAt("text/plain", 1),
   1.178 +              "IndexSizeError", "getDataAt index too high");
   1.179 +  expectError(function() dt.mozClearDataAt("text/plain", 1),
   1.180 +              "IndexSizeError", "clearDataAt index too high");
   1.181 +
   1.182 +  dt.setData("text/plain", "Sample Text");
   1.183 +  is(dt.mozItemCount, 1, "added plaintext itemCount");
   1.184 +  checkOneDataItem(dt, ["text/plain"], ["Sample Text"], 0, "added plaintext");
   1.185 +
   1.186 +   // after all those exceptions, the data should still be the same
   1.187 +  checkOneDataItem(dt, ["text/plain"], ["Sample Text"], 0, "added plaintext after exception");
   1.188 +
   1.189 +  // modifying the data associated with the format should give it the new value
   1.190 +  dt.setData("text/plain", "Modified Text");
   1.191 +  is(dt.mozItemCount, 1, "modified plaintext itemCount");
   1.192 +  checkOneDataItem(dt, ["text/plain"], ["Modified Text"], 0, "modified plaintext");
   1.193 +
   1.194 +  dt.setData("text/html", "<strong>Modified Text</strong>");
   1.195 +  is(dt.mozItemCount, 1, "modified html itemCount");
   1.196 +  checkOneDataItem(dt, ["text/plain", "text/html"],
   1.197 +                       ["Modified Text", "<strong>Modified Text</strong>"],
   1.198 +                       0, "modified html");
   1.199 +
   1.200 +  // modifying data for a type that already exists should adjust it in place,
   1.201 +  // not reinsert it at the beginning
   1.202 +  dt.setData("text/plain", "New Text");
   1.203 +  is(dt.mozItemCount, 1, "modified text again itemCount");
   1.204 +  checkOneDataItem(dt, ["text/plain", "text/html"],
   1.205 +                       ["New Text", "<strong>Modified Text</strong>"],
   1.206 +                       0, "modified text again");
   1.207 +
   1.208 +  var draggable = $("draggable");
   1.209 +  dt.setData("application/-moz-node", draggable);
   1.210 +  checkOneDataItem(dt, ["text/plain", "text/html", "application/-moz-node"],
   1.211 +                       ["New Text", "<strong>Modified Text</strong>", draggable],
   1.212 +                       0, "added node");
   1.213 +
   1.214 +  dt.clearData(""); // null means clear all
   1.215 +  is(dt.mozItemCount, 0, "itemCount after clearData empty string");
   1.216 +  checkTypes(dt, [], 0, "empty after clearData empty string");
   1.217 +  
   1.218 +  dt.setData("text/plain", 22);
   1.219 +  dt.setData("text/html", 5.6);
   1.220 +  dt.setData("text/xml", 5.6);
   1.221 +  checkTypes(dt, ["text/plain", "text/html", "text/xml"], ["22", "5.6", ""], 0, "add numeric and empty data");
   1.222 +
   1.223 +  dt.clearData(); // no argument means clear all
   1.224 +  is(dt.mozItemCount, 0, "itemCount after clearData no argument");
   1.225 +  checkTypes(dt, [], 0, "empty after clearData no argument");
   1.226 +
   1.227 +  // check 'Text' type which should convert into text/plain
   1.228 +  dt.setData("Text", "Sample Text");
   1.229 +  checkOneDataItem(dt, ["text/plain"], ["Sample Text"], 0, "set Text");
   1.230 +  is(dt.getData("Text"), "Sample Text", "getData Text");
   1.231 +  is(dt.mozGetDataAt("Text", 0), "Sample Text", "getDataAt Text");
   1.232 +  dt.setData("text/plain", "More Text");
   1.233 +  checkOneDataItem(dt, ["text/plain"], ["More Text"], 0, "set text/plain after set Text");
   1.234 +
   1.235 +  dt.mozClearDataAt("", 0); // null means clear all
   1.236 +  is(dt.mozItemCount, 0, "itemCount after clearDataAt empty string");
   1.237 +  checkTypes(dt, [], 0, "empty after clearDataAt empty string");
   1.238 +
   1.239 +  // check text/uri-list type
   1.240 +  dt.setData("text/uri-list", "http://www.mozilla.org");
   1.241 +  checkURL(dt, "http://www.mozilla.org", "http://www.mozilla.org", 0, "set text/uri-list");
   1.242 +
   1.243 +  // check URL type which should add text/uri-list data
   1.244 +  dt.setData("URL", "ftp://ftp.example.com");
   1.245 +  checkURL(dt, "ftp://ftp.example.com", "ftp://ftp.example.com", 0, "set URL");
   1.246 +  checkTypes(dt, ["text/uri-list"], ["ftp://ftp.example.com"], "url types");
   1.247 +
   1.248 +  // clearing text/uri-list data
   1.249 +  dt.clearData("text/uri-list");
   1.250 +  is(dt.mozItemCount, 0, "itemCount after clear url-list");
   1.251 +  is(dt.getData("text/uri-list"), "", "text/uri-list after clear url-list");
   1.252 +  is(dt.getData("URL"), "", "URL after clear url-list");
   1.253 +
   1.254 +  // check text/uri-list parsing
   1.255 +  dt.setData("text/uri-list", "#http://www.mozilla.org\nhttp://www.xulplanet.com\nhttp://www.example.com");
   1.256 +  checkURL(dt, "http://www.xulplanet.com",
   1.257 +           "#http://www.mozilla.org\nhttp://www.xulplanet.com\nhttp://www.example.com",
   1.258 +           0, "uri-list 3 lines");
   1.259 +
   1.260 +  dt.setData("text/uri-list", "#http://www.mozilla.org");
   1.261 +  is(dt.getData("URL"), "", "uri-list commented");
   1.262 +  dt.setData("text/uri-list", "#http://www.mozilla.org\n");
   1.263 +  is(dt.getData("URL"), "", "uri-list commented with newline");
   1.264 +
   1.265 +  // check that clearing the URL type also clears the text/uri-list type
   1.266 +  dt.clearData("URL");
   1.267 +  is(dt.getData("text/uri-list"), "", "clear URL");
   1.268 +
   1.269 +  dt.setData("text/uri-list", "#http://www.mozilla.org\n\n\n\n\n");
   1.270 +  is(dt.getData("URL"), "", "uri-list with blank lines");
   1.271 +  dt.setData("text/uri-list", "");
   1.272 +  is(dt.getData("URL"), "", "empty uri-list");
   1.273 +  dt.setData("text/uri-list", "#http://www.mozilla.org\n#Sample\nhttp://www.xulplanet.com  \r\n");
   1.274 +  is(dt.getData("URL"), "http://www.xulplanet.com", "uri-list mix");
   1.275 +  dt.setData("text/uri-list", "\nhttp://www.mozilla.org");
   1.276 +  is(dt.getData("URL"), "", "empty line to start uri-list");
   1.277 +  dt.setData("text/uri-list", "  http://www.mozilla.org#anchor  ");
   1.278 +  is(dt.getData("URL"), "http://www.mozilla.org#anchor", "uri-list with spaces and hash");
   1.279 +
   1.280 +  // ensure that setDataAt works the same way
   1.281 +  dt.mozSetDataAt("text/uri-list", "#http://www.mozilla.org\n#Sample\nhttp://www.xulplanet.com  \r\n", 0);
   1.282 +  checkURL(dt, "http://www.xulplanet.com",
   1.283 +           "#http://www.mozilla.org\n#Sample\nhttp://www.xulplanet.com  \r\n",
   1.284 +           0, "uri-list mix setDataAt");
   1.285 +
   1.286 +  // now test adding multiple items to be dragged using the setDataAt method
   1.287 +  dt.clearData();
   1.288 +  dt.mozSetDataAt("text/plain", "First Item", 0);
   1.289 +  dt.mozSetDataAt("text/plain", "Second Item", 1);
   1.290 +  expectError(function() dt.mozSetDataAt("text/plain", "Some Text", 3),
   1.291 +              "IndexSizeError", "setDataAt index too high with two items");
   1.292 +  is(dt.mozItemCount, 2, "setDataAt item itemCount");
   1.293 +  checkOneDataItem(dt, ["text/plain"], ["First Item"], 0, "setDataAt item at index 0");
   1.294 +  checkOneDataItem(dt, ["text/plain"], ["Second Item"], 1, "setDataAt item at index 1");
   1.295 +
   1.296 +  dt.mozSetDataAt("text/html", "<em>First Item</em>", 0);
   1.297 +  dt.mozSetDataAt("text/html", "<em>Second Item</em>", 1);
   1.298 +  is(dt.mozItemCount, 2, "setDataAt two types item itemCount");
   1.299 +  checkOneDataItem(dt, ["text/plain", "text/html"],
   1.300 +                   ["First Item", "<em>First Item</em>"], 0, "setDataAt two types item at index 0");
   1.301 +  checkOneDataItem(dt, ["text/plain", "text/html"],
   1.302 +                   ["Second Item", "<em>Second Item</em>"], 1, "setDataAt two types item at index 1");
   1.303 +
   1.304 +  dt.mozSetDataAt("text/html", "<em>Changed First Item</em>", 0);
   1.305 +  dt.mozSetDataAt("text/plain", "Changed Second Item", 1);
   1.306 +  is(dt.mozItemCount, 2, "changed with setDataAt item itemCount");
   1.307 +  checkOneDataItem(dt, ["text/plain", "text/html"],
   1.308 +                   ["First Item", "<em>Changed First Item</em>"], 0, "changed with setDataAt item at index 0");
   1.309 +  checkOneDataItem(dt, ["text/plain", "text/html"],
   1.310 +                   ["Changed Second Item", "<em>Second Item</em>"], 1, "changed with setDataAt item at index 1");
   1.311 +
   1.312 +  dt.setData("text/html", "Changed with setData");
   1.313 +  is(dt.mozItemCount, 2, "changed with setData");
   1.314 +  checkOneDataItem(dt, ["text/plain", "text/html"],
   1.315 +                   ["First Item", "Changed with setData"], 0, "changed with setData item at index 0");
   1.316 +  checkOneDataItem(dt, ["text/plain", "text/html"],
   1.317 +                   ["Changed Second Item", "<em>Second Item</em>"], 1, "changed with setData item at index 1");
   1.318 +
   1.319 +  dt.mozSetDataAt("application/-moz-node", draggable, 2);
   1.320 +  is(dt.mozItemCount, 3, "setDataAt node itemCount");
   1.321 +  checkOneDataItem(dt, ["application/-moz-node"], [draggable], 2, "setDataAt node item at index 2");
   1.322 +
   1.323 +  dt.mozClearDataAt("text/html", 1);
   1.324 +  is(dt.mozItemCount, 3, "clearDataAt itemCount");
   1.325 +  checkOneDataItem(dt, ["text/plain", "text/html"],
   1.326 +                   ["First Item", "Changed with setData"], 0, "clearDataAt item at index 0");
   1.327 +  checkOneDataItem(dt, ["text/plain"], ["Changed Second Item"], 1, "clearDataAt item at index 1");
   1.328 +
   1.329 +  dt.mozClearDataAt("text/plain", 1);
   1.330 +  is(dt.mozItemCount, 2, "clearDataAt last type itemCount");
   1.331 +  checkOneDataItem(dt, ["text/plain", "text/html"],
   1.332 +                   ["First Item", "Changed with setData"], 0, "clearDataAt last type at index 0");
   1.333 +  checkOneDataItem(dt, ["application/-moz-node"], [draggable], 1, "clearDataAt last type item at index 2");
   1.334 +  expectError(function() dt.mozGetDataAt("text/plain", 2),
   1.335 +              "IndexSizeError", "getDataAt after item removed index too high");
   1.336 +
   1.337 +  dt.mozSetDataAt("text/unknown", "Unknown type", 2);
   1.338 +  dt.mozSetDataAt("text/unknown", "Unknown type", 1);
   1.339 +  is(dt.mozItemCount, 3, "add unknown type");
   1.340 +  checkOneDataItem(dt, ["application/-moz-node", "text/unknown"],
   1.341 +                   [draggable, "Unknown type"], 1, "add unknown type item at index 1");
   1.342 +  checkOneDataItem(dt, ["text/unknown"], ["Unknown type"], 2, "add unknown type item at index 2");
   1.343 +
   1.344 +  dt.mozClearDataAt("", 1);
   1.345 +  is(dt.mozItemCount, 2, "clearDataAt empty string");
   1.346 +  checkOneDataItem(dt, ["text/plain", "text/html"],
   1.347 +                   ["First Item", "Changed with setData"], 0, "clearDataAt empty string item at index 0");
   1.348 +  checkOneDataItem(dt, ["text/unknown"],
   1.349 +                   ["Unknown type"], 1, "clearDataAt empty string item at index 1");
   1.350 +
   1.351 +  // passing a format that doesn't exist to clearData or clearDataAt should just
   1.352 +  // do nothing
   1.353 +  dt.clearData("text/something");
   1.354 +  dt.mozClearDataAt("text/something", 1);
   1.355 +  is(dt.mozItemCount, 2, "clearData type that does not exist");
   1.356 +  checkOneDataItem(dt, ["text/plain", "text/html"],
   1.357 +                   ["First Item", "Changed with setData"], 0, "clearData type that does not exist item at index 0");
   1.358 +  checkOneDataItem(dt, ["text/unknown"],
   1.359 +                   ["Unknown type"], 1, "clearData type that does not exist item at index 1");
   1.360 +
   1.361 +  expectError(function() dt.mozClearDataAt("text/plain", 3),
   1.362 +              "IndexSizeError", "clearData index too high with two items");
   1.363 +
   1.364 +  // ensure that clearData() removes all data associated with the first item
   1.365 +  dt.clearData();
   1.366 +  is(dt.mozItemCount, 1, "clearData no argument with multiple items itemCount");
   1.367 +  checkOneDataItem(dt, ["text/unknown"],
   1.368 +                   ["Unknown type"], 0, "clearData no argument with multiple items item at index 1");
   1.369 +
   1.370 +  // remove tha remaining data
   1.371 +  dt.mozClearDataAt("", 0);
   1.372 +  is(dt.mozItemCount, 0, "all data cleared");
   1.373 +
   1.374 +  // now check the effectAllowed and dropEffect properties
   1.375 +  is(dt.dropEffect, "none", "initial dropEffect");
   1.376 +  is(dt.effectAllowed, "uninitialized", "initial effectAllowed");
   1.377 +
   1.378 +  ["copy", "none", "link", "", "other", "copyMove", "all", "uninitialized", "move"].forEach(
   1.379 +    function (i) {
   1.380 +      dt.dropEffect = i;
   1.381 +      is(dt.dropEffect, i == "" || i == "other" || i == "copyMove" ||
   1.382 +                        i == "all" || i == "uninitialized" ? "link" : i,
   1.383 +         "dropEffect set to " + i);
   1.384 +      is(dt.effectAllowed, "uninitialized", "effectAllowed not modified by dropEffect set to " + i);
   1.385 +    }
   1.386 +  );
   1.387 +
   1.388 +  ["move", "copy", "link", "", "other", "moveCopy", "copyMove",
   1.389 +   "linkMove", "copyLink", "all", "uninitialized", "none"].forEach(
   1.390 +    function (i) {
   1.391 +      dt.effectAllowed = i;
   1.392 +      is(dt.dropEffect, "move", "dropEffect not modified by effectAllowed set to " + i);
   1.393 +      is(dt.effectAllowed, i == "" || i == "other" || i == "moveCopy" ? "link" : i,
   1.394 +         "effectAllowed set to " + i);
   1.395 +    }
   1.396 +  );
   1.397 +}
   1.398 +
   1.399 +function doDragStartLink(event)
   1.400 +{
   1.401 +  var dt = event.dataTransfer;
   1.402 +  checkTypes(dt, ["text/x-moz-url", "text/x-moz-url-data", "text/x-moz-url-desc", "text/uri-list",
   1.403 +                  "text/_moz_htmlcontext", "text/_moz_htmlinfo", "text/html", "text/plain"], 0, "initial link");
   1.404 +
   1.405 +  is(dt.mozItemCount, 1, "initial link item count");
   1.406 +  is(dt.getData("text/uri-list"), "http://www.mozilla.org/", "link text/uri-list");
   1.407 +  is(dt.getData("text/plain"), "http://www.mozilla.org/", "link text/plain");
   1.408 +
   1.409 +  event.preventDefault();
   1.410 +
   1.411 +  gExtraDragTests++;
   1.412 +}
   1.413 +
   1.414 +function doDragStartImage(event)
   1.415 +{
   1.416 +  var dataurl = $("image").src;
   1.417 +
   1.418 +  var dt = event.dataTransfer;
   1.419 +  checkTypes(dt, ["text/x-moz-url", "text/x-moz-url-data", "text/x-moz-url-desc", "text/uri-list",
   1.420 +                  "text/_moz_htmlcontext", "text/_moz_htmlinfo", "text/html", "text/plain"], 0, "initial image");
   1.421 +
   1.422 +  is(dt.mozItemCount, 1, "initial image item count");
   1.423 +  is(dt.getData("text/uri-list"), dataurl, "image text/uri-list");
   1.424 +  is(dt.getData("text/plain"), dataurl, "image text/plain");
   1.425 +
   1.426 +  event.preventDefault();
   1.427 +
   1.428 +  gExtraDragTests++;
   1.429 +}
   1.430 +
   1.431 +function doDragStartInput(event)
   1.432 +{
   1.433 +  var dt = event.dataTransfer;
   1.434 +  checkTypes(dt, ["text/plain"], 0, "initial input");
   1.435 +
   1.436 +  is(dt.mozItemCount, 1, "initial input item count");
   1.437 +//  is(dt.getData("text/plain"), "Text", "input text/plain");
   1.438 +
   1.439 +//  event.preventDefault();
   1.440 +}
   1.441 +
   1.442 +function doDragStartSynthetic(event)
   1.443 +{
   1.444 +  is(event.type, "dragstart", "synthetic dragstart event type");
   1.445 +
   1.446 +  var dt = event.dataTransfer;
   1.447 +  todo(dt instanceof DataTransfer, "synthetic dragstart dataTransfer is DataTransfer");
   1.448 +//  Uncomment next line once the todo instanceof above is fixed.
   1.449 +//  checkTypes(dt, [], 0, "synthetic dragstart");
   1.450 +
   1.451 +  is(event.detail, 1, "synthetic dragstart detail");
   1.452 +  is(event.screenX, 40, "synthetic dragstart screenX");
   1.453 +  is(event.screenY, 35, "synthetic dragstart screenY");
   1.454 +  is(event.clientX, 20, "synthetic dragstart clientX");
   1.455 +  is(event.clientY, 15, "synthetic dragstart clientY");
   1.456 +  is(event.ctrlKey, false, "synthetic dragstart ctrlKey");
   1.457 +  is(event.altKey, true, "synthetic dragstart altKey");
   1.458 +  is(event.shiftKey, false, "synthetic dragstart shiftKey");
   1.459 +  is(event.metaKey, false, "synthetic dragstart metaKey");
   1.460 +  is(event.button, 0, "synthetic dragstart button ");
   1.461 +  is(event.relatedTarget, null, "synthetic dragstart relatedTarget");
   1.462 +
   1.463 +//  Uncomment next two lines once the todo instanceof above is fixed.
   1.464 +//  dt.setData("text/plain", "Text");
   1.465 +//  is(dt.getData("text/plain"), "Text", "synthetic dragstart data is set after adding");
   1.466 +}
   1.467 +
   1.468 +function doDragOverSynthetic(event)
   1.469 +{
   1.470 +  is(event.type, "dragover", "synthetic dragover event type");
   1.471 +
   1.472 +  var dt = event.dataTransfer;
   1.473 +  todo(dt instanceof DataTransfer, "synthetic dragover dataTransfer is DataTransfer");
   1.474 +//  Uncomment next line once the todo instanceof above is fixed.
   1.475 +// checkTypes(dt, [], 0, "synthetic dragover");
   1.476 +
   1.477 +  is(event.detail, 0, "synthetic dragover detail");
   1.478 +  is(event.screenX, 40, "synthetic dragover screenX");
   1.479 +  is(event.screenY, 35, "synthetic dragover screenY");
   1.480 +  is(event.clientX, 20, "synthetic dragover clientX");
   1.481 +  is(event.clientY, 15, "synthetic dragover clientY");
   1.482 +  is(event.ctrlKey, true, "synthetic dragover ctrlKey");
   1.483 +  is(event.altKey, false, "synthetic dragover altKey");
   1.484 +  is(event.shiftKey, true, "synthetic dragover shiftKey");
   1.485 +  is(event.metaKey, true, "synthetic dragover metaKey");
   1.486 +  is(event.button, 2, "synthetic dragover button");
   1.487 +  is(event.relatedTarget, document.documentElement, "synthetic dragover relatedTarget");
   1.488 +
   1.489 +//  Uncomment next two lines once the todo instanceof above is fixed.
   1.490 +//  dt.setData("text/plain", "Text");
   1.491 +//  is(dt.getData("text/plain"), "Text", "synthetic dragover data is set after adding");
   1.492 +}
   1.493 +
   1.494 +function onDragStartDraggable(event)
   1.495 +{
   1.496 +  var dt = event.dataTransfer;
   1.497 +  ok(dt.mozItemCount == 0 && dt.types.length == 0 && event.originalTarget == gDragInfo.target, gDragInfo.testid);
   1.498 +
   1.499 +  gExtraDragTests++;
   1.500 +}
   1.501 +
   1.502 +function checkOneDataItem(dt, expectedtypes, expecteddata, index, testid)
   1.503 +{
   1.504 +  checkTypes(dt, expectedtypes, index, testid);
   1.505 +  for (var f = 0; f < expectedtypes.length; f++) {
   1.506 +    if (index == 0)
   1.507 +      is(dt.getData(expectedtypes[f]), expecteddata[f], testid + " getData " + expectedtypes[f]);
   1.508 +    is(dt.mozGetDataAt(expectedtypes[f], index), expecteddata[f] ? expecteddata[f] : null,
   1.509 +       testid + " getDataAt " + expectedtypes[f]);
   1.510 +  }
   1.511 +}
   1.512 +
   1.513 +function checkTypes(dt, expectedtypes, index, testid)
   1.514 +{
   1.515 +  if (index == 0) {
   1.516 +    var types = dt.types;
   1.517 +    is(types.length, expectedtypes.length, testid + " types length");
   1.518 +    for (var f = 0; f < expectedtypes.length; f++) {
   1.519 +      is(types[f], expectedtypes[f], testid + " " + types[f] + " check");
   1.520 +    }
   1.521 +  }
   1.522 +
   1.523 +  types = dt.mozTypesAt(index);
   1.524 +  is(types.length, expectedtypes.length, testid + " typesAt length");
   1.525 +  for (var f = 0; f < expectedtypes.length; f++) {
   1.526 +    is(types[f], expectedtypes[f], testid + " " + types[f] + " at " + index + " check");
   1.527 +  }
   1.528 +}
   1.529 +
   1.530 +function checkURL(dt, url, fullurllist, index, testid)
   1.531 +{
   1.532 +  is(dt.getData("text/uri-list"), fullurllist, testid + " text/uri-list");
   1.533 +  is(dt.getData("URL"), url, testid + " URL");
   1.534 +  is(dt.mozGetDataAt("text/uri-list", 0), fullurllist, testid + " text/uri-list");
   1.535 +  is(dt.mozGetDataAt("URL", 0), fullurllist, testid + " URL");
   1.536 +}
   1.537 +
   1.538 +function expectError(fn, eid, testid)
   1.539 +{
   1.540 +  var error = "";
   1.541 +  try {
   1.542 +    fn();
   1.543 +  } catch (ex) {
   1.544 +    error = ex.name;
   1.545 +  }
   1.546 +  is(error, eid, testid + " causes exception " + eid);
   1.547 +}
   1.548 +
   1.549 +</script>
   1.550 +
   1.551 +</head>
   1.552 +
   1.553 +<body style="height: 300px; overflow: auto;" onload="setTimeout(runTests, 0)">
   1.554 +
   1.555 +<div id="draggable" ondragstart="doDragStartSelection(event)">This is a <em>draggable</em> bit of text.</div>
   1.556 +
   1.557 +<fieldset>
   1.558 +<a id="link" href="http://www.mozilla.org/" ondragstart="doDragStartLink(event)">mozilla.org</a>
   1.559 +</fieldset>
   1.560 +
   1.561 +<label>
   1.562 +<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"
   1.563 +     ondragstart="doDragStartImage(event)">
   1.564 +</label>
   1.565 +
   1.566 +<input id="input" value="Text in a box" ondragstart="doDragStartInput(event)">
   1.567 +
   1.568 +<div ondragstart="onDragStartDraggable(event)">
   1.569 +  <div id="dragtrue" draggable="true">
   1.570 +    This is a <span id="spantrue">draggable</span> area.
   1.571 +  </div>
   1.572 +  <div id="dragfalse" draggable="false">
   1.573 +    This is a <span id="spanfalse">non-draggable</span> area.
   1.574 +  </div>
   1.575 +</div>
   1.576 +
   1.577 +<!--iframe src="http://www.mozilla.org" width="400" height="400"></iframe-->
   1.578 +
   1.579 +<div id="synthetic" ondragstart="doDragStartSynthetic(event)">Synthetic Event Dispatch</div>
   1.580 +<div id="synthetic2" ondragover="doDragOverSynthetic(event)">Synthetic Event Dispatch</div>
   1.581 +
   1.582 +</body>
   1.583 +</html>

mercurial