-Add a file transfer test that tests https, and the response body.
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/commit/1a2ede88 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/tree/1a2ede88 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/diff/1a2ede88 Branch: refs/heads/master Commit: 1a2ede8894743c69ac364cb01769bb5b57233a0c Parents: 84976a9 Author: Andrew Grieve <agri...@chromium.org> Authored: Fri Aug 31 13:44:20 2012 -0400 Committer: Andrew Grieve <agri...@chromium.org> Committed: Tue Sep 18 09:59:44 2012 -0400 ---------------------------------------------------------------------- autotest/tests/filetransfer.tests.js | 33 ++++++++++++++++++++++++++++- 1 files changed, 32 insertions(+), 1 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/1a2ede88/autotest/tests/filetransfer.tests.js ---------------------------------------------------------------------- diff --git a/autotest/tests/filetransfer.tests.js b/autotest/tests/filetransfer.tests.js index c140343..10f2f76 100644 --- a/autotest/tests/filetransfer.tests.js +++ b/autotest/tests/filetransfer.tests.js @@ -74,6 +74,17 @@ describe('FileTransfer', function() { }, error); }; + var readFileEntry = function(entry, success, error) { + entry.file(function(file) { + var reader = new FileReader(); + reader.onerror = error; + reader.onload = function(e) { + success(reader.result); + }; + reader.readAsText(file); + }, error); + }; + var getMalformedUrl = function() { if (device.platform.match(/Android/i)) { // bad protocol causes a MalformedUrlException on Android @@ -145,7 +156,7 @@ describe('FileTransfer', function() { // - Item 1 String cordova-filetransfer.jitsu.com // - Item 2 String *.apache.org - it("should be able to download a file", function() { + it("should be able to download a file using http", function() { var fail = createDoNotCallSpy('downloadFail'); var remoteFile = server + "/robots.txt" var localFileName = remoteFile.substring(remoteFile.lastIndexOf('/')+1); @@ -161,6 +172,26 @@ describe('FileTransfer', function() { waitsForAny(downloadWin, fail); }); + it("should be able to download a file using https", function() { + var remoteFile = "https://www.apache.org/licenses/"; + var localFileName = 'httpstest.html'; + var downloadFail = createDoNotCallSpy('downloadFail', 'Ensure ' + remoteFile + ' is in the white-list'); + var fileFail = createDoNotCallSpy('fileFail'); + var downloadWin = function(entry) { + readFileEntry(entry, fileWin, fileFail); + }; + var fileWin = jasmine.createSpy().andCallFake(function(content) { + expect(content).toMatch(/The Apache Software Foundation/); + deleteFile(localFileName); + }); + + runs(function() { + var ft = new FileTransfer(); + ft.download(remoteFile, root.fullPath + "/" + localFileName, downloadWin, downloadFail); + }); + + waitsForAny(fileWin, downloadFail, fileFail); + }); it("should get http status on failure", function() { var downloadWin = createDoNotCallSpy('downloadWin');