mirror of
https://github.com/apache/cordova-plugin-file-transfer.git
synced 2026-04-28 00:02:49 +08:00
CB-9969 Filetransfer upload error deletes original file
Adds corresponding test and fixes for iOS and Windows Also fixes filetransfer.spec.9, which used an incorrect path in the root.getFile call.
This commit is contained in:
+41
-1
@@ -450,7 +450,7 @@ exports.defineAutoTests = function () {
|
||||
expect(transfer.onprogress).toHaveBeenCalled();
|
||||
|
||||
// check that there is no file
|
||||
root.getFile(localFilePath, null, unexpectedCallbacks.fileSystemWin, done);
|
||||
root.getFile(fileName, null, unexpectedCallbacks.fileSystemWin, done);
|
||||
};
|
||||
|
||||
// abort at the first onprogress event
|
||||
@@ -972,6 +972,46 @@ exports.defineAutoTests = function () {
|
||||
// NOTE: removing uploadOptions cause Android to timeout
|
||||
transfer.upload(localFilePath, fileURL, uploadWin, unexpectedCallbacks.httpFail, uploadOptions);
|
||||
}, UPLOAD_TIMEOUT);
|
||||
|
||||
it("filetransfer.spec.34 should not delete a file on upload error", function (done) {
|
||||
|
||||
var fileURL = SERVER + '/upload';
|
||||
|
||||
var uploadFail = function (e) {
|
||||
expect(e.code).toBe(FileTransferError.ABORT_ERR);
|
||||
expect(transfer.onprogress).toHaveBeenCalled();
|
||||
|
||||
// check that the file is there
|
||||
root.getFile(fileName, null, function(entry) {
|
||||
expect(entry).toBeDefined();
|
||||
|
||||
// delay calling done() to wait for the bogus abort()
|
||||
setTimeout(done, GRACE_TIME_DELTA * 2);
|
||||
}, function(err) {
|
||||
expect(err).not.toBeDefined(err && err.code);
|
||||
done();
|
||||
});
|
||||
};
|
||||
|
||||
var fileWin = function () {
|
||||
|
||||
expect(transfer.abort).not.toThrow();
|
||||
|
||||
// NOTE: removing uploadOptions cause Android to timeout
|
||||
transfer.upload(localFilePath, fileURL, unexpectedCallbacks.httpWin, uploadFail, uploadOptions);
|
||||
|
||||
// abort at the first onprogress event
|
||||
transfer.onprogress = function (event) {
|
||||
if (event.loaded > 0) {
|
||||
transfer.abort();
|
||||
}
|
||||
};
|
||||
|
||||
spyOn(transfer, 'onprogress').and.callThrough();
|
||||
};
|
||||
|
||||
writeFile(root, fileName, new Array(100000).join('aborttest!'), fileWin);
|
||||
}, UPLOAD_TIMEOUT);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user