cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [2/2] spec commit: Merge branch 'CB-5602' of https://github.com/sgrebnov/cordova-mobile-spec
Date Wed, 08 Jan 2014 01:32:19 GMT
Merge branch 'CB-5602' of https://github.com/sgrebnov/cordova-mobile-spec


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

Branch: refs/heads/master
Commit: 0602f126abeab2f07af540b791c820b0ff5178e9
Parents: a8340a5 578c5e1
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Tue Jan 7 17:32:03 2014 -0800
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Tue Jan 7 17:32:03 2014 -0800

----------------------------------------------------------------------
 autotest/tests/file.tests.js | 493 ++++++++------------------------------
 1 file changed, 100 insertions(+), 393 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/0602f126/autotest/tests/file.tests.js
----------------------------------------------------------------------
diff --cc autotest/tests/file.tests.js
index 8e83e63,bfae317..2706661
--- a/autotest/tests/file.tests.js
+++ b/autotest/tests/file.tests.js
@@@ -3692,239 -3586,5 +3586,52 @@@ 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(outputFileName);
-                 }),
-                 writeFile = function(fileName, fileData, win) {
-                     var theWriter,
-                         filePath = joinURL(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(outputFileName);
-                 }),
-                 writeFile = function(fileName, fileData, win) {
-                     var theWriter,
-                         filePath = joinURL(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();
-             });
- 
-         });
-         it("file.spec.108 should be able to write binary data from a File", function() {
-             // Skip test if Blobs are not supported (e.g.: Android 2.3).
-             if (typeof window.Blob == 'undefined' || typeof window.ArrayBuffer == 'undefined')
{
-                 return;
-             }
-             var dummyFileName = "blobwriter.bin",
-                 outputFileName = 'verify.bin',
-                 fail = createFail('FileWriter'),
-                 // file content
-                 data = new ArrayBuffer(32),
-                 dataView = new Int8Array(data),
-                 blob,
-                 // for verifying file length
-                 length = 32,
-                 verifier = jasmine.createSpy("verifier").andCallFake(function(outputFileWriter)
{
-                     expect(outputFileWriter.length).toBe(length);
-                     expect(outputFileWriter.position).toBe(length);
- 
-                     // cleanup
-                     deleteFile(outputFileName);
-                 }),
-                 writeFile = function(fileName, fileData, win) {
-                     var theWriter,
-                         filePath = joinURL(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);
-                 };
- 
-             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();
-                 }
-             }
- 
-             runs(function() {
-                 writeFile(dummyFileName, blob, 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();
-             });
-         });
      });
 +    describe('Backwards compatibility', function() {
 +        /* These specs exist to test that the File plugin can still recognize file:///
 +         * URLs, and can resolve them to FileEntry and DirectoryEntry objects.
 +         * They rely on an undocumented interface to File which provides absolute file
 +         * paths, which are not used internally anymore.
 +         * If that interface is not present, then these tests will silently succeed.
 +         */
 +        it("file.spec.109 should be able to resolve a file:/// URL", function() {
 +            var localFilename = 'file.txt';
 +            var localURL = dirPath = joinURL(root.toURL(), 'file.txt');
 +            var originalEntry;
 +            
 +            var unsupportedOperation = jasmine.createSpy("Operation not supported");
 +
 +			var resolveWin = jasmine.createSpy("resolveWin").andCallFake(function(fileEntry) {
 +        		expect(fileEntry.toURL()).toEqual(originalEntry.toURL());
 +                // cleanup
 +                deleteFile(localFilename);
 +	        });
 +            var resolveFail = createDoNotCallSpy('resolveFail');
 +            var getFail = createDoNotCallSpy('getFail');
 +			
 +			runs(function() {
 +                root.getFile(localFilename, {create: true}, function(entry) {
 +                    originalEntry = entry;
 +		            /* This is an undocumented interface to File which exists only for testing
 +		             * backwards compatibilty. By obtaining the raw filesystem path of the download
 +		             * location, we can pass that to ft.download() to make sure that previously-stored
 +		             * paths are still valid.
 +		             */
 +		            cordova.exec(function(localPath) {
 +		            	window.resolveLocalFileSystemURI("file://" + localPath, resolveWin, resolveFail);
 +		            }, unsupportedOperation, 'File', '_getLocalFilesystemPath', [entry.toURL()]);
 +                }, getFail);
 +	        });
 +	        
 +            waitsForAny(resolveWin, resolveFail, getFail, unsupportedOperation);
 +            
 +            runs(function() {
 +                if (!unsupportedOperation.wasCalled) {
 +	                expect(resolveWin).toHaveBeenCalled();
 +	                expect(resolveFail).not.toHaveBeenCalled();
 +                }
 +            });
 +            
 +        });
 +    });
  });


Mime
View raw message