cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmo...@apache.org
Subject [1/3] git commit: CB-6466 created mobile-spec test
Date Fri, 15 Aug 2014 20:00:41 GMT
Repository: cordova-plugin-file-transfer
Updated Branches:
  refs/heads/master e89989dc3 -> b5d1dffc2


CB-6466 created mobile-spec test

Added a test to check that filetransfer.download() automatically creates
any nonexistent directories.

Also removed some unused code


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/0b257f53
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/0b257f53
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/0b257f53

Branch: refs/heads/master
Commit: 0b257f534c96c6c1584ebc4657ecdd0be9a6ccff
Parents: e89989d
Author: Staci Cooper <smcooper@us.ibm.com>
Authored: Tue Aug 12 13:06:36 2014 -0400
Committer: Staci Cooper <smcooper@us.ibm.com>
Committed: Tue Aug 12 13:06:36 2014 -0400

----------------------------------------------------------------------
 tests/tests.js | 60 +++++++++++++++++++++--------------------------------
 1 file changed, 24 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/0b257f53/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 2eedd95..213913c 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -868,36 +868,9 @@ exports.defineManualTests = function (contentEl, createActionButton)
{
         results.innerHTML = '';
     }
 
-    function downloadImgCDV(ev) {
-        ev.preventDefault();
-        ev.stopPropagation();
-        downloadImg(imageURL, function (entry) { return entry.toURL(); }, new Image());
-    }
-
-    function downloadImgNative(ev) {
-        ev.preventDefault();
-        ev.stopPropagation();
-        downloadImg(imageURL, function (entry) { return entry.toNativeURL(); }, new Image);
-    }
-
-    function downloadVideoCDV(ev) {
-        ev.preventDefault();
-        ev.stopPropagation();
-        var videoElement = document.createElement('video');
-        videoElement.controls = "controls";
-        downloadImg(videoURL, function (entry) { return entry.toURL(); }, videoElement);
-    }
-
-    function downloadVideoNative(ev) {
-        ev.preventDefault();
-        ev.stopPropagation();
-        var videoElement = document.createElement('video');
-        videoElement.controls = "controls";
-        downloadImg(videoURL, function (entry) { return entry.toNativeURL(); }, videoElement);
-    }
-
-    function downloadImg(source, urlFn, element) {
+    function downloadImg(source, urlFn, element, directory) {
         var filename = source.substring(source.lastIndexOf("/") + 1);
+        filename = directory + filename || filename;
         function download(fileSystem) {
             var ft = new FileTransfer();
             console.log("Starting download");
@@ -913,14 +886,25 @@ exports.defineManualTests = function (contentEl, createActionButton)
{
         clearResults();
         requestFileSystem(TEMPORARY, 0, function (fileSystem) {
             console.log("Checking for existing file");
-            fileSystem.root.getFile(filename, { create: false }, function (entry) {
-                console.log("Removing existing file");
-                entry.remove(function () {
+            if (directory != undefined) {
+                console.log("Checking for existing directory.");
+                fileSystem.root.getDirectory(directory, {}, function (dirEntry) {
+                    dirEntry.removeRecursively(function () {
+                        download(fileSystem);
+                    }, function (e) { console.log("ERROR: dirEntry.removeRecursively") });
+                }, function () {
                     download(fileSystem);
-                }, function (e) { console.log("ERROR: entry.remove"); });
-            }, function () {
-                download(fileSystem);
-            });
+                });
+            } else {
+                fileSystem.root.getFile(filename, { create: false }, function (entry) {
+                    console.log("Removing existing file");
+                    entry.remove(function () {
+                        download(fileSystem);
+                    }, function (e) { console.log("ERROR: entry.remove"); });
+                }, function () {
+                    download(fileSystem);
+                });
+            }
         }, function (e) { console.log("ERROR: requestFileSystem"); });
     }
 
@@ -937,6 +921,10 @@ exports.defineManualTests = function (contentEl, createActionButton)
{
         downloadImg(imageURL, function (entry) { return entry.toNativeURL(); }, new Image);
     }, 'actions');
 
+    createActionButton('Download to a non-existent dir (should work)', function () {
+        downloadImg(imageURL, function (entry) { return entry.toURL(); }, new Image, '/nonExistentDirTest/');
+    }, 'actions');
+
     createActionButton('Download and play video (cdvfile)', function () {
         var videoElement = document.createElement('video');
         videoElement.controls = "controls";


Mime
View raw message