filer/tests/spec/idbfs.spec.js

130 lines
2.6 KiB
JavaScript
Raw Normal View History

2013-05-31 07:52:04 +00:00
var TEST_DATABASE_NAME = 'test';
2013-07-12 15:11:05 +00:00
var DEFAULT_TIMEOUT = 5000;
2013-05-31 07:52:04 +00:00
2013-07-12 15:11:05 +00:00
var next_id = 1;
function mk_db_name() {
return TEST_DATABASE_NAME + next_id++;
};
describe("IDBFS", function() {
it("is defined", function() {
expect(typeof IDBFS).not.toEqual(undefined);
});
it("has FileSystem constructor", function() {
expect(typeof IDBFS.FileSystem).toEqual('function');
});
});
describe("new fs", 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("is an object", function() {
expect(typeof this.fs).toEqual('object');
});
var api_methods = [
"mkdir",
"rmdir",
"readdir",
"link",
"unlink",
"open",
"close",
"read",
"write",
"setxattr",
"getxattr",
"stat",
"fstat",
];
api_methods.forEach(function(method) {
it("has method " + method, function() {
expect(typeof this.fs[method]).toEqual('function');
});
});
it('should have a root directory', function() {
var complete = false;
var _error, _result;
this.fs.stat('/', function(error, result) {
_error = error;
_result = result;
complete = true;
});
waitsFor(function() {
return complete;
}, 'stat to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_result).toBeDefined();
2013-05-31 07:52:04 +00:00
});
2013-07-12 15:11:05 +00:00
});
});
describe('stat', 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;
});
describe('on path that does not exist', function() {
it('should return an error', function() {
var complete = false;
var _error, _result;
this.fs.stat('/tmp', function(error, result) {
_error = error;
_result = result;
2013-05-31 07:52:04 +00:00
2013-07-12 15:11:05 +00:00
complete = true;
});
waitsFor(function() {
return complete;
}, 'stat to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
});
2013-05-31 07:52:04 +00:00
});
2013-07-12 15:11:05 +00:00
it('should not return a result', function() {
var complete = false;
var _error, _result;
this.fs.stat('/tmp', function(error, result) {
jasmine.log(error, result);
_error = error;
_result = result;
complete = true;
});
waitsFor(function() {
return complete;
}, 'stat to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_result).not.toBeDefined();
});
2013-05-31 07:52:04 +00:00
});
2013-07-12 15:11:05 +00:00
});
2013-05-31 07:52:04 +00:00
});