4 <script src=
"../../resources/js-test.js"></script>
7 <input id=
"source1" value=
"Lorem ipsum">Lorem ipsum
</input>
8 <input id=
"source2" value=
"http://example.com"></input>
9 <div id=
"destination" style=
"min-height:100px; border: solid 1px black">Drop text here if you test this manually
</div>
12 description('This tests the basic functionality and properties of DataTransferItems for string data with drag and drop. This test requires DRT.')
14 window
.jsTestIsAsync
= true;
16 var testSources
= [ 'source1', 'source2' ];
18 var expectedDroppedText
= '';
22 var destination
= document
.getElementById('destination');
23 destination
.addEventListener('dragover', handleDragOver
, false);
24 destination
.addEventListener('drop', handleDrop
, false);
26 if (!window
.testRunner
)
32 function runNextTest()
34 if (testIndex
== testSources
.length
) {
39 var sourceId
= testSources
[testIndex
++];
40 var source
= document
.getElementById(sourceId
);
41 expectedDroppedText
= source
.value
;
42 debug('Dragging text in ' + sourceId
+ ': ' + source
.value
);
44 // Drag a text in the source element.
45 source
.setSelectionRange(0, source
.value
.length
);
46 x
= source
.offsetLeft
+ 10;
47 y
= source
.offsetTop
+ source
.offsetHeight
/ 2;
48 eventSender
.mouseMoveTo(x
, y
);
49 eventSender
.mouseDown();
51 // Drop it off to the destination field.
52 var destination
= document
.getElementById("destination");
53 eventSender
.leapForward(500);
54 eventSender
.mouseMoveTo(destination
.offsetLeft
+ 10, destination
.offsetTop
+ destination
.offsetHeight
/ 2);
55 eventSender
.mouseUp();
58 function handleDragOver(e
)
65 function handleDrop(e
)
70 debug('Verifying contents of DataTransferItems...');
72 var items
= e
.dataTransfer
.items
;
73 var remaining
= items
.length
;
75 for (var i
= 0; i
< items
.length
; ++i
) {
76 debug('items.length: ' + items
.length
);
77 debug('items[' + i
+ '].kind: ' + items
[i
].kind
);
78 debug('items[' + i
+ '].type: ' + items
[i
].type
);
80 currentItem
= items
[i
];
81 shouldThrow('currentItem.getAsString()', '"TypeError: Failed to execute \'getAsString\' on \'DataTransferItem\': 1 argument required, but only 0 present."');
82 shouldNotThrow('currentItem.getAsString(null)');
83 items
[i
].getAsString(function(data
) {
84 window
.stringData
= data
;
85 shouldBeEqualToString('stringData', expectedDroppedText
);
86 if (--remaining
== 0 && window
.testRunner
)