cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [3/3] spec commit: [CB-2213] Added three new tests to Camera.
Date Thu, 17 Jan 2013 15:00:30 GMT
Updated Branches:
  refs/heads/native-uri [created] 077fd412b


[CB-2213] Added three new tests to Camera.

The tests ensure that FileEntry.remove, FileEntry.setMetadata, and FileReader.readAsText return
errors when used with a native URI.

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/077fd412
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/077fd412
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/077fd412

Branch: refs/heads/native-uri
Commit: 077fd412b73babfe60972a6ba3a2d781ac3ba148
Parents: 5e640cb
Author: Max Woghiren <max.woghiren@gmail.com>
Authored: Wed Jan 16 15:12:24 2013 -0500
Committer: Max Woghiren <max.woghiren@gmail.com>
Committed: Wed Jan 16 15:12:24 2013 -0500

----------------------------------------------------------------------
 camera/index.html |   45 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 39 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/077fd412/camera/index.html
----------------------------------------------------------------------
diff --git a/camera/index.html b/camera/index.html
index 22cdedb..4d56619 100644
--- a/camera/index.html
+++ b/camera/index.html
@@ -74,7 +74,7 @@
                 img.style.display = "block";
                 //img.src = "data:image/jpeg;base64," + data;
                 img.src = data;
-                document.getElementById('camera_status').innerHTML = "Success";
+               document.getElementById('camera_status').innerHTML = "Success";
             },
             function(e) {
                 console.log("Error getting picture: " + e);
@@ -92,6 +92,30 @@
             document.getElementById('camera_status').innerHTML += "FileEntry.getMetadata
<b>success</b>: modificationTime = " + metadata.modificationTime + "<br />";
         };
 
+        var onMetadataSet = function() {
+            document.getElementById('camera_status').innerHTML += "FileEntry.setMetadata
<b>error</b>: setMetadata succeeded when it should fail<br />";
+        };
+
+        var onMetadataSetError = function(e) {
+            document.getElementById('camera_status').innerHTML += "FileEntry.setMetadata
<b>success</b> (failed as expected): " + e.code + "<br />"
+        };
+
+        var onFileEntryRemoved = function() {
+            document.getElementById('camera_status').innerHTML += "FileEntry.remove <b>error</b>:
remove succeeded when it should fail<br />";
+        };
+
+        var onFileEntryRemoveError = function(e) {
+            document.getElementById('camera_status').innerHTML += "FileEntry.remove <b>success</b>
(failed as expected): " + e.code + "<br />"
+        };
+
+        var onFileReadAsText = function(evt) {
+            document.getElementById('camera_status').innerHTML += "FileReader.readAsText
<b>error</b>: readAsText succeeded when it should fail: " + evt.target.result
+ "<br />";
+        };
+
+        var onFileReadAsTextError = function(evt) {
+            document.getElementById('camera_status').innerHTML += "FileReader.readAsText
<b>success</b> (failed as expected): " + evt.target.error.code + "<br />"
+        };
+
         var onFileReadAsDataURL = function(evt) {
             var img = document.getElementById('camera_image');
             img.style.visibility = "visible";
@@ -105,25 +129,34 @@
             document.getElementById('camera_status').innerHTML += "; type = " + file.type
+ "; size = " + file.size + "; date = " + file.lastModifiedDate + "<br />";
 
             // Test File API here.
-            var reader = new FileReader();
-            reader.onload = onFileReadAsDataURL;
-            reader.onerror = function(evt) {
+            var textReader = new FileReader();
+            textReader.onload = onFileReadAsText;
+            textReader.onerror = onFileReadAsTextError;
+            textReader.readAsText(file);
+
+            var dataUrlReader = new FileReader();
+            dataUrlReader.onload = onFileReadAsDataURL;
+            dataUrlReader.onerror = function(evt) {
                 onError(evt.target.error);
             };
-            reader.readAsDataURL(file);
+            dataUrlReader.readAsDataURL(file);
         };
 
         var onError = function(e) {
             console.log("Error getting picture: " + e.code);
-            document.getElementById('camera_status').innerHTML += "Error getting picture:
" + e.code + "<br />";
+            document.getElementById('camera_status').innerHTML += "<b>Error</b>
getting picture: " + e.code + "<br />";
         };
 
+        document.getElementById('camera_status').innerHTML = "";
+
         navigator.camera.getPicture(
             function(data) {
                 var fileEntry = new FileEntry('image_name.png', data);
 
                 // Test FileEntry API here.
                 fileEntry.getMetadata(onMetadataReceived, onError);
+                fileEntry.setMetadata(onMetadataSet, onMetadataSetError, { "com.apple.MobileBackup":
1 });
+                fileEntry.remove(onFileEntryRemoved, onFileEntryRemoveError);
                 fileEntry.file(onFileReceived, onError);
             },
             onError,


Mime
View raw message