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-5960: Validate handling of parent references in file api
Date Fri, 31 Jan 2014 21:58:33 GMT
CB-5960: Validate handling of parent references in file api


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

Branch: refs/heads/master
Commit: c04c25c22837d1da560d69b5fbe10bd34aae1037
Parents: 00e5c24
Author: Ian Clelland <iclelland@chromium.org>
Authored: Fri Jan 31 16:50:07 2014 -0500
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Fri Jan 31 16:50:07 2014 -0500

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


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/c04c25c2/autotest/tests/file.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/file.tests.js b/autotest/tests/file.tests.js
index 65ef4a9..1dc6ee5 100644
--- a/autotest/tests/file.tests.js
+++ b/autotest/tests/file.tests.js
@@ -3969,5 +3969,97 @@ describe('File API', function() {
             waitsFor(function() { return resolveCallback.wasCalled; }, "createFile callback
never called", Tests.TEST_TIMEOUT);
         });
 
+        it("file.spec.111 should not traverse above above the root directory", function()
{
+            var fileName = "traverse.file.uri",
+                win = jasmine.createSpy().andCallFake(function(fileEntry) {
+                    expect(fileEntry).toBeDefined();
+                    expect(fileEntry.name).toBe(fileName);
+                    expect(fileEntry.fullPath).toBe('/' + fileName);
+
+                    // cleanup
+                    deleteEntry(fileName);
+                }),
+                fail = createFail('spec.111'),
+                createCallback = jasmine.createSpy().andCallFake(function(entry) {
+                    // lookup file system entry
+                    runs(function() {
+                        root.getFile('../' + fileName, {create: false}, win, fail);
+                    });
+
+                    waitsFor(function() { return (win.wasCalled || fail.wasCalled); }, "getFile
callback never called", Tests.TEST_TIMEOUT);
+
+                    runs(function() {
+                        expect(win).toHaveBeenCalled();
+                        expect(fail).not.toHaveBeenCalled();
+                    });
+                });
+
+            // create a new file entry
+            runs(function() {
+                createFile(fileName, createCallback, fail);
+            });
+
+            waitsFor(function() { return createCallback.wasCalled; }, "createFile callback
never called", Tests.TEST_TIMEOUT);
+        });
+
+        it("file.spec.112 should traverse above above the current directory", function()
{
+            var fileName = "traverse2.file.uri",
+                dirName = "traverse2.subdir",
+                win = jasmine.createSpy().andCallFake(function(fileEntry) {
+                    expect(fileEntry).toBeDefined();
+                    expect(fileEntry.name).toBe(fileName);
+                    expect(fileEntry.fullPath).toBe('/' + fileName);
+
+                    // cleanup
+                    deleteEntry(fileName);
+                    deleteEntry(dirName);
+                }),
+                fail = createFail('spec.112'),
+                createCallback = jasmine.createSpy().andCallFake(function(entry) {
+                    // lookup file system entry
+                    runs(function() {
+                        entry.getFile('../' + fileName, {create: false}, win, fail);
+                    });
+
+                    waitsFor(function() { return (win.wasCalled || fail.wasCalled); }, "getFile
callback never called", Tests.TEST_TIMEOUT);
+
+                    runs(function() {
+                        expect(win).toHaveBeenCalled();
+                        expect(fail).not.toHaveBeenCalled();
+                    });
+                });
+
+            // create a new directory and a file entry
+            runs(function() {
+                createFile(fileName, function(entry) {
+                    createDirectory(dirName, createCallback, fail);
+                }, fail);
+            });
+
+            waitsFor(function() { return createCallback.wasCalled; }, "createFile callback
never called", Tests.TEST_TIMEOUT);
+        });
+
+        it("file.spec.113 getFile: get Entry should error for missing file above root directory",
function() {
+            var fileName = "../missing.file",
+                filePath = joinURL(root.fullPath, fileName),
+                fail = jasmine.createSpy().andCallFake(function(error) {
+                    expect(error).toBeDefined();
+                    expect(error).toBeFileError(FileError.NOT_FOUND_ERR);
+                }),
+                win = createWin('DirectoryEntry');
+
+            // create:false, exclusive:false, file does not exist
+            runs(function() {
+                root.getFile(fileName, {create:false}, win, fail);
+            });
+
+            waitsFor(function() { return fail.wasCalled; }, "error callback never called",
Tests.TEST_TIMEOUT);
+
+            runs(function() {
+                expect(fail).toHaveBeenCalled();
+                expect(win).not.toHaveBeenCalled();
+            });
+        });
+
     });
 });


Mime
View raw message