2018-06-28 23:26:08 +00:00
|
|
|
var Filer = require('../../src');
|
2014-06-23 17:09:02 +00:00
|
|
|
|
|
|
|
var needsCleanup = [];
|
|
|
|
if(global.addEventListener) {
|
|
|
|
global.addEventListener('beforeunload', function() {
|
|
|
|
needsCleanup.forEach(function(f) { f(); });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function IndexedDBTestProvider(name) {
|
|
|
|
var _done = false;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
function cleanup(callback) {
|
2014-11-27 15:30:57 +00:00
|
|
|
callback = callback || function(){};
|
|
|
|
|
2014-06-23 17:09:02 +00:00
|
|
|
if(!that.provider || _done) {
|
2014-08-16 20:22:41 +00:00
|
|
|
return callback();
|
2014-06-23 17:09:02 +00:00
|
|
|
}
|
2014-01-21 21:25:09 +00:00
|
|
|
|
2014-06-23 17:09:02 +00:00
|
|
|
function finished() {
|
|
|
|
that.provider = null;
|
|
|
|
_done = true;
|
|
|
|
callback();
|
2014-01-21 21:25:09 +00:00
|
|
|
}
|
2017-05-21 22:11:12 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
// We have to force any other connections to close
|
|
|
|
// before we can delete a db.
|
|
|
|
if(that.provider.db) {
|
|
|
|
that.provider.db.close();
|
|
|
|
}
|
|
|
|
|
2019-01-03 04:36:20 +00:00
|
|
|
var indexedDB = global.indexedDB ||
|
|
|
|
global.mozIndexedDB ||
|
|
|
|
global.webkitIndexedDB ||
|
|
|
|
global.msIndexedDB;
|
|
|
|
|
2017-05-21 22:11:12 +00:00
|
|
|
var request = indexedDB.deleteDatabase(name);
|
|
|
|
request.onsuccess = finished;
|
|
|
|
request.onerror = finished;
|
|
|
|
} catch(e) {
|
2018-07-27 15:03:43 +00:00
|
|
|
/* eslint no-console:0 */
|
2018-07-15 17:25:35 +00:00
|
|
|
console.log('Failed to delete test database', e);
|
2017-05-21 22:11:12 +00:00
|
|
|
finished();
|
|
|
|
}
|
2014-06-23 17:09:02 +00:00
|
|
|
}
|
2014-01-21 21:25:09 +00:00
|
|
|
|
2014-06-23 17:09:02 +00:00
|
|
|
function init() {
|
|
|
|
if(that.provider) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
that.provider = new Filer.FileSystem.providers.IndexedDB(name);
|
|
|
|
needsCleanup.push(cleanup);
|
2014-01-21 21:25:09 +00:00
|
|
|
}
|
|
|
|
|
2014-06-23 17:09:02 +00:00
|
|
|
this.init = init;
|
|
|
|
this.cleanup = cleanup;
|
|
|
|
}
|
2014-08-16 20:22:41 +00:00
|
|
|
IndexedDBTestProvider.isSupported = function() {
|
|
|
|
return Filer.FileSystem.providers.IndexedDB.isSupported();
|
|
|
|
};
|
2014-01-21 21:25:09 +00:00
|
|
|
|
2014-06-23 17:09:02 +00:00
|
|
|
module.exports = IndexedDBTestProvider;
|