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: const name = this.window ? window.location.pathname : "Splendid Test"; michael@0: michael@0: let request = indexedDB.open(name, 1); michael@0: request.onerror = errorHandler; michael@0: request.onupgradeneeded = grabEventAndContinueHandler; michael@0: request.onsuccess = unexpectedSuccessHandler; michael@0: michael@0: let request2 = indexedDB.open(name, 2); michael@0: request2.onerror = errorHandler; michael@0: request2.onupgradeneeded = unexpectedSuccessHandler; michael@0: request2.onsuccess = unexpectedSuccessHandler; michael@0: michael@0: let event = yield undefined; michael@0: is(event.type, "upgradeneeded", "Expect an upgradeneeded event"); michael@0: is(event.target, request, "Event should be fired on the request"); michael@0: ok(event.target.result instanceof IDBDatabase, "Expect a database here"); michael@0: michael@0: let db = event.target.result; michael@0: is(db.version, 1, "Database has correct version"); michael@0: michael@0: db.onupgradeneeded = function() { michael@0: ok(false, "our ongoing VERSION_CHANGE transaction should exclude any others!"); michael@0: } michael@0: michael@0: db.createObjectStore("foo"); michael@0: michael@0: try { michael@0: db.transaction("foo"); michael@0: ok(false, "Transactions should be disallowed now!"); michael@0: } catch (e) { michael@0: ok(e instanceof DOMException, "Expect a DOMException"); michael@0: is(e.name, "InvalidStateError", "Expect an InvalidStateError"); michael@0: is(e.code, DOMException.INVALID_STATE_ERR, "Expect an INVALID_STATE_ERR"); michael@0: } michael@0: michael@0: request.onupgradeneeded = unexpectedSuccessHandler; michael@0: request.transaction.oncomplete = grabEventAndContinueHandler; michael@0: michael@0: event = yield undefined; michael@0: is(event.type, "complete", "Got complete event"); michael@0: michael@0: try { michael@0: db.transaction("foo"); michael@0: ok(true, "Transactions should be allowed now!"); michael@0: } catch (e) { michael@0: ok(false, "Transactions should be allowed now!"); michael@0: } michael@0: michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: michael@0: event = yield undefined; michael@0: is(event.type, "success", "Expect a success event"); michael@0: is(event.target.result, db, "Same database"); michael@0: michael@0: db.onversionchange = function() { michael@0: ok(true, "next setVersion was unblocked appropriately"); michael@0: db.close(); michael@0: } michael@0: michael@0: try { michael@0: db.transaction("foo"); michael@0: ok(true, "Transactions should be allowed now!"); michael@0: } catch (e) { michael@0: ok(false, "Transactions should be allowed now!"); michael@0: } michael@0: michael@0: request.onsuccess = unexpectedSuccessHandler; michael@0: request2.onupgradeneeded = grabEventAndContinueHandler; michael@0: michael@0: event = yield undefined; michael@0: is(event.type, "upgradeneeded", "Expect an upgradeneeded event"); michael@0: michael@0: db = event.target.result; michael@0: is(db.version, 2, "Database has correct version"); michael@0: michael@0: request2.onupgradeneeded = unexpectedSuccessHandler; michael@0: request2.onsuccess = grabEventAndContinueHandler; michael@0: michael@0: event = yield undefined; michael@0: is(event.type, "success", "Expect a success event"); michael@0: is(event.target.result, db, "Same database"); michael@0: is(db.version, 2, "Database has correct version"); michael@0: michael@0: finishTest(); michael@0: yield undefined; michael@0: }