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

View File

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