diff --git a/test/app-test-definitions.js b/test/app-test-definitions.js index 82dc897..18b3aab 100644 --- a/test/app-test-definitions.js +++ b/test/app-test-definitions.js @@ -6,7 +6,17 @@ const hooks = { const helpers = { acceptAllCerts: function(done) { cordova.plugin.http.acceptAllCerts(true, done, done); }, - setJsonSerializer: function(done) { done(cordova.plugin.http.setDataSerializer('json')); } + setJsonSerializer: function(done) { done(cordova.plugin.http.setDataSerializer('json')); }, + getWithXhr: function(done, url) { + var xhr = new XMLHttpRequest(); + + xhr.addEventListener('load', function() { + done(this.responseText); + }); + + xhr.open('GET', url); + xhr.send(); + } }; const tests = [ @@ -166,6 +176,30 @@ const tests = [ result.type.should.be.equal('resolved'); result.data.url.should.be.equal('http://httpbin.org/anything'); } + },{ + description: 'should download a file from given URL to given path in local filesystem', + expected: 'resolved: {"content": "\\n\\n" ...', + func: function(resolve, reject) { + var sourceUrl = 'http://httpbin.org/xml'; + var targetPath = cordova.file.cacheDirectory + 'test.xml'; + + cordova.plugin.http.downloadFile(sourceUrl, {}, {}, targetPath, function(entry) { + helpers.getWithXhr(function(content) { + resolve({ + sourceUrl: sourceUrl, + targetPath: targetPath, + fullPath: entry.fullPath, + name: entry.name, + content: content + }); + }, targetPath); + }, reject); + }, + validationFunc: function(driver, result) { + result.type.should.be.equal('resolved'); + result.data.name.should.be.equal('test.xml'); + result.data.content.should.be.equal("\n\n\n\n\n\n \n \n Wake up to WonderWidgets!\n \n\n \n \n Overview\n Why WonderWidgets are great\n \n Who buys WonderWidgets\n \n\n"); + } } ];