2013-07-13 16:41:10 +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-13 16:41:10 +00:00
|
|
|
var test_database_names = [];
|
|
|
|
window.onbeforeunload = function() {
|
|
|
|
test_database_names.forEach(function(name) {
|
|
|
|
indexedDB.deleteDatabase(name);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function mk_id(length) {
|
|
|
|
var text = '';
|
|
|
|
var tokens = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
|
|
|
|
for( var i=0; i < length; i++ )
|
|
|
|
text += tokens.charAt(Math.floor(Math.random() * tokens.length));
|
|
|
|
|
|
|
|
return text;
|
|
|
|
};
|
|
|
|
|
2013-07-12 15:11:05 +00:00
|
|
|
function mk_db_name() {
|
2013-07-13 16:41:10 +00:00
|
|
|
var name = TEST_DATABASE_NAME + mk_id(5);
|
|
|
|
test_database_names.push(name);
|
|
|
|
return name;
|
2013-07-12 15:11:05 +00:00
|
|
|
};
|
|
|
|
|
2013-07-22 17:08:35 +00:00
|
|
|
function array_buffer_equal(left, right) {
|
2013-07-22 18:31:44 +00:00
|
|
|
if(left.length !== right.length) {
|
2013-07-22 17:08:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-22 18:31:44 +00:00
|
|
|
for(var i = 0; i < left.length; ++ i) {
|
2013-07-22 17:08:35 +00:00
|
|
|
if(left[i] !== right[i]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2013-07-12 15:11:05 +00:00
|
|
|
describe("IDBFS", function() {
|
|
|
|
it("is defined", function() {
|
|
|
|
expect(typeof IDBFS).not.toEqual(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("has FileSystem constructor", function() {
|
|
|
|
expect(typeof IDBFS.FileSystem).toEqual('function');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-07-13 16:41:10 +00:00
|
|
|
describe("fs", function() {
|
2013-07-12 15:11:05 +00:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have a root directory', function() {
|
|
|
|
var complete = false;
|
2013-07-13 16:41:10 +00:00
|
|
|
var _result;
|
2013-07-12 15:11:05 +00:00
|
|
|
|
|
|
|
this.fs.stat('/', function(error, result) {
|
|
|
|
_result = result;
|
|
|
|
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
2013-07-19 15:22:23 +00:00
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
2013-07-12 15:11:05 +00:00
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_result).toBeDefined();
|
2013-05-31 07:52:04 +00:00
|
|
|
});
|
2013-07-12 15:11:05 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-07-15 15:52:41 +00:00
|
|
|
describe('fs.stat', function() {
|
2013-07-12 15:11:05 +00:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
2013-07-13 16:41:10 +00:00
|
|
|
it('should be a function', function() {
|
|
|
|
expect(typeof this.fs.stat).toEqual('function');
|
|
|
|
});
|
2013-07-12 15:11:05 +00:00
|
|
|
|
2013-07-13 16:41:10 +00:00
|
|
|
it('should return an error if path does not exist', function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error, _result;
|
2013-05-31 07:52:04 +00:00
|
|
|
|
2013-07-13 16:41:10 +00:00
|
|
|
this.fs.stat('/tmp', function(error, result) {
|
|
|
|
_error = error;
|
|
|
|
_result = result;
|
2013-07-12 15:11:05 +00:00
|
|
|
|
2013-07-13 16:41:10 +00:00
|
|
|
complete = true;
|
|
|
|
});
|
2013-07-12 15:11:05 +00:00
|
|
|
|
2013-07-13 16:41:10 +00:00
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
2013-07-19 15:22:23 +00:00
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
2013-07-13 16:41:10 +00:00
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).toBeDefined();
|
|
|
|
expect(_result).not.toBeDefined();
|
2013-05-31 07:52:04 +00:00
|
|
|
});
|
2013-07-13 16:41:10 +00:00
|
|
|
});
|
2013-05-31 07:52:04 +00:00
|
|
|
|
2013-07-13 16:41:10 +00:00
|
|
|
it('should return a stat object if path exists', function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error, _result;
|
|
|
|
var that = this;
|
2013-07-12 15:11:05 +00:00
|
|
|
|
2013-07-13 16:41:10 +00:00
|
|
|
that.fs.stat('/', function(error, result) {
|
|
|
|
_error = error;
|
|
|
|
_result = result;
|
2013-07-12 15:11:05 +00:00
|
|
|
|
2013-07-13 16:41:10 +00:00
|
|
|
complete = true;
|
|
|
|
});
|
2013-07-12 15:11:05 +00:00
|
|
|
|
2013-07-13 16:41:10 +00:00
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
2013-07-19 15:22:23 +00:00
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
2013-07-12 15:11:05 +00:00
|
|
|
|
2013-07-13 16:41:10 +00:00
|
|
|
runs(function() {
|
|
|
|
expect(_result).toBeDefined();
|
|
|
|
expect(_error).not.toBeDefined();
|
2013-07-26 02:49:53 +00:00
|
|
|
expect(_result['node']).toBeDefined();
|
2013-07-13 16:41:10 +00:00
|
|
|
expect(_result['dev']).toEqual(that.db_name);
|
2013-07-22 18:31:44 +00:00
|
|
|
expect(_result['size']).toBeDefined();
|
2013-07-13 16:41:10 +00:00
|
|
|
expect(_result['nlinks']).toEqual(jasmine.any(Number));
|
|
|
|
expect(_result['atime']).toEqual(jasmine.any(Number));
|
|
|
|
expect(_result['mtime']).toEqual(jasmine.any(Number));
|
|
|
|
expect(_result['ctime']).toEqual(jasmine.any(Number));
|
2013-07-26 15:59:32 +00:00
|
|
|
expect(_result['type']).toBeDefined();
|
2013-05-31 07:52:04 +00:00
|
|
|
});
|
2013-07-12 15:11:05 +00:00
|
|
|
});
|
2013-07-13 16:41:10 +00:00
|
|
|
});
|
|
|
|
|
2013-07-15 15:52:41 +00:00
|
|
|
describe('fs.mkdir', function() {
|
2013-07-13 16:41:10 +00:00
|
|
|
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;
|
|
|
|
});
|
2013-07-12 16:07:57 +00:00
|
|
|
|
2013-07-15 15:52:41 +00:00
|
|
|
it('should be a function', function() {
|
|
|
|
expect(typeof this.fs.mkdir).toEqual('function');
|
|
|
|
});
|
|
|
|
|
2013-07-13 16:41:10 +00:00
|
|
|
it('should return an error if part of the parent path does not exist', function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error;
|
|
|
|
var that = this;
|
2013-07-12 16:07:57 +00:00
|
|
|
|
2013-07-13 16:41:10 +00:00
|
|
|
that.fs.mkdir('/tmp/mydir', function(error) {
|
|
|
|
_error = error;
|
2013-07-12 16:07:57 +00:00
|
|
|
|
2013-07-13 16:41:10 +00:00
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'stat to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-07-15 15:52:41 +00:00
|
|
|
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;
|
2013-07-19 15:22:23 +00:00
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
2013-07-15 15:52:41 +00:00
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should make a new directory', function() {
|
2013-07-13 16:41:10 +00:00
|
|
|
var complete = false;
|
|
|
|
var _error, _result, _stat;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
that.fs.mkdir('/tmp', function(error, result) {
|
|
|
|
_error = error;
|
|
|
|
_result = result;
|
2013-07-12 16:07:57 +00:00
|
|
|
|
2013-07-13 16:41:10 +00:00
|
|
|
that.fs.stat('/tmp', function(error, result) {
|
|
|
|
_stat = result;
|
|
|
|
|
|
|
|
complete = true;
|
2013-07-12 16:07:57 +00:00
|
|
|
});
|
|
|
|
});
|
2013-07-13 16:41:10 +00:00
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
2013-07-19 15:22:23 +00:00
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
2013-07-13 16:41:10 +00:00
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).not.toBeDefined();
|
|
|
|
expect(_result).not.toBeDefined();
|
|
|
|
expect(_stat).toBeDefined();
|
|
|
|
});
|
2013-07-12 16:07:57 +00:00
|
|
|
});
|
2013-07-13 16:41:10 +00:00
|
|
|
});
|
2013-07-15 15:52:41 +00:00
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2013-07-19 15:22:23 +00:00
|
|
|
it('should return an error if the path does not exist', function() {
|
2013-07-15 15:52:41 +00:00
|
|
|
var complete = false;
|
|
|
|
var _error;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
that.fs.rmdir('/tmp/mydir', function(error) {
|
|
|
|
_error = error;
|
|
|
|
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
2013-07-19 15:22:23 +00:00
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
2013-07-15 15:52:41 +00:00
|
|
|
|
|
|
|
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;
|
2013-07-19 15:22:23 +00:00
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
2013-07-15 15:52:41 +00:00
|
|
|
|
|
|
|
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;
|
2013-07-19 15:22:23 +00:00
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
2013-07-15 15:52:41 +00:00
|
|
|
|
|
|
|
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;
|
2013-07-19 15:22:23 +00:00
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
2013-07-15 15:52:41 +00:00
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).not.toBeDefined();
|
|
|
|
expect(_stat).not.toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
2013-07-19 15:22:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('fs.open', 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.open).toEqual('function');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return an error if the parent path does not exist', function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error, _result;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
that.fs.open('/tmp/myfile', 'w+', function(error, result) {
|
|
|
|
_error = error;
|
|
|
|
_result = result;
|
|
|
|
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).toBeDefined();
|
|
|
|
expect(_result).not.toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return an error when flagged for read and the path does not exist', function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error, _result;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
that.fs.open('/myfile', 'r+', function(error, result) {
|
|
|
|
_error = error;
|
|
|
|
_result = result;
|
|
|
|
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).toBeDefined();
|
|
|
|
expect(_result).not.toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should return an error when flagged for write and the path is a directory', function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error, _result;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
that.fs.mkdir('/tmp', function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
that.fs.open('/tmp', 'w', function(error, result) {
|
|
|
|
_error = error;
|
|
|
|
_result = result;
|
|
|
|
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).toBeDefined();
|
|
|
|
expect(_result).not.toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return an error when flagged for append and the path is a directory', function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error, _result;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
that.fs.mkdir('/tmp', function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
that.fs.open('/tmp', 'a', function(error, result) {
|
|
|
|
_error = error;
|
|
|
|
_result = result;
|
|
|
|
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).toBeDefined();
|
|
|
|
expect(_result).not.toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
2013-07-22 17:08:35 +00:00
|
|
|
|
2013-07-19 15:22:23 +00:00
|
|
|
it('should return a unique file descriptor', function() {
|
2013-07-22 17:08:35 +00:00
|
|
|
var complete1 = false;
|
|
|
|
var complete2 = false;
|
|
|
|
var _error, _result1, _result2;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
that.fs.open('/file1', 'w+', function(error, fd) {
|
|
|
|
if(error) throw error;
|
|
|
|
_error = error;
|
|
|
|
_result1 = fd;
|
|
|
|
|
|
|
|
complete1 = true;
|
|
|
|
});
|
|
|
|
that.fs.open('/file2', 'w+', function(error, fd) {
|
|
|
|
if(error) throw error;
|
|
|
|
_error = error;
|
|
|
|
_result2 = fd;
|
|
|
|
|
|
|
|
complete2 = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete1 && complete2;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).not.toBeDefined();
|
|
|
|
expect(_result1).toBeDefined();
|
|
|
|
expect(_result2).toBeDefined();
|
|
|
|
expect(_result1).not.toEqual(_result2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create a new file when flagged for write', function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error, _result;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
that.fs.open('/myfile', 'w', function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
that.fs.stat('/myfile', function(error, result) {
|
|
|
|
_error = error;
|
|
|
|
_result = result;
|
|
|
|
|
|
|
|
complete = true;
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).not.toBeDefined();
|
|
|
|
expect(_result).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fs.write', 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.write).toEqual('function');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should write data to a file', function() {
|
|
|
|
var complete = false;
|
2013-07-22 18:31:44 +00:00
|
|
|
var _error, _result, _stats;
|
2013-07-22 17:08:35 +00:00
|
|
|
var that = this;
|
|
|
|
|
|
|
|
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
|
|
|
|
|
|
that.fs.open('/myfile', 'w', function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
var fd = result;
|
|
|
|
that.fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
|
|
|
|
_error = error;
|
|
|
|
_result = result;
|
|
|
|
|
2013-07-22 18:31:44 +00:00
|
|
|
that.fs.stat('/myfile', function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
_stats = result;
|
|
|
|
|
|
|
|
complete = true;
|
|
|
|
});
|
2013-07-22 17:08:35 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).not.toBeDefined();
|
|
|
|
expect(_result).toEqual(buffer.length);
|
2013-07-22 18:31:44 +00:00
|
|
|
expect(_stats.size).toEqual(buffer.length);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should update the current file position', function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error, _result, _stats;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
|
|
_result = 0;
|
|
|
|
|
|
|
|
that.fs.open('/myfile', 'w', function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
var fd = result;
|
|
|
|
that.fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
_result += result;
|
|
|
|
|
|
|
|
that.fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
_result += result;
|
|
|
|
|
|
|
|
that.fs.stat('/myfile', function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
_stats = result;
|
|
|
|
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).not.toBeDefined();
|
|
|
|
expect(_result).toEqual(2 * buffer.length);
|
|
|
|
expect(_stats.size).toEqual(_result);
|
2013-07-22 17:08:35 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fs.read', 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.read).toEqual('function');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should read data from a file', function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error, _result;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
var wbuffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
|
|
var rbuffer = new Uint8Array(wbuffer.length);
|
|
|
|
|
|
|
|
that.fs.open('/myfile', 'w+', function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
var fd = result;
|
|
|
|
that.fs.write(fd, wbuffer, 0, wbuffer.length, 0, function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
that.fs.read(fd, rbuffer, 0, rbuffer.length, 0, function(error, result) {
|
|
|
|
_error = error;
|
|
|
|
_result = result;
|
|
|
|
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
2013-07-22 18:31:44 +00:00
|
|
|
runs(function() {
|
|
|
|
expect(_error).not.toBeDefined();
|
|
|
|
expect(_result).toEqual(rbuffer.length);
|
|
|
|
expect(array_buffer_equal(wbuffer, rbuffer)).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should update the current file position', function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error, _result;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
var wbuffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
|
|
var rbuffer = new Uint8Array(wbuffer.length);
|
|
|
|
_result = 0;
|
|
|
|
|
|
|
|
that.fs.open('/myfile', 'w+', function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
var fd = result;
|
|
|
|
that.fs.write(fd, wbuffer, 0, wbuffer.length, 0, function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
that.fs.read(fd, rbuffer, 0, rbuffer.length / 2, undefined, function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
_result += result;
|
|
|
|
that.fs.read(fd, rbuffer, rbuffer.length / 2, rbuffer.length, undefined, function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
_result += result;
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
2013-07-22 17:08:35 +00:00
|
|
|
runs(function() {
|
|
|
|
expect(_error).not.toBeDefined();
|
|
|
|
expect(_result).toEqual(rbuffer.length);
|
|
|
|
expect(array_buffer_equal(wbuffer.buffer, rbuffer.buffer)).toEqual(true);
|
|
|
|
});
|
2013-07-19 15:22:23 +00:00
|
|
|
});
|
2013-07-23 03:34:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('fs.close', 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.close).toEqual('function');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should release the file descriptor', function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
var buffer = new Uint8Array(0);
|
|
|
|
|
|
|
|
that.fs.open('/myfile', 'w+', function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
var fd = result;
|
|
|
|
that.fs.close(fd, function(error) {
|
|
|
|
that.fs.read(fd, buffer, 0, buffer.length, undefined, function(error, result) {
|
|
|
|
_error = error;
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fs.link', 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.link).toEqual('function');
|
|
|
|
});
|
2013-07-26 02:49:53 +00:00
|
|
|
|
|
|
|
it('should create a link to an existing file', function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error, _oldstats, _newstats;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
that.fs.open('/myfile', 'w+', function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
var fd = result;
|
|
|
|
that.fs.close(fd, function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
that.fs.link('/myfile', '/myotherfile', function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
that.fs.stat('/myfile', function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
_oldstats = result;
|
|
|
|
that.fs.stat('/myotherfile', function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
_newstats = result;
|
|
|
|
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).not.toBeDefined();
|
|
|
|
expect(_newstats.node).toEqual(_oldstats.node);
|
|
|
|
expect(_newstats.nlinks).toEqual(2);
|
|
|
|
expect(_newstats).toEqual(_oldstats);
|
|
|
|
});
|
|
|
|
});
|
2013-07-23 03:34:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('fs.unlink', 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.unlink).toEqual('function');
|
|
|
|
});
|
2013-07-26 04:15:48 +00:00
|
|
|
|
|
|
|
it('should remove a link to an existing file', function() {
|
|
|
|
var complete1 = false;
|
|
|
|
var complete2 = false;
|
|
|
|
var _error, _stats;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
that.fs.open('/myfile', 'w+', function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
var fd = result;
|
|
|
|
that.fs.close(fd, function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
that.fs.link('/myfile', '/myotherfile', function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
that.fs.unlink('/myfile', function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
that.fs.stat('/myfile', function(error, result) {
|
|
|
|
_error = error;
|
|
|
|
complete1 = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
that.fs.stat('/myotherfile', function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
_stats = result;
|
|
|
|
complete2 = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete1 && complete2;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).toBeDefined();
|
|
|
|
expect(_error).toBeDefined();
|
|
|
|
expect(_stats.nlinks).toEqual(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|