You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/04/18 23:49:52 UTC
[16/37] did.. did I just do that?
http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/0592abe1/autotest/tests/file.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/file.tests.js b/autotest/tests/file.tests.js
index ecc21c9..c8c62ae 100644
--- a/autotest/tests/file.tests.js
+++ b/autotest/tests/file.tests.js
@@ -399,11 +399,11 @@ describe('File API', function() {
var fileName = "de.create.exclusive.file",
filePath = root.fullPath + '/' + fileName,
win = jasmine.createSpy().andCallFake(function(entry) {
- expect(typeof entry !== 'undefined' && entry !== null, "file entry should not be null");
- expect(entry.isFile, true, "entry 'isFile' attribute should be true");
- expect(entry.isDirectory, false, "entry 'isDirectory' attribute should be false");
- expect(entry.name, fileName, "entry 'name' attribute should be set");
- expect(entry.fullPath, filePath, "entry 'fullPath' attribute should be set");
+ expect(entry).toBeDefined();
+ expect(entry.isFile).toBe(true);
+ expect(entry.isDirectory).toBe(false);
+ expect(entry.name).toBe(fileName);
+ expect(entry.fullPath).toBe(filePath);
// cleanup
entry.remove(null, null);
@@ -425,2386 +425,3033 @@ describe('File API', function() {
it("DirectoryEntry.getFile: create file that already exists", function() {
var fileName = "de.create.existing.file",
filePath = root.fullPath + '/' + fileName,
- getFile = function(file) {
+ getFile = jasmine.createSpy().andCallFake(function(file) {
// create:true, exclusive:false, file exists
- root.getFile(fileName, {create:true}, win, fail);
- },
- itFile = function(entry) {
- expect(typeof entry !== 'undefined' && entry !== null, "file entry should not be null");
- expect(entry.isFile, true, "entry 'isFile' attribute should be true");
- expect(entry.isDirectory, false, "entry 'isDirectory' attribute should be false");
- expect(entry.name, fileName, "entry 'name' attribute should be set");
- expect(entry.fullPath, filePath, "entry 'fullPath' attribute should be set");
+ runs(function() {
+ root.getFile(fileName, {create:true}, win, fail);
+ });
+
+ waitsFor(function() { return win.wasCalled; }, "win was never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(win).toHaveBeenCalled();
+ expect(fail).not.toHaveBeenCalled();
+ });
+ }),
+ fail = createFail('DirectoryEntry'),
+ win = jasmine.createSpy().andCallFake(function(entry) {
+ expect(entry).toBeDefined();
+ expect(entry.isFile).toBe(true);
+ expect(entry.isDirectory).toBe(false);
+ expect(entry.name).toBe(fileName);
+ expect(entry.fullPath).toBe(filePath);
// cleanup
- entry.remove(null, that.fail);
- QUnit.start();
- };
-
+ entry.remove(null, fail);
+ });
// create file to kick off it
- root.getFile(fileName, {create:true}, getFile, this.fail);
+ runs(function() {
+ root.getFile(fileName, {create:true}, getFile, fail);
+ }):
+
+ waitsFor(function() { return getFile.wasCalled; }, "getFile was never called", Tests.TEST_TIMEOUT);
});
it("DirectoryEntry.getFile: create file that already exists (exclusive)", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
var fileName = "de.create.exclusive.existing.file",
- filePath = this.root.fullPath + '/' + fileName,
- that = this,
+ filePath = root.fullPath + '/' + fileName,
existingFile,
- getFile = function(file) {
+ getFile = jasmine.createSpy().andCallFake(function(file) {
existingFile = file;
// create:true, exclusive:true, file exists
- that.root.getFile(fileName, {create:true, exclusive:true}, null, itFile);
- },
- itFile = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "creating exclusive file that already exists is an error");
- expect(error.code, FileError.PATH_EXISTS_ERR, "error code should be FileError.PATH_EXISTS_ERR");
+ runs(function() {
+ root.getFile(fileName, {create:true, exclusive:true}, win, fail);
+ });
+
+ waitsFor(function() { return fail.wasCalled; }, "fail never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(fail).toHaveBeenCalled();
+ expect(win).not.toHaveBeenCalled();
+ });
+ }),
+ fail = jasmine.createSpy().andCallFake(function(error) {
+ expect(error).toBeDefined();
+ expect(error.code).toBe(FileError.PATH_EXISTS_ERR);
// cleanup
- existingFile.remove(null, that.fail);
- QUnit.start();
- };
+ existingFile.remove(null, fail);
+ }),
+ win = createWin('DirectoryEntry');
// create file to kick off it
- this.root.getFile(fileName, {create:true}, getFile, this.fail);
+ runs(function() {
+ root.getFile(fileName, {create:true}, getFile, fail);
+ });
+
+ waitsFor(function() { return getFile.wasCalled; }, "getFile never called", Tests.TEST_TIMEOUT);
});
it("DirectoryEntry.getFile: get Entry for existing file", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(5);
-
var fileName = "de.get.file",
- filePath = this.root.fullPath + '/' + fileName,
- that = this,
- getFile = function(file) {
+ filePath = root.fullPath + '/' + fileName,
+ getFile = jasmine.createSpy().andCallFake(function(file) {
// create:false, exclusive:false, file exists
- that.root.getFile(fileName, {create:false}, itFile, that.fail);
+ runs(function() {
+ root.getFile(fileName, {create:false}, win, fail);
+ });
+
+ waitsFor(function() { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(win).toHaveBeenCalled();
+ expect(fail).not.toHaveBeenCalled();
+ });
},
- itFile = function(entry) {
- expect(typeof entry !== 'undefined' && entry !== null, "file entry should not be null");
- expect(entry.isFile, true, "entry 'isFile' attribute should be true");
- expect(entry.isDirectory, false, "entry 'isDirectory' attribute should be false");
- expect(entry.name, fileName, "entry 'name' attribute should be set");
- expect(entry.fullPath, filePath, "entry 'fullPath' attribute should be set");
+ win = function(entry) {
+ expect(entry).toBeDefined();
+ expect(entry.isFile).toBe(true);
+ expect(entry.isDirectory).toBe(false);
+ expect(entry.name).toBe(fileName);
+ expect(entry.fullPath).toBe(filePath);
+
+ entry.remove(null, fail); //clean up
+ }),
+ fail = createFail('DirectoryEntry');
- // cleanup
- entry.remove(null, that.fail);
- QUnit.start();
- };
-
// create file to kick off it
- this.root.getFile(fileName, {create:true}, getFile, this.fail);
+ runs(function() {
+ root.getFile(fileName, {create:true}, getFile, fail);
+ });
+
+ waitsFor(function() { return getFile.wasCalled; }, "getFile never called", Tests.TEST_TIMEOUT);
});
it("DirectoryEntry.getFile: get FileEntry for invalid path", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
var fileName = "de:invalid:path",
- that = this,
- itFile = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "retrieving a file using an invalid path is an error");
- expect(error.code, FileError.ENCODING_ERR, "error code should be FileError.ENCODING_ERR");
-
- // cleanup
- QUnit.start();
- };
-
+ fail = jasmine.createSpy().andCallFake(function(error) {
+ expect(error).toBeDefined();
+ expect(error.code).toBe(FileError.ENCODING_ERR);
+ }),
+ win = createWin('DirectoryEntry');
+
// create:false, exclusive:false, invalid path
- this.root.getFile(fileName, {create:false}, null, itFile);
+ runs(function() {
+ root.getFile(fileName, {create:false}, win, fail);
+ });
+
+ waitsFor(function() { return fail.wasCalled; }, "fail never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(fail).toHaveBeenCalled();
+ expect(win).not.toHaveBeenCalled();
+ });
+
});
it("DirectoryEntry.getDirectory: get Entry for directory that does not exist", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
var dirName = "de.no.dir",
- dirPath = this.root.fullPath + '/' + dirName,
- that = this,
- itDir = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "retrieving a directory that does not exist is an error");
- expect(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR");
-
- // cleanup
- QUnit.start();
- };
+ dirPath = root.fullPath + '/' + dirName,
+ fail = jasmine.createSpy().andCallFake(function(error) {
+ expect(error).toBeDefined();
+ expect(error.code).toBe(FileError.NOT_FOUND_ERR);
+ }),
+ win = createWin('DirectoryEntry');
// create:false, exclusive:false, directory does not exist
- this.root.getDirectory(dirName, {create:false}, null, itDir);
+ runs(function() {
+ root.getDirectory(dirName, {create:false}, win, fail);
+ });
+
+ waitsFor(function() { return fail.wasCalled; }, "fail never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(fail).toHaveBeenCalled();
+ expect(win).not.toHaveBeenCalled();
+ });
});
it("DirectoryEntry.getDirectory: create new dir with space then resolveFileSystemURL", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(5);
-
var dirName = "de create dir",
- dirPath = this.root.fullPath + '/' + dirName,
- that = this,
- getDir = function(dirEntry) {
-
- var dirURL = dirEntry.toURL();
- // now encode URL and try to resolve
- window.resolveLocalFileSystemURI(dirURL, itDirFromURL, that.fail);
-
- },
- itDirFromURL = function(directory) {
- expect(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null");
- expect(directory.isFile, false, "directory 'isFile' attribute should be false");
- expect(directory.isDirectory, true, "directory 'isDirectory' attribute should be true");
- expect(directory.name, dirName, "directory 'name' attribute should be set");
- expect(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set");
+ dirPath = root.fullPath + '/' + dirName,
+ getDir = jasmine.createSpy().andCallFake(function(dirEntry) {
+ var dirURL = dirEntry.toURL();
+ // now encode URL and try to resolve
+ runs(function() {
+ window.resolveLocalFileSystemURI(dirURL, win, fail);
+ });
+
+ waitsFor(function() { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(win).toHaveBeenCalled();
+ expect(fail).not.toHaveBeenCalled();
+ });
- // cleanup
- directory.remove(null, that.fail);
- QUnit.start();
- };
+ }), win = jasmine.createSpy().andCallFake(function(directory) {
+ expect(directory).toBeDefined();
+ expect(directory.isFile).toBe(false);
+ expect(directory.isDirectory).toBe(true);
+ expect(directory.name).toBe(dirName);
+ expect(directory.fullPath).toBe(dirPath);
+
+ // cleanup
+ directory.remove(null, fail);
+ }),
+ fail = createFail('DirectoryEntry');
// create:true, exclusive:false, directory does not exist
- this.root.getDirectory(dirName, {create: true}, getDir, this.fail);
+ runs(function() {
+ root.getDirectory(dirName, {create: true}, getDir, fail);
+ });
+
+ waitsFor(function() { return getDir.wasCalled; }, "getDir never called", Tests.TEST_TIMEOUT);
});
it("DirectoryEntry.getDirectory: create new dir with space resolveFileSystemURL with encoded URL", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(5);
-
var dirName = "de create dir",
- dirPath = this.root.fullPath + '/' + dirName,
- that = this,
- getDir = function(dirEntry) {
-
- var dirURL = dirEntry.toURL();
- // now encode URL and try to resolve
- window.resolveLocalFileSystemURI(encodeURI(dirURL), itDirFromURL, that.fail);
-
- },
- itDirFromURL = function(directory) {
- expect(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null");
- expect(directory.isFile, false, "directory 'isFile' attribute should be false");
- expect(directory.isDirectory, true, "directory 'isDirectory' attribute should be true");
- expect(directory.name, dirName, "directory 'name' attribute should be set");
- expect(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set");
-
- // cleanup
- directory.remove(null, that.fail);
- QUnit.start();
- };
+ dirPath = root.fullPath + '/' + dirName,
+ getDir = jasmine.createSpy().andCallFake(function(dirEntry) {
+ var dirURL = dirEntry.toURL();
+ // now encode URL and try to resolve
+ runs(function() {
+ window.resolveLocalFileSystemURI(encodeURI(dirURL), win, fail);
+ });
+
+ waitsFor(function() { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(win).toHaveBeenCalled();
+ expect(fail).not.toHaveBeenCalled();
+ });
+ }),
+ win = jasmine.createSpy().andCallFake(function(directory) {
+ expect(directory).toBeDefined();
+ expect(directory.isFile).toBe(false);
+ expect(directory.isDirectory).toBe(true);
+ expect(directory.name).toBe(dirName);
+ expect(directory.fullPath).toBe(dirPath);
+ // cleanup
+ directory.remove(null, fail);
+ }),
+ fail = createFail('DirectoryEntry');
// create:true, exclusive:false, directory does not exist
- this.root.getDirectory(dirName, {create: true}, getDir, this.fail);
+ runs(function() {
+ root.getDirectory(dirName, {create: true}, getDir, fail);
+ });
+
+ waitsFor(function() { return getDir.wasCalled; }, "getDir never called", Tests.TEST_TIMEOUT);
});
it("DirectoryEntry.getDirectory: create new directory", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(5);
-
var dirName = "de.create.dir",
- dirPath = this.root.fullPath + '/' + dirName,
- that = this,
- itDir = function(directory) {
- expect(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null");
- expect(directory.isFile, false, "directory 'isFile' attribute should be false");
- expect(directory.isDirectory, true, "directory 'isDirectory' attribute should be true");
- expect(directory.name, dirName, "directory 'name' attribute should be set");
- expect(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set");
+ dirPath = root.fullPath + '/' + dirName,
+ win = jasmine.createSpy().andCallFake(function(directory) {
+ expect(directory).toBeDefined();
+ expect(directory.isFile).toBe(false);
+ expect(directory.isDirectory).toBe(true);
+ expect(directory.name).toBe(dirName);
+ expect(directory.fullPath).toBe(dirPath);
// cleanup
- directory.remove(null, that.fail);
- QUnit.start();
- };
+ directory.remove(null, fail);
+ }),
+ fail = createFail('DirectoryEntry');
// create:true, exclusive:false, directory does not exist
- this.root.getDirectory(dirName, {create: true}, itDir, this.fail);
+ runs(function() {
+ root.getDirectory(dirName, {create: true}, win, fail);
+ });
+
+ waitsFor(function() { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(win).toHaveBeenCalled();
+ expect(fail).not.toHaveBeenCalled();
+ });
});
it("DirectoryEntry.getDirectory: create new directory (exclusive)", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(5);
-
var dirName = "de.create.exclusive.dir",
- dirPath = this.root.fullPath + '/' + dirName,
- that = this,
- itDir = function(directory) {
- expect(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null");
- expect(directory.isFile, false, "directory 'isFile' attribute should be false");
- expect(directory.isDirectory, true, "directory 'isDirectory' attribute should be true");
- expect(directory.name, dirName, "directory 'name' attribute should be set");
- expect(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set");
+ dirPath = root.fullPath + '/' + dirName,
+ win = jasmine.createSpy().andCallFake(function(directory) {
+ expect(directory).toBeDefined();
+ expect(directory.isFile).toBe(false);
+ expect(directory.isDirectory).toBe(true);
+ expect(directory.name).toBe(dirName);
+ expect(directory.fullPath).toBe(dirPath);
// cleanup
- directory.remove(null, that.fail);
- QUnit.start();
- };
-
+ directory.remove(null, fail);
+ }),
+ fail = createFail('DirectoryEntry');
// create:true, exclusive:true, directory does not exist
- this.root.getDirectory(dirName, {create: true, exclusive:true}, itDir, this.fail);
+ runs(function() {
+ root.getDirectory(dirName, {create: true, exclusive:true}, win, fail);
+ });
+
+ waitsFor(function() { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(win).toHaveBeenCalled();
+ expect(fail).not.toHaveBeenCalled();
+ });
});
it("DirectoryEntry.getDirectory: create directory that already exists", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(5);
-
var dirName = "de.create.existing.dir",
- dirPath = this.root.fullPath + '/' + dirName,
- that = this,
- getDir = function(directory) {
+ dirPath = root.fullPath + '/' + dirName,
+ getDir = jasmine.createSpy().andCallFake(function(directory) {
// create:true, exclusive:false, directory exists
- that.root.getDirectory(dirName, {create:true}, itDir, that.fail);
- },
- itDir = function(directory) {
- expect(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null");
- expect(directory.isFile, false, "directory 'isFile' attribute should be false");
- expect(directory.isDirectory, true, "directory 'isDirectory' attribute should be true");
- expect(directory.name, dirName, "directory 'name' attribute should be set");
- expect(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set");
+ runs(function() {
+ root.getDirectory(dirName, {create:true}, win, fail);
+ });
+
+ waitsFor(function() { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(win).toHaveBeenCalled();
+ expect(fail).not.toHaveBeenCalled();
+ });
+ }),
+ win = jasmine.createSpy().andCallFake(function(directory) {
+ expect(directory).toBeDefined();
+ expect(directory.isFile).toBe(false);
+ expect(directory.isDirectory).toBe(true);
+ expect(directory.name).toBe(dirName);
+ expect(directory.fullPath).toBe(dirPath);
// cleanup
- directory.remove(null, that.fail);
- QUnit.start();
- };
+ directory.remove(null, fail);
+ }),
+ fail = createFail('DirectoryEntry');
// create directory to kick off it
- this.root.getDirectory(dirName, {create:true}, getDir, this.fail);
+ runs(function() {
+ root.getDirectory(dirName, {create:true}, getDir, this.fail);
+ });
+
+ waitsFor(function() { return getDir.wasCalled; }, "getDir never called", Tests.TEST_TIMEOUT);
});
it("DirectoryEntry.getDirectory: create directory that already exists (exclusive)", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
var dirName = "de.create.exclusive.existing.dir",
- dirPath = this.root.fullPath + '/' + dirName,
- that = this,
+ dirPath = root.fullPath + '/' + dirName,
existingDir,
- getDir = function(directory) {
+ getDir = jasmine.createSpy().andCallFake(function(directory) {
existingDir = directory;
// create:true, exclusive:true, directory exists
- that.root.getDirectory(dirName, {create:true, exclusive:true}, null, itDir);
- },
- itDir = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "creating exclusive directory that already exists is an error");
- expect(error.code, FileError.PATH_EXISTS_ERR, "error code should be FileError.PATH_EXISTS_ERR");
+ runs(function() {
+ root.getDirectory(dirName, {create:true, exclusive:true}, win, fail);
+ });
+
+ waitsFor(function() { return fail.wasCalled; }, "fail never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(fail).toHaveBeenCalled();
+ expect(win).not.toHaveBeenCalled();
+ });
+ }),
+ fail = jasmine.createSpy().andCallFake(function(error) {
+ expect(error).toBeDefined();
+ expect(error.code).toBe(FileError.PATH_EXISTS_ERR);
// cleanup
- existingDir.remove(null, that.fail);
- QUnit.start();
- };
+ existingDir.remove(null, fail);
+ }),
+ win = createWin('DirectoryEntry');
// create directory to kick off it
- this.root.getDirectory(dirName, {create:true}, getDir, this.fail);
+ runs(function() {
+ root.getDirectory(dirName, {create:true}, getDir, fail);
+ });
+
+ waitsFor(function() { return getDir.wasCalled; }, "getDir never called", Tests.TEST_TIMEOUT);
});
it("DirectoryEntry.getDirectory: get Entry for existing directory", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(5);
-
var dirName = "de.get.dir",
- dirPath = this.root.fullPath + '/' + dirName,
- that = this,
- getDir = function(directory) {
+ dirPath = root.fullPath + '/' + dirName,
+ getDir = jasmine.createSpy().andCallFake(function(directory) {
// create:false, exclusive:false, directory exists
- that.root.getDirectory(dirName, {create:false}, itDir, that.fail);
- },
- itDir = function(directory) {
- expect(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null");
- expect(directory.isFile, false, "directory 'isFile' attribute should be false");
- expect(directory.isDirectory, true, "directory 'isDirectory' attribute should be true");
- expect(directory.name, dirName, "directory 'name' attribute should be set");
- expect(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set");
+ runs(function() {
+ root.getDirectory(dirName, {create:false}, win, fail);
+ });
+
+ waitsFor(function() { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(win).toHaveBeenCalled();
+ expect(fail).not.toHaveBeenCalled();
+ });
+ }),
+ win = jasmine.createSpy().andCallFake(function(directory) {
+ expect(directory).toBeDefined();
+ expect(directory.isFile).toBe(false);
+ expect(directory.isDirectory).toBe(true);
+ expect(directory.name).toBe(dirName);
+
+ expect(directory.fullPath).toBe(dirPath);
// cleanup
- directory.remove(null, that.fail);
- QUnit.start();
- };
+ directory.remove(null, fail);
+ }),
+ fail = createFail('DirectoryEntry');
// create directory to kick off it
- this.root.getDirectory(dirName, {create:true}, getDir, this.fail);
+ root.getDirectory(dirName, {create:true}, getDir, fail);
});
it("DirectoryEntry.getDirectory: get DirectoryEntry for invalid path", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
var dirName = "de:invalid:path",
- that = this,
- itDir = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "retrieving a directory using an invalid path is an error");
- expect(error.code, FileError.ENCODING_ERR, "error code should be FileError.ENCODING_ERR");
-
- // cleanup
- QUnit.start();
- };
+ fail = jasmine.createSpy().andCallFake(function(error) {
+ expect(error).toBeDefined();
+ expect(error.code).toBe(FileError.ENCODING_ERR);
+ }),
+ win = createWin('DirectoryEntry');
// create:false, exclusive:false, invalid path
- this.root.getDirectory(dirName, {create:false}, null, itDir);
+ runs(function() {
+ root.getDirectory(dirName, {create:false}, win, fail);
+ });
+
+ waitsFor(function() { return fail.wasCalled; }, "fail never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(fail).toHaveBeenCalled();
+ expect(win).not.toHaveBeenCalled();
+ });
});
it("DirectoryEntry.getDirectory: get DirectoryEntry for existing file", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
var fileName = "de.existing.file",
existingFile,
- filePath = this.root.fullPath + '/' + fileName,
- that = this,
- getDir = function(file) {
+ filePath = root.fullPath + '/' + fileName,
+ getDir = jasmine.createSpy().andCallFake(function(file) {
existingFile = file;
// create:false, exclusive:false, existing file
- that.root.getDirectory(fileName, {create:false}, null, itDir);
- },
- itDir = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "retrieving directory for existing file is an error");
- expect(error.code, FileError.TYPE_MISMATCH_ERR, "error code should be FileError.TYPE_MISMATCH_ERR");
+ runs(function() {
+ root.getDirectory(fileName, {create:false}, win, fail);
+ });
+
+ waitsFor(function() { return fail.wasCalled; }, "fail never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(fail).toHaveBeenCalled();
+ expect(win).not.toHaveBeenCalled();
+ });
+ }),
+ fail = jasmine.createSpy().andCallFake(function(error) {
+ expect(error).toBeDefined();
+ expect(error.code).toBe(FileError.TYPE_MISMATCH_ERR);
// cleanup
- existingFile.remove(null, that.fail);
- QUnit.start();
- };
+ existingFile.remove(null, null);
+ }),
+ win = createWin('DirectoryEntry');
// create file to kick off it
- this.root.getFile(fileName, {create:true}, getDir, this.fail);
+ runs(function() {
+ root.getFile(fileName, {create:true}, getDir, fail);
+ });
+
+ waitsFor(function() { return getDir.wasCalled; }, "getDir was called", Tests.TEST_TIMEOUT);
});
it("DirectoryEntry.getFile: get FileEntry for existing directory", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
var dirName = "de.existing.dir",
existingDir,
- dirPath = this.root.fullPath + '/' + dirName,
- that = this,
- getFile = function(directory) {
+ dirPath = root.fullPath + '/' + dirName,
+ getFile = jasmine.createSpy().andCallFake(function(directory) {
existingDir = directory;
// create:false, exclusive:false, existing directory
- that.root.getFile(dirName, {create:false}, null, itFile);
- },
- itFile = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "retrieving file for existing directory is an error");
- expect(error.code, FileError.TYPE_MISMATCH_ERR, "error code should be FileError.TYPE_MISMATCH_ERR");
-
- // cleanup
- existingDir.remove(null, that.fail);
- QUnit.start();
- };
-
+ runs(function() {
+ root.getFile(dirName, {create:false}, win, fail);
+ });
+
+ waitsFor(function() { return fail.wasCalled; }, "fail never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(fail).toHaveBeenCalled();
+ expect(win).not.toHaveBeenCalled();
+ });
+ }),
+ fail = jasmine.createSpy().andCallFake(function(error) {
+ expect(error).toBeDefined();
+ expect(error.code).toBe(FileError.TYPE_MISMATCH_ERR);
+
+ // cleanup
+ existingDir.remove(null, null);
+ }),
+ win = createWin('DirectoryEntry');
+
// create directory to kick off it
- this.root.getDirectory(dirName, {create:true}, getFile, this.fail);
+ runs(function() {
+ root.getDirectory(dirName, {create:true}, getFile, fail);
+ });
+
+ waitsFor(function() { return getFile.wasCalled; }, "getFile never called", Tests.TEST_TIMEOUT);
});
it("DirectoryEntry.removeRecursively on directory", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
var dirName = "de.removeRecursively",
subDirName = "dir",
- dirPath = this.root.fullPath + '/' + dirName,
+ dirPath = root.fullPath + '/' + dirName,
//subDirPath = this.root.fullPath + '/' + subDirName,
- subDirPath = dirPath + '/' + subDirName,
- that = this,
- entryCallback = function(entry) {
+ subDirPath = dirPath + '/' + subDirName,
+ entryCallback = jasmine.createSpy().andCallFake(function(entry) {
// delete directory
- var deleteDirectory = function(directory) {
- entry.removeRecursively(itRemove, that.fail);
- };
+ var deleteDirectory = jasmine.createSpy().andCallFake(function(directory) {
+ runs(function() {
+ entry.removeRecursively(remove, fail);
+ });
+
+ waitsFor(function() { return remove.wasCalled; }, "remove never called", Tests.TEST_TIMEOUT);
+ });
// create a sub-directory within directory
- entry.getDirectory(subDirName, {create: true}, deleteDirectory, that.fail);
- },
- itRemove = function() {
- // it that removed directory no longer exists
- that.root.getDirectory(dirName, {create:false}, null, itDirExists);
- },
- itDirExists = function(error){
- expect(typeof error !== 'undefined' && error !== null, "removed directory should not exist");
- expect(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR");
- QUnit.start();
- };
+ runs(function() {
+ entry.getDirectory(subDirName, {create: true}, deleteDirectory, fail);
+ });
+
+ waitsFor(function() { return deleteDirectory.wasCalled; }, "deleteDirectory never called", Tests.TEST_TIMEOUT);
+ }),
+ remove = jasmine.createSpy().andCallFake(function() {
+ // it that removed directory no longer exists
+ runs(function() {
+ root.getDirectory(dirName, {create:false}, win, dirExists);
+ });
+
+ waitsFor(function() { return dirExists.wasCalled; }, "dirExists never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(dirExists).toHaveBeenCalled();
+ expect(win).not.toHaveBeenCalled();
+ });
+ }),
+ dirExists = jasmine.createSpy().andCallFake(function(error){
+ expect(error).toBeDefined();
+ expect(error.code).toBe(FileError.NOT_FOUND_ERR);
+ }),
+ fail = createFail('DirectoryEntry'),
+ win = createWin('DirectoryEntry');
// create a new directory entry to kick off it
- this.root.getDirectory(dirName, {create:true}, entryCallback, this.fail);
+ runs(function() {
+ root.getDirectory(dirName, {create:true}, entryCallback, fail);
+ });
+
+ waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT);
});
it("DirectoryEntry.createReader: create reader on existing directory", function() {
- expect(2);
-
// create reader for root directory
- var reader = this.root.createReader();
- expect(typeof reader !== 'undefined' && reader !== null, "reader object should not be null");
- expect(typeof reader.readEntries === 'function', "reader object should have a 'readEntries' method");
+ var reader = root.createReader();
+ expect(reader).toBeDefined();
+ expect(reader.readEntries).toBe(jasmine.any(Function));
+ });
+ it("DirectoryEntry.removeRecursively on root file system", function() {
+ var remove = jasmine.createSpy().andCallFake(function(error) {
+ expect(error).toBeDefined();
+ expect(error.code).toBe(FileError.NO_MODIFICATION_ALLOWED_ERR);
+ }),
+ win = createWin('DirectoryEntry');
+
+ // remove root file system
+ runs(function() {
+ root.removeRecursively(win, remove);
+ });
+
+ waitsFor(function() { return remove.wasCalled; }, "remove never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(win).not.toHaveBeenCalled();
+ expect(fail).toHaveBeenCalled();
+ });
});
});
- module('DirectoryReader interface', {
- // setup function will run before each it
- setup: function() {
- this.root = getFileSystemRoot();
- this.fail = function(error) {
- console.log('file error: ' + error.code);
- };
- }
- });
- it("DirectoryReader.readEntries: read contents of existing directory", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(4);
-
- var reader,
- itEntries = function(entries) {
- expect(typeof entries !== 'undefined' && entries !== null, "directory entries should not be null");
- expect(entries.constructor === Array, "readEntries should return an array of entries");
- QUnit.start();
- };
+
+ describe('DirectoryReader interface', function() {
+ describe("readEntries", function() {
+ it("should read contents of existing directory", function() {
+ var reader,
+ win = jasmine.createSpy().andCallFake(function(entries) {
+ expect(entries).toBeDefined();
+ expect(entries.constructor).toBe(jasmine.any(Array));
+ }),
+ fail = createFail('DirectoryReader');
- // create reader for root directory
- reader = this.root.createReader();
- expect(typeof reader !== 'undefined' && reader !== null, "reader object should not be null");
- expect(typeof reader.readEntries === 'function', "reader object should have a 'readEntries' method");
-
- // read entries
- reader.readEntries(itEntries, this.fail);
- });
- it("DirectoryReader.readEntries: read contents of directory that has been removed", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(4);
-
- var dirName = "de.createReader.notfound",
- dirPath = this.root.fullPath + '/' + dirName,
- that = this,
- entryCallback = function(directory) {
+ // create reader for root directory
+ reader = root.createReader();
// read entries
- var readEntries = function() {
- var reader = directory.createReader();
- reader.readEntries(null, itReader);
- };
- // delete directory
- directory.removeRecursively(readEntries, that.fail);
- },
- itReader = function(error) {
- var itDirectoryExists = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "reading entries on a directory that does not exist is an error")
- expect(error.code, FileError.NOT_FOUND_ERR, "removed directory should not exist");
- QUnit.start();
- };
- expect(typeof error !== 'undefined' && error !== null, "reading entries on a directory that does not exist is an error")
- expect(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR");
- that.root.getDirectory(dirName, {create:false}, null, itDirectoryExists);
- };
-
- // create a new directory entry to kick off it
- this.root.getDirectory(dirName, {create:true}, entryCallback, this.fail);
- });
- it("DirectoryEntry.removeRecursively on root file system", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
- var itRemove = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "removing root file system should generate an error");
- expect(error.code, FileError.NO_MODIFICATION_ALLOWED_ERR, "error code should be FileError.NO_MODIFICATION_ALLOWED_ERR");
- QUnit.start();
- };
-
- // remove root file system
- this.root.removeRecursively(null, itRemove);
- });
- module('File interface');
- it("File constructor should be defined", function() {
- expect(1);
- expect(typeof File === 'function', "File constructor should be a function.");
- });
- it("File attributes should be defined", function() {
- expect(5);
- var file = new File();
- expect(typeof file.name !== 'undefined', "File object should have a 'name' attribute");
- expect(typeof file.fullPath !== 'undefined', "File object should have a 'fullPath' attribute");
- expect(typeof file.type !== 'undefined', "File object should have a 'type' attribute");
- expect(typeof file.lastModifiedDate !== 'undefined', "File object should have a 'lastModifiedDate' attribute");
- expect(typeof file.size !== 'undefined', "File object should have a 'size' attribute");
- });
- module('FileEntry interface', {
- // setup function will run before each it
- setup: function() {
- this.root = getFileSystemRoot();
- this.fail = function(error) {
- console.log('file error: ' + error.code);
- };
- }
- });
- it("FileEntry methods should be defined", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(3);
-
- var fileName = "fe.methods",
- that = this,
- itFileEntry = function(fileEntry) {
- expect(typeof fileEntry !== 'undefined' && fileEntry !== null, "FileEntry should not be null");
- expect(typeof fileEntry.createWriter === 'function', "FileEntry should have a 'createWriter' method");
- expect(typeof fileEntry.file === 'function', "FileEntry should have a 'file' method");
-
- // cleanup
- fileEntry.remove(null, that.fail);
- QUnit.start();
- };
-
- // create a new file entry to kick off it
- this.root.getFile(fileName, {create:true}, itFileEntry, this.fail);
- });
- it("FileEntry.createWriter should return a FileWriter object", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
- var fileName = "fe.createWriter",
- that = this,
- itFile,
- entryCallback = function(fileEntry) {
- itFile = fileEntry;
- fileEntry.createWriter(itWriter, that.fail);
- },
- itWriter = function(writer) {
- expect(typeof writer !== 'undefined' && writer !== null, "FileWriter object should not be null");
- expect(writer.constructor === FileWriter, "writer should be a FileWriter object");
-
- // cleanup
- itFile.remove(null, that.fail);
- QUnit.start();
- };
-
- // create a new file entry to kick off it
- this.root.getFile(fileName, {create:true}, entryCallback, this.fail);
- });
- it("FileEntry.file should return a File object", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
- var fileName = "fe.file",
- that = this,
- newFile,
- entryCallback = function(fileEntry) {
- newFile = fileEntry;
- fileEntry.file(itFile, that.fail);
- },
- itFile = function(file) {
- expect(typeof file !== 'undefined' && file !== null, "File object should not be null");
- expect(file.constructor === File, "File object should be a File");
-
- // cleanup
- newFile.remove(null, that.fail);
- QUnit.start();
- };
-
- // create a new file entry to kick off it
- this.root.getFile(fileName, {create:true}, entryCallback, this.fail);
- });
- it("FileEntry.file: on File that has been removed", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
- var fileName = "fe.no.file",
- that = this,
- entryCallback = function(fileEntry) {
- // create File object
- var getFile = function() {
- fileEntry.file(null, itFile);
- };
- // delete file
- fileEntry.remove(getFile, that.fail);
- },
- itFile = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "invexpecting FileEntry.file on a file that does not exist is an error");
- expect(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR");
- QUnit.start();
- };
-
- // create a new file entry to kick off it
- this.root.getFile(fileName, {create:true}, entryCallback, this.fail);
- });
- module('Entry interface', {
- // setup function will run before each it
- setup: function() {
- var that = this;
- this.root = getFileSystemRoot();
- this.fail = function(error) {
- console.log('file error: ' + error.code);
- };
- this.unexpectedSuccess = function() {
- console.log('!!! success function called when not expected !!!');
- };
- // deletes specified file or directory
- this.deleteEntry = function(name, success, error) {
- // deletes entry, if it exists
- window.resolveLocalFileSystemURI(that.root.toURL() + '/' + name,
- function(entry) {
- console.log('Deleting: ' + entry.fullPath);
- if (entry.isDirectory === true) {
- entry.removeRecursively(success, error);
- }
- else {
- entry.remove(success, error);
- }
- },
- // doesn't exist
- success);
- };
- // deletes and re-creates the specified file
- this.createFile = function(fileName, success, error) {
- that.deleteEntry(fileName, function() {
- console.log('Creating file: ' + that.root.fullPath + '/' + fileName);
- that.root.getFile(fileName, {create: true}, success, error);
- }, error);
- };
- // deletes and re-creates the specified directory
- this.createDirectory = function(dirName, success, error) {
- that.deleteEntry(dirName, function() {
- console.log('Creating directory: ' + that.root.fullPath + '/' + dirName);
- that.root.getDirectory(dirName, {create: true}, success, error);
- }, error);
- };
- }
- });
- it("Entry object", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(13);
-
- var fileName = "entry",
- that = this,
- fullPath = this.root.fullPath + '/' + fileName,
- itEntry = function(entry) {
- expect(typeof entry !== 'undefined' && entry !== null, "entry should not be null.");
- expect(entry.isFile, true, "entry.isFile should be true");
- expect(entry.isDirectory, false, "entry.isDirectory should be false");
- expect(entry.name, fileName, "entry object 'name' property should be set");
- expect(entry.fullPath, fullPath, "entry object 'fullPath' property should be set");
- expect(typeof entry.getMetadata === 'function', "entry object should have a 'getMetadata' function.");
- expect(typeof entry.moveTo === 'function', "entry object should have a 'moveTo' function.");
- expect(typeof entry.copyTo === 'function', "entry object should have a 'copyTo' function.");
- expect(typeof entry.toURL === 'function', "entry object should have a 'toURL' function.");
- expect(typeof entry.remove === 'function', "entry object should have a 'remove' function.");
- expect(typeof entry.getParent === 'function', "entry object should have a 'getParent' function.");
- expect(typeof entry.createWriter === 'function', "entry object should have a 'createWriter' function.");
- expect(typeof entry.file === 'function', "entry object should have a 'file' function.");
-
- // cleanup
- that.deleteEntry(fileName);
- QUnit.start();
- };
+ runs(function() {
+ reader.readEntries(win, fail);
+ });
- // create a new file entry
- this.createFile(fileName, itEntry, this.fail);
- });
- it("Entry.getMetadata on file", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
- var fileName = "entry.metadata.file",
- that = this,
- entryCallback = function(entry) {
- entry.getMetadata(itMetadata, this.fail);
- },
- itMetadata = function(metadata) {
- expect(typeof metadata !== 'undefined' && metadata !== null, "metadata should not be null.");
- expect(metadata.modificationTime instanceof Date, "metadata.modificationTime should be Date object");
-
- // cleanup
- that.deleteEntry(fileName);
- QUnit.start();
- };
-
- // create a new file entry
- this.createFile(fileName, entryCallback, this.fail);
- });
- it("Entry.getMetadata on directory", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
- var dirName = "entry.metadata.dir",
- that = this,
- entryCallback = function(entry) {
- entry.getMetadata(itMetadata, this.fail);
- },
- itMetadata = function(metadata) {
- expect(typeof metadata !== 'undefined' && metadata !== null, "metadata should not be null.");
- expect(metadata.modificationTime instanceof Date, "metadata.modificationTime should be Date object");
-
- // cleanup
- that.deleteEntry(dirName);
- QUnit.start();
- };
-
- // create a new directory entry
- this.createDirectory(dirName, entryCallback, this.fail);
- });
- it("Entry.getParent on file in root file system", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
- var fileName = "entry.parent.file",
- that = this,
- rootPath = this.root.fullPath,
- entryCallback = function(entry) {
- entry.getParent(itParent, this.fail);
- },
- itParent = function(parent) {
- expect(typeof parent !== 'undefined' && parent !== null, "parent directory should not be null.");
- expect(parent.fullPath, rootPath, "parent fullPath should be root file system");
-
- // cleanup
- that.deleteEntry(fileName);
- QUnit.start();
- };
-
- // create a new file entry
- this.createFile(fileName, entryCallback, this.fail);
- });
- it("Entry.getParent on directory in root file system", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
- var dirName = "entry.parent.dir",
- that = this,
- rootPath = this.root.fullPath,
- entryCallback = function(entry) {
- entry.getParent(itParent, this.fail);
- },
- itParent = function(parent) {
- expect(typeof parent !== 'undefined' && parent !== null, "parent directory should not be null.");
- expect(parent.fullPath, rootPath, "parent fullPath should be root file system");
-
- // cleanup
- that.deleteEntry(dirName);
- QUnit.start();
- };
-
- // create a new directory entry
- this.createDirectory(dirName, entryCallback, this.fail);
- });
- it("Entry.getParent on root file system", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
- var rootPath = this.root.fullPath,
- itParent = function(parent) {
- expect(typeof parent !== 'undefined' && parent !== null, "parent directory should not be null.");
- expect(parent.fullPath, rootPath, "parent fullPath should be root file system");
- QUnit.start();
- };
-
- // create a new directory entry
- this.root.getParent(itParent, this.fail);
- });
- it("Entry.toURL on file", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
- var fileName = "entry.uri.file",
- that = this,
- rootPath = this.root.fullPath,
- itURL = function(entry) {
- var uri = entry.toURL();
- expect(typeof uri !== 'undefined' && uri !== null, "URL should not be null.");
- expect(uri.indexOf(rootPath) !== -1, "URL should contain root file system path");
-
- // cleanup
- that.deleteEntry(fileName);
- QUnit.start();
- };
-
- // create a new file entry
- this.createFile(fileName, itURL, this.fail);
- });
- it("Entry.toURL on directory", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
- var dirName = "entry.uri.dir",
- that = this,
- rootPath = this.root.fullPath,
- itURL = function(entry) {
- var uri = entry.toURL();
- expect(typeof uri !== 'undefined' && uri !== null, "URL should not be null.");
- expect(uri.indexOf(rootPath) !== -1, "URL should contain root file system path");
-
- // cleanup
- that.deleteEntry(dirName);
- QUnit.start();
- };
-
- // create a new directory entry
- this.createDirectory(dirName, itURL, this.fail);
- });
- it("Entry.remove on file", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(3);
-
- var fileName = "entry.rm.file",
- that = this,
- fullPath = this.root.fullPath + '/' + fileName,
- entryCallback = function(entry) {
- var checkRemove = function() {
- that.root.getFile(fileName, null, that.unexpectedSuccess, itRemove);
- };
- expect(typeof entry !== 'undefined' && entry !== null, "entry should not be null.");
- entry.remove(checkRemove, that.fail);
- },
- itRemove = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "file should not exist");
- expect(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR");
- // cleanup
- that.deleteEntry(fileName);
- QUnit.start();
- };
-
- // create a new file entry
- this.createFile(fileName, entryCallback, this.fail);
- });
- it("Entry.remove on empty directory", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(3);
-
- var dirName = "entry.rm.dir",
- that = this,
- fullPath = this.root.fullPath + '/' + dirName,
- entryCallback = function(entry) {
- var checkRemove = function() {
- that.root.getDirectory(dirName, null, that.unexpectedSuccess, itRemove);
- };
- expect(typeof entry !== 'undefined' && entry !== null, "entry should not be null.");
- entry.remove(checkRemove, that.fail);
- },
- itRemove = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "directory should not exist");
- expect(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR");
- // cleanup
- that.deleteEntry(dirName);
- QUnit.start();
- };
-
- // create a new directory entry
- this.createDirectory(dirName, entryCallback, this.fail);
- });
- it("Entry.remove on non-empty directory", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(4);
-
- var dirName = "entry.rm.dir.not.empty",
- that = this,
- fullPath = this.root.fullPath + '/' + dirName,
- fileName = "remove.txt",
- entryCallback = function(entry) {
- var checkFile = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "removing non-empty directory should generate an error");
- expect(error.code, FileError.INVALID_MODIFICATION_ERR, "error code should be FileError.INVALID_MODIFICATION_ERR");
- // verify that dir still exists
- that.root.getDirectory(dirName, null, itRemove, that.fail);
- };
- // delete directory
- var deleteDirectory = function(fileEntry) {
- entry.remove(that.unexpectedSuccess, checkFile);
- };
- // create a file within directory, then try to delete directory
- entry.getFile(fileName, {create: true}, deleteDirectory, that.fail);
- },
- itRemove = function(entry) {
- expect(typeof entry !== 'undefined' && entry !== null, "entry should not be null.");
- expect(entry.fullPath, fullPath, "dir entry should still exisit");
- // cleanup
- that.deleteEntry(dirName);
- QUnit.start();
- };
-
- // create a new directory entry
- this.createDirectory(dirName, entryCallback, this.fail);
- });
- it("Entry.remove on root file system", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
- var itRemove = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "removing root file system should generate an error");
- expect(error.code, FileError.NO_MODIFICATION_ALLOWED_ERR, "error code should be FileError.NO_MODIFICATION_ALLOWED_ERR");
- QUnit.start();
- };
-
- // remove entry that doesn't exist
- this.root.remove(null, itRemove);
- });
- it("Entry.copyTo: file", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(10);
-
- var file1 = "entry.copy.file1",
- file2 = "entry.copy.file2",
- that = this,
- fullPath = this.root.fullPath + '/' + file2,
- entryCallback = function(entry) {
- // copy file1 to file2
- entry.copyTo(that.root, file2, itCopy, that.fail);
- },
- itCopy = function(entry) {
-
- expect(typeof entry !== 'undefined' && entry !== null, "copied file entry should not be null");
- expects(entry.isFile, true, "entry 'isFile' attribute should be set to true");
- expects(entry.isDirectory, false, "entry 'isDirectory' attribute should be set to false");
- expects(entry.fullPath, fullPath, "entry 'fullPath' should be set correctly");
- expects(entry.name, file2, "entry 'name' attribute should be set correctly");
- that.root.getFile(file2, {create:false}, itFileExists, null);
-
- },
- itFileExists = function(entry2) {
- // a bit redundant since copy returned this entry already
- expect(typeof entry2 !== 'undefined' && entry2 !== null, "copied file entry should not be null");
- expects(entry2.isFile, true, "entry 'isFile' attribute should be set to true");
- expects(entry2.isDirectory, false, "entry 'isDirectory' attribute should be set to false");
- expects(entry2.fullPath, fullPath, "entry 'fullPath' should be set correctly");
- expects(entry2.name, file2, "entry 'name' attribute should be set correctly");
-
- // cleanup
- that.deleteEntry(file1);
- that.deleteEntry(file2);
- QUnit.start();
- };
-
- // create a new file entry to kick off it
- this.createFile(file1, entryCallback, this.fail);
+ waitsFor(function() { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(win).toHaveBeenCalled();
+ expect(fail).not.toHaveBeenCalled();
+ });
+ });
+ it("should read contents of directory that has been removed", function() {
+ var dirName = "de.createReader.notfound",
+ dirPath = root.fullPath + '/' + dirName,
+ entryCallback = jasmine.createSpy().andCallFake(function(directory) {
+ // read entries
+ var readEntries = jasmine.createSpy().andCallFake(function() {
+ var reader = directory.createReader();
+
+ runs(function() {
+ reader.readEntries(win, itReader);
+ });
+
+ waitsFor(function() { return itReader.wasCalled; }, "itReader never called", Tests.TEST_TIMEOUT);
+ });
+ // delete directory
+ runs(function() {
+ directory.removeRecursively(readEntries, fail);
+ });
+
+ waitsFor(function() { return readEntries.wasCalled; }, "readEntries never called", Tests.TEST_TIMEOUT);
+ }),
+ itReader = jasmine.createSpy().andCallFake(function(error) {
+ var itDirectoryExists = jasmine.createSpy().andCallFake(function(error) {
+ expect(error).toBeDefined();
+ expect(error.code).toBe(FileError.NOT_FOUND_ERR);
+ });
+
+ expect(error).toBeDefined();
+ expect(error.code).toBe(FileError.NOT_FOUND_ERR);
+
+ runs(function() {
+ root.getDirectory(dirName, {create:false}, win, itDirectoryExists);
+ });
+
+ waitsFor(function() { return itDirectoryExists.wasCalled; }, "itDirectoryExists never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(itDirectoryExists).toHaveBeenCalled();
+ expect(win).not.toHaveBeenCalled();
+ });
+ }),
+ fail = createFail('DirectoryReader'),
+ win = createWin('DirectoryReader');
+
+ // create a new directory entry to kick off it
+ runs(function() {
+ root.getDirectory(dirName, {create:true}, entryCallback, fail);
+ });
+
+ waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT);
+ });
+ });
});
- it("Entry.copyTo: file onto itself", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
- var file1 = "entry.copy.fos.file1",
- that = this,
- entryCallback = function(entry) {
- // copy file1 onto itself
- entry.copyTo(that.root, null, null, itCopy);
- },
- itCopy = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "it is an error to copy an entry into its parent if a different name is not specified");
- expect(error.code, FileError.INVALID_MODIFICATION_ERR, "error code should be FileError.INVALID_MODIFICATION_ERR");
-
- // cleanup
- that.deleteEntry(file1);
- QUnit.start();
- };
-
- // create a new file entry to kick off it
- this.createFile(file1, entryCallback, this.fail);
+
+ describe('File interface', function() {
+ it("constructor should be defined", function() {
+ expect(File).toBe(jasmine.any(Function));
+ });
+ it("should be define File attributes", function() {
+ var file = new File();
+ expect(file.name).toBeDefined();
+ expect(file.fullPath).toBeDefined();
+ expect(file.type).toBeDefined();
+ expect(file.lastModifiedDate).toBeDefined();
+ expect(file.size).toBeDefined();
+ });
});
- it("Entry.copyTo: directory", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(15);
-
- var file1 = "file1",
- srcDir = "entry.copy.srcDir",
- dstDir = "entry.copy.dstDir",
- dstPath = this.root.fullPath + '/' + dstDir,
- filePath = dstPath + '/' + file1,
- that = this,
- entryCallback = function(directory) {
- var copyDir = function(fileEntry) {
- // copy srcDir to dstDir
- directory.copyTo(that.root, dstDir, itCopy, that.fail);
- };
- // create a file within new directory
- directory.getFile(file1, {create: true}, copyDir, that.fail);
- },
- itCopy = function(directory) {
-
- expect(typeof directory !== 'undefined' && directory !== null, "copied directory entry should not be null");
- expects(directory.isFile, false, "entry 'isFile' attribute should be false");
- expects(directory.isDirectory, true, "entry 'isDirectory' attribute should be true");
- expects(directory.fullPath, dstPath, "entry 'fullPath' should be set correctly");
- expects(directory.name, dstDir, "entry 'name' attribute should be set correctly");
-
- that.root.getDirectory(dstDir, {create:false}, itDirExists, that.fail);
- },
- itDirExists = function(dirEntry) {
- expect(typeof dirEntry !== 'undefined' && dirEntry !== null, "copied directory entry should not be null");
- expects(dirEntry.isFile, false, "entry 'isFile' attribute should be false");
- expects(dirEntry.isDirectory, true, "entry 'isDirectory' attribute should be true");
- expects(dirEntry.fullPath, dstPath, "entry 'fullPath' should be set correctly");
- expects(dirEntry.name, dstDir, "entry 'name' attribute should be set correctly");
-
- dirEntry.getFile(file1, {create:false}, itFileExists, that.fail);
-
- };
- itFileExists = function(fileEntry) {
- expect(typeof fileEntry !== 'undefined' && fileEntry !== null, "copied directory entry should not be null");
- expects(fileEntry.isFile, true, "entry 'isFile' attribute should be true");
- expects(fileEntry.isDirectory, false, "entry 'isDirectory' attribute should be false");
- expects(fileEntry.fullPath, filePath, "entry 'fullPath' should be set correctly");
- expects(fileEntry.name, file1, "entry 'name' attribute should be set correctly");
-
- // cleanup
- that.deleteEntry(srcDir);
- that.deleteEntry(dstDir);
- QUnit.start();
- };
+ describe('FileEntry interface', function() {
+ it("should be define FileEntry methods", function() {
+ var fileName = "fe.methods",
+ itFileEntry = jasmine.createSpy().andCallFake(function(fileEntry) {
+ expect(fileEntry).toBeDefined();
+ expect(fileEntry.createWriter).toBe(jasmine.any(Function));
+ expect(fileEntry.file).toBe(jasmine.any(Function));
+
+ // cleanup
+ fileEntry.remove(null, fail);
+ }),
+ fail = createFail('FileEntry');
+
+ // create a new file entry to kick off it
+ runs(function() {
+ root.getFile(fileName, {create:true}, itFileEntry, fail);
+ });
- // create a new directory entry to kick off it
- this.createDirectory(srcDir, entryCallback, this.fail);
- });
- it("Entry.copyTo: directory to backup at same root directory", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(15);
-
- var file1 = "file1",
- srcDir = "entry.copy.srcDir",
- dstDir = "entry.copy.srcDir-backup",
- dstPath = this.root.fullPath + '/' + dstDir,
- filePath = dstPath + '/' + file1,
- that = this,
- entryCallback = function(directory) {
- var copyDir = function(fileEntry) {
- // copy srcDir to dstDir
- directory.copyTo(that.root, dstDir, itCopy, that.fail);
- };
- // create a file within new directory
- directory.getFile(file1, {create: true}, copyDir, that.fail);
- },
- itCopy = function(directory) {
-
- expect(typeof directory !== 'undefined' && directory !== null, "copied directory entry should not be null");
- expects(directory.isFile, false, "entry 'isFile' attribute should be false");
- expects(directory.isDirectory, true, "entry 'isDirectory' attribute should be true");
- expects(directory.fullPath, dstPath, "entry 'fullPath' should be set correctly");
- expects(directory.name, dstDir, "entry 'name' attribute should be set correctly");
-
- that.root.getDirectory(dstDir, {create:false}, itDirExists, that.fail);
- },
- itDirExists = function(dirEntry) {
- expect(typeof dirEntry !== 'undefined' && dirEntry !== null, "copied directory entry should not be null");
- expects(dirEntry.isFile, false, "entry 'isFile' attribute should be false");
- expects(dirEntry.isDirectory, true, "entry 'isDirectory' attribute should be true");
- expects(dirEntry.fullPath, dstPath, "entry 'fullPath' should be set correctly");
- expects(dirEntry.name, dstDir, "entry 'name' attribute should be set correctly");
-
- dirEntry.getFile(file1, {create:false}, itFileExists, that.fail);
-
- };
- itFileExists = function(fileEntry) {
- expect(typeof fileEntry !== 'undefined' && fileEntry !== null, "copied directory entry should not be null");
- expects(fileEntry.isFile, true, "entry 'isFile' attribute should be true");
- expects(fileEntry.isDirectory, false, "entry 'isDirectory' attribute should be false");
- expects(fileEntry.fullPath, filePath, "entry 'fullPath' should be set correctly");
- expects(fileEntry.name, file1, "entry 'name' attribute should be set correctly");
-
+ waitsFor(function() { return itFileEntry.wasCalled; }, "itFileEntry never called", Tests.TEST_TIMEOUT);
- // cleanup
- that.deleteEntry(srcDir);
- that.deleteEntry(dstDir);
- QUnit.start();
- };
+ runs(function() {
+ expect(itFileEntry).toHaveBeenCalled();
+ expect(fail).not.toHaveBeenCalled();
+ });
+ });
+ it("FileEntry.createWriter should return a FileWriter object", function() {
+ var fileName = "fe.createWriter",
+ itFile,
+ entryCallback = jasmine.createSpy().andCallFake(function(fileEntry) {
+ itFile = fileEntry;
- // create a new directory entry to kick off it
- this.createDirectory(srcDir, entryCallback, this.fail);
- });
- it("Entry.copyTo: directory onto itself", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(6);
-
- var file1 = "file1",
- srcDir = "entry.copy.dos.srcDir",
- srcPath = this.root.fullPath + '/' + srcDir,
- filePath = srcPath + '/' + file1,
- that = this,
- entryCallback = function(directory) {
- var copyDir = function(fileEntry) {
- // copy srcDir onto itself
- directory.copyTo(that.root, null, null, itCopy);
- };
- // create a file within new directory
- directory.getFile(file1, {create: true}, copyDir, that.fail);
- },
- itCopy = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "it is an error to copy an entry into its parent if a different name is not specified");
- expect(error.code, FileError.INVALID_MODIFICATION_ERR, "error code should be FileError.INVALID_MODIFICATION_ERR");
-
- that.root.getDirectory(srcDir, {create:false}, itDirectoryExists, null);
- },
- itDirectoryExists = function(dirEntry) {
- // returning confirms existence so just check fullPath entry
- expect(typeof dirEntry !== 'undefined' && dirEntry !== null, "original directory should exist.");
- expects(dirEntry.fullPath, srcPath, "entry 'fullPath' should be set correctly");
-
- dirEntry.getFile(file1, {create:false}, itFileExists, null);
- },
- itFileExists = function(fileEntry) {
- expect(typeof fileEntry !== 'undefined' && fileEntry !== null, "original directory contents should exist.");
- expects(fileEntry.fullPath, filePath, "entry 'fullPath' should be set correctly");
-
- // cleanup
- that.deleteEntry(srcDir);
- QUnit.start();
- };
+ runs(function() {
+ fileEntry.createWriter(itWriter, fail);
+ });
- // create a new directory entry to kick off it
- this.createDirectory(srcDir, entryCallback, this.fail);
- });
- it("Entry.copyTo: directory into itself", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(4);
-
- var srcDir = "entry.copy.dis.srcDir",
- dstDir = "entry.copy.dis.dstDir",
- srcPath = this.root.fullPath + '/' + srcDir,
- that = this,
- entryCallback = function(directory) {
- // copy source directory into itself
- directory.copyTo(directory, dstDir, null, itCopy);
- },
- itCopy = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "it is an error to copy a directory into itself");
- expect(error.code, FileError.INVALID_MODIFICATION_ERR, "error code should be FileError.INVALID_MODIFICATION_ERR");
-
- that.root.getDirectory(srcDir, {create:false}, itDirectoryExists, null);
- },
- itDirectoryExists = function(dirEntry) {
- // returning confirms existence so just check fullPath entry
- expect(typeof dirEntry !== 'undefined' && dirEntry !== null, "original directory should exist.");
- expects(dirEntry.fullPath, srcPath, "entry 'fullPath' should be set correctly");
-
- // cleanup
- that.deleteEntry(srcDir);
- QUnit.start();
- };
-
- // create a new directory entry to kick off it
- this.createDirectory(srcDir, entryCallback, this.fail);
- });
- it("Entry.copyTo: directory that does not exist", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(4);
-
- var file1 = "entry.copy.dnf.file1",
- dstDir = "entry.copy.dnf.dstDir",
- filePath = this.root.fullPath + '/' + file1,
- dstPath = this.root.fullPath + '/' + dstDir,
- that = this,
- entryCallback = function(entry) {
- // copy file to target directory that does not exist
- directory = new DirectoryEntry();
- directory.fullPath = dstPath;
- entry.copyTo(directory, null, null, itCopy);
- },
- itCopy = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "it is an error to copy to a directory that does not exist");
- expect(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR");
- that.root.getFile(file1, {create: false}, itFileExists, null);
- },
- itFileExists = function(fileEntry) {
- expect(typeof fileEntry !== 'undefined' && fileEntry !== null, "original file should exist");
- expects(fileEntry.fullPath, filePath, "entry 'fullPath' should be set correctly");
-
- // cleanup
- that.deleteEntry(file1);
- QUnit.start();
- };
-
- // create a new file entry to kick off it
- this.createFile(file1, entryCallback, this.fail);
- });
- it("Entry.copyTo: invalid target name", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(2);
-
- var file1 = "entry.copy.itn.file1",
- file2 = "bad:file:name",
- that = this,
- filePath = this.root.fullPath + '/' + file1,
- entryCallback = function(entry) {
- // copy file1 to file2
- entry.copyTo(that.root, file2, null, itCopy);
- },
- itCopy = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "invalid file name should result in error");
- expect(error.code, FileError.ENCODING_ERR, "error code should be FileError.ENCODING_ERR");
-
- // cleanup
- that.deleteEntry(file1);
- QUnit.start();
- };
-
- // create a new file entry
- this.createFile(file1, entryCallback, this.fail);
- });
- it("Entry.moveTo: file to same parent", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(9);
-
- var file1 = "entry.move.fsp.file1",
- file2 = "entry.move.fsp.file2",
- that = this,
- srcPath = this.root.fullPath + '/' + file1,
- dstPath = this.root.fullPath + '/' + file2,
- entryCallback = function(entry) {
- // move file1 to file2
- entry.moveTo(that.root, file2, itMove, that.fail);
- },
- itMove = function(entry) {
- expect(typeof entry !== 'undefined' && entry !== null, "file entry should not be null");
- expects(entry.isFile, true, "entry 'isFile' attribute should be set to true");
- expects(entry.isDirectory, false, "entry 'isDirectory' attribute should be set to false");
- expects(entry.fullPath, dstPath, "entry 'fullPath' should be set correctly");
- expects(entry.name, file2, "entry 'name' attribute should be set correctly");
-
- that.root.getFile(file2, {create:false}, itMovedExists, null);
- },
- itMovedExists = function(fileEntry) {
- expect(typeof fileEntry !== 'undefined' && fileEntry !== null, "moved file should exist");
- expects(fileEntry.fullPath, dstPath, "entry 'fullPath' should be set correctly");
-
- that.root.getFile(file1, {create:false}, null, itOrig);
- },
- itOrig = function(error) {
- //expect(navigator.fileMgr.itFileExists(srcPath) === false, "original file should not exist.");
- expect(typeof error !== 'undefined' && error !== null, "it is an error if original file exists after a move");
- expect(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR");
-
-
- // cleanup
- that.deleteEntry(file1);
- that.deleteEntry(file2);
- QUnit.start();
- };
-
- // create a new file entry to kick off it
- this.createFile(file1, entryCallback, this.fail);
- });
- it("Entry.moveTo: file to new parent", function() {
- QUnit.stop(its.it_TIMEOUT);
- expect(9);
-
- var file1 = "entry.move.fnp.file1",
- dir = "entry.move.fnp.dir",
- that = this,
- srcPath = this.root.fullPath + '/' + file1,
- dstPath = this.root.fullPath + '/' + dir + '/' + file1,
- entryCallback = function(entry) {
- // move file1 to new directory
- var moveFile = function(directory) {
-
- var itMove = function(entry) {
- expect(typeof entry !== 'undefined' && entry !== null, "file entry should not be null");
- expects(entry.isFile, true, "entry 'isFile' attribute should be set to true");
- expects(entry.isDirectory, false, "entry 'isDirectory' attribute should be set to false");
- expects(entry.fullPath, dstPath, "entry 'fullPath' should be set correctly");
- expects(entry.name, file1, "entry 'name' attribute should be set correctly");
- // it the moved file exists
- directory.getFile(file1, {create:false}, itMovedExists, null);
- };
- // move the file
- entry.moveTo(directory, null, itMove, that.fail);
- };
-
- // create a parent directory to move file to
- that.root.getDirectory(dir, {create: true}, moveFile, that.fail);
- },
- itMovedExists = function(fileEntry) {
- expect(typeof fileEntry !== 'undefined' && fileEntry !== null, "moved file should exist");
- expects(fileEntry.fullPath, dstPath, "entry 'fullPath' should be set correctly");
-
- that.root.getFile(file1, {create:false}, null, itOrig);
- },
- itOrig = function(error) {
- expect(typeof error !== 'undefined' && error !== null, "it is an error if original file exists after a move");
- expect(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR");
-
- // cleanup
- that.deleteEntry(file1);
- that.deleteEntry(dir);
- QUnit.start();
- };
-
- // ensure destination directory is cleaned up before it
- this.deleteEntry(dir, function() {
+ waitsFor(function() { return itWriter.wasCalled; }, "itWriter never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(itWriter).toHaveBeenCalled();
+ expect(fail).not.toHaveBeenCalled();
+ });
+ }),
+ itWriter = jasmine.createSpy().andCallFake(function(writer) {
+ expect(writer).toBeDefined();
+ expect(writer.constructor).toBe(jasmine.any(FileWriter));
+
+ // cleanup
+ itFile.remove(null, fail);
+ }),
+ fail = createFail('FileEntry');
+
// create a new file entry to ki
<TRUNCATED>