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',
18 { path
: 'resources/copy-backslash-euc.html',
21 { path
: 'resources/test_directory',
28 var console
= document
.getElementById('console');
29 console
.appendChild(document
.createTextNode(text
));
30 console
.appendChild(document
.createElement('br'));
33 function test(expect
, actual
)
35 log((expect
== actual
? 'PASS' : 'FAIL') + ': "' + expect
+ '" == "' + actual
+ '"');
40 var destination
= document
.getElementById('destination');
41 destination
.addEventListener('dragover', handleDragOver
, false);
42 destination
.addEventListener('drop', handleDrop
, false);
44 if (!window
.testRunner
)
46 testRunner
.waitUntilDone();
47 testRunner
.dumpAsText();
50 for (var i
= 0; i
< testFiles
.length
; ++i
) {
51 log('Dragging file: ' + testFiles
[i
].path
);
52 files
.push(testFiles
[i
].path
);
55 // Perform drag-and-drop with the testFiles.
56 eventSender
.beginDragWithFiles(files
);
57 eventSender
.leapForward(100);
58 eventSender
.mouseMoveTo(destination
.offsetLeft
+ 10, destination
.offsetTop
+ destination
.offsetHeight
/ 2);
59 eventSender
.mouseUp();
62 function handleDragOver(e
)
68 function handleDrop(e
)
73 log('Verifying contents of DataTransferItems...');
74 var items
= e
.dataTransfer
.items
;
76 test(testFiles
.length
, items
.length
);
77 for (var i
= 0; i
< items
.length
; ++i
) {
78 // The items should be in the same order as we added.
79 var expected
= testFiles
[i
];
80 var file
= items
[i
].getAsFile();
83 test('file', items
[i
].kind
);
84 var entry
= items
[i
].webkitGetAsEntry();
85 log('entry: ' + entry
.fullPath
+ (entry
.isDirectory
? ' [dir]' : ' [file]'));
87 var components
= expected
.path
.split('/');
88 var name
= components
[components
.length
- 1];
89 test('/' + name
, entry
.fullPath
);
90 test(expected
.directory
, entry
.isDirectory
);
92 with ({last
: i
+ 1 == items
.length
, expected
: expected
}) {
93 entry
.getMetadata(function(metadata
) {
94 if (!expected
.directory
)
95 test(expected
.size
, metadata
.size
);
96 if (last
&& window
.testRunner
)
97 testRunner
.notifyDone();