incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject js commit: [CB-912] adding test cases + parameter checking to address source/target undefined variables being passed into FileTransfer methods
Date Tue, 19 Jun 2012 17:28:28 GMT
Updated Branches:
  refs/heads/master f8fa7c8f5 -> 8d25620f1


[CB-912] adding test cases + parameter checking to address source/target undefined variables
being passed into FileTransfer methods


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/8d25620f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/8d25620f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/8d25620f

Branch: refs/heads/master
Commit: 8d25620f18e47deb0da95606848fe46e7743df07
Parents: f8fa7c8
Author: Fil Maj <maj.fil@gmail.com>
Authored: Tue Jun 19 10:29:23 2012 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Tue Jun 19 10:29:23 2012 -0700

----------------------------------------------------------------------
 lib/common/plugin/FileTransfer.js |    4 ++
 test/test.filetransfer.js         |   54 ++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/8d25620f/lib/common/plugin/FileTransfer.js
----------------------------------------------------------------------
diff --git a/lib/common/plugin/FileTransfer.js b/lib/common/plugin/FileTransfer.js
index c92137d..3ec6721 100644
--- a/lib/common/plugin/FileTransfer.js
+++ b/lib/common/plugin/FileTransfer.js
@@ -18,6 +18,8 @@ var FileTransfer = function() {};
 * @param trustAllHosts {Boolean} Optional trust all hosts (e.g. for self-signed certs), defaults
to false
 */
 FileTransfer.prototype.upload = function(filePath, server, successCallback, errorCallback,
options, trustAllHosts) {
+    // sanity parameter checking
+    if (!filePath || !server) throw new Error("FileTransfer.upload requires filePath and
server URL parameters at the minimum.");
     // check for options
     var fileKey = null;
     var fileName = null;
@@ -55,6 +57,8 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback,
erro
  * @param errorCallback {Function}    Callback to be invoked upon error
  */
 FileTransfer.prototype.download = function(source, target, successCallback, errorCallback)
{
+    // sanity parameter checking
+    if (!source || !target) throw new Error("FileTransfer.download requires source URI and
target URI parameters at the minimum.");
     var win = function(result) {
         var entry = null;
         if (result.isDirectory) {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/8d25620f/test/test.filetransfer.js
----------------------------------------------------------------------
diff --git a/test/test.filetransfer.js b/test/test.filetransfer.js
new file mode 100644
index 0000000..cb3d203
--- /dev/null
+++ b/test/test.filetransfer.js
@@ -0,0 +1,54 @@
+describe("FileTransfer", function() {
+    var FileTransfer = new (require('cordova/plugin/FileTransfer'))();
+    describe("download", function() {
+        it("should throw an exception if source or target is not defined", function() {
+            var win = jasmine.createSpy(),
+                fail = jasmine.createSpy();
+
+            expect(function() {
+                FileTransfer.download(null, null, win, fail);
+            }).toThrow();
+            expect(function() {
+                FileTransfer.download(undefined, undefined, win, fail);
+            }).toThrow();
+            expect(function() {
+                FileTransfer.download(null, undefined, win, fail);
+            }).toThrow();
+            expect(function() {
+                FileTransfer.download(undefined, null, win, fail);
+            }).toThrow();
+            expect(function() {
+                FileTransfer.download("test.txt", undefined, win, fail);
+            }).toThrow();
+            expect(function() {
+                FileTransfer.download(undefined, "http://google.com/robots.txt", win, fail);
+            }).toThrow();
+        });
+    });
+
+    describe("upload", function() {
+        it("should throw an exception if filePath or server is not defined", function() {
+            var win = jasmine.createSpy(),
+                fail = jasmine.createSpy();
+
+            expect(function() {
+                FileTransfer.upload(null, null, win, fail);
+            }).toThrow();
+            expect(function() {
+                FileTransfer.upload(undefined, undefined, win, fail);
+            }).toThrow();
+            expect(function() {
+                FileTransfer.upload(null, undefined, win, fail);
+            }).toThrow();
+            expect(function() {
+                FileTransfer.upload(undefined, null, win, fail);
+            }).toThrow();
+            expect(function() {
+                FileTransfer.upload("test.txt", undefined, win, fail);
+            }).toThrow();
+            expect(function() {
+                FileTransfer.upload(undefined, "http://google.com/robots.txt", win, fail);
+            }).toThrow();
+        });
+    });
+});


Mime
View raw message