mirror of
https://github.com/apache/cordova-plugin-file-transfer.git
synced 2026-04-28 00:02:49 +08:00
CB-8641 Fixed tests to pass on windows and wp8
This commit is contained in:
committed by
Vladimir Kotikov
parent
918b2cf8d2
commit
8e22d5a6b0
+48
-45
@@ -28,10 +28,12 @@
|
||||
exports.defineAutoTests = function () {
|
||||
|
||||
// constants
|
||||
var GRACE_TIME_DELTA = 300; // in milliseconds
|
||||
var GRACE_TIME_DELTA = 600; // in milliseconds
|
||||
var DEFAULT_FILESYSTEM_SIZE = 1024*50; //filesystem size in bytes
|
||||
var UNKNOWN_HOST = "http://foobar.apache.org";
|
||||
var HEADERS_ECHO = "http://whatheaders.com"; // NOTE: this site is very useful!
|
||||
var DOWNLOAD_TIMEOUT = 10000; // download tests sometimes need a higher timeout to complete successfully
|
||||
var ABORT_DELAY = 100; // for abort() tests
|
||||
|
||||
// config for upload test server
|
||||
// NOTE:
|
||||
@@ -305,7 +307,7 @@ exports.defineAutoTests = function () {
|
||||
// - 'httpssss://example.com'
|
||||
// - 'apache.org', with subdomains="true"
|
||||
// - 'cordova-filetransfer.jitsu.com'
|
||||
describe('download', function() {
|
||||
describe('download', function () {
|
||||
|
||||
// helpers
|
||||
var verifyDownload = function (fileEntry) {
|
||||
@@ -317,6 +319,10 @@ exports.defineAutoTests = function () {
|
||||
deleteFile(root, fileName, done);
|
||||
});
|
||||
|
||||
it('ensures that test file does not exist', function (done) {
|
||||
deleteFile(root, fileName, done);
|
||||
});
|
||||
|
||||
it('filetransfer.spec.4 should download a file', function (done) {
|
||||
|
||||
var fileURL = SERVER + '/robots.txt';
|
||||
@@ -342,7 +348,7 @@ exports.defineAutoTests = function () {
|
||||
};
|
||||
|
||||
transfer.download(fileURL, localFilePath, downloadWin, unexpectedCallbacks.httpFail);
|
||||
});
|
||||
}, DOWNLOAD_TIMEOUT);
|
||||
|
||||
it('filetransfer.spec.5 should download a file using http basic auth', function (done) {
|
||||
|
||||
@@ -354,7 +360,7 @@ exports.defineAutoTests = function () {
|
||||
};
|
||||
|
||||
transfer.download(fileURL, localFilePath, downloadWin, unexpectedCallbacks.httpFail);
|
||||
});
|
||||
}, DOWNLOAD_TIMEOUT);
|
||||
|
||||
it('filetransfer.spec.6 should get 401 status on http basic auth failure', function (done) {
|
||||
|
||||
@@ -368,8 +374,13 @@ exports.defineAutoTests = function () {
|
||||
done();
|
||||
};
|
||||
|
||||
transfer.download(fileURL, localFilePath, unexpectedCallbacks.httpWin, downloadFail);
|
||||
});
|
||||
transfer.download(fileURL, localFilePath, unexpectedCallbacks.httpWin, downloadFail, null,
|
||||
{
|
||||
headers: {
|
||||
'If-Modified-Since': 'Thu, 19 Mar 2015 00:00:00 GMT'
|
||||
}
|
||||
});
|
||||
}, DOWNLOAD_TIMEOUT);
|
||||
|
||||
it("filetransfer.spec.7 should download a file using file:// (when hosted from file://)", function (done) {
|
||||
|
||||
@@ -394,7 +405,7 @@ exports.defineAutoTests = function () {
|
||||
};
|
||||
|
||||
transfer.download(fileURL, localFilePath, downloadWin, unexpectedCallbacks.httpFail);
|
||||
});
|
||||
}, DOWNLOAD_TIMEOUT);
|
||||
|
||||
it("filetransfer.spec.8 should download a file using https://", function (done) {
|
||||
|
||||
@@ -419,15 +430,17 @@ exports.defineAutoTests = function () {
|
||||
};
|
||||
|
||||
transfer.download(fileURL, localFilePath, downloadWin, unexpectedCallbacks.httpFail);
|
||||
});
|
||||
}, DOWNLOAD_TIMEOUT);
|
||||
|
||||
it("filetransfer.spec.11 should call the error callback on abort()", function (done) {
|
||||
|
||||
var fileURL = 'http://cordova.apache.org/downloads/BlueZedEx.mp3';
|
||||
|
||||
transfer.download(fileURL, localFilePath, unexpectedCallbacks.httpWin, done);
|
||||
transfer.abort();
|
||||
});
|
||||
setTimeout(function() {
|
||||
transfer.abort();
|
||||
}, ABORT_DELAY);
|
||||
}, DOWNLOAD_TIMEOUT);
|
||||
|
||||
it("filetransfer.spec.9 should not leave partial file due to abort", function (done) {
|
||||
|
||||
@@ -452,7 +465,7 @@ exports.defineAutoTests = function () {
|
||||
spyOn(transfer, 'onprogress').and.callThrough();
|
||||
|
||||
transfer.download(fileURL, localFilePath, unexpectedCallbacks.httpWin, downloadFail);
|
||||
});
|
||||
}, DOWNLOAD_TIMEOUT);
|
||||
|
||||
it("filetransfer.spec.10 should be stopped by abort() right away", function (done) {
|
||||
|
||||
@@ -472,13 +485,15 @@ exports.defineAutoTests = function () {
|
||||
};
|
||||
|
||||
transfer.download(fileURL, localFilePath, unexpectedCallbacks.httpWin, downloadFail);
|
||||
transfer.abort();
|
||||
setTimeout(function() {
|
||||
transfer.abort();
|
||||
}, ABORT_DELAY);
|
||||
|
||||
// call abort() again, after a time greater than the grace period
|
||||
setTimeout(function () {
|
||||
expect(transfer.abort).not.toThrow();
|
||||
}, GRACE_TIME_DELTA);
|
||||
});
|
||||
}, DOWNLOAD_TIMEOUT);
|
||||
|
||||
it("filetransfer.spec.12 should get http status on failure", function (done) {
|
||||
|
||||
@@ -493,7 +508,7 @@ exports.defineAutoTests = function () {
|
||||
};
|
||||
|
||||
transfer.download(fileURL, localFilePath, unexpectedCallbacks.httpWin, downloadFail);
|
||||
});
|
||||
}, DOWNLOAD_TIMEOUT);
|
||||
|
||||
it("filetransfer.spec.13 should get http body on failure", function (done) {
|
||||
|
||||
@@ -511,7 +526,7 @@ exports.defineAutoTests = function () {
|
||||
};
|
||||
|
||||
transfer.download(fileURL, localFilePath, unexpectedCallbacks.httpWin, downloadFail);
|
||||
});
|
||||
}, DOWNLOAD_TIMEOUT);
|
||||
|
||||
it("filetransfer.spec.14 should handle malformed urls", function (done) {
|
||||
|
||||
@@ -531,33 +546,19 @@ exports.defineAutoTests = function () {
|
||||
transfer.download(fileURL, localFilePath, unexpectedCallbacks.httpWin, downloadFail);
|
||||
});
|
||||
|
||||
describe('unknown host:', function () {
|
||||
var originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||
it("filetransfer.spec.15 should handle unknown host", function (done) {
|
||||
var fileURL = UNKNOWN_HOST;
|
||||
|
||||
beforeEach(function() {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
|
||||
});
|
||||
var downloadFail = function (error) {
|
||||
expect(error.code).toBe(FileTransferError.CONNECTION_ERR);
|
||||
done();
|
||||
};
|
||||
|
||||
afterEach(function() {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
||||
});
|
||||
// turn off the onprogress handler
|
||||
transfer.onprogress = function () {};
|
||||
|
||||
it("filetransfer.spec.15 should handle unknown host", function (done) {
|
||||
|
||||
var fileURL = UNKNOWN_HOST;
|
||||
|
||||
var downloadFail = function (error) {
|
||||
expect(error.code).toBe(FileTransferError.CONNECTION_ERR);
|
||||
done();
|
||||
};
|
||||
|
||||
// turn off the onprogress handler
|
||||
transfer.onprogress = function () {};
|
||||
|
||||
transfer.download(fileURL, localFilePath, unexpectedCallbacks.httpWin, downloadFail);
|
||||
});
|
||||
});
|
||||
|
||||
transfer.download(fileURL, localFilePath, unexpectedCallbacks.httpWin, downloadFail);
|
||||
}, 30000);
|
||||
|
||||
it("filetransfer.spec.16 should handle bad file path", function (done) {
|
||||
var fileURL = SERVER;
|
||||
@@ -580,7 +581,7 @@ exports.defineAutoTests = function () {
|
||||
};
|
||||
|
||||
transfer.download(fileURL, localFilePath, downloadWin, unexpectedCallbacks.httpFail);
|
||||
});
|
||||
}, DOWNLOAD_TIMEOUT);
|
||||
|
||||
it("filetransfer.spec.30 downloaded file entries should have a toNativeURL method", function (done) {
|
||||
|
||||
@@ -613,7 +614,7 @@ exports.defineAutoTests = function () {
|
||||
};
|
||||
|
||||
transfer.download(fileURL, localFilePath, downloadWin, unexpectedCallbacks.httpFail);
|
||||
});
|
||||
}, DOWNLOAD_TIMEOUT);
|
||||
|
||||
it("filetransfer.spec.28 (compatibility) should be able to download a file using local paths", function (done) {
|
||||
|
||||
@@ -757,15 +758,17 @@ exports.defineAutoTests = function () {
|
||||
|
||||
// NOTE: removing uploadOptions cause Android to timeout
|
||||
transfer.upload(localFilePath, fileURL, unexpectedCallbacks.httpWin, uploadFail, uploadOptions);
|
||||
transfer.abort();
|
||||
setTimeout(function() {
|
||||
transfer.abort();
|
||||
}, ABORT_DELAY);
|
||||
|
||||
setTimeout(function () {
|
||||
expect(transfer.abort).not.toThrow();
|
||||
}, GRACE_TIME_DELTA);
|
||||
};
|
||||
|
||||
writeFile(root, fileName, new Array(10000).join('aborttest!'), fileWin);
|
||||
});
|
||||
writeFile(root, fileName, new Array(100000).join('aborttest!'), fileWin);
|
||||
}, 10000); // we are creating a pretty big file here so we need some time
|
||||
|
||||
it("filetransfer.spec.22 should get http status and body on failure", function (done) {
|
||||
|
||||
@@ -804,7 +807,7 @@ exports.defineAutoTests = function () {
|
||||
};
|
||||
|
||||
transfer.upload(localFilePath, fileURL, unexpectedCallbacks.httpWin, uploadFail, {});
|
||||
});
|
||||
}, 30000); // unknown host may need quite some time on some devices
|
||||
|
||||
it("filetransfer.spec.25 should handle missing file", function (done) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user