cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject spec commit: CB-6106: Test fileEntry.toNativeURL method
Date Thu, 27 Feb 2014 21:44:03 GMT
Repository: cordova-mobile-spec
Updated Branches:
  refs/heads/master 28694215d -> dcef9fb7c


CB-6106: Test fileEntry.toNativeURL method


Project: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/commit/dcef9fb7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/dcef9fb7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/dcef9fb7

Branch: refs/heads/master
Commit: dcef9fb7c668fb120d496491e332d5b5806d8b78
Parents: 2869421
Author: Ian Clelland <iclelland@chromium.org>
Authored: Thu Feb 27 16:41:23 2014 -0500
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Thu Feb 27 16:41:23 2014 -0500

----------------------------------------------------------------------
 autotest/tests/file.tests.js         | 90 +++++++++++++++++++++++++++++++
 autotest/tests/filetransfer.tests.js | 25 +++++++++
 file/index.html                      | 22 ++++++--
 3 files changed, 132 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/dcef9fb7/autotest/tests/file.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/file.tests.js b/autotest/tests/file.tests.js
index bc6daf3..14c32a5 100644
--- a/autotest/tests/file.tests.js
+++ b/autotest/tests/file.tests.js
@@ -4068,4 +4068,94 @@ describe('File API', function() {
         });
 
     });
+    describe('toNativeURL interface', function() {
+        /* These specs verify that FileEntries have a toNativeURL method
+         * which appears to be sane.
+         */
+        it("file.spec.114 fileEntry should have a toNativeURL method", function() {
+            var fileName = "native.file.uri",
+                win = jasmine.createSpy().andCallFake(function(fileEntry) {
+                    expect(fileEntry).toBeDefined();
+                    expect(fileEntry.name).toCanonicallyMatch(fileName);
+
+                    // cleanup
+                    deleteEntry(fileName);
+                }),
+                fail = createFail('window.resolveLocalFileSystemURI'),
+                createCallback = jasmine.createSpy().andCallFake(function(entry) {
+                    expect(entry.toNativeURL).toBeDefined();
+                    expect(typeof entry.toNativeURL).toBe('function');
+                    var nativeURL = entry.toNativeURL();
+                    expect(typeof nativeURL).toBe("string");
+                    expect(nativeURL.substring(0,7)).toEqual("file://");
+                    expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);
+                });
+
+            // create a new file entry
+            runs(function() {
+                createFile(fileName, createCallback, fail);
+            });
+
+            waitsFor(function() { return createCallback.wasCalled; }, "createFile callback
never called", Tests.TEST_TIMEOUT);
+        });
+        it("file.spec.115 DirectoryReader should return entries with toNativeURL method",
function(done) {
+            var fail = createFail('DirectoryReader', done),
+                dirName = 'nativeEntries.dir',
+                fileName = 'nativeEntries.file',
+                checkEntries = jasmine.createSpy().andCallFake(function(entries) {
+                    expect(entries).toBeDefined();
+                    expect(entries instanceof Array).toBe(true);
+                    expect(entries.length).toBe(1);
+                    expect(entries[0].toNativeURL).toBeDefined();
+                    expect(typeof entries[0].toNativeURL).toBe('function');
+                    var nativeURL = entries[0].toNativeURL();
+                    expect(typeof nativeURL).toBe("string");
+                    expect(nativeURL.substring(0,7)).toEqual("file://");
+                    expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);
+
+                    // cleanup
+                    directory.removeRecursively(done, fail);
+                });
+            // create a new file entry
+            runs(function() {
+            root.getDirectory(dirName, {create: true}, function(directory) {
+                directory.getFile(fileName, {create: true}, function(fileEntry) {
+                    var reader = directory.createReader();
+                    reader.readEntries(checkEntries, fail);
+                }, fail);
+            }, fail);
+            });
+
+            waitsFor(function() { return checkEntries.wasCalled; }, "checkEntries callback
never called", Tests.TEST_TIMEOUT);
+        });
+        it("file.spec.116 resolveLocalFileSystemURL should return entries with toNativeURL
method", function() {
+            var fileName = "native.resolve.uri",
+                win = jasmine.createSpy().andCallFake(function(fileEntry) {
+                    expect(fileEntry).toBeDefined();
+                    expect(fileEntry.name).toCanonicallyMatch(fileName);
+
+                    // cleanup
+                    deleteEntry(fileName);
+                }),
+                fail = createFail('window.resolveLocalFileSystemURI'),
+                checkEntry = jasmine.createSpy().andCallFake(function(entry) {
+                    expect(entry.toNativeURL).toBeDefined();
+                    expect(typeof entry.toNativeURL).toBe('function');
+                    var nativeURL = entry.toNativeURL();
+                    expect(typeof nativeURL).toBe("string");
+                    expect(nativeURL.substring(0,7)).toEqual("file://");
+                    expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);
+                });
+
+            // create a new file entry
+            runs(function() {
+                createFile(fileName, function(entry) {
+                    resolveLocalFileSystemURL(entry.toURL(), checkEntry, fail);
+                }, fail);
+            });
+
+            waitsFor(function() { return checkEntry.wasCalled; }, "checkEntry callback never
called", Tests.TEST_TIMEOUT);
+        });
+
+    });
 });

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/dcef9fb7/autotest/tests/filetransfer.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/filetransfer.tests.js b/autotest/tests/filetransfer.tests.js
index d1bce9e..16ae271 100644
--- a/autotest/tests/filetransfer.tests.js
+++ b/autotest/tests/filetransfer.tests.js
@@ -887,4 +887,29 @@ describe('FileTransfer', function() {
             });
         });
     });
+    describe('native URL interface', function() {
+        it("filetransfer.spec.30 downloaded file entries should have a toNativeURL method",
function() {
+            var fail = createDoNotCallSpy('downloadFail');
+            var remoteFile = server + "/robots.txt";
+            var localFileName = remoteFile.substring(remoteFile.lastIndexOf('/')+1)+".spec30";
+
+            var downloadWin = jasmine.createSpy().andCallFake(function(entry) {
+                expect(entry.toNativeURL).toBeDefined();
+                expect(typeof entry.toNativeURL).toBe("function");
+                var nativeURL = entry.toNativeURL();
+                expect(typeof nativeURL).toBe("string");
+                expect(nativeURL.substring(0,7)).toBe('file://');
+            });
+
+            this.after(function() {
+                deleteFile(localFileName);
+            });
+            runs(function() {
+                var ft = new FileTransfer();
+                ft.download(remoteFile, root.toURL() + "/" + localFileName, downloadWin,
fail);
+            });
+
+            waitsForAny(downloadWin, fail);
+        });
+    });
 });

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/dcef9fb7/file/index.html
----------------------------------------------------------------------
diff --git a/file/index.html b/file/index.html
index a3938e3..8b4da1a 100644
--- a/file/index.html
+++ b/file/index.html
@@ -51,7 +51,8 @@
     }
 
     function bindEvents() {
-        document.getElementById('downloadImg').addEventListener('click', downloadImg, false);
+        document.getElementById('downloadImgCDV').addEventListener('click', downloadImgCDV,
false);
+        document.getElementById('downloadImgNative').addEventListener('click', downloadImgNative,
false);
     }
 
     function clearLog() {
@@ -75,9 +76,19 @@
         };
     }
 
-    function downloadImg(ev) {
+    function downloadImgNative(ev) {
         ev.preventDefault();
         ev.stopPropagation();
+        downloadImg(function(entry) { return entry.toNativeURL(); });
+    }
+
+    function downloadImgCDV(ev) {
+        ev.preventDefault();
+        ev.stopPropagation();
+        downloadImg(function(entry) { return entry.toURL(); });
+    }
+
+    function downloadImg(urlFn) {
         var filename = "feather0.gif";
         function download(fileSystem) {
             var ft = new FileTransfer();
@@ -86,8 +97,8 @@
             ft.download(imageURL, fileSystem.root.toURL() + "/" + filename, function(entry)
{
                 logMessage("Download complete")
                 var imgElement = new Image();
-                logMessage("Image URL is " + entry.toURL(), "green");
-                imgElement.src = entry.toURL();
+                imgElement.src = urlFn(entry)
+                logMessage("Image URL is " + imgElement.src, "green");
                 logMessage("Inserting image");
                 document.getElementById("output").appendChild(imgElement);
             }, logError("ft.download"));
@@ -113,7 +124,8 @@
 
     <h1>File and File Transfer</h1>
     <h2>File</h2>
-    <div class="btn large" id="downloadImg">Download and display img</div>
+    <div class="btn large" id="downloadImgCDV">Download and display img (cdvfile)</div>
+    <div class="btn large" id="downloadImgNative">Download and display img (native)</div>
 
     <div id="log"></div>
     <div id="output"></div>


Mime
View raw message