cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject spec commit: [CB-2406] Add ArrayBuffer and Blob FileWriter tests
Date Wed, 12 Jun 2013 17:34:56 GMT
Updated Branches:
  refs/heads/master 579475ee5 -> cf3e6ac50


[CB-2406] Add ArrayBuffer and Blob FileWriter tests


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

Branch: refs/heads/master
Commit: cf3e6ac5045a6d01cbf7fed029c8532c3fbc0080
Parents: 579475e
Author: Ian Clelland <iclelland@chromium.org>
Authored: Wed Jun 12 08:46:16 2013 -0400
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Wed Jun 12 13:33:51 2013 -0400

----------------------------------------------------------------------
 autotest/tests/file.tests.js | 98 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/cf3e6ac5/autotest/tests/file.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/file.tests.js b/autotest/tests/file.tests.js
index dcbe832..c481ed3 100644
--- a/autotest/tests/file.tests.js
+++ b/autotest/tests/file.tests.js
@@ -3472,5 +3472,103 @@ describe('File API', function() {
                 expect(fail).not.toHaveBeenCalled();
             });
         });
+        it("file.spec.104 should be able to write binary data from an ArrayBuffer", function()
{
+            var fileName = "bufferwriter.bin",
+                filePath = root.fullPath + '/' + fileName,
+                theWriter,
+                // file content
+                data = new ArrayBuffer(32),
+                dataView = new Int8Array(data),
+                fail = createFail('FileWriter'),
+                // for verifying file length
+                length = 32,
+                verifier = jasmine.createSpy().andCallFake(function(evt) {
+                    expect(theWriter.length).toBe(length);
+                    expect(theWriter.position).toBe(length);
+
+                    // cleanup
+                    deleteFile(fileName);
+                }),
+                // writes file content
+                write_file = function(fileEntry) {
+                    fileEntry.createWriter(function(writer) {
+                        theWriter = writer;
+                        theWriter.onwriteend = verifier;
+                        theWriter.write(data);
+                    }, fail);
+                };
+
+            for (i=0; i < dataView.length; i++) {
+                dataView[i] = i;
+            }
+
+            // creates file, then write content
+            runs(function() {
+                createFile(fileName, write_file);
+            });
+
+            waitsFor(function() { return verifier.wasCalled; }, "verifier", Tests.TEST_TIMEOUT);
+
+            runs(function() {
+                expect(verifier).toHaveBeenCalled();
+                expect(fail).not.toHaveBeenCalled();
+            });
+        });
+        it("file.spec.105 should be able to write binary data from a Blob", function() {
+            var fileName = "blobwriter.bin",
+                filePath = root.fullPath + '/' + fileName,
+                theWriter,
+                fail = createFail('FileWriter'),
+                // file content
+                data = new ArrayBuffer(32),
+                dataView = new Int8Array(data),
+                blob,
+                // for verifying file length
+                length = 32,
+                verifier = jasmine.createSpy().andCallFake(function(evt) {
+                    expect(theWriter.length).toBe(length);
+                    expect(theWriter.position).toBe(length);
+
+                    // cleanup
+                    deleteFile(fileName);
+                }),
+                // writes file content
+                write_file = function(fileEntry) {
+                    fileEntry.createWriter(function(writer) {
+                        theWriter = writer;
+                        theWriter.onwriteend = verifier;
+                        theWriter.write(blob);
+                    }, fail);
+                };
+            for (i=0; i < dataView.length; i++) {
+                dataView[i] = i;
+            }
+            try {
+                // Mobile Safari: Use Blob constructor
+                blob = new Blob([data], {"type": "application/octet-stream"})
+            } catch(e) {
+                if (window.WebKitBlobBuilder) {
+                    // Android Browser: Use deprecated BlobBuilder
+                    var builder = new WebKitBlobBuilder()
+                    builder.append(data)
+                    blob = builder.getBlob('application/octet-stream');
+                } else {
+                    // We have no way defined to create a Blob, so fail
+                    fail();
+                }
+            }
+
+            // creates file, then write content
+            runs(function() {
+                createFile(fileName, write_file);
+            });
+
+            waitsFor(function() { return verifier.wasCalled; }, "verifier", Tests.TEST_TIMEOUT);
+
+            runs(function() {
+                expect(verifier).toHaveBeenCalled();
+                expect(fail).not.toHaveBeenCalled();
+            });
+        });
     });
 });


Mime
View raw message