3 <div>This tests basic cross-filesystem operations.
</div>
5 <div id=
"destination" style=
"min-height:100px; border: solid 1px black">Drop files here if you test this manually
</div>
7 <div id=
"console"></div>
10 var methods
= [ 'copyTo', 'moveTo' ];
11 var sourceTestDirectory
, destTestDirectory
;
13 var destDirectoryPath
= '/test';
14 var sourceDirectoryPath
= '../../editing/pasteboard/resources';
16 // Actual files in the sourceDirectoryPath.
19 { path
:'mozilla.gif' },
20 { path
:'drop-file-svg.svg' },
21 { path
:'copy-backslash-euc.html' },
22 { path
:'test_directory', directory
:true },
23 { path
:'test_directory/test.txt' }
26 // Note: for now we don't run moveTo test since drag-and-drop isolated
27 // filesystem, which we use for source filesystem, is read-only.
28 // FIXME: allow writing to PERSISTENT filesystem without quota error in
29 // DumpRenderTree so that we can test TEMPORARY <-> PERSISTENT cross operation
38 var console
= document
.getElementById('console');
39 console
.appendChild(document
.createTextNode(text
));
40 console
.appendChild(document
.createElement('br'));
43 function test(expect
, actual
)
45 log((expect
== actual
? 'PASS' : 'FAIL') + ': "' + expect
+ '" == "' + actual
+ '"');
49 function errorCallback(msg
)
53 log('ERROR:' + msg
+ ': ' + e
.name
);
54 if (window
.testRunner
)
55 testRunner
.notifyDone();
59 function setupDestFileSystem(successCallback
) {
60 webkitRequestFileSystem(window
.TEMPORARY
, 1024, function (fs
) {
65 destTestDirectory
= entry
;
68 errorCallback('dest: createDirectory(' + destDirectoryPath
+ ')'));
69 }, errorCallback('dest: requestFileSystem for PERSISTENT'));
72 function runTests(index
, successCallback
) {
73 if (index
>= tests
.length
) {
77 var next = function() { runTests(index
+ 1, successCallback
); };
78 resetDirectory(destTestDirectory
, function() { tests
[index
](next
); });
81 function testCopyFile(successCallback
) {
82 testOnFile(0, 'copyTo', successCallback
);
85 function testCopyDirectory(successCallback
) {
86 testOnDirectory(0, 'copyTo', successCallback
);
89 function testOnFile(index
, method
, successCallback
) {
90 if (index
>= testFiles
.length
) {
94 var next = function() { testOnFile(index
+ 1, method
, successCallback
); };
95 if (testFiles
[index
].directory
) {
99 var file
= testFiles
[index
];
100 log('Testing ' + method
+ ' ' + file
.path
+ ': ' + sourceTestDirectory
.fullPath
+ ' => ' + destTestDirectory
.fullPath
);
101 sourceTestDirectory
.getFile(
102 file
.path
, {create
:false}, function(source
) {
103 source
[method
](destTestDirectory
, '', function(dest
) {
104 verifyFile(source
, dest
, next
);
105 }, errorCallback('testOnFile: ' + method
+ ':' + file
.path
));
106 }, errorCallback('testOnFile: getFile:' + file
.path
));
109 function testOnDirectory(index
, method
, successCallback
) {
110 if (index
>= testFiles
.length
) {
114 var next = function() { testOnFile(index
+ 1, method
, successCallback
); };
115 if (!testFiles
[index
].directory
) {
119 var file
= testFiles
[index
];
120 log('Testing ' + method
+ ' ' + file
.path
+ ': ' + sourceTestDirectory
.fullPath
+ ' => ' + destTestDirectory
.fullPath
);
121 sourceTestDirectory
.getDirectory(
122 file
.path
, {create
:false}, function(source
) {
123 source
[method
](destTestDirectory
, '', function(dest
) {
124 verifyFile(source
, dest
, next
);
125 }, errorCallback('testOnDirectory: ' + method
+ ':' + file
.path
));
126 }, errorCallback('testOnDirectory: getDirectory:' + file
.path
));
129 function verifyFile(source
, dest
, successCallback
) {
130 test(source
.name
, dest
.name
);
131 source
.getMetadata(function(sourceMetadata
) {
132 var expectedSize
= sourceMetadata
.size
;
133 dest
.getMetadata(function(destMetadata
) {
134 test(expectedSize
, destMetadata
.size
);
136 }, errorCallback('getMetadata:' + dest
.fullPath
));
137 }, errorCallback('getMetadata:' + source
.fullPath
));
140 function verifyDirectory(source
, dest
, successCallback
) {
141 getDirectoryEntries(source
, function(sourceEntries
) {
142 getDirectoryEntries(dest
, function(destEntries
) {
143 sourceEntries
.sort();
145 test(sourceEntries
.length
, destEntries
.length
);
146 var verifyOne = function(index
) {
147 verifyFile(sourceEntries
[index
], destEntries
[index
], function() {
148 if (index
>= sourceEntries
.length
) {
152 verifyOne(index
+ 1);
160 function getDirectoryEntries(entry
, entriesCallback
) {
162 var addEntries = function(entries
, continueCallback
) {
163 if (entries
.length
== 0) {
164 entriesCallback(allEntries
);
167 allEntries
.concat(entries
);
168 if (entries
.length
!= 0) continueCallback();
170 var entriesCallback = function(entries
) {
171 addEntries(entries
, successCallback
, function() {
172 reader
.readDirectory(entriesCallback
);
175 var reader
= entry
.createReader();
176 reader
.readDirectory(entriesCallback
, errorCallback('readDirectory: ' + entry
.fullPath
));
179 function cleanupDirectory(directory
, successCallback
) {
180 directory
.removeRecursively(
182 errorCallback('removeRecursively:' + directory
.fullPath
));
185 function resetDirectory(directory
, successCallback
) {
186 var fs
= directory
.filesystem
;
187 var path
= directory
.fullPath
;
188 cleanupDirectory(directory
, function() {
189 fs
.root
.getDirectory(path
, {create
:true},
191 log(fs
.name
+ ': reset ' + path
);
193 }, errorCallback('getDirectory(create):' + path
));
197 function setupFiles(root
, index
, successCallback
)
199 if (index
>= testFiles
.length
) {
203 var file
= testFiles
[index
];
204 var msg
= 'create testFiles[' + index
+ ']: ' + file
.path
;
205 var callback = function(entry
) { setupFiles(root
, index
+ 1, successCallback
); };
206 if (file
.directory
) {
207 root
.getDirectory(destDirectoryPath
+ '/' + file
.path
, {create
:true}, callback
, errorCallback(msg
));
211 root
.getFile(file
.path
, {create
:true}, function(entry
) {
212 entry
.createWriter(function (writer
) {
213 writer
.truncate(file
.size
);
214 writer
.onerror
= errorCallback('truncate ' + entry
.fullPath
);
215 writer
.onwriteend
= callback
;
216 }, errorCallback('create writer for ' + entry
.fullPath
));
217 }, errorCallback(msg
));
220 function startTest(e
) {
221 e
.stopPropagation(e
);
224 log('Verifying contents of DataTransferItems...');
225 var items
= e
.dataTransfer
.items
;
226 test(1, items
.length
);
227 test('file', items
[0].kind
);
229 var entry
= items
[0].webkitGetAsEntry();
230 test(true, entry
.isDirectory
);
231 sourceTestDirectory
= entry
;
232 setupDestFileSystem(function() {
233 log('Successfully setup test environment.');
234 runTests(0, function() {
235 log('Successfully ran ' + tests
.length
+ ' tests.');
236 cleanupDirectory(destTestDirectory
, function() {
237 log('Cleanup done.');
238 if (window
.testRunner
)
239 testRunner
.notifyDone();
245 var destination
= document
.getElementById('destination');
246 destination
.addEventListener('dragover', function(e
) {
250 destination
.addEventListener('drop', startTest
, false);
252 if (window
.testRunner
) {
253 testRunner
.waitUntilDone();
254 testRunner
.dumpAsText();
256 eventSender
.beginDragWithFiles([sourceDirectoryPath
]);
257 eventSender
.leapForward(100);
258 eventSender
.mouseMoveTo(destination
.offsetLeft
+ 10, destination
.offsetTop
+ destination
.offsetHeight
/ 2);
259 eventSender
.mouseUp();