Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / pasteboard / data-transfer-items-drag-drop-entry.html
blob9f5674b19b9b34dfc55abc6a3b6dbc73f360f948
1 <!DOCTYPE html>
2 <html>
3 <body>
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>
10 <script>
11 var testFiles = [
12 { path: 'resources/mozilla.gif',
13 directory: false,
14 size: 2593 },
15 { path: 'resources/drop-file-svg.svg',
16 directory: false,
17 size: 109 },
18 { path: 'resources/copy-backslash-euc.html',
19 directory: false,
20 size: 478 },
21 { path: 'resources/test_directory',
22 directory: true,
23 size: 0 }
26 function log(text)
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 + '"');
38 function startTest()
40 var destination = document.getElementById('destination');
41 destination.addEventListener('dragover', handleDragOver, false);
42 destination.addEventListener('drop', handleDrop, false);
44 if (!window.testRunner)
45 return;
46 testRunner.waitUntilDone();
47 testRunner.dumpAsText();
49 var files = [];
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)
64 e.stopPropagation();
65 e.preventDefault();
68 function handleDrop(e)
70 e.stopPropagation();
71 e.preventDefault();
73 log('Verifying contents of DataTransferItems...');
74 var items = e.dataTransfer.items;
75 var files = [];
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();
81 files.push(file);
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();
98 });
103 startTest();
105 </script>
106 </body>
107 </html>