2014-01-21 21:25:09 +00:00
|
|
|
define(["Filer", "util"], function(Filer, util) {
|
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-02-17 16:28:04 +00:00
|
|
|
if(navigator.userAgent.indexOf('PhantomJS') > -1) {
|
|
|
|
console.log("Skipping Filer.FileSystem.providers.WebSQL tests, since PhantomJS doesn't support it.");
|
|
|
|
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-21 21:25:09 +00:00
|
|
|
expect(Filer.FileSystem.providers.WebSQL.isSupported()).to.be.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();
|
2014-01-21 21:25:09 +00:00
|
|
|
expect(webSQLProvider.open).to.be.a('function');
|
|
|
|
expect(webSQLProvider.getReadOnlyContext).to.be.a('function');
|
|
|
|
expect(webSQLProvider.getReadWriteContext).to.be.a('function');
|
2013-11-27 21:52:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("open an WebSQL provider", function() {
|
2014-01-21 21:25:09 +00:00
|
|
|
var _provider;
|
2013-11-27 21:52:52 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
beforeEach(function() {
|
|
|
|
_provider = new util.providers.WebSQL(util.uniqueName());
|
|
|
|
_provider.init();
|
|
|
|
});
|
2013-11-27 21:52:52 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
afterEach(function(done) {
|
|
|
|
_provider.cleanup(done);
|
|
|
|
_provider = null;
|
|
|
|
});
|
2013-11-27 21:52:52 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it("should open a new WebSQL database", function(done) {
|
|
|
|
var provider = _provider.provider;
|
|
|
|
provider.open(function(error, firstAccess) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(firstAccess).to.be.true;
|
|
|
|
done();
|
2013-11-27 21:52:52 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Read/Write operations on an WebSQL provider", function() {
|
2014-01-21 21:25:09 +00:00
|
|
|
var _provider;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
_provider = new util.providers.WebSQL(util.uniqueName());
|
|
|
|
_provider.init();
|
2013-11-27 21:52:52 +00:00
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
afterEach(function(done) {
|
|
|
|
_provider.cleanup(done);
|
|
|
|
_provider = null;
|
|
|
|
});
|
2013-11-27 21:52:52 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it("should allow put() and get()", function(done) {
|
|
|
|
var provider = _provider.provider;
|
|
|
|
provider.open(function(error, firstAccess) {
|
|
|
|
if(error) throw error;
|
2013-11-27 21:52:52 +00:00
|
|
|
|
|
|
|
var context = provider.getReadWriteContext();
|
2014-01-21 21:25:09 +00:00
|
|
|
context.put("key", "value", function(error, result) {
|
|
|
|
if(error) throw error;
|
2013-11-27 21:52:52 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
context.get("key", function(error, result) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result).to.equal("value");
|
|
|
|
done();
|
2013-11-27 21:52:52 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it("should allow delete()", function(done) {
|
|
|
|
var provider = _provider.provider;
|
|
|
|
provider.open(function(error, firstAccess) {
|
|
|
|
if(error) throw error;
|
2013-11-27 21:52:52 +00:00
|
|
|
|
|
|
|
var context = provider.getReadWriteContext();
|
2014-01-21 21:25:09 +00:00
|
|
|
context.put("key", "value", function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
context.delete("key", function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
context.get("key", function(error, result) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result).not.to.exist;
|
|
|
|
done();
|
2013-11-27 21:52:52 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it("should allow clear()", function(done) {
|
|
|
|
var provider = _provider.provider;
|
|
|
|
provider.open(function(error, firstAccess) {
|
|
|
|
if(error) throw error;
|
2013-11-27 21:52:52 +00:00
|
|
|
|
|
|
|
var context = provider.getReadWriteContext();
|
2014-01-21 21:25:09 +00:00
|
|
|
context.put("key1", "value1", function(error, result) {
|
|
|
|
if(error) throw error;
|
2013-11-27 21:52:52 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
context.put("key2", "value2", function(error, result) {
|
|
|
|
if(error) throw error;
|
2013-11-27 21:52:52 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
context.clear(function(err) {
|
|
|
|
if(error) throw error;
|
2013-11-27 21:52:52 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
context.get("key1", function(error, result) {
|
|
|
|
if(error) throw error;
|
|
|
|
expect(result).not.to.exist;
|
2013-11-27 21:52:52 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
context.get("key2", function(error, result) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result).not.to.exist;
|
|
|
|
done();
|
2013-11-27 21:52:52 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it("should fail when trying to write on ReadOnlyContext", function(done) {
|
|
|
|
var provider = _provider.provider;
|
|
|
|
provider.open(function(error, firstAccess) {
|
|
|
|
if(error) throw error;
|
2013-11-27 21:52:52 +00:00
|
|
|
|
|
|
|
var context = provider.getReadOnlyContext();
|
2014-01-21 21:25:09 +00:00
|
|
|
context.put("key1", "value1", function(error, result) {
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(result).not.to.exist;
|
|
|
|
done();
|
2013-11-27 21:52:52 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|