Merge pull request #120 from humphd/issue119

Default provider for tests should be indexeddb. Fixes #119
This commit is contained in:
Alan K 2014-02-19 18:22:43 -05:00
commit b6b4ac8fec
1 changed files with 20 additions and 1 deletions

View File

@ -11,6 +11,24 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) {
return 'filer-testdb-' + uniqueName.seed++; return 'filer-testdb-' + uniqueName.seed++;
} }
function findBestProvider() {
// When running tests, and when no explicit provider is defined,
// prefer providers in this order: IndexedDB, WebSQL, Memory.
// However, if we're running in PhantomJS, use Memory first.
if(navigator.userAgent.indexOf('PhantomJS') > -1) {
return MemoryTestProvider;
}
var providers = Filer.FileSystem.providers;
if(providers.IndexedDB.isSupported()) {
return IndexedDBTestProvider;
}
if(providers.WebSQL.isSupported()) {
return WebSQLTestProvider;
}
return MemoryTestProvider;
}
function setup(callback) { function setup(callback) {
// We support specifying the provider via the query string // We support specifying the provider via the query string
// (e.g., ?filer-provider=IndexedDB). If not specified, we use // (e.g., ?filer-provider=IndexedDB). If not specified, we use
@ -31,7 +49,8 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) {
case 'memory': case 'memory':
/* falls through */ /* falls through */
default: default:
_provider = new MemoryTestProvider(name); var BestProvider = findBestProvider();
_provider = new BestProvider(name);
break; break;
} }