2014-01-14 15:56:36 +00:00
|
|
|
define(["Filer"], function(Filer) {
|
2013-11-27 21:52:52 +00:00
|
|
|
|
|
|
|
var WEBSQL_NAME = "websql-test-db";
|
|
|
|
|
2013-11-27 22:12:46 +00:00
|
|
|
function wipeDB(provider) {
|
|
|
|
var context = provider.getReadWriteContext();
|
|
|
|
context.clear(function(err) {
|
2013-11-28 00:35:52 +00:00
|
|
|
if(err) {
|
|
|
|
console.error("Problem clearing WebSQL db: [" + err.code + "] - " + err.message);
|
|
|
|
}
|
2013-11-27 21:52:52 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-01-14 15:56:36 +00:00
|
|
|
if(!Filer.FileSystem.providers.WebSQL.isSupported()) {
|
|
|
|
console.log("Skipping Filer.FileSystem.providers.WebSQL tests, since WebSQL isn't supported.");
|
2013-11-27 22:12:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-14 15:56:36 +00:00
|
|
|
describe("Filer.FileSystem.providers.WebSQL", function() {
|
2013-11-27 21:52:52 +00:00
|
|
|
it("is supported -- if it isn't, none of these tests can run.", function() {
|
2014-01-14 15:56:36 +00:00
|
|
|
expect(Filer.FileSystem.providers.WebSQL.isSupported()).toEqual(true);
|
2013-11-27 21:52:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("has open, getReadOnlyContext, and getReadWriteContext instance methods", function() {
|
2014-01-14 15:56:36 +00:00
|
|
|
var webSQLProvider = new Filer.FileSystem.providers.WebSQL();
|
2013-11-27 21:52:52 +00:00
|
|
|
expect(typeof webSQLProvider.open).toEqual('function');
|
|
|
|
expect(typeof webSQLProvider.getReadOnlyContext).toEqual('function');
|
|
|
|
expect(typeof webSQLProvider.getReadWriteContext).toEqual('function');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("open an WebSQL provider", function() {
|
|
|
|
afterEach(function() {
|
2013-11-27 22:12:46 +00:00
|
|
|
wipeDB(this.provider);
|
2013-11-27 21:52:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should open a new WebSQL database", function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error, _result;
|
|
|
|
|
2014-01-14 15:56:36 +00:00
|
|
|
var provider = this.provider = new Filer.FileSystem.providers.WebSQL(WEBSQL_NAME);
|
2013-11-27 21:52:52 +00:00
|
|
|
provider.open(function(err, firstAccess) {
|
|
|
|
_error = err;
|
|
|
|
_result = firstAccess;
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).toEqual(null);
|
|
|
|
expect(_result).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Read/Write operations on an WebSQL provider", function() {
|
|
|
|
afterEach(function() {
|
2013-11-27 22:12:46 +00:00
|
|
|
wipeDB(this.provider);
|
2013-11-27 21:52:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should allow put() and get()", function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error, _result;
|
|
|
|
|
2014-01-14 15:56:36 +00:00
|
|
|
var provider = this.provider = new Filer.FileSystem.providers.WebSQL(WEBSQL_NAME);
|
2013-11-27 21:52:52 +00:00
|
|
|
provider.open(function(err, firstAccess) {
|
|
|
|
_error = err;
|
|
|
|
|
|
|
|
var context = provider.getReadWriteContext();
|
|
|
|
context.put("key", "value", function(err, result) {
|
|
|
|
_error = _error || err;
|
|
|
|
context.get("key", function(err, result) {
|
|
|
|
_error = _error || err;
|
|
|
|
_result = result;
|
|
|
|
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).toEqual(null);
|
|
|
|
expect(_result).toEqual("value");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should allow delete()", function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error, _result;
|
|
|
|
|
2014-01-14 15:56:36 +00:00
|
|
|
var provider = this.provider = new Filer.FileSystem.providers.WebSQL(WEBSQL_NAME);
|
2013-11-27 21:52:52 +00:00
|
|
|
provider.open(function(err, firstAccess) {
|
|
|
|
_error = err;
|
|
|
|
|
|
|
|
var context = provider.getReadWriteContext();
|
|
|
|
context.put("key", "value", function(err, result) {
|
|
|
|
_error = _error || err;
|
|
|
|
context.delete("key", function(err, result) {
|
|
|
|
_error = _error || err;
|
|
|
|
context.get("key", function(err, result) {
|
|
|
|
_error = _error || err;
|
|
|
|
_result = result;
|
|
|
|
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).toEqual(null);
|
|
|
|
expect(_result).toEqual(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should allow clear()", function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error, _result1, _result2;
|
|
|
|
|
2014-01-14 15:56:36 +00:00
|
|
|
var provider = this.provider = new Filer.FileSystem.providers.WebSQL(WEBSQL_NAME);
|
2013-11-27 21:52:52 +00:00
|
|
|
provider.open(function(err, firstAccess) {
|
|
|
|
_error = err;
|
|
|
|
|
|
|
|
var context = provider.getReadWriteContext();
|
|
|
|
context.put("key1", "value1", function(err, result) {
|
|
|
|
_error = _error || err;
|
|
|
|
context.put("key2", "value2", function(err, result) {
|
|
|
|
_error = _error || err;
|
|
|
|
|
|
|
|
context.clear(function(err) {
|
|
|
|
_error = _error || err;
|
|
|
|
|
|
|
|
context.get("key1", function(err, result) {
|
|
|
|
_error = _error || err;
|
|
|
|
_result1 = result;
|
|
|
|
|
|
|
|
context.get("key2", function(err, result) {
|
|
|
|
_error = _error || err;
|
|
|
|
_result2 = result;
|
|
|
|
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).toEqual(null);
|
|
|
|
expect(_result1).toEqual(null);
|
|
|
|
expect(_result2).toEqual(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should fail when trying to write on ReadOnlyContext", function() {
|
|
|
|
var complete = false;
|
|
|
|
var _error, _result;
|
|
|
|
|
2014-01-14 15:56:36 +00:00
|
|
|
var provider = this.provider = new Filer.FileSystem.providers.WebSQL(WEBSQL_NAME);
|
2013-11-27 21:52:52 +00:00
|
|
|
provider.open(function(err, firstAccess) {
|
|
|
|
_error = err;
|
|
|
|
|
|
|
|
var context = provider.getReadOnlyContext();
|
|
|
|
context.put("key1", "value1", function(err, result) {
|
|
|
|
_error = _error || err;
|
|
|
|
_result = result;
|
|
|
|
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).toBeDefined();
|
|
|
|
expect(_result).toEqual(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|