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
[19/37] rewriting file specs to jasmine: part 1
http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/14c67854/autotest/tests/file.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/file.tests.js b/autotest/tests/file.tests.js
index f1ff6b6..7e7618f 100644
--- a/autotest/tests/file.tests.js
+++ b/autotest/tests/file.tests.js
@@ -1,6 +1,6 @@
/**
* Retrieves root file system entries once, so they don't have to be
- * repeated for every test (file system shouldn't change during test run).
+ * repeated for every it (file system shouldn't change during it run).
*/
var getFileSystemRoot = (function() {
@@ -8,17 +8,19 @@ var getFileSystemRoot = (function() {
var temp_root, persistent_root;
var onError = function(error) {
- console.log('unable to retrieve file system: ' + error.code);
+ console.log('[ERROR getFileSystemRoot] Unable to retrieve file system: ' + error.code);
};
// one-time retrieval of the root file system entry
var init = function() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function(fileSystem) {
+ console.log('File API test Init: Setting PERSISTENT FS.');
persistent_root = fileSystem.root;
}, onError);
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0,
function(fileSystem) {
+ console.log('File API test Init: Setting TEMPORARY FS.');
temp_root = fileSystem.root;
}, onError);
};
@@ -33,733 +35,785 @@ var getFileSystemRoot = (function() {
};
}()); // execute immediately
-Tests.prototype.FileTests = function() {
- module('FileError interface');
- test("FileError constants should be defined", function() {
- expect(12);
- equal(FileError.NOT_FOUND_ERR, 1, "FileError.NOT_FOUND_ERR should be defined");
- equal(FileError.SECURITY_ERR, 2, "FileError.SECURITY_ERR should be defined");
- equal(FileError.ABORT_ERR, 3, "FileError.ABORT should be defined");
- equal(FileError.NOT_READABLE_ERR, 4, "FileError.NOT_READABLE_ERR should be defined");
- equal(FileError.ENCODING_ERR, 5, "FileError.ENCODING_ERR should be defined");
- equal(FileError.NO_MODIFICATION_ALLOWED_ERR, 6, "FileError.NO_MODIFICATION_ALLOWED_ERR should be defined");
- equal(FileError.INVALID_STATE_ERR, 7, "FileError.INVALID_STATE_ERR should be defined");
- equal(FileError.SYNTAX_ERR, 8, "FileError.SYNTAX_ERR should be defined");
- equal(FileError.INVALID_MODIFICATION_ERR, 9, "FileError.INVALID_MODIFICATION_ERR should be defined");
- equal(FileError.QUOTA_EXCEEDED_ERR, 10, "FileError.QUOTA_EXCEEDED_ERR should be defined");
- equal(FileError.TYPE_MISMATCH_ERR, 11, "FileError.TYPE_MISMATCH_ERR should be defined");
- equal(FileError.PATH_EXISTS_ERR, 12, "FileError.PATH_EXISTS_ERR should be defined");
- });
-
- module('LocalFileSystem interface', {
- // setup function will run before each test
- setup: function() {
+describe('File API', function() {
+ describe('FileError object', function() {
+ it("should define FileError constants", function() {
+ expect(FileError.NOT_FOUND_ERR).toBe(1);
+ expect(FileError.SECURITY_ERR).toBe(2);
+ expect(FileError.ABORT_ERR).tobe(3);
+ expect(FileError.NOT_READABLE_ERR).toBe(4);
+ expect(FileError.ENCODING_ERR).toBe(5);
+ expect(FileError.NO_MODIFICATION_ALLOWED_ERR).toBe(6);
+ expect(FileError.INVALID_STATE_ERR).toBe(7);
+ expect(FileError.SYNTAX_ERR).toBe(8);
+ expect(FileError.INVALID_MODIFICATION_ERR).toBe(9);
+ expect(FileError.QUOTA_EXCEEDED_ERR).toBe(10);
+ expect(FileError.TYPE_MISMATCH_ERR).toBe(11);
+ expect(FileError.PATH_EXISTS_ERR).toBe(12);
+ });
+ });
+
+ describe('LocalFileSystem', function() {
+ beforeEach(function() {
+ // TODO: how does qunit scope `this`
var that = this;
this.root = getFileSystemRoot();
- this.fail = function(error) {
- console.log('file error: ' + error.code);
- };
+ this.fail = jasmine.createSpy().andCallFake(function(error) {
+ console.log('ERROR [LocalFileSystem]: ' + error.code);
+ });
this.unexpectedSuccess = function() {
- console.log('!!! success function called when not expected !!!');
+ console.log('ERROR [LocalFileSystem] Success callback 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);
+ 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);
};
- }
- });
- test("window.requestFileSystem function should be defined", function() {
- expect(1);
- ok(typeof window.requestFileSystem === 'function', "window.requestFileSystem should be a function.");
- });
- test("window.resolveLocalFileSystemURI function should be defined", function() {
- expect(1);
- ok(typeof window.resolveLocalFileSystemURI === 'function', "window.resolveLocalFileSystemURI should be a function.");
- });
- test("File system types should be defined", function() {
- expect(2);
- equal(LocalFileSystem.TEMPORARY, 0, "LocalFileSystem.TEMPORARY should be defined");
- equal(LocalFileSystem.PERSISTENT, 1, "LocalFileSystem.PERSISTENT should be defined");
- });
- test("retrieve PERSISTENT file system", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(4);
+ });
+
+ it("should define LocalFileSystem constants", function() {
+ expect(LocalFileSystem.TEMPORARY).toBe(0);
+ expect(LocalFileSystem.PERSISTENT).toBe(1);
+ });
+
+ describe('window.requestFileSystem', function() {
+ it("should be defined", function() {
+ expect(window.requestFileSystem).toBeDefined();
+ });
+ it("should be able to retrieve a PERSISTENT file system", function() {
+ var win = jasmine.createSpy().andCallFake(function(fileSystem) {
+ expect(fileSystem).toBeDefined();
+ expect(fileSystem.name).toBeDefined();
+ expect(fileSystem.name).toBe("persistent");
+ expect(fileSystem.root).toBeDefined();
+ }),
+ fail = jasmine.createSpy();
+
+ // retrieve PERSISTENT file system
+ runs(function() {
+ window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, win, fail);
+ });
+
+ waitsFor(function() { return win.wasCalled; }, "success callback never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(fail).not.toHaveBeenCalled();
+ expect(win).toHaveBeenCalled();
+ });
+ });
+ it("should be able to retrieve a TEMPORARY file system", function() {
+ var win = jasmine.createSpy().andCallFake(function(fileSystem) {
+ expect(fileSystem).toBeDefined();
+ expect(fileSystem.name).toBeDefined();
+ expect(fileSystem.name).toBe("temporary");
+ expect(fileSystem.root).toBeDefined();
+ }),
+ fail = jasmine.createSpy();
+
+ // Request the file system
+ runs(function() {
+ window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, win, fail);
+ });
+
+ waitsFor(function() { return win.wasCalled; }, "success callback never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(fail).not.toHaveBeenCalled();
+ expect(win).toHaveBeenCalled();
+ });
+ });
+ it("should error if you request a file system that is too large", function() {
+ var fail = jasmine.createSpy().andCallFake(function(error) {
+ expect(error).toBeDefined();
+ expect(error.code).toBe(FileError.QUOTA_EXCEEDED_ERR);
+ }),
+ win = jasmine.createSpy();
+
+ // Request the file system
+ runs(function() {
+ window.requestFileSystem(LocalFileSystem.TEMPORARY, 1000000000000000, win, fail);
+ });
+
+ waitsFor(function() { return fail.wasCalled; }, "error callback never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(win).not.toHaveBeenCalled();
+ expect(fail).toHaveBeenCalled();
+ });
+ });
+ it("should error out if you request a file system that does not exist", function() {
+ var fail = jasmine.createSpy().andCallFake(function(error) {
+ expect(error).toBeDefined();
+ expect(error.code).toBe(FileError.SYNTAX_ERR);
+ }),
+ win = jasmine.createSpy();
+
+ // Request the file system
+ runs(function() {
+ window.requestFileSystem(-1, 0, win, fail);
+ });
+
+ waitsFor(function() { return fail.wasCalled; }, "error callback never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(win).not.toHaveBeenCalled();
+ expect(fail).toHaveBeenCalled();
+ });
+ });
+ });
+
+ describe('window.resolveLocalFileSystemURI', function() {
+ it("should be defined", function() {
+ expect(window.resolveLocalFileSystemURI).toBeDefined();
+ });
+ it("should resolve a valid file name", function() {
+ var fileName = "resolve.file.uri",
+ that = this,
+ itEntry = jasmine.createSpy().andCallFake(function(fileEntry) {
+ expect(fileEntry).toBeDefined();
+ expect(fileEntry.name).toBe(fileName);
- var testPersistent = function(fileSystem) {
- ok(typeof fileSystem !== 'undefined' && fileSystem !== null, "window.requestFileSystem should return an object.");
- ok(typeof fileSystem.name !== 'undefined' && fileSystem.name !== null, "filesystem should include a 'name' property.");
- equal(fileSystem.name, "persistent", "file system 'name' attribute should be set properly");
- ok(typeof fileSystem.root !== 'undefined' && fileSystem.root !== null, "filesystem should include a 'root' property.");
- QUnit.start();
- };
-
- // retrieve PERSISTENT file system
- window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, testPersistent,
- function(error) {
- console.log('error retrieving file system: ' + error.code);
- });
- });
- test("retrieve TEMPORARY file system", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(4);
-
- var testTemporary = function(fileSystem) {
- ok(typeof fileSystem !== 'undefined' && fileSystem !== null, "window.requestFileSystem should return an object.");
- ok(typeof fileSystem.name !== 'undefined' && fileSystem.name !== null, "filesystem should include a 'name' property.");
- equal(fileSystem.name, "temporary", "file system 'name' attribute should be set properly");
- ok(typeof fileSystem.root !== 'undefined' && fileSystem.root !== null, "filesystem should include a 'root' property.");
- QUnit.start();
- };
-
- // Request the file system
- window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, testTemporary,
- function(error) {
- console.log('error retrieving file system: ' + error.code);
- });
- });
- test("request a file system that is too large", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(2);
-
- var failFS = function(error) {
- ok(error !== null, "error should not be null.");
- equal(error.code, FileError.QUOTA_EXCEEDED_ERR, "Shoud receive error code FileError.QUOTA_EXCEEDED_ERR");
- QUnit.start();
- };
-
- // Request the file system
- window.requestFileSystem(LocalFileSystem.TEMPORARY, 1000000000000000, null, failFS);
- });
- test("request a file system that does not exist", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(2);
+ // cleanup
+ that.deleteEntry(fileName);
+ }),
+ resolveCallback = jasmine.createSpy().andCallFake(function(entry) {
+ // lookup file system entry
+ runs(function() {
+ window.resolveLocalFileSystemURI(entry.toURI(), itEntry, that.fail);
+ });
+
+ waitsFor(function() { return itEntry.wasCalled; }, "resolveLocalFileSystemURI callback never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(itEntry).toHaveBeenCalled();
+ expect(that.fail).not.toHaveBeenCalled();
+ });
+ });
+
+ // create a new file entry
+ runs(function() {
+ that.createFile(fileName, resolveCallback, that.fail);
+ });
+
+ waitsFor(function() { return resolveCallback.wasCalled; }, "createFile callback never called", Tests.TEST_TIMEOUT);
+ });
+ it("resolve valid file name with parameters", function() {
+ var fileName = "resolve.file.uri.params",
+ that = this,
+ itEntry = jasmine.createSpy().andCallFake(function(fileEntry) {
+ expect(fileEntry).toBeDefined();
+ expect(fileEntry.name).toBe(fileName);
- var failFS = function(error) {
- ok(typeof error !== 'undefined' && error !== null, "error should not be null.");
- equal(error.code, FileError.SYNTAX_ERR, "Shoud receive error code FileError.SYNTAX_ERR");
- QUnit.start();
- };
-
- // Request the file system
- window.requestFileSystem(-1, 0, null, failFS);
- });
- test("resolve valid file name", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(2);
-
- var fileName = "resolve.file.uri",
- that = this,
- resolveCallback = function(entry) {
+ // cleanup
+ that.deleteEntry(fileName);
+ }),
+ resolveCallback = jasmine.createSpy().andCallFake(function(entry) {
+ // lookup file system entry
+ runs(function() {
+ window.resolveLocalFileSystemURI(entry.toURI() + "?1234567890", itEntry, that.fail);
+ });
+
+ waitsFor(function() { return itEntry.wasCalled; }, "resolveLocalFileSystemURI callback never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(itEntry).toHaveBeenCalled();
+ expect(that.fail).not.toHaveBeenCalled();
+ });
+ });
+
+ // create a new file entry
+ runs(function() {
+ that.createFile(fileName, resolveCallback, that.fail);
+ });
+
+ waitsFor(function() { return resolveCallback.wasCalled; }, "createFile callback never called", Tests.TEST_TIMEOUT);
+ });
+ it("should error out when resolving invalid file name", function() {
+ var fail = jasmine.createSpy().andCallFake(function(error) {
+ expect(error).toBeDefined();
+ expect(error.code).toBe(FileError.NOT_FOUND_ERR);
+ }),
+ win = jasmine.createSpy();
+
// lookup file system entry
- window.resolveLocalFileSystemURI(entry.toURI(), testEntry, this.fail);
- },
- testEntry = function(fileEntry) {
- ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "fileEntry should not be null.");
- ok(fileEntry.name == fileName, "fileEntry.name should equal 'resolve.file.uri'");
+ runs(function() {
+ window.resolveLocalFileSystemURI("file:///this.is.not.a.valid.file.txt", win, fail);
+ });
+
+ waitsFor(function() { return fail.wasCalled; }, "error callback never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(fail).toHaveBeenCalled();
+ expect(win).not.toHaveBeenCalled();
+ });
+ });
+ it("resolve invalid URL", function() {
+ var fail = jasmine.createSpy().andCallFake(function(error) {
+ expect(error).toBeDefined();
+ expect(error.code).toBe(FileError.ENCODING_ERR);
+ }),
+ win = jasmine.createSpy();
- // cleanup
- that.deleteEntry(fileName);
- QUnit.start();
- };
-
- // create a new file entry
- this.createFile(fileName, resolveCallback, this.fail);
- });
- test("resolve valid file name with parameters", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(2);
-
- var fileName = "resolve.file.uri.params",
- that = this,
- resolveCallback = function(entry) {
// lookup file system entry
- window.resolveLocalFileSystemURI(entry.toURI() + "?1234567890", testEntry, this.fail);
- },
- testEntry = function(fileEntry) {
- ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "fileEntry should not be null.");
- ok(fileEntry.name == fileName, "fileEntry.name should equal 'resolve.file.uri.params'");
-
- // cleanup
- that.deleteEntry(fileName);
- QUnit.start();
- };
-
- // create a new file entry
- this.createFile(fileName, resolveCallback, this.fail);
- });
- test("resolve invalid file name", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(2);
-
- var failURL = function(error) {
- ok(typeof error !== 'undefined' && error !== null, "error should not be null.");
- equal(error.code, FileError.NOT_FOUND_ERR, "Shoud receive error code FileError.NOT_FOUND_ERR");
- QUnit.start();
- };
-
- // lookup file system entry
- window.resolveLocalFileSystemURI("file:///this.is.not.a.valid.file.txt", null, failURL);
- });
- test("resolve invalid URL", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(2);
+ runs(function() {
+ window.resolveLocalFileSystemURI("/this.is.not.a.valid.url", win, fail);
+ });
+
+ waitsFor(function() { return fail.wasCalled; }, "error callback never called", Tests.TEST_TIMEOUT);
+
+ runs(function() {
+ expect(fail).toHaveBeenCalled();
+ expect(win).not.toHaveBeenCalled();
+ });
+ });
+ });
+ });
+
+ describe('Metadata interface', function() {
+ it("should exist and have the right properties", function() {
+ var metadata = new Metadata();
+ expect(metadata).toBeDefined();
+ expect(metadata.modificationTime).toBeDefined();
+ });
+ });
+
+ describe('Flags interface', function() {
+ it("should exist and have the right properties", function() {
+ var flags = new Flags(false, true);
+ expect(flags).toBeDefined();
+ expect(flags.create).toBeDefined();
+ expect(flags.create).toBe(false);
+ expect(flags.exclusive).toBeDefined();
+ expect(flags.exclusive).toBe(true);
+ });
+ });
+
+ describe('FileSystem interface', function() {
+ it("should have a root that is a DirectoryEntry", function() {
+ var root = getFileSystemRoot(),
+ itFSRoot = jasmine.createSpy().andCallFake(function(entry) {
+ expect(entry).toBeDefined();
+ expect(entry.isFile).toBe(false);
+ expect(entry.isDirectory).toBe(true);
+ expect(entry.name).toBeDefined();
+ expect(entry.fullPath).toBeDefined();
+ expect(entry.getMetadata).toBeDefined();
+ expect(entry.moveTo).toBeDefined();
+ expect(entry.copyTo).toBeDefined();
+ expect(entry.toURL).toBeDefined();
+ expect(entry.remove).toBeDefined();
+ expect(entry.getParent).toBeDefined();
+ expect(entry.createReader).toBeDefined();
+ expect(entry.getFile).toBeDefined();
+ expect(entry.getDirectory).toBeDefined();
+ expect(entry.removeRecursively).toBeDefined();
+ }), fail = jasmine.createSpy();
+
+ runs(function() {
+ window.resolveLocalFileSystemURI(root.toURL(), itFSRoot, fail);
+ });
- var failURL = function(error) {
- ok(typeof error !== 'undefined' && error !== null, "error should not be null.");
- equal(error.code, FileError.ENCODING_ERR, "Shoud receive an error code FileError.ENCODING_ERR");
- QUnit.start();
- };
-
- // lookup file system entry
- window.resolveLocalFileSystemURI("/this.is.not.a.valid.url", null, failURL);
- });
+ waitsFor(function() { return itFSRoot.wasCalled; }, "success callback never called", Tests.TEST_TIMEOUT);
- module('Metadata interface');
- test("Metadata constructor should exist", function() {
- expect(2);
- var metadata = new Metadata();
- ok(metadata !== null, "Metadata object should not be null.");
- ok(typeof metadata.modificationTime !== 'undefined', "Metadata object should have a 'modificationTime' property.");
+ runs(function() {
+ expect(fail).not.toHaveBeenCalled();
+ expect(itFSRoot).toHaveBeenCalled();
+ });
+ });
});
- module('Flags interface');
- test("Flags constructor should exist", function() {
- expect(5);
- var flags = new Flags(false, true);
- ok(flags !== null, "Flags object should not be null.");
- ok(typeof flags.create !== 'undefined' && flags.create !== null, "Flags object should have a 'create' property.");
- equal(flags.create, false, "Flags.create should be set properly");
- ok(typeof flags.exclusive !== 'undefined' && flags.exclusive !== null, "Flags object should have an 'exclusive' property.");
- equal(flags.exclusive, true, "flags.exclusive should be set properly");
- });
- module('FileSystem interface');
- test("FileSystem root should be a DirectoryEntry", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(15);
- var root = getFileSystemRoot(),
- testFSRoot = function(entry) {
- ok(typeof entry !== 'undefined' && entry !== null, "entry should be non-null");
- equal(entry.isFile, false, "entry.isFile should be false");
- equal(entry.isDirectory, true, "entry.isDirectory should be true");
- ok(typeof entry.name !== 'undefined' && entry.name !== null, "entry should include a 'name' property.");
- ok(typeof entry.fullPath !== 'undefined' && entry.fullPath !== null, "entry should include a 'fullPath' property.");
- ok(typeof entry.getMetadata === 'function', "entry object should have a 'getMetadata' function.");
- ok(typeof entry.moveTo === 'function', "entry object should have a 'moveTo' function.");
- ok(typeof entry.copyTo === 'function', "entry object should have a 'copyTo' function.");
- ok(typeof entry.toURL === 'function', "entry object should have a 'toURL' function.");
- ok(typeof entry.remove === 'function', "entry object should have a 'remove' function.");
- ok(typeof entry.getParent === 'function', "entry object should have a 'getParent' function.");
- ok(typeof entry.createReader === 'function', "entry object should have a 'createReader' function.");
- ok(typeof entry.getFile === 'function', "entry object should have a 'getFile' function.");
- ok(typeof entry.getDirectory === 'function', "entry object should have a 'getDirectory' function.");
- ok(typeof entry.removeRecursively === 'function', "entry object should have a 'removeRecursively' function.");
- QUnit.start();
- };
-
- window.resolveLocalFileSystemURI(root.toURL(), testFSRoot, null);
-
- });
- module('DirectoryEntry interface', {
- // setup function will run before each test
- setup: function() {
+ describe('DirectoryEntry interface', function() {
+ beforeEach(function() {
+ // TODO: `this` equivalent in jasmine
this.root = getFileSystemRoot();
- this.fail = function(error) {
- console.log('file error: ' + error.code);
- };
+ this.fail = jasmine.createSpy().andCallFake(function(error) {
+ console.log('[ERROR DirectoryEntry] File error: ' + error.code);
+ });
this.unexpectedSuccess = function() {
- console.log('!!! success function called when not expected !!!');
- };
- }
- });
- test("DirectoryEntry.getFile: get Entry for file that does not exist", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(2);
-
- var fileName = "de.no.file",
- filePath = this.root.fullPath + '/' + fileName,
- that = this,
- testFile = function(error) {
- ok(typeof error !== 'undefined' && error !== null, "retrieving a file that does not exist is an error");
- equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR");
-
- // cleanup
- QUnit.start();
- };
-
- // create:false, exclusive:false, file does not exist
- this.root.getFile(fileName, {create:false}, null, testFile);
- });
- test("DirectoryEntry.getFile: create new file", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(5);
-
- var fileName = "de.create.file",
- filePath = this.root.fullPath + '/' + fileName,
- that = this,
- testFile = function(entry) {
- ok(typeof entry !== 'undefined' && entry !== null, "file entry should not be null");
- equal(entry.isFile, true, "entry 'isFile' attribute should be true");
- equal(entry.isDirectory, false, "entry 'isDirectory' attribute should be false");
- equal(entry.name, fileName, "entry 'name' attribute should be set");
- equal(entry.fullPath, filePath, "entry 'fullPath' attribute should be set");
-
- // cleanup
- entry.remove(null, that.fail);
- QUnit.start();
- };
-
- // create:true, exclusive:false, file does not exist
- this.root.getFile(fileName, {create: true}, testFile, this.fail);
- });
- test("DirectoryEntry.getFile: create new file (exclusive)", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(5);
-
- var fileName = "de.create.exclusive.file",
- filePath = this.root.fullPath + '/' + fileName,
- that = this,
- testFile = function(entry) {
- ok(typeof entry !== 'undefined' && entry !== null, "file entry should not be null");
- equal(entry.isFile, true, "entry 'isFile' attribute should be true");
- equal(entry.isDirectory, false, "entry 'isDirectory' attribute should be false");
- equal(entry.name, fileName, "entry 'name' attribute should be set");
- equal(entry.fullPath, filePath, "entry 'fullPath' attribute should be set");
-
- // cleanup
- entry.remove(null, that.fail);
- QUnit.start();
- };
-
- // create:true, exclusive:true, file does not exist
- this.root.getFile(fileName, {create: true, exclusive:true}, testFile, this.fail);
- });
- test("DirectoryEntry.getFile: create file that already exists", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(5);
-
- var fileName = "de.create.existing.file",
- filePath = this.root.fullPath + '/' + fileName,
- that = this,
- getFile = function(file) {
- // create:true, exclusive:false, file exists
- that.root.getFile(fileName, {create:true}, testFile, that.fail);
- },
- testFile = function(entry) {
- ok(typeof entry !== 'undefined' && entry !== null, "file entry should not be null");
- equal(entry.isFile, true, "entry 'isFile' attribute should be true");
- equal(entry.isDirectory, false, "entry 'isDirectory' attribute should be false");
- equal(entry.name, fileName, "entry 'name' attribute should be set");
- equal(entry.fullPath, filePath, "entry 'fullPath' attribute should be set");
-
- // cleanup
- entry.remove(null, that.fail);
- QUnit.start();
- };
-
- // create file to kick off test
- this.root.getFile(fileName, {create:true}, getFile, this.fail);
- });
- test("DirectoryEntry.getFile: create file that already exists (exclusive)", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(2);
-
- var fileName = "de.create.exclusive.existing.file",
- filePath = this.root.fullPath + '/' + fileName,
- that = this,
- existingFile,
- getFile = function(file) {
- existingFile = file;
- // create:true, exclusive:true, file exists
- that.root.getFile(fileName, {create:true, exclusive:true}, null, testFile);
- },
- testFile = function(error) {
- ok(typeof error !== 'undefined' && error !== null, "creating exclusive file that already exists is an error");
- equal(error.code, FileError.PATH_EXISTS_ERR, "error code should be FileError.PATH_EXISTS_ERR");
-
- // cleanup
- existingFile.remove(null, that.fail);
- QUnit.start();
- };
-
- // create file to kick off test
- this.root.getFile(fileName, {create:true}, getFile, this.fail);
- });
- test("DirectoryEntry.getFile: get Entry for existing file", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(5);
-
- var fileName = "de.get.file",
- filePath = this.root.fullPath + '/' + fileName,
- that = this,
- getFile = function(file) {
- // create:false, exclusive:false, file exists
- that.root.getFile(fileName, {create:false}, testFile, that.fail);
- },
- testFile = function(entry) {
- ok(typeof entry !== 'undefined' && entry !== null, "file entry should not be null");
- equal(entry.isFile, true, "entry 'isFile' attribute should be true");
- equal(entry.isDirectory, false, "entry 'isDirectory' attribute should be false");
- equal(entry.name, fileName, "entry 'name' attribute should be set");
- equal(entry.fullPath, filePath, "entry 'fullPath' attribute should be set");
-
- // cleanup
- entry.remove(null, that.fail);
- QUnit.start();
- };
-
- // create file to kick off test
- this.root.getFile(fileName, {create:true}, getFile, this.fail);
- });
- test("DirectoryEntry.getFile: get FileEntry for invalid path", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(2);
-
- var fileName = "de:invalid:path",
- that = this,
- testFile = function(error) {
- ok(typeof error !== 'undefined' && error !== null, "retrieving a file using an invalid path is an error");
- equal(error.code, FileError.ENCODING_ERR, "error code should be FileError.ENCODING_ERR");
-
- // cleanup
- QUnit.start();
- };
-
- // create:false, exclusive:false, invalid path
- this.root.getFile(fileName, {create:false}, null, testFile);
- });
- test("DirectoryEntry.getDirectory: get Entry for directory that does not exist", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(2);
-
- var dirName = "de.no.dir",
- dirPath = this.root.fullPath + '/' + dirName,
- that = this,
- testDir = function(error) {
- ok(typeof error !== 'undefined' && error !== null, "retrieving a directory that does not exist is an error");
- equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR");
-
- // cleanup
- QUnit.start();
- };
-
- // create:false, exclusive:false, directory does not exist
- this.root.getDirectory(dirName, {create:false}, null, testDir);
- });
- test("DirectoryEntry.getDirectory: create new dir with space then resolveFileSystemURL", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(5);
-
- var dirName = "de create dir",
- dirPath = this.root.fullPath + '/' + dirName,
- that = this,
- getDir = function(dirEntry) {
+ console.log('[ERROR DirectoryEntry] Success function called when not expected');
+ };
+ });
+ it("DirectoryEntry.getFile: get Entry for file that does not exist", function() {
+ var fileName = "de.no.file",
+ filePath = this.root.fullPath + '/' + fileName,
+ that = this,
+ itFile = function(error) {
+ expect(typeof error !== 'undefined' && error !== null, "retrieving a file that does not exist is an error");
+ expect(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR");
+ };
+
+ // create:false, exclusive:false, file does not exist
+ runs(function() {
+ this.root.getFile(fileName, {create:false}, null, itFile);
+ });
+ });
+ it("DirectoryEntry.getFile: create new file", function() {
+ QUnit.stop(its.it_TIMEOUT);
+ expect(5);
- var dirURL = dirEntry.toURL();
- // now encode URL and try to resolve
- window.resolveLocalFileSystemURI(dirURL, testDirFromURL, that.fail);
+ var fileName = "de.create.file",
+ filePath = this.root.fullPath + '/' + fileName,
+ that = this,
+ 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");
+
+ // cleanup
+ entry.remove(null, that.fail);
+ QUnit.start();
+ };
+
+ // create:true, exclusive:false, file does not exist
+ this.root.getFile(fileName, {create: true}, itFile, this.fail);
+ });
+ it("DirectoryEntry.getFile: create new file (exclusive)", function() {
+ QUnit.stop(its.it_TIMEOUT);
+ expect(5);
- },
- testDirFromURL = function(directory) {
- ok(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null");
- equal(directory.isFile, false, "directory 'isFile' attribute should be false");
- equal(directory.isDirectory, true, "directory 'isDirectory' attribute should be true");
- equal(directory.name, dirName, "directory 'name' attribute should be set");
- equal(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set");
+ var fileName = "de.create.exclusive.file",
+ filePath = this.root.fullPath + '/' + fileName,
+ that = this,
+ 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");
+
+ // cleanup
+ entry.remove(null, that.fail);
+ QUnit.start();
+ };
+
+ // create:true, exclusive:true, file does not exist
+ this.root.getFile(fileName, {create: true, exclusive:true}, itFile, this.fail);
+ });
+ it("DirectoryEntry.getFile: create file that already exists", function() {
+ QUnit.stop(its.it_TIMEOUT);
+ expect(5);
- // cleanup
- directory.remove(null, that.fail);
- QUnit.start();
- };
-
- // create:true, exclusive:false, directory does not exist
- this.root.getDirectory(dirName, {create: true}, getDir, this.fail);
- });
- test("DirectoryEntry.getDirectory: create new dir with space resolveFileSystemURL with encoded URL", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(5);
-
- var dirName = "de create dir",
- dirPath = this.root.fullPath + '/' + dirName,
- that = this,
- getDir = function(dirEntry) {
+ var fileName = "de.create.existing.file",
+ filePath = this.root.fullPath + '/' + fileName,
+ that = this,
+ getFile = function(file) {
+ // create:true, exclusive:false, file exists
+ that.root.getFile(fileName, {create:true}, itFile, that.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");
+
+ // cleanup
+ entry.remove(null, that.fail);
+ QUnit.start();
+ };
+
+ // create file to kick off it
+ this.root.getFile(fileName, {create:true}, getFile, this.fail);
+ });
+ it("DirectoryEntry.getFile: create file that already exists (exclusive)", function() {
+ QUnit.stop(its.it_TIMEOUT);
+ expect(2);
- var dirURL = dirEntry.toURL();
- // now encode URL and try to resolve
- window.resolveLocalFileSystemURI(encodeURI(dirURL), testDirFromURL, that.fail);
+ var fileName = "de.create.exclusive.existing.file",
+ filePath = this.root.fullPath + '/' + fileName,
+ that = this,
+ existingFile,
+ getFile = 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");
+
+ // cleanup
+ existingFile.remove(null, that.fail);
+ QUnit.start();
+ };
+
+ // create file to kick off it
+ this.root.getFile(fileName, {create:true}, getFile, this.fail);
+ });
+ 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) {
+ // create:false, exclusive:false, file exists
+ that.root.getFile(fileName, {create:false}, itFile, that.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");
- },
- testDirFromURL = function(directory) {
- ok(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null");
- equal(directory.isFile, false, "directory 'isFile' attribute should be false");
- equal(directory.isDirectory, true, "directory 'isDirectory' attribute should be true");
- equal(directory.name, dirName, "directory 'name' attribute should be set");
- equal(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set");
-
// cleanup
- directory.remove(null, that.fail);
- QUnit.start();
- };
-
- // create:true, exclusive:false, directory does not exist
- this.root.getDirectory(dirName, {create: true}, getDir, this.fail);
- });
-
- test("DirectoryEntry.getDirectory: create new directory", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(5);
-
- var dirName = "de.create.dir",
+ entry.remove(null, that.fail);
+ QUnit.start();
+ };
+
+ // create file to kick off it
+ this.root.getFile(fileName, {create:true}, getFile, this.fail);
+ });
+ 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();
+ };
+
+ // create:false, exclusive:false, invalid path
+ this.root.getFile(fileName, {create:false}, null, itFile);
+ });
+ 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();
+ };
+
+ // create:false, exclusive:false, directory does not exist
+ this.root.getDirectory(dirName, {create:false}, null, itDir);
+ });
+ 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,
- testDir = function(directory) {
- ok(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null");
- equal(directory.isFile, false, "directory 'isFile' attribute should be false");
- equal(directory.isDirectory, true, "directory 'isDirectory' attribute should be true");
- equal(directory.name, dirName, "directory 'name' attribute should be set");
- equal(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set");
+ getDir = function(dirEntry) {
- // cleanup
- directory.remove(null, that.fail);
- QUnit.start();
- };
-
- // create:true, exclusive:false, directory does not exist
- this.root.getDirectory(dirName, {create: true}, testDir, this.fail);
- });
-
- test("DirectoryEntry.getDirectory: create new directory (exclusive)", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(5);
-
- var dirName = "de.create.exclusive.dir",
- dirPath = this.root.fullPath + '/' + dirName,
- that = this,
- testDir = function(directory) {
- ok(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null");
- equal(directory.isFile, false, "directory 'isFile' attribute should be false");
- equal(directory.isDirectory, true, "directory 'isDirectory' attribute should be true");
- equal(directory.name, dirName, "directory 'name' attribute should be set");
- equal(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set");
-
- // cleanup
- directory.remove(null, that.fail);
- QUnit.start();
- };
+ var dirURL = dirEntry.toURL();
+ // now encode URL and try to resolve
+ window.resolveLocalFileSystemURI(dirURL, itDirFromURL, that.fail);
- // create:true, exclusive:true, directory does not exist
- this.root.getDirectory(dirName, {create: true, exclusive:true}, testDir, this.fail);
- });
- test("DirectoryEntry.getDirectory: create directory that already exists", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(5);
-
- var dirName = "de.create.existing.dir",
- dirPath = this.root.fullPath + '/' + dirName,
- that = this,
- getDir = function(directory) {
- // create:true, exclusive:false, directory exists
- that.root.getDirectory(dirName, {create:true}, testDir, that.fail);
},
- testDir = function(directory) {
- ok(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null");
- equal(directory.isFile, false, "directory 'isFile' attribute should be false");
- equal(directory.isDirectory, true, "directory 'isDirectory' attribute should be true");
- equal(directory.name, dirName, "directory 'name' attribute should be set");
- equal(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set");
+ 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();
};
-
- // create directory to kick off test
- this.root.getDirectory(dirName, {create:true}, getDir, this.fail);
- });
- test("DirectoryEntry.getDirectory: create directory that already exists (exclusive)", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(2);
-
- var dirName = "de.create.exclusive.existing.dir",
+
+ // create:true, exclusive:false, directory does not exist
+ this.root.getDirectory(dirName, {create: true}, getDir, this.fail);
+ });
+ 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,
- existingDir,
- getDir = function(directory) {
- existingDir = directory;
- // create:true, exclusive:true, directory exists
- that.root.getDirectory(dirName, {create:true, exclusive:true}, null, testDir);
- },
- testDir = function(error) {
- ok(typeof error !== 'undefined' && error !== null, "creating exclusive directory that already exists is an error");
- equal(error.code, FileError.PATH_EXISTS_ERR, "error code should be FileError.PATH_EXISTS_ERR");
+ getDir = function(dirEntry) {
- // cleanup
- existingDir.remove(null, that.fail);
- QUnit.start();
- };
+ var dirURL = dirEntry.toURL();
+ // now encode URL and try to resolve
+ window.resolveLocalFileSystemURI(encodeURI(dirURL), itDirFromURL, that.fail);
- // create directory to kick off test
- this.root.getDirectory(dirName, {create:true}, getDir, this.fail);
- });
- test("DirectoryEntry.getDirectory: get Entry for existing directory", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(5);
-
- var dirName = "de.get.dir",
- dirPath = this.root.fullPath + '/' + dirName,
- that = this,
- getDir = function(directory) {
- // create:false, exclusive:false, directory exists
- that.root.getDirectory(dirName, {create:false}, testDir, that.fail);
},
- testDir = function(directory) {
- ok(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null");
- equal(directory.isFile, false, "directory 'isFile' attribute should be false");
- equal(directory.isDirectory, true, "directory 'isDirectory' attribute should be true");
- equal(directory.name, dirName, "directory 'name' attribute should be set");
- equal(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set");
-
+ 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();
};
-
- // create directory to kick off test
- this.root.getDirectory(dirName, {create:true}, getDir, this.fail);
- });
- test("DirectoryEntry.getDirectory: get DirectoryEntry for invalid path", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(2);
-
- var dirName = "de:invalid:path",
- that = this,
- testDir = function(error) {
- ok(typeof error !== 'undefined' && error !== null, "retrieving a directory using an invalid path is an error");
- equal(error.code, FileError.ENCODING_ERR, "error code should be FileError.ENCODING_ERR");
-
- // cleanup
- QUnit.start();
- };
-
- // create:false, exclusive:false, invalid path
- this.root.getDirectory(dirName, {create:false}, null, testDir);
- });
- test("DirectoryEntry.getDirectory: get DirectoryEntry for existing file", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(2);
-
- var fileName = "de.existing.file",
- existingFile,
- filePath = this.root.fullPath + '/' + fileName,
- that = this,
- getDir = function(file) {
- existingFile = file;
- // create:false, exclusive:false, existing file
- that.root.getDirectory(fileName, {create:false}, null, testDir);
- },
- testDir = function(error) {
- ok(typeof error !== 'undefined' && error !== null, "retrieving directory for existing file is an error");
- equal(error.code, FileError.TYPE_MISMATCH_ERR, "error code should be FileError.TYPE_MISMATCH_ERR");
-
- // cleanup
- existingFile.remove(null, that.fail);
- QUnit.start();
- };
-
- // create file to kick off test
- this.root.getFile(fileName, {create:true}, getDir, this.fail);
- });
- test("DirectoryEntry.getFile: get FileEntry for existing directory", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(2);
-
- var dirName = "de.existing.dir",
- existingDir,
- dirPath = this.root.fullPath + '/' + dirName,
- that = this,
- getFile = function(directory) {
- existingDir = directory;
- // create:false, exclusive:false, existing directory
- that.root.getFile(dirName, {create:false}, null, testFile);
- },
- testFile = function(error) {
- ok(typeof error !== 'undefined' && error !== null, "retrieving file for existing directory is an error");
- equal(error.code, FileError.TYPE_MISMATCH_ERR, "error code should be FileError.TYPE_MISMATCH_ERR");
-
- // cleanup
- existingDir.remove(null, that.fail);
- QUnit.start();
- };
-
- // create directory to kick off test
- this.root.getDirectory(dirName, {create:true}, getFile, this.fail);
- });
- test("DirectoryEntry.removeRecursively on directory", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
- expect(2);
+
+ // create:true, exclusive:false, directory does not exist
+ this.root.getDirectory(dirName, {create: true}, getDir, this.fail);
+ });
+
+ 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");
+
+ // cleanup
+ directory.remove(null, that.fail);
+ QUnit.start();
+ };
+
+ // create:true, exclusive:false, directory does not exist
+ this.root.getDirectory(dirName, {create: true}, itDir, this.fail);
+ });
- var dirName = "de.removeRecursively",
- subDirName = "dir",
- dirPath = this.root.fullPath + '/' + dirName,
- //subDirPath = this.root.fullPath + '/' + subDirName,
- subDirPath = dirPath + '/' + subDirName,
- that = this,
- entryCallback = function(entry) {
- // delete directory
- var deleteDirectory = function(directory) {
- entry.removeRecursively(testRemove, that.fail);
- };
- // create a sub-directory within directory
- entry.getDirectory(subDirName, {create: true}, deleteDirectory, that.fail);
+ 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");
+
+ // cleanup
+ directory.remove(null, that.fail);
+ QUnit.start();
+ };
+
+ // create:true, exclusive:true, directory does not exist
+ this.root.getDirectory(dirName, {create: true, exclusive:true}, itDir, this.fail);
+ });
+ 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) {
+ // 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");
+
+ // cleanup
+ directory.remove(null, that.fail);
+ QUnit.start();
+ };
+
+ // create directory to kick off it
+ this.root.getDirectory(dirName, {create:true}, getDir, this.fail);
+ });
+ 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,
+ existingDir,
+ getDir = function(directory) {
+ existingDir = directory;
+ // create:true, exclusive:true, directory exists
+ that.root.getDirectory(dirName, {create:true, exclusive:true}, null, itDir);
},
- testRemove = function() {
- // test that removed directory no longer exists
- that.root.getDirectory(dirName, {create:false}, null, testDirExists);
+ 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");
+
+ // cleanup
+ existingDir.remove(null, that.fail);
+ QUnit.start();
+ };
+
+ // create directory to kick off it
+ this.root.getDirectory(dirName, {create:true}, getDir, this.fail);
+ });
+ 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) {
+ // 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");
+
+ // cleanup
+ directory.remove(null, that.fail);
+ QUnit.start();
+ };
+
+ // create directory to kick off it
+ this.root.getDirectory(dirName, {create:true}, getDir, this.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();
+ };
+
+ // create:false, exclusive:false, invalid path
+ this.root.getDirectory(dirName, {create:false}, null, itDir);
+ });
+ 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) {
+ 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");
+
+ // cleanup
+ existingFile.remove(null, that.fail);
+ QUnit.start();
+ };
+
+ // create file to kick off it
+ this.root.getFile(fileName, {create:true}, getDir, this.fail);
+ });
+ 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) {
+ existingDir = directory;
+ // create:false, exclusive:false, existing directory
+ that.root.getFile(dirName, {create:false}, null, itFile);
},
- testDirExists = function(error){
- ok(typeof error !== 'undefined' && error !== null, "removed directory should not exist");
- equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR");
+ 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();
};
+
+ // create directory to kick off it
+ this.root.getDirectory(dirName, {create:true}, getFile, this.fail);
+ });
+ it("DirectoryEntry.removeRecursively on directory", function() {
+ QUnit.stop(its.it_TIMEOUT);
+ expect(2);
+
+ var dirName = "de.removeRecursively",
+ subDirName = "dir",
+ dirPath = this.root.fullPath + '/' + dirName,
+ //subDirPath = this.root.fullPath + '/' + subDirName,
+ subDirPath = dirPath + '/' + subDirName,
+ that = this,
+ entryCallback = function(entry) {
+ // delete directory
+ var deleteDirectory = function(directory) {
+ entry.removeRecursively(itRemove, that.fail);
+ };
+ // 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();
+ };
- // create a new directory entry to kick off test
- this.root.getDirectory(dirName, {create:true}, entryCallback, this.fail);
- });
- test("DirectoryEntry.createReader: create reader on existing directory", function() {
- expect(2);
-
- // create reader for root directory
- var reader = this.root.createReader();
- ok(typeof reader !== 'undefined' && reader !== null, "reader object should not be null");
- ok(typeof reader.readEntries === 'function', "reader object should have a 'readEntries' method");
+ // create a new directory entry to kick off it
+ this.root.getDirectory(dirName, {create:true}, entryCallback, this.fail);
+ });
+ 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");
+ });
});
module('DirectoryReader interface', {
- // setup function will run before each test
+ // setup function will run before each it
setup: function() {
this.root = getFileSystemRoot();
this.fail = function(error) {
@@ -767,27 +821,27 @@ Tests.prototype.FileTests = function() {
};
}
});
- test("DirectoryReader.readEntries: read contents of existing directory", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
+ it("DirectoryReader.readEntries: read contents of existing directory", function() {
+ QUnit.stop(its.it_TIMEOUT);
expect(4);
var reader,
- testEntries = function(entries) {
- ok(typeof entries !== 'undefined' && entries !== null, "directory entries should not be null");
- ok(entries.constructor === Array, "readEntries should return an array of entries");
+ 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();
};
// create reader for root directory
reader = this.root.createReader();
- ok(typeof reader !== 'undefined' && reader !== null, "reader object should not be null");
- ok(typeof reader.readEntries === 'function', "reader object should have a 'readEntries' method");
+ 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(testEntries, this.fail);
+ reader.readEntries(itEntries, this.fail);
});
- test("DirectoryReader.readEntries: read contents of directory that has been removed", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
+ it("DirectoryReader.readEntries: read contents of directory that has been removed", function() {
+ QUnit.stop(its.it_TIMEOUT);
expect(4);
var dirName = "de.createReader.notfound",
@@ -797,54 +851,54 @@ Tests.prototype.FileTests = function() {
// read entries
var readEntries = function() {
var reader = directory.createReader();
- reader.readEntries(null, testReader);
+ reader.readEntries(null, itReader);
};
// delete directory
directory.removeRecursively(readEntries, that.fail);
},
- testReader = function(error) {
- var testDirectoryExists = function(error) {
- ok(typeof error !== 'undefined' && error !== null, "reading entries on a directory that does not exist is an error")
- equal(error.code, FileError.NOT_FOUND_ERR, "removed directory should not exist");
- QUnit.start();
- };
- ok(typeof error !== 'undefined' && error !== null, "reading entries on a directory that does not exist is an error")
- equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR");
- that.root.getDirectory(dirName, {create:false}, null, testDirectoryExists);
+ 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 test
+ // create a new directory entry to kick off it
this.root.getDirectory(dirName, {create:true}, entryCallback, this.fail);
});
- test("DirectoryEntry.removeRecursively on root file system", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
+ it("DirectoryEntry.removeRecursively on root file system", function() {
+ QUnit.stop(its.it_TIMEOUT);
expect(2);
- var testRemove = function(error) {
- ok(typeof error !== 'undefined' && error !== null, "removing root file system should generate an error");
- equal(error.code, FileError.NO_MODIFICATION_ALLOWED_ERR, "error code should be FileError.NO_MODIFICATION_ALLOWED_ERR");
+ 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, testRemove);
+ this.root.removeRecursively(null, itRemove);
});
module('File interface');
- test("File constructor should be defined", function() {
+ it("File constructor should be defined", function() {
expect(1);
- ok(typeof File === 'function', "File constructor should be a function.");
+ expect(typeof File === 'function', "File constructor should be a function.");
});
- test("File attributes should be defined", function() {
+ it("File attributes should be defined", function() {
expect(5);
var file = new File();
- ok(typeof file.name !== 'undefined', "File object should have a 'name' attribute");
- ok(typeof file.fullPath !== 'undefined', "File object should have a 'fullPath' attribute");
- ok(typeof file.type !== 'undefined', "File object should have a 'type' attribute");
- ok(typeof file.lastModifiedDate !== 'undefined', "File object should have a 'lastModifiedDate' attribute");
- ok(typeof file.size !== 'undefined', "File object should have a 'size' attribute");
+ 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 test
+ // setup function will run before each it
setup: function() {
this.root = getFileSystemRoot();
this.fail = function(error) {
@@ -852,50 +906,50 @@ Tests.prototype.FileTests = function() {
};
}
});
- test("FileEntry methods should be defined", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
+ it("FileEntry methods should be defined", function() {
+ QUnit.stop(its.it_TIMEOUT);
expect(3);
var fileName = "fe.methods",
that = this,
- testFileEntry = function(fileEntry) {
- ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "FileEntry should not be null");
- ok(typeof fileEntry.createWriter === 'function', "FileEntry should have a 'createWriter' method");
- ok(typeof fileEntry.file === 'function', "FileEntry should have a 'file' method");
+ 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 test
- this.root.getFile(fileName, {create:true}, testFileEntry, this.fail);
+ // create a new file entry to kick off it
+ this.root.getFile(fileName, {create:true}, itFileEntry, this.fail);
});
- test("FileEntry.createWriter should return a FileWriter object", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
+ it("FileEntry.createWriter should return a FileWriter object", function() {
+ QUnit.stop(its.it_TIMEOUT);
expect(2);
var fileName = "fe.createWriter",
that = this,
- testFile,
+ itFile,
entryCallback = function(fileEntry) {
- testFile = fileEntry;
- fileEntry.createWriter(testWriter, that.fail);
+ itFile = fileEntry;
+ fileEntry.createWriter(itWriter, that.fail);
},
- testWriter = function(writer) {
- ok(typeof writer !== 'undefined' && writer !== null, "FileWriter object should not be null");
- ok(writer.constructor === FileWriter, "writer should be a FileWriter object");
+ 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
- testFile.remove(null, that.fail);
+ itFile.remove(null, that.fail);
QUnit.start();
};
- // create a new file entry to kick off test
+ // create a new file entry to kick off it
this.root.getFile(fileName, {create:true}, entryCallback, this.fail);
});
- test("FileEntry.file should return a File object", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
+ it("FileEntry.file should return a File object", function() {
+ QUnit.stop(its.it_TIMEOUT);
expect(2);
var fileName = "fe.file",
@@ -903,22 +957,22 @@ Tests.prototype.FileTests = function() {
newFile,
entryCallback = function(fileEntry) {
newFile = fileEntry;
- fileEntry.file(testFile, that.fail);
+ fileEntry.file(itFile, that.fail);
},
- testFile = function(file) {
- ok(typeof file !== 'undefined' && file !== null, "File object should not be null");
- ok(file.constructor === File, "File object should be a File");
+ 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 test
+ // create a new file entry to kick off it
this.root.getFile(fileName, {create:true}, entryCallback, this.fail);
});
- test("FileEntry.file: on File that has been removed", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
+ it("FileEntry.file: on File that has been removed", function() {
+ QUnit.stop(its.it_TIMEOUT);
expect(2);
var fileName = "fe.no.file",
@@ -926,22 +980,22 @@ Tests.prototype.FileTests = function() {
entryCallback = function(fileEntry) {
// create File object
var getFile = function() {
- fileEntry.file(null, testFile);
+ fileEntry.file(null, itFile);
};
// delete file
fileEntry.remove(getFile, that.fail);
},
- testFile = function(error) {
- ok(typeof error !== 'undefined' && error !== null, "invoking FileEntry.file on a file that does not exist is an error");
- equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR");
+ 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 test
+ // 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 test
+ // setup function will run before each it
setup: function() {
var that = this;
this.root = getFileSystemRoot();
@@ -983,27 +1037,27 @@ Tests.prototype.FileTests = function() {
};
}
});
- test("Entry object", function() {
- QUnit.stop(Tests.TEST_TIMEOUT);
+ it("Entry object", function() {
+ QUnit.stop(its.it_TIMEOUT);
expect(13);
var fileName = "entry",
that = this,
fullPath = this.root.fullPath + '/' + fileName,
- testEntry = function(entry) {
- ok(typeof entry !== 'undefined' && entry !== null, "entry should not be null.");
- equal(entry.isFile, true, "entry.isFile should be true");
- equal(entry.isDirectory, false, "entry.isDirectory should be false");
- equal(entry.name, fileName, "entry object 'name' property should be set");
- equal(entry.fullPath, fullPath, "entry object 'fullPath' property should be set");
- ok(typeof entry.getMetadata === 'function', "entry object should have a 'getMetadata' function.");
- ok(typeof entry.moveTo === 'function', "entry object should have a 'moveTo' function.");
- ok(typeof entry.copyTo === 'function', "entry object should have a 'copyTo' function.");
- ok(typeof entry.toURL === 'function', "entry object should have a 'toURL' function.");
- ok(typeof entry.remove === 'function', "entry object should have a 'remove' function.");
- ok(typeof entry.getParent === 'function', "entry object should have a 'getParent' function.");
- ok(typeof entry.createWriter === 'function', "entry object should have a 'createWriter' function.");
- ok(typeof entry.file === 'function', "entry object should have a 'file' function.");
+ itEntry = function(entry) {
+ expect(typeof entry !== 'undefined' && entry !== null, "entry should not be null.");
+ expect(entry.isFile, true, "entry.isFile should be true");
+
<TRUNCATED>