Updated tests.
This commit is contained in:
parent
cfd0932736
commit
5853704bab
|
@ -5950,6 +5950,7 @@ define('src/file-system',['require','lodash','when','src/path','src/path','src/p
|
|||
*/
|
||||
|
||||
function read_object(objectStore, id, callback) {
|
||||
try {
|
||||
var getRequest = objectStore.get(id);
|
||||
getRequest.onsuccess = function onsuccess(event) {
|
||||
var result = event.target.result;
|
||||
|
@ -5958,6 +5959,9 @@ define('src/file-system',['require','lodash','when','src/path','src/path','src/p
|
|||
getRequest.onerror = function onerror(error) {
|
||||
callback(error);
|
||||
};
|
||||
} catch(error) {
|
||||
callback(new EIO(error.message));
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -5965,6 +5969,7 @@ define('src/file-system',['require','lodash','when','src/path','src/path','src/p
|
|||
*/
|
||||
|
||||
function write_object(objectStore, object, id, callback) {
|
||||
try {
|
||||
var putRequest = objectStore.put(object, id);
|
||||
putRequest.onsuccess = function onsuccess(event) {
|
||||
var result = event.target.result;
|
||||
|
@ -5973,6 +5978,9 @@ define('src/file-system',['require','lodash','when','src/path','src/path','src/p
|
|||
putRequest.onerror = function onerror(error) {
|
||||
callback(error);
|
||||
};
|
||||
} catch(error) {
|
||||
callback(new EIO(error.message));
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -6105,6 +6113,8 @@ define('src/file-system',['require','lodash','when','src/path','src/path','src/p
|
|||
function check_if_directory_exists(error, result) {
|
||||
if(error) {
|
||||
callback(error);
|
||||
} else if(ROOT_DIRECTORY_NAME == name) {
|
||||
callback(new EBusy());
|
||||
} else if(!result) {
|
||||
callback(new ENoEntry());
|
||||
} else {
|
||||
|
@ -6386,22 +6396,21 @@ define('src/file-system',['require','lodash','when','src/path','src/path','src/p
|
|||
};
|
||||
openRequest.onsuccess = function onsuccess(event) {
|
||||
var db = event.target.result;
|
||||
var transaction = db.transaction([FILE_STORE_NAME], IDB_RW);
|
||||
var files = transaction.objectStore(FILE_STORE_NAME);
|
||||
|
||||
function complete(error) {
|
||||
that.db = db;
|
||||
if(error) {
|
||||
that.readyState = FS_ERROR;
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
that.readyState = FS_READY;
|
||||
that.db = db;
|
||||
deferred.resolve();
|
||||
}
|
||||
};
|
||||
|
||||
if(format) {
|
||||
var transaction = db.transaction([FILE_STORE_NAME], IDB_RW);
|
||||
var files = transaction.objectStore(FILE_STORE_NAME);
|
||||
|
||||
var clearRequest = files.clear();
|
||||
clearRequest.onsuccess = function onsuccess(event) {
|
||||
make_root_directory(files, complete);
|
||||
|
@ -6513,8 +6522,11 @@ define('src/file-system',['require','lodash','when','src/path','src/path','src/p
|
|||
);
|
||||
};
|
||||
FileSystem.prototype.rmdir = function rmdir(path, callback) {
|
||||
var that = this;
|
||||
this.promise.then(
|
||||
function() {
|
||||
var deferred = when.defer();
|
||||
var transaction = this.db.transaction([FILE_STORE_NAME], IDB_RW);
|
||||
var transaction = that.db.transaction([FILE_STORE_NAME], IDB_RW);
|
||||
var files = transaction.objectStore(FILE_STORE_NAME);
|
||||
|
||||
function check_result(error) {
|
||||
|
@ -6527,7 +6539,19 @@ define('src/file-system',['require','lodash','when','src/path','src/path','src/p
|
|||
};
|
||||
|
||||
remove_directory(files, path, check_result);
|
||||
deferred.then(callback);
|
||||
deferred.promise.then(
|
||||
function() {
|
||||
callback();
|
||||
},
|
||||
function(error) {
|
||||
callback(error);
|
||||
}
|
||||
);
|
||||
},
|
||||
function() {
|
||||
callback(new EFileSystemError('unknown error'));
|
||||
}
|
||||
);
|
||||
};
|
||||
FileSystem.prototype.readdir = function readdir(path, callback) {
|
||||
|
||||
|
|
|
@ -21,19 +21,11 @@ var flags = 'FORMAT';
|
|||
//var flags;
|
||||
|
||||
var fs = new IDBFS.FileSystem('local', flags);
|
||||
fs.stat('/', function(error, result) {
|
||||
console.log('stat /', error, result);
|
||||
// indexedDB.deleteDatabase('local');
|
||||
});
|
||||
|
||||
/*
|
||||
fs.mkdir('/tmp', function(error) {
|
||||
if(error) throw error;
|
||||
fs.stat('/tmp', function(error, result) {
|
||||
console.log('stat /tmp', error, result);
|
||||
});
|
||||
/*fs.rmdir('/tmp', function(error) {
|
||||
console.log('!');
|
||||
});*/
|
||||
});
|
||||
*/
|
||||
|
||||
/*
|
||||
function make_tmp_directory() {
|
||||
|
|
|
@ -313,6 +313,8 @@ define(function(require) {
|
|||
function check_if_directory_exists(error, result) {
|
||||
if(error) {
|
||||
callback(error);
|
||||
} else if(ROOT_DIRECTORY_NAME == name) {
|
||||
callback(new EBusy());
|
||||
} else if(!result) {
|
||||
callback(new ENoEntry());
|
||||
} else {
|
||||
|
@ -720,8 +722,11 @@ define(function(require) {
|
|||
);
|
||||
};
|
||||
FileSystem.prototype.rmdir = function rmdir(path, callback) {
|
||||
var that = this;
|
||||
this.promise.then(
|
||||
function() {
|
||||
var deferred = when.defer();
|
||||
var transaction = this.db.transaction([FILE_STORE_NAME], IDB_RW);
|
||||
var transaction = that.db.transaction([FILE_STORE_NAME], IDB_RW);
|
||||
var files = transaction.objectStore(FILE_STORE_NAME);
|
||||
|
||||
function check_result(error) {
|
||||
|
@ -734,7 +739,19 @@ define(function(require) {
|
|||
};
|
||||
|
||||
remove_directory(files, path, check_result);
|
||||
deferred.then(callback);
|
||||
deferred.promise.then(
|
||||
function() {
|
||||
callback();
|
||||
},
|
||||
function(error) {
|
||||
callback(error);
|
||||
}
|
||||
);
|
||||
},
|
||||
function() {
|
||||
callback(new EFileSystemError('unknown error'));
|
||||
}
|
||||
);
|
||||
};
|
||||
FileSystem.prototype.readdir = function readdir(path, callback) {
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ describe("fs", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('stat', function() {
|
||||
describe('fs.stat', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new IDBFS.FileSystem(this.db_name, 'FORMAT');
|
||||
|
@ -133,7 +133,7 @@ describe('stat', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('mkdir', function() {
|
||||
describe('fs.mkdir', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new IDBFS.FileSystem(this.db_name, 'FORMAT');
|
||||
|
@ -144,6 +144,10 @@ describe('mkdir', function() {
|
|||
delete this.fs;
|
||||
});
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.mkdir).toEqual('function');
|
||||
});
|
||||
|
||||
it('should return an error if part of the parent path does not exist', function() {
|
||||
var complete = false;
|
||||
var _error;
|
||||
|
@ -164,7 +168,27 @@ describe('mkdir', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should return with no result if successful', function() {
|
||||
it('should return an error if the path already exists', function() {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
that.fs.mkdir('/', function(error) {
|
||||
_error = error;
|
||||
|
||||
complete = true;
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'stat to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('should make a new directory', function() {
|
||||
var complete = false;
|
||||
var _error, _result, _stat;
|
||||
var that = this;
|
||||
|
@ -191,3 +215,109 @@ describe('mkdir', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('fs.rmdir', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new IDBFS.FileSystem(this.db_name, 'FORMAT');
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.rmdir).toEqual('function');
|
||||
});
|
||||
|
||||
it('should return an error if part of the path does not exist', function() {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
that.fs.rmdir('/tmp/mydir', function(error) {
|
||||
_error = error;
|
||||
|
||||
complete = true;
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'rmdir to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error if attempting to remove the root directory', function() {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
that.fs.rmdir('/', function(error) {
|
||||
_error = error;
|
||||
|
||||
complete = true;
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'rmdir to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error if the directory is not empty', function() {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
that.fs.mkdir('/tmp', function(error) {
|
||||
that.fs.mkdir('/tmp/mydir', function(error) {
|
||||
that.fs.rmdir('/', function(error) {
|
||||
_error = error;
|
||||
|
||||
complete = true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'rmdir to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('should remove an existing directory', function() {
|
||||
var complete = false;
|
||||
var _error, _stat;
|
||||
var that = this;
|
||||
|
||||
that.fs.mkdir('/tmp', function(error) {
|
||||
that.fs.rmdir('/tmp', function(error) {
|
||||
_error = error;
|
||||
that.fs.stat('/tmp', function(error, result) {
|
||||
_stat = result;
|
||||
|
||||
complete = true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'rmdir to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).not.toBeDefined();
|
||||
expect(_stat).not.toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue