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 |
75 function handleDrop(e) | 64 function handleDrop(e) |
76 { | 65 { |
77 e.stopPropagation(); | 66 e.stopPropagation(); |
78 e.preventDefault(); | 67 e.preventDefault(); |
79 | 68 |
80 log('Verifying contents of DataTransferItems...'); | 69 debug('Verifying contents of DataTransferItems...'); |
81 | 70 |
82 var items = e.dataTransfer.items; | 71 var items = e.dataTransfer.items; |
83 var remaining = items.length; | 72 var remaining = items.length; |
84 | 73 |
85 for (var i = 0; i < items.length; ++i) { | 74 for (var i = 0; i < items.length; ++i) { |
86 log('items.length: ' + items.length); | 75 debug('items.length: ' + items.length); |
87 log('items[' + i + '].kind: ' + items[i].kind); | 76 debug('items[' + i + '].kind: ' + items[i].kind); |
88 log('items[' + i + '].type: ' + items[i].type); | 77 debug('items[' + i + '].type: ' + items[i].type); |
89 | 78 |
79 window.currentItem = items[i]; | |
arv (Not doing code reviews)
2013/08/07 17:55:24
or
var currentItem;
function handleDrop() {
..
do-not-use
2013/08/07 18:07:59
Yes, I have seen both ways used in the tests and I
| |
80 shouldThrow('currentItem.getAsString()', '"TypeError: Not enough argumen ts"'); | |
81 shouldNotThrow('currentItem.getAsString(null)'); | |
90 items[i].getAsString(function(data) { | 82 items[i].getAsString(function(data) { |
91 test(expectedDroppedText, data); | 83 window.stringData = data; |
84 shouldBeEqualToString('stringData', expectedDroppedText); | |
92 if (--remaining == 0 && window.testRunner) | 85 if (--remaining == 0 && window.testRunner) |
93 runNextTest(); | 86 runNextTest(); |
94 }); | 87 }); |
95 } | 88 } |
96 } | 89 } |
97 | 90 |
98 startTest(); | 91 startTest(); |
99 | 92 |
100 </script> | 93 </script> |
94 <script src="../../fast/js/resources/js-test-post.js"></script> | |
101 </body> | 95 </body> |
102 </html> | 96 </html> |
OLD | NEW |