4 <div>This tests the basic functionality and properties of DataTransferItems for files with drag and drop. This test requires DRT.
</div>
6 <div id=
"destination" style=
"min-height:100px; border: solid 1px black">Drop files here if you test this manually
</div>
8 <div id=
"console"></div>
12 { path
: 'resources/mozilla.gif',
15 { path
: 'resources/drop-file-svg.svg',
16 type
: 'image/svg+xml',
18 { path
: 'resources/copy-backslash-euc.html',
25 var console
= document
.getElementById('console');
26 console
.appendChild(document
.createTextNode(text
));
27 console
.appendChild(document
.createElement('br'));
30 function test(expect
, actual
)
32 log((expect
== actual
? 'PASS' : 'FAIL') + ': "' + expect
+ '" == "' + actual
+ '"');
37 var destination
= document
.getElementById('destination');
38 destination
.addEventListener('dragover', handleDragOver
, false);
39 destination
.addEventListener('drop', handleDrop
, false);
41 if (!window
.testRunner
)
43 testRunner
.waitUntilDone();
44 testRunner
.dumpAsText();
47 for (var i
= 0; i
< testFiles
.length
; ++i
) {
48 log('Dragging file: ' + testFiles
[i
].path
);
49 files
.push(testFiles
[i
].path
);
52 // Perform drag-and-drop with the testFiles.
53 eventSender
.beginDragWithFiles(files
);
54 eventSender
.leapForward(500);
55 eventSender
.mouseMoveTo(destination
.offsetLeft
+ 10, destination
.offsetTop
+ destination
.offsetHeight
/ 2);
56 eventSender
.mouseUp();
59 function handleDragOver(e
)
65 function handleDrop(e
)
70 log('Verifying contents of DataTransferItems...');
71 var items
= e
.dataTransfer
.items
;
73 test(testFiles
.length
, items
.length
);
74 for (var i
= 0; i
< items
.length
; ++i
) {
75 // The items should be in the same order as we added.
76 var expected
= testFiles
[i
];
78 var file
= items
[i
].getAsFile();
81 test('file', items
[i
].kind
);
82 test(expected
.type
, items
[i
].type
);
83 test(expected
.type
, file
.type
);
84 test(expected
.size
, file
.size
);
86 var components
= expected
.path
.split('/');
87 var name
= components
[components
.length
- 1];
88 test(name
, file
.name
);
91 testRunner
.notifyDone();