cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [6/11] spec commit: [CB-2213] Added tests for write and truncate.
Date Tue, 12 Feb 2013 03:15:59 GMT
[CB-2213] Added tests for write and truncate.

Also added a method to clear the status before each test.


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

Branch: refs/heads/master
Commit: f1b2807dfe07c0663aa6a8a66ddcf0390c928337
Parents: 0306175
Author: Max Woghiren <max.woghiren@gmail.com>
Authored: Thu Jan 17 15:52:17 2013 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Mon Feb 11 21:19:34 2013 -0500

----------------------------------------------------------------------
 camera/index.html |   60 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 58 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/f1b2807d/camera/index.html
----------------------------------------------------------------------
diff --git a/camera/index.html b/camera/index.html
index 9bf9071..989d71e 100644
--- a/camera/index.html
+++ b/camera/index.html
@@ -60,6 +60,7 @@
      * Capture picture
      */
     function getPicture() {
+        clearStatus();
         navigator.camera.getPicture(getPictureWin, getPictureFail,
             { quality: 50, destinationType:
             Camera.DestinationType.FILE_URI, sourceType : Camera.PictureSourceType.CAMERA});
@@ -88,6 +89,7 @@
      * Select image from library using a FILE_URI destination type
      */
     function getImageUsingFileUri(upload) {
+        clearStatus();
         navigator.camera.getPicture(
             function(data) {
                 getPictureWin(data);
@@ -162,8 +164,7 @@
             document.getElementById('camera_status').innerHTML += "<b>Error</b>
getting picture: " + e.code + "<br />";
         };
 
-        document.getElementById('camera_status').innerHTML = "";
-
+        clearStatus();
         navigator.camera.getPicture(
             function(data) {
                 var fileEntry = new FileEntry('image_name.png', data);
@@ -261,9 +262,63 @@
                 Camera.DestinationType.NATIVE_URI, sourceType: Camera.PictureSourceType.PHOTOLIBRARY});
         };
 
+        clearStatus();
         window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, onFileSystemReceived, null);
     };
 
+    function writeImageUsingNativeUri() {
+        var onFileWrite = function(evt) {
+            document.getElementById('camera_status').innerHTML += "FileWriter.write <b>error</b>:
write succeeded when it should fail<br />"
+        };
+
+        var onFileWriteError = function(evt) {
+            document.getElementById('camera_status').innerHTML += "FileWriter.write <b>success</b>
(failed as expected): " + evt.target.error.code + "<br />"
+        };
+
+        var onFileTruncate = function(evt) {
+            document.getElementById('camera_status').innerHTML += "FileWriter.truncate <b>error</b>:
truncate succeeded when it should fail<br />"
+        };
+
+        var onFileTruncateError = function(evt) {
+            document.getElementById('camera_status').innerHTML += "FileWriter.truncate <b>success</b>
(failed as expected): " + evt.target.error.code + "<br />"
+        };
+
+        var onFileWriterReceived = function(fileWriter) {
+          fileWriter.onwrite = onFileWrite;
+          fileWriter.onerror = onFileWriteError;
+          fileWriter.write("some text!");
+        };
+
+        var onFileTruncateWriterReceived = function(fileWriter) {
+          fileWriter.onwrite = onFileTruncate;
+          fileWriter.onerror = onFileTruncateError;
+          fileWriter.truncate(10);
+        };
+
+        var onError = function(e) {
+            console.log("Error getting picture: " + e.code);
+            document.getElementById('camera_status').innerHTML += "<b>Error</b>
getting picture: " + e.code + "<br />";
+        };
+
+        clearStatus();
+        navigator.camera.getPicture(
+            function(data) {
+                var fileEntry = new FileEntry('image_name.png', data);
+
+                // Test FileEntry API here.
+                fileEntry.createWriter(onFileWriterReceived, onError);
+                fileEntry.createWriter(onFileTruncateWriterReceived, onError);
+            },
+            onError,
+            { quality: 50, destinationType:
+            Camera.DestinationType.NATIVE_URI, sourceType: Camera.PictureSourceType.PHOTOLIBRARY});
+    };
+
+    function clearStatus() {
+        document.getElementById('camera_status').innerHTML = "";
+        document.getElementById('camera_image').style.visibility = "hidden";
+    }
+
     /**
      * Function called when page has finished loading.
      */
@@ -298,6 +353,7 @@
     <div class="btn large" onclick="getImageUsingNativeUri();">Native URI: Select Image,
Show Image</div>
     <div class="btn large" onclick="getImageUsingNativeUri();">Select Image Using Native
URI</div>
     <div class="btn large" onclick="copyImageUsingNativeUri();">Copy Image Using Native
URI</div>
+    <div class="btn large" onclick="writeImageUsingNativeUri();">Write Image Using
Native URI</div>
     <h3>input type=file</h3>
     <input type="file" onchange="testNativeFile(this)">
     <h3>capture=camera</h3>


Mime
View raw message