4 <input type=
"file" name=
"files" id=
"files">
5 <pre id=
"console"></pre>
6 <script src=
"../../../resources/js-test.js"></script>
8 description('Tests the webkitEntries attribute of <input type="file">');
16 ['apple.gif', 'dir1/UTF8.txt', 'dir2/green.jpg'],
17 // Multiple directories.
20 ['dir1', 'dir1/UTF8.txt', 'test.txt', 'dir2']
23 // The expected directories/files info in the actual resources directory.
24 var expectedFileAttributes
= {
25 'dir1': { 'directory': true, 'files':[ '/dir1/UTF8.txt', '/dir1/UTF8-2.txt' ] },
26 'dir2': { 'directory': true, 'files':[ '/dir2/green.jpg' ] },
27 'apple.gif': { 'directory': false, 'size': 3340 },
28 'test.txt': { 'directory': false, 'size': 5 },
29 'dir1/UTF8.txt': { 'directory': false, 'size': 5 },
30 'dir1/UTF8-2.txt': { 'directory': false, 'size': 9 },
31 'dir2/green.jpg': { 'directory': false, 'size': 764 }
34 var droppedEntries
, verifyingEntry
, returnedMetadata
, returnedEntries
;
36 var jsTestIsAsync
= true;
37 if (window
.testRunner
) {
38 testRunner
.waitUntilDone();
42 function doTest(index
)
44 if (index
>= testCases
.length
) {
49 debug('* Testing testCases[' + index
+ ']');
50 var paths
= testCases
[index
];
51 var input
= document
.getElementById('files');
52 input
.onchange = function() { onInputFileChange(index
); };
54 input
.setAttribute('multiple', 'multiple')
56 input
.removeAttribute('multiple')
57 var testPaths
= paths
.map(function(path
) { return '../resources/' + path
});
58 eventSender
.beginDragWithFiles(testPaths
);
59 var centerX
= input
.offsetLeft
+ input
.offsetWidth
/ 2;
60 var centerY
= input
.offsetTop
+ input
.offsetHeight
/ 2;
61 eventSender
.mouseMoveTo(centerX
, centerY
);
62 eventSender
.mouseUp();
65 function onInputFileChange(index
)
67 droppedEntries
= document
.getElementById('files').webkitEntries
;
68 shouldEvaluateTo('droppedEntries.length', testCases
[index
].length
);
69 verifyEntry(index
, 0);
72 function verifyEntry(testIndex
, entryIndex
)
74 if (entryIndex
== testCases
[testIndex
].length
) {
75 doTest(testIndex
+ 1);
79 var entry
= verifyingEntry
= droppedEntries
[entryIndex
];
80 debug('Verifying entry (' + entryIndex
+ '/' + testCases
[testIndex
].length
+ '):' + entry
.fullPath
);
82 var path
= testCases
[testIndex
][entryIndex
];
83 var expected
= expectedFileAttributes
[path
];
84 var expectedPath
= '/' + getBaseName(path
);
86 shouldBeEqualToString('verifyingEntry.fullPath', expectedPath
);
87 shouldEvaluateTo('verifyingEntry.isDirectory', expected
.directory
);
89 var callback = function() { verifyEntry(testIndex
, entryIndex
+ 1); };
91 entry
.getMetadata(verifyFile
.bind(this, expected
, callback
), onError
);
93 var reader
= entry
.createReader();
94 reader
.readEntries(verifyDirectory
.bind(this, expected
, callback
), onError
);
98 function verifyFile(expected
, callback
, metadata
)
100 returnedMetadata
= metadata
;
101 shouldEvaluateTo('returnedMetadata.size', expected
.size
);
105 function verifyDirectory(expected
, callback
, entries
)
107 returnedEntries
= [];
108 for (var i
= 0; i
< entries
.length
; i
++) {
109 // Skip the entries that start with '.' (so that we do not get '.svn' etc)
110 if (entries
[i
].name
.indexOf('.') == 0)
112 returnedEntries
.push(entries
[i
].fullPath
);
114 returnedEntries
.sort();
115 shouldEvaluateTo('returnedEntries.length', expected
.files
.length
);
116 for (var i
= 0; i
< returnedEntries
.length
; i
++)
117 debug(returnedEntries
[i
]);
121 function getBaseName(path
)
123 var components
= path
.split('/');
124 return components
[components
.length
- 1];
127 function onError(error
)
129 testFailed('Test finished with unexpected error: ' + error
.code
);