cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject [2/2] spec commit: [CB-3992] Test that FileWrite.write() supports File objects
Date Mon, 24 Jun 2013 18:43:58 GMT
[CB-3992] Test that FileWrite.write() supports File objects


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

Branch: refs/heads/master
Commit: 4e9b35e34c9f5fef5a89fb790631c5821ec840e7
Parents: bb00902
Author: Ian Clelland <iclelland@chromium.org>
Authored: Fri Jun 21 14:02:43 2013 -0400
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Mon Jun 24 14:43:07 2013 -0400

----------------------------------------------------------------------
 autotest/tests/file.tests.js | 111 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 109 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/4e9b35e3/autotest/tests/file.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/file.tests.js b/autotest/tests/file.tests.js
index 3ebaffc..3176472 100644
--- a/autotest/tests/file.tests.js
+++ b/autotest/tests/file.tests.js
@@ -95,13 +95,13 @@ describe('File API', function() {
     };
 
     var createFail = function(module) {
-        return jasmine.createSpy().andCallFake(function(err) {
+        return jasmine.createSpy("Fail").andCallFake(function(err) {
             console.log('[ERROR ' + module + '] ' + JSON.stringify(err));
         });
     };
 
     var createWin = function(module) {
-        return jasmine.createSpy().andCallFake(function() {
+        return jasmine.createSpy("Win").andCallFake(function() {
             console.log('[ERROR ' + module + '] Unexpected success callback');
         });
     };
@@ -1086,6 +1086,7 @@ describe('File API', function() {
                     expect(fileEntry).toBeDefined();
                     expect(typeof fileEntry.createWriter).toBe('function');
                     expect(typeof fileEntry.file).toBe('function');
+                    expect(fileEntry.file instanceof file).toBe(true);
 
                     // cleanup
                     fileEntry.remove(null, fail);
@@ -3586,5 +3587,111 @@ describe('File API', function() {
                 expect(fail).not.toHaveBeenCalled();
             });
         });
+        it("file.spec.106 should be able to write a File to a FileWriter", function() {
+            var dummyFileName = 'dummy.txt',
+                outputFileName = 'verify.txt',
+                dummyFileText = 'This text should be written to two files',
+                fail = createFail('FileWriter'),
+                verifier = jasmine.createSpy("verifier").andCallFake(function(outputFileWriter)
{
+                    expect(outputFileWriter.length).toBe(dummyFileText.length);
+                    expect(outputFileWriter.position).toBe(dummyFileText.length);
+                    deleteFile(fileName);
+                }),
+                writeFile = function(fileName, fileData, win) {
+                    var theWriter,
+                        filePath = root.fullPath + '/' + fileName,
+                        // writes file content to new file
+                        write_file = function(fileEntry) {
+                            writerEntry = fileEntry;
+                            fileEntry.createWriter(function(writer) {
+                                theWriter = writer;
+                                writer.onwriteend = function(ev) {
+                                    if (typeof fileData.length !== "undefined") {
+                                        expect(theWriter.length).toBe(fileData.length);
+                                        expect(theWriter.position).toBe(fileData.length);
+                                    }
+                                    win(theWriter);
+                                }
+                                writer.onerror = fail;
+                                writer.write(fileData);
+                            }, fail);
+                        };
+                    createFile(fileName, write_file, fail);
+                },
+
+                openFile = function(fileName, callback) {
+                    root.getFile(fileName, {create: false}, function(fileEntry) {
+                        fileEntry.file(callback, fail);
+                    }, fail);
+                };
+
+            runs(function() {
+                writeFile(dummyFileName, dummyFileText, function(dummyFileWriter) {
+                    openFile(dummyFileName, function(file) {
+                        writeFile(outputFileName, file, verifier);
+                    });
+                });
+            });
+            waitsFor(function() { return (verifier.wasCalled || fail.wasCalled); }, "callbacks
never called", Tests.TEST_TIMEOUT);
+
+            runs(function() {
+                expect(verifier).toHaveBeenCalled();
+                expect(fail).not.toHaveBeenCalled();
+            });
+
+        });
+        it("file.spec.107 should be able to write a sliced File to a FileWriter", function()
{
+            var dummyFileName = 'dummy2.txt',
+                outputFileName = 'verify2.txt',
+                dummyFileText = 'This text should be written to two files',
+                fail = createFail('FileWriter'),
+                verifier = jasmine.createSpy("verifier").andCallFake(function(outputFileWriter)
{
+                    expect(outputFileWriter.length).toBe(10);
+                    expect(outputFileWriter.position).toBe(10);
+                    deleteFile(fileName);
+                }),
+                writeFile = function(fileName, fileData, win) {
+                    var theWriter,
+                        filePath = root.fullPath + '/' + fileName,
+                        // writes file content to new file
+                        write_file = function(fileEntry) {
+                            writerEntry = fileEntry;
+                            fileEntry.createWriter(function(writer) {
+                                theWriter = writer;
+                                writer.onwriteend = function(ev) {
+                                    if (typeof fileData.length !== "undefined") {
+                                        expect(theWriter.length).toBe(fileData.length);
+                                        expect(theWriter.position).toBe(fileData.length);
+                                    }
+                                    win(theWriter);
+                                }
+                                writer.onerror = fail;
+                                writer.write(fileData);
+                            }, fail);
+                        };
+                    createFile(fileName, write_file, fail);
+                },
+
+                openFile = function(fileName, callback) {
+                    root.getFile(fileName, {create: false}, function(fileEntry) {
+                        fileEntry.file(callback, fail);
+                    }, fail);
+                };
+
+            runs(function() {
+                writeFile(dummyFileName, dummyFileText, function(dummyFileWriter) {
+                    openFile(dummyFileName, function(file) {
+                        writeFile(outputFileName, file.slice(10,20), verifier);
+                    });
+                });
+            });
+            waitsFor(function() { return (verifier.wasCalled || fail.wasCalled); }, "callbacks
never called", Tests.TEST_TIMEOUT);
+
+            runs(function() {
+                expect(verifier).toHaveBeenCalled();
+                expect(fail).not.toHaveBeenCalled();
+            });
+
+        });
     });
 });


Mime
View raw message