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: const objectStores = [ "foo", "bar" ]; michael@0: michael@0: let request = indexedDB.open(name, 1); michael@0: request.onerror = errorHandler; michael@0: request.onupgradeneeded = grabEventAndContinueHandler; michael@0: let event = yield undefined; michael@0: michael@0: let db = event.target.result; michael@0: is(db.objectStoreNames.length, 0, "Correct objectStoreNames list"); michael@0: michael@0: event.target.onsuccess = grabEventAndContinueHandler; michael@0: for (let i in objectStores) { michael@0: db.createObjectStore(objectStores[i], { autoIncrement: true }); michael@0: } michael@0: let event = yield undefined; michael@0: michael@0: is(db.objectStoreNames.length, objectStores.length, michael@0: "Correct objectStoreNames list"); michael@0: michael@0: for (let i = 0; i < 50; i++) { michael@0: let stepNumber = 0; michael@0: michael@0: request = db.transaction(["foo"], "readwrite") michael@0: .objectStore("foo") michael@0: .add({}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: is(stepNumber, 1, "This callback came first"); michael@0: stepNumber++; michael@0: event.target.transaction.oncomplete = grabEventAndContinueHandler; michael@0: } michael@0: michael@0: request = db.transaction(["foo"], "readwrite") michael@0: .objectStore("foo") michael@0: .add({}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: is(stepNumber, 2, "This callback came second"); michael@0: stepNumber++; michael@0: event.target.transaction.oncomplete = grabEventAndContinueHandler; michael@0: } michael@0: michael@0: request = db.transaction(["foo", "bar"], "readwrite") michael@0: .objectStore("bar") michael@0: .add({}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: is(stepNumber, 3, "This callback came third"); michael@0: stepNumber++; michael@0: event.target.transaction.oncomplete = grabEventAndContinueHandler; michael@0: } michael@0: michael@0: request = db.transaction(["foo", "bar"], "readwrite") michael@0: .objectStore("bar") michael@0: .add({}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: is(stepNumber, 4, "This callback came fourth"); michael@0: stepNumber++; michael@0: event.target.transaction.oncomplete = grabEventAndContinueHandler; michael@0: } michael@0: michael@0: request = db.transaction(["bar"], "readwrite") michael@0: .objectStore("bar") michael@0: .add({}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: is(stepNumber, 5, "This callback came fifth"); michael@0: stepNumber++; michael@0: event.target.transaction.oncomplete = grabEventAndContinueHandler; michael@0: } michael@0: michael@0: stepNumber++; michael@0: yield undefined; yield undefined; yield undefined; yield undefined; yield undefined; michael@0: michael@0: is(stepNumber, 6, "All callbacks received"); michael@0: } michael@0: michael@0: finishTest(); michael@0: yield undefined; michael@0: } michael@0: