cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an-s...@apache.org
Subject cordova-plugin-file-transfer git commit: CB-8641 Fixed tests to pass on windows and wp8
Date Wed, 08 Apr 2015 10:10:03 GMT
Repository: cordova-plugin-file-transfer
Updated Branches:
  refs/heads/master 918b2cf8d -> 8e22d5a6b


CB-8641 Fixed tests to pass on windows and wp8


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/8e22d5a6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/8e22d5a6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/8e22d5a6

Branch: refs/heads/master
Commit: 8e22d5a6b0402f881751b3283e99fd69f021235c
Parents: 918b2cf
Author: alsorokin <alexander.sorokin@akvelon.com>
Authored: Thu Apr 2 12:50:45 2015 +0300
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Wed Apr 8 13:09:12 2015 +0300

----------------------------------------------------------------------
 src/wp/FileTransfer.cs |  2 +-
 tests/tests.js         | 93 +++++++++++++++++++++++----------------------
 2 files changed, 49 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/8e22d5a6/src/wp/FileTransfer.cs
----------------------------------------------------------------------
diff --git a/src/wp/FileTransfer.cs b/src/wp/FileTransfer.cs
index 11db284..1ddfc28 100644
--- a/src/wp/FileTransfer.cs
+++ b/src/wp/FileTransfer.cs
@@ -513,7 +513,7 @@ namespace WPCordovaClassLib.Cordova.Commands
             string id = optionStrings[0];
             string callbackId = optionStrings[1];
 
-            if (InProcDownloads.ContainsKey(id))
+            if (id != null && InProcDownloads.ContainsKey(id))
             {
                 DownloadRequestState state = InProcDownloads[id];
                 if (!state.isCancelled)

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/8e22d5a6/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 682ccc9..c13a88f 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -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;
-
-                    beforeEach(function() {
-                        jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
-                    });
-
-                    afterEach(function() {
-                        jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
-                    });
-
-                    it("filetransfer.spec.15 should handle unknown host", function (done)
{
-
-                        var fileURL = UNKNOWN_HOST;
+                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();
-                        };
+                    var downloadFail = function (error) {
+                        expect(error.code).toBe(FileTransferError.CONNECTION_ERR);
+                        done();
+                    };
 
-                        // turn off the onprogress handler
-                        transfer.onprogress = function () {};
+                    // 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) {
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message