|
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 <script> |
|
9 |
|
10 var gGotHandlingDrop = false; |
|
11 var gGotNotHandlingDrop = false; |
|
12 |
|
13 SimpleTest.waitForExplicitFinish(); |
|
14 |
|
15 function fireEvent(target, event) { |
|
16 SpecialPowers.DOMWindowUtils.dispatchDOMEventViaPresShell(target, event, true); |
|
17 } |
|
18 |
|
19 function fireDrop(element, shouldAllowDrop, shouldAllowOnlyChromeDrop) { |
|
20 var ds = SpecialPowers.Cc["@mozilla.org/widget/dragservice;1"]. |
|
21 getService(SpecialPowers.Ci.nsIDragService); |
|
22 |
|
23 var dataTransfer; |
|
24 var trapDrag = function(event) { |
|
25 dataTransfer = event.dataTransfer; |
|
26 dataTransfer.setData("text/plain", "Hello");; |
|
27 dataTransfer.dropEffect = "move"; |
|
28 event.preventDefault(); |
|
29 event.stopPropagation(); |
|
30 } |
|
31 |
|
32 // need to use real mouse action |
|
33 window.addEventListener("dragstart", trapDrag, true); |
|
34 synthesizeMouse(element, 2, 2, { type: "mousedown" }); |
|
35 synthesizeMouse(element, 11, 11, { type: "mousemove" }); |
|
36 synthesizeMouse(element, 20, 20, { type: "mousemove" }); |
|
37 window.removeEventListener("dragstart", trapDrag, true); |
|
38 synthesizeMouse(element, 20, 20, { type: "mouseup" }); |
|
39 |
|
40 ds.startDragSession(); |
|
41 |
|
42 var event = document.createEvent("DragEvents"); |
|
43 event.initDragEvent("dragover", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null, dataTransfer); |
|
44 fireEvent(element, event); |
|
45 |
|
46 is(ds.getCurrentSession().canDrop, shouldAllowDrop, "Unexpected .canDrop"); |
|
47 is(ds.getCurrentSession().onlyChromeDrop, shouldAllowOnlyChromeDrop, |
|
48 "Unexpected .onlyChromeDrop"); |
|
49 |
|
50 event = document.createEvent("DragEvents"); |
|
51 event.initDragEvent("drop", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null, dataTransfer); |
|
52 fireEvent(element, event); |
|
53 |
|
54 ds.endDragSession(false); |
|
55 ok(!ds.getCurrentSession(), "There shouldn't be a drag session anymore!"); |
|
56 } |
|
57 |
|
58 var chromeGotEvent = false; |
|
59 function chromeListener(e) { |
|
60 chromeGotEvent = true; |
|
61 } |
|
62 |
|
63 function runTests() |
|
64 { |
|
65 var targetHandling = document.getElementById("handling_target"); |
|
66 fireDrop(targetHandling, true, false); |
|
67 |
|
68 is(gGotHandlingDrop, true, "Got drop on accepting element (1)"); |
|
69 is(gGotNotHandlingDrop, false, "Didn't get drop on unaccepting element (1)"); |
|
70 |
|
71 // reset |
|
72 gGotHandlingDrop = false; |
|
73 gGotNotHandlingDrop = false; |
|
74 |
|
75 SpecialPowers.addChromeEventListener("drop", chromeListener, true, false); |
|
76 var targetNotHandling = document.getElementById("nothandling_target"); |
|
77 fireDrop(targetNotHandling, true, true); |
|
78 SpecialPowers.removeChromeEventListener("drop", chromeListener, true); |
|
79 ok(chromeGotEvent, "Chrome should have got drop event!"); |
|
80 is(gGotHandlingDrop, false, "Didn't get drop on accepting element (2)"); |
|
81 is(gGotNotHandlingDrop, false, "Didn't get drop on unaccepting element (2)"); |
|
82 |
|
83 SimpleTest.finish(); |
|
84 } |
|
85 |
|
86 </script> |
|
87 |
|
88 <body onload="window.setTimeout(runTests, 0);"> |
|
89 |
|
90 <img style="width: 100px; height: 100px;" |
|
91 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" |
|
92 id="handling_target" |
|
93 ondragenter="event.preventDefault()" |
|
94 ondragover="event.preventDefault()" |
|
95 ondrop="gGotHandlingDrop = true;"> |
|
96 |
|
97 <img style="width: 100px; height: 100px;" |
|
98 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" |
|
99 id="nothandling_target" |
|
100 ondrop="gGotNotHandlingDrop = true;"> |
|
101 |
|
102 </body> |
|
103 </html> |