michael@0: /** michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: var testGenerator = testSteps(); michael@0: michael@0: function testSteps() michael@0: { michael@0: let request = indexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1); michael@0: request.onerror = errorHandler; michael@0: request.onupgradeneeded = grabEventAndContinueHandler; michael@0: request.onsuccess = unexpectedSuccessHandler; michael@0: let event = yield undefined; michael@0: michael@0: let db = event.target.result; michael@0: db.onerror = errorHandler; michael@0: michael@0: event.target.transaction.onerror = errorHandler; michael@0: event.target.transaction.oncomplete = grabEventAndContinueHandler; michael@0: michael@0: let os = db.createObjectStore("foo", { autoIncrement: true }); michael@0: let index = os.createIndex("bar", "foo.bar"); michael@0: event = yield undefined; michael@0: michael@0: is(request.transaction, event.target, michael@0: "request.transaction should still be set"); michael@0: michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: is(request.transaction, null, "request.transaction should be cleared"); michael@0: michael@0: let transaction = db.transaction("foo", "readwrite"); michael@0: michael@0: os = transaction.objectStore("foo"); michael@0: // Place a request to keep the transaction alive long enough for our michael@0: // executeSoon. michael@0: let requestComplete = false; michael@0: michael@0: let wasAbleToGrabObjectStoreOutsideOfCallback = false; michael@0: let wasAbleToGrabIndexOutsideOfCallback = false; michael@0: executeSoon(function() { michael@0: ok(!requestComplete, "Ordering is correct."); michael@0: wasAbleToGrabObjectStoreOutsideOfCallback = !!transaction.objectStore("foo"); michael@0: wasAbleToGrabIndexOutsideOfCallback = michael@0: !!transaction.objectStore("foo").index("bar"); michael@0: }); michael@0: michael@0: request = os.add({}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: michael@0: event = yield undefined; michael@0: michael@0: requestComplete = true; michael@0: michael@0: ok(wasAbleToGrabObjectStoreOutsideOfCallback, michael@0: "Should be able to get objectStore"); michael@0: ok(wasAbleToGrabIndexOutsideOfCallback, michael@0: "Should be able to get index"); michael@0: michael@0: transaction.oncomplete = grabEventAndContinueHandler; michael@0: yield undefined; michael@0: michael@0: try { michael@0: transaction.objectStore("foo"); michael@0: ok(false, "Should have thrown!"); michael@0: } michael@0: catch (e) { michael@0: ok(e instanceof DOMException, "Got database exception."); michael@0: is(e.name, "InvalidStateError", "Good error."); michael@0: is(e.code, DOMException.INVALID_STATE_ERR, "Good error code."); michael@0: } michael@0: michael@0: continueToNextStep(); michael@0: yield undefined; michael@0: michael@0: try { michael@0: transaction.objectStore("foo"); michael@0: ok(false, "Should have thrown!"); michael@0: } michael@0: catch (e) { michael@0: ok(e instanceof DOMException, "Got database exception."); michael@0: is(e.name, "InvalidStateError", "Good error."); michael@0: is(e.code, DOMException.INVALID_STATE_ERR, "Good error code."); michael@0: } michael@0: michael@0: finishTest(); michael@0: yield undefined; michael@0: }