blob: aa62a58b89d54aa386f72e0378e47d8a7b56d7ad [file] [log] [blame]
<!DOCTYPE html>
<html>
<body>
<div>This tests the basic functionality and properties of DataTransferItems for files with drag and drop. This test requires DRT.</div>
<div id="destination" style="min-height:100px; border: solid 1px black">Drop files here if you test this manually</div>
<div id="console"></div>
<script>
var testFiles = [
{ path: 'resources/mozilla.gif',
type: 'image/gif',
size: 2593 },
{ path: 'resources/drop-file-svg.svg',
type: 'image/svg+xml',
size: 109 },
{ path: 'resources/copy-backslash-euc.html',
type: 'text/html',
size: 478 }
];
function log(text)
{
var console = document.getElementById('console');
console.appendChild(document.createTextNode(text));
console.appendChild(document.createElement('br'));
}
function test(expect, actual)
{
log((expect == actual ? 'PASS' : 'FAIL') + ': "' + expect + '" == "' + actual + '"');
}
function startTest()
{
var destination = document.getElementById('destination');
destination.addEventListener('dragover', handleDragOver, false);
destination.addEventListener('drop', handleDrop, false);
if (!window.testRunner)
return;
testRunner.waitUntilDone();
testRunner.dumpAsText();
var files = [];
for (var i = 0; i < testFiles.length; ++i) {
log('Dragging file: ' + testFiles[i].path);
files.push(testFiles[i].path);
}
// Perform drag-and-drop with the testFiles.
eventSender.beginDragWithFiles(files);
eventSender.leapForward(500);
eventSender.mouseMoveTo(destination.offsetLeft + 10, destination.offsetTop + destination.offsetHeight / 2);
eventSender.mouseUp();
}
function handleDragOver(e)
{
e.stopPropagation();
e.preventDefault();
}
function handleDrop(e)
{
e.stopPropagation();
e.preventDefault();
log('Verifying contents of DataTransferItems...');
var items = e.dataTransfer.items;
var files = [];
test(testFiles.length, items.length);
for (var i = 0; i < items.length; ++i) {
// The items should be in the same order as we added.
var expected = testFiles[i];
var file = items[i].getAsFile();
files.push(file);
test('file', items[i].kind);
test(expected.type, items[i].type);
test(expected.type, file.type);
test(expected.size, file.size);
var components = expected.path.split('/');
var name = components[components.length - 1];
test(name, file.name);
}
testRunner.notifyDone();
}
startTest();
</script>
</body>
</html>