You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/01/11 20:59:13 UTC

spec commit: Add a test that reads a native Blob with a FileReader.

Updated Branches:
  refs/heads/master f9186feea -> fa02bfdb9


Add a test that reads a native Blob with a FileReader.

Related to: https://issues.apache.org/jira/browse/CB-2206


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

Branch: refs/heads/master
Commit: fa02bfdb9627a01a14853f100d8006ff3c68ecdc
Parents: f9186fe
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Jan 11 13:57:33 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Jan 11 14:58:58 2013 -0500

----------------------------------------------------------------------
 autotest/tests/file.tests.js |   34 +++++++++++++++++++++++++++++-----
 1 files changed, 29 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/fa02bfdb/autotest/tests/file.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/file.tests.js b/autotest/tests/file.tests.js
index 9a540da..45a789f 100644
--- a/autotest/tests/file.tests.js
+++ b/autotest/tests/file.tests.js
@@ -3001,15 +3001,39 @@ describe('File API', function() {
             var myFile = new File();
             myFile.fullPath = root.fullPath + '/' + "doesnotexist.err";
 
-            runs(function() {
-                reader.readAsText(myFile);
-            });
+            reader.readAsText(myFile);
 
             waitsFor(function() { return verifier.wasCalled; }, "verifier never called", Tests.TEST_TIMEOUT);
+        });
+        // This test fails on Android <= 2.3 and iOS <= 5 due to a lack of
+        // Blob creation on these platforms.
+        it("should be able to read native blob objects", function() {
+            var contents = 'asdf';
+            var uint8Array = new Uint8Array(contents.length);
+            for (var i = 0; i < contents.length; ++i) {
+              uint8Array[i] = contents.charCodeAt(i);
+            }
+            var Builder = window.BlobBuilder || window.WebKitBlobBuilder;
+            var blob;
+            if (Builder) {
+                var builder = new Builder();
+                builder.append(uint8Array.buffer);
+                builder.append(contents);
+                blob = builder.getBlob("text/plain");
+            } else {
+                // iOS 6 does not support Views here.
+                blob = new Blob([uint8Array.buffer, contents]);
+            }
 
-            runs(function() {
-                expect(verifier).toHaveBeenCalled();
+            var verifier = jasmine.createSpy().andCallFake(function(evt) {
+                expect(evt).toBeDefined();
+                expect(evt.target.result).toBe('asdfasdf');
             });
+            var reader = new FileReader();
+            reader.onloadend = verifier;
+            reader.readAsText(blob);
+
+            waitsFor(function() { return verifier.wasCalled; }, "verifier never called", 300);
         });
         it("should read file properly, Data URI", function() {
             // path of file