Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / pasteboard / data-transfer-items-drag-drop-string.html
blobdc52a09cf9bd7dd892ab9c5f1f3fa574df399b48
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <body>
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>
11 <script>
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' ];
17 var testIndex = 0;
18 var expectedDroppedText = '';
20 function startTest()
22 var destination = document.getElementById('destination');
23 destination.addEventListener('dragover', handleDragOver, false);
24 destination.addEventListener('drop', handleDrop, false);
26 if (!window.testRunner)
27 return;
29 runNextTest();
32 function runNextTest()
34 if (testIndex == testSources.length) {
35 finishJSTest();
36 return;
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)
60 e.stopPropagation();
61 e.preventDefault();
64 var currentItem;
65 function handleDrop(e)
67 e.stopPropagation();
68 e.preventDefault();
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)
87 runNextTest();
88 });
92 startTest();
94 </script>
95 </body>
96 </html>