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 2014/04/30 19:50:20 UTC
spec commit: CB-6571 Add test for DirectoryEntry.toURL() having a
trailing slash
Repository: cordova-mobile-spec
Updated Branches:
refs/heads/master 1e11f80f8 -> 3ed5cc52b
CB-6571 Add test for DirectoryEntry.toURL() having a trailing slash
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/3ed5cc52
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/3ed5cc52
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/3ed5cc52
Branch: refs/heads/master
Commit: 3ed5cc52b451856e12e12dfb0aaf2a9a09a76ca1
Parents: 1e11f80
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed Apr 30 13:49:52 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Apr 30 13:50:16 2014 -0400
----------------------------------------------------------------------
autotest/tests/file.tests.js | 117 +++++++++++++++++---------------------
1 file changed, 51 insertions(+), 66 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/3ed5cc52/autotest/tests/file.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/file.tests.js b/autotest/tests/file.tests.js
index da46c66..27add47 100644
--- a/autotest/tests/file.tests.js
+++ b/autotest/tests/file.tests.js
@@ -153,6 +153,8 @@ describe('File API', function() {
expect(fileSystem.root.filesystem).toBeDefined();
// Shouldn't use cdvfile by default.
expect(fileSystem.root.toURL()).not.toMatch(/^cdvfile:/);
+ // All DirectoryEntry URLs should always have a trailing slash.
+ expect(fileSystem.root.toURL()).toMatch(/\/$/);
}),
fail = createFail('window.requestFileSystem');
@@ -236,37 +238,44 @@ describe('File API', function() {
expect(window.resolveLocalFileSystemURI).toBeDefined();
});
it("file.spec.9 should resolve a valid file name", function() {
- var fileName = "resolve.file.uri",
- win = jasmine.createSpy().andCallFake(function(fileEntry) {
+ var createDirectoryFail = createFail('createDirectory');
+ var resolveFail = createFail('resolveLocalFileSystemURI');
+ var fileName = 'file.spec.9';
+ var win = jasmine.createSpy().andCallFake(function(fileEntry) {
expect(fileEntry).toBeDefined();
expect(fileEntry.name).toCanonicallyMatch(fileName);
- // Shouldn't use cdvfile by default.
- expect(fileEntry.toURL()).not.toMatch(/^cdvfile:/);
+ expect(fileEntry.toURL()).not.toMatch(/^cdvfile:/, 'should not use cdvfile URL');
+ expect(fileEntry.toURL()).not.toMatch(/\/$/, 'URL should not end with a slash');
// cleanup
deleteEntry(fileName);
- }),
- fail = createFail('window.resolveLocalFileSystemURI');
- resolveCallback = jasmine.createSpy().andCallFake(function(entry) {
- // lookup file system entry
- runs(function() {
- window.resolveLocalFileSystemURI(entry.toURL(), win, fail);
- });
-
- waitsFor(function() { return win.wasCalled; }, "resolveLocalFileSystemURI callback never called", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(win).toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalled();
- });
});
+ function gotDirectory(entry) {
+ // lookup file system entry
+ window.resolveLocalFileSystemURL(entry.toURL(), win, resolveFail);
+ }
+ createFile(fileName, gotDirectory, createDirectoryFail, createDirectoryFail);
+ waitsForAny(win, resolveFail, createDirectoryFail);
+ });
+ it("file.spec.9.5 should resolve a directory", function() {
+ var createDirectoryFail = createFail('createDirectory');
+ var resolveFail = createFail('resolveLocalFileSystemURI');
+ var fileName = 'file.spec.9.5';
+ var win = jasmine.createSpy().andCallFake(function(fileEntry) {
+ expect(fileEntry).toBeDefined();
+ expect(fileEntry.name).toCanonicallyMatch(fileName);
+ expect(fileEntry.toURL()).not.toMatch(/^cdvfile:/, 'should not use cdvfile URL');
+ expect(fileEntry.toURL()).toMatch(/\/$/, 'URL end with a slash');
- // create a new file entry
- runs(function() {
- createFile(fileName, resolveCallback, fail);
+ // cleanup
+ deleteEntry(fileName);
});
-
- waitsFor(function() { return resolveCallback.wasCalled; }, "createFile callback never called", Tests.TEST_TIMEOUT);
+ function gotDirectory(entry) {
+ // lookup file system entry
+ window.resolveLocalFileSystemURL(entry.toURL(), win, resolveFail);
+ }
+ createDirectory(fileName, gotDirectory, createDirectoryFail, createDirectoryFail);
+ waitsForAny(win, resolveFail, createDirectoryFail);
});
it("file.spec.10 resolve valid file name with parameters", function() {
var fileName = "resolve.file.uri.params",
@@ -2023,52 +2032,28 @@ describe('File API', function() {
waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT);
});
it("file.spec.63 copyTo: directory that does not exist", function() {
- var file1 = "entry.copy.dnf.file1",
- dstDir = "entry.copy.dnf.dstDir",
- filePath = joinURL(root.fullPath, file1),
- dstPath = joinURL(root.fullPath, dstDir),
- win = createWin('Entry'),
- fail = createFail('Entry'),
- entryCallback = jasmine.createSpy().andCallFake(function(entry) {
- // copy file to target directory that does not exist
- runs(function() {
- directory = new DirectoryEntry();
- directory.filesystem = root.filesystem;
- directory.fullPath = dstPath;
- entry.copyTo(directory, null, win, itCopy);
- });
-
- waitsFor(function() { return itCopy.wasCalled; }, "itCopy never called", Tests.TEST_TIMEOUT);
- }),
- itCopy = jasmine.createSpy().andCallFake(function(error) {
- expect(error).toBeDefined();
- expect(error).toBeFileError(FileError.NOT_FOUND_ERR);
- runs(function() {
- root.getFile(file1, {create: false}, itFileExists, fail);
- });
-
- waitsFor(function() { return itFileExists.wasCalled; }, "itFileExists never called", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(itFileExists).toHaveBeenCalled();
- expect(win).not.toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalled();
- });
- }),
- itFileExists = jasmine.createSpy().andCallFake(function(fileEntry) {
- expect(fileEntry).toBeDefined();
- expect(fileEntry.fullPath).toCanonicallyMatch(filePath);
+ var file1 = "entry.copy.dnf.file1";
+ var dirName = 'dir-foo';
+ var copySucceeded = createFail('copySucceeded');
+ var fail = createFail('Entry');
- // cleanup
- deleteEntry(file1);
- });
-
- // create a new file entry to kick off it
- runs(function() {
- createFile(file1, entryCallback, fail);
+ var copyFailed = jasmine.createSpy().andCallFake(function(error) {
+ expect(error).toBeDefined();
+ expect(error).toBeFileError(FileError.NOT_FOUND_ERR);
});
- waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT);
+ function afterCreateFile(fileEntry) {
+ createDirectory(dirName, afterDirCreate, fail);
+ function afterDirCreate(dirEntry) {
+ dirEntry.remove(afterDirRemove, fail);
+ function afterDirRemove() {
+ fileEntry.copyTo(dirEntry, null, copySucceeded, copyFailed);
+ }
+ }
+ }
+ createFile(file1, afterCreateFile, fail);
+
+ waitsForAny(fail, copySucceeded, copyFailed);
});
it("file.spec.64 copyTo: invalid target name", function() {
var file1 = "entry.copy.itn.file1",