Mocked out events and targets.

This commit is contained in:
Alan Kligman 2013-05-25 21:26:18 -04:00
parent 4f495fe785
commit c80a08bb07
2 changed files with 19 additions and 9 deletions

View File

@ -21,7 +21,7 @@ require(["src/indexeddb"], function(idb) {
var db; var db;
idb.open('test').then( idb.open('test').then(
function(event) { function(event) {
db = event.target._result; db = event.target.result;
var transaction = db.transaction(['FILES'], 'readwrite'); var transaction = db.transaction(['FILES'], 'readwrite');
var files = transaction.objectStore('FILES'); var files = transaction.objectStore('FILES');
return files.clear(); return files.clear();
@ -30,7 +30,7 @@ require(["src/indexeddb"], function(idb) {
console.error('error:', event); console.error('error:', event);
}, },
function(event) { function(event) {
db = event.target._result; db = event.target.result;
if(db.objectStoreNames().contains('FILES')) { if(db.objectStoreNames().contains('FILES')) {
db.deleteObjectStore('FILES'); db.deleteObjectStore('FILES');
} }

View File

@ -4,6 +4,18 @@ define(function(require) {
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB; var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
function Event(idbEvent, target) {
this._event = idbEvent;
this.type = idbEvent.type;
this.timeStamp = idbEvent.timeStamp;
this.target = target || idbEvent.target;
};
function Target(idbTarget, result) {
this.idbTarget = idbTarget;
this.result = result || idbTarget.result;
};
/* /*
* ObjectStore * ObjectStore
*/ */
@ -91,7 +103,7 @@ define(function(require) {
}; };
ObjectStore.prototype.index = function index(name) { ObjectStore.prototype.index = function index(name) {
var idbObjectStore = this.idbObjectStore; var idbObjectStore = this.idbObjectStore;
return idbObjectStore.index.call(idbObjectStore, name); return idbObjectStore.index(name);
}; };
ObjectStore.prototype.openCursor = function openCursor(range, direction) { ObjectStore.prototype.openCursor = function openCursor(range, direction) {
var idbObjectStore = this.idbObjectStore; var idbObjectStore = this.idbObjectStore;
@ -177,14 +189,12 @@ define(function(require) {
var request = indexedDB.open(name); var request = indexedDB.open(name);
request.onupgradeneeded = function(event) { request.onupgradeneeded = function(event) {
var result = new Database(event.target.result); var result = new Event(event, new Target(event.target, new Database(event.target.result)));
event.target._result = result; deferred.notify(result);
deferred.notify(event);
}; };
request.onsuccess = function(event) { request.onsuccess = function(event) {
var result = new Database(event.target.result); var result = new Event(event, new Target(event.target, new Database(event.target.result)));
event.target._result = result; deferred.resolve(result);
deferred.resolve(event);
}; };
request.onerror = function(event) { request.onerror = function(event) {
deferred.reject(event); deferred.reject(event);