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