| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> |
| 4 <script src="../../fast/js/resources/js-test-pre.js"></script> |
| 5 </head> |
| 3 <body> | 6 <body> |
| 4 <div>This tests the basic functionality and properties of DataTransferItems for
string data with drag and drop. This test requires DRT.</div> | |
| 5 | |
| 6 <input id="source1" value="Lorem ipsum">Lorem ipsum</input> | 7 <input id="source1" value="Lorem ipsum">Lorem ipsum</input> |
| 7 <input id="source2" value="http://example.com"></input> | 8 <input id="source2" value="http://example.com"></input> |
| 8 <div id="destination" style="min-height:100px; border: solid 1px black">Drop tex
t here if you test this manually</div> | 9 <div id="destination" style="min-height:100px; border: solid 1px black">Drop tex
t here if you test this manually</div> |
| 9 | 10 |
| 10 <div id="console"></div> | 11 <script> |
| 12 description('This tests the basic functionality and properties of DataTransferIt
ems for string data with drag and drop. This test requires DRT.') |
| 11 | 13 |
| 12 <script> | 14 window.jsTestIsAsync = true; |
| 15 |
| 13 var testSources = [ 'source1', 'source2' ]; | 16 var testSources = [ 'source1', 'source2' ]; |
| 14 var testIndex = 0; | 17 var testIndex = 0; |
| 15 var expectedDroppedText = ''; | 18 var expectedDroppedText = ''; |
| 16 | 19 |
| 17 function log(text) | |
| 18 { | |
| 19 var console = document.getElementById('console'); | |
| 20 console.appendChild(document.createTextNode(text)); | |
| 21 console.appendChild(document.createElement('br')); | |
| 22 } | |
| 23 | |
| 24 function test(expect, actual) | |
| 25 { | |
| 26 log((expect == actual ? 'PASS' : 'FAIL') + ': "' + expect + '" == "' + actua
l + '"'); | |
| 27 } | |
| 28 | |
| 29 function startTest() | 20 function startTest() |
| 30 { | 21 { |
| 31 var destination = document.getElementById('destination'); | 22 var destination = document.getElementById('destination'); |
| 32 destination.addEventListener('dragover', handleDragOver, false); | 23 destination.addEventListener('dragover', handleDragOver, false); |
| 33 destination.addEventListener('drop', handleDrop, false); | 24 destination.addEventListener('drop', handleDrop, false); |
| 34 | 25 |
| 35 if (!window.testRunner) | 26 if (!window.testRunner) |
| 36 return; | 27 return; |
| 37 testRunner.waitUntilDone(); | |
| 38 testRunner.dumpAsText(); | |
| 39 | 28 |
| 40 runNextTest(); | 29 runNextTest(); |
| 41 } | 30 } |
| 42 | 31 |
| 43 function runNextTest() | 32 function runNextTest() |
| 44 { | 33 { |
| 45 if (testIndex == testSources.length) { | 34 if (testIndex == testSources.length) { |
| 46 testRunner.notifyDone(); | 35 finishJSTest(); |
| 47 return; | 36 return; |
| 48 } | 37 } |
| 49 | 38 |
| 50 var sourceId = testSources[testIndex++]; | 39 var sourceId = testSources[testIndex++]; |
| 51 var source = document.getElementById(sourceId); | 40 var source = document.getElementById(sourceId); |
| 52 expectedDroppedText = source.value; | 41 expectedDroppedText = source.value; |
| 53 log('Dragging text in ' + sourceId + ': ' + source.value); | 42 debug('Dragging text in ' + sourceId + ': ' + source.value); |
| 54 | 43 |
| 55 // Drag a text in the source element. | 44 // Drag a text in the source element. |
| 56 source.setSelectionRange(0, source.value.length); | 45 source.setSelectionRange(0, source.value.length); |
| 57 x = source.offsetLeft + 10; | 46 x = source.offsetLeft + 10; |
| 58 y = source.offsetTop + source.offsetHeight / 2; | 47 y = source.offsetTop + source.offsetHeight / 2; |
| 59 eventSender.mouseMoveTo(x, y); | 48 eventSender.mouseMoveTo(x, y); |
| 60 eventSender.mouseDown(); | 49 eventSender.mouseDown(); |
| 61 | 50 |
| 62 // Drop it off to the destination field. | 51 // Drop it off to the destination field. |
| 63 var destination = document.getElementById("destination"); | 52 var destination = document.getElementById("destination"); |
| 64 eventSender.leapForward(500); | 53 eventSender.leapForward(500); |
| 65 eventSender.mouseMoveTo(destination.offsetLeft + 10, destination.offsetTop +
destination.offsetHeight / 2); | 54 eventSender.mouseMoveTo(destination.offsetLeft + 10, destination.offsetTop +
destination.offsetHeight / 2); |
| 66 eventSender.mouseUp(); | 55 eventSender.mouseUp(); |
| 67 } | 56 } |
| 68 | 57 |
| 69 function handleDragOver(e) | 58 function handleDragOver(e) |
| 70 { | 59 { |
| 71 e.stopPropagation(); | 60 e.stopPropagation(); |
| 72 e.preventDefault(); | 61 e.preventDefault(); |
| 73 } | 62 } |
| 74 | 63 |
| 64 var currentItem; |
| 75 function handleDrop(e) | 65 function handleDrop(e) |
| 76 { | 66 { |
| 77 e.stopPropagation(); | 67 e.stopPropagation(); |
| 78 e.preventDefault(); | 68 e.preventDefault(); |
| 79 | 69 |
| 80 log('Verifying contents of DataTransferItems...'); | 70 debug('Verifying contents of DataTransferItems...'); |
| 81 | 71 |
| 82 var items = e.dataTransfer.items; | 72 var items = e.dataTransfer.items; |
| 83 var remaining = items.length; | 73 var remaining = items.length; |
| 84 | 74 |
| 85 for (var i = 0; i < items.length; ++i) { | 75 for (var i = 0; i < items.length; ++i) { |
| 86 log('items.length: ' + items.length); | 76 debug('items.length: ' + items.length); |
| 87 log('items[' + i + '].kind: ' + items[i].kind); | 77 debug('items[' + i + '].kind: ' + items[i].kind); |
| 88 log('items[' + i + '].type: ' + items[i].type); | 78 debug('items[' + i + '].type: ' + items[i].type); |
| 89 | 79 |
| 80 currentItem = items[i]; |
| 81 shouldThrow('currentItem.getAsString()', '"TypeError: Not enough argumen
ts"'); |
| 82 shouldNotThrow('currentItem.getAsString(null)'); |
| 90 items[i].getAsString(function(data) { | 83 items[i].getAsString(function(data) { |
| 91 test(expectedDroppedText, data); | 84 window.stringData = data; |
| 85 shouldBeEqualToString('stringData', expectedDroppedText); |
| 92 if (--remaining == 0 && window.testRunner) | 86 if (--remaining == 0 && window.testRunner) |
| 93 runNextTest(); | 87 runNextTest(); |
| 94 }); | 88 }); |
| 95 } | 89 } |
| 96 } | 90 } |
| 97 | 91 |
| 98 startTest(); | 92 startTest(); |
| 99 | 93 |
| 100 </script> | 94 </script> |
| 95 <script src="../../fast/js/resources/js-test-post.js"></script> |
| 101 </body> | 96 </body> |
| 102 </html> | 97 </html> |
| OLD | NEW |