From c7462390345d9e9ad87e08458134f8f168a5c62c Mon Sep 17 00:00:00 2001 From: James Keshavarzi Date: Wed, 16 Apr 2014 12:21:39 -0400 Subject: [PATCH] Implemented blackberry.io.filetransfer download and upload tests -Fixed minor issue with blackberry.io.filetransfer.PERMISSIONS_ERR --- .../www/client.js | 2 +- .../spec/blackberry.io.filetransfer.js | 78 ++++++++++++++++++- test/test-app/config.xml | 11 +-- 3 files changed, 82 insertions(+), 9 deletions(-) diff --git a/plugin/com.blackberry.io.filetransfer/www/client.js b/plugin/com.blackberry.io.filetransfer/www/client.js index 3d8a01f..a3fa7e8 100644 --- a/plugin/com.blackberry.io.filetransfer/www/client.js +++ b/plugin/com.blackberry.io.filetransfer/www/client.js @@ -85,6 +85,6 @@ _self.download = function (source, target, successCallback, errorCallback) { defineReadOnlyField(_self, "FILE_NOT_FOUND_ERR", 1); defineReadOnlyField(_self, "INVALID_URL_ERR", 2); defineReadOnlyField(_self, "CONNECTION_ERR", 3); -defineReadOnlyField(_self, "PERMISSIONS_ERR", 3); +defineReadOnlyField(_self, "PERMISSIONS_ERR", 4); module.exports = _self; diff --git a/test/test-app/automatic/spec/blackberry.io.filetransfer.js b/test/test-app/automatic/spec/blackberry.io.filetransfer.js index 757f2ab..ad6e912 100644 --- a/test/test-app/automatic/spec/blackberry.io.filetransfer.js +++ b/test/test-app/automatic/spec/blackberry.io.filetransfer.js @@ -14,8 +14,7 @@ * limitations under the License. */ -var upload_source, - upload_target; +var upload_target = "http://ci0000001875214.rim.net/upload.php"; function testConstantValue(field, value) { expect(blackberry.io.filetransfer[field]).toBeDefined(); @@ -39,10 +38,83 @@ describe("blackberry.io.filetransfer", function () { expect(blackberry.io.filetransfer).toBeDefined(); }); - it('blackberry.io.filetransfer.* should be defined', function () { + it('blackberry.io.filetransfer.FILE_NOT_FOUND_ERR should be defined', function () { testConstantValue("FILE_NOT_FOUND_ERR", 1); + }); + + it('blackberry.io.filetransfer.INVALID_URL_ERR should be defined', function () { testConstantValue("INVALID_URL_ERR", 2); + }); + + it('blackberry.io.filetransfer.CONNECTION_ERR should be defined', function () { testConstantValue("CONNECTION_ERR", 3); }); + + it('blackberry.io.filetransfer.PERMISSIONS_ERR should be defined', function () { + testConstantValue("PERMISSIONS_ERR", 4); + }); + + describe("blackberry.io.filetransfer.download", function () { + it('blackberry.io.filetransfer.download should exist', function () { + expect(blackberry.io.filetransfer.download).toBeDefined(); + }); + + it('blackberry.io.filetransfer.download can download a file', function () { + var result, + failCallback = jasmine.createSpy('failCallback '); + + runs(function () { + blackberry.io.filetransfer.download( + "http://www.w3.org/2011/Talks/0928-webtv-nem-fd/slides.pdf", + blackberry.io.sharedFolder + "/downloads/W3html5TV.pdf", + function(callbackResult) { + result = callbackResult; + }, failCallback); + }) + + waitsFor(function() { + return result; + }, "Timeout occurred downloading file", 20000); + + runs(function () { + expect(result).toBeDefined(); + expect(result.name).toEqual("slides.pdf"); + expect(result.fullPath).toBeDefined(); + expect(failCallback.callCount).toEqual(0); + }) + }); + }); + + describe("blackberry.io.filetransfer.upload", function () { + it('blackberry.io.filetransfer.upload should exist', function () { + expect(blackberry.io.filetransfer.upload).toBeDefined(); + }); + + it('blackberry.io.filetransfer.upload can upload a file', function () { + var result, + failCallback = jasmine.createSpy('failCallback '); + + runs(function () { + blackberry.io.filetransfer.upload( + blackberry.io.sharedFolder + "/../app/native/img/blackberry10.jpg", + upload_target, + function(callbackResult) { + result = callbackResult; + }, failCallback); + }) + + waitsFor(function() { + return result; + }, "Timeout occurred uploading file", 20000); + + runs(function () { + expect(result).toBeDefined(); + expect(result.response).toEqual("1"); + expect(result.responseCode).toEqual(200); + expect(result.bytesSent).not.toEqual(0); + expect(failCallback.callCount).toEqual(0); + }) + }); + }); }); diff --git a/test/test-app/config.xml b/test/test-app/config.xml index 2e574a9..93d5e09 100644 --- a/test/test-app/config.xml +++ b/test/test-app/config.xml @@ -1,9 +1,9 @@ - WebWorks Test Application WebWorks Test App-fr @@ -63,6 +63,7 @@ +