2012-01-04 07:43:33 -08:00
|
|
|
/**
|
|
|
|
* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*/
|
|
|
|
|
|
|
|
var testGenerator = testSteps();
|
|
|
|
|
|
|
|
function testSteps()
|
|
|
|
{
|
|
|
|
const name = this.window ? window.location.pathname : "Splendid Test";
|
|
|
|
const description = "My Test Database";
|
|
|
|
|
|
|
|
let request = mozIndexedDB.open(name, 1, description);
|
2012-06-19 18:50:39 -07:00
|
|
|
request.onerror = errorHandler;
|
2012-01-04 07:43:33 -08:00
|
|
|
request.onsuccess = unexpectedSuccessHandler;
|
|
|
|
request.onupgradeneeded = grabEventAndContinueHandler;
|
|
|
|
let event = yield;
|
|
|
|
|
|
|
|
let db = event.target.result;
|
|
|
|
|
|
|
|
let objectStore = db.createObjectStore("foo");
|
|
|
|
let index = objectStore.createIndex("bar", "baz");
|
|
|
|
|
|
|
|
is(db.version, 1, "Correct version");
|
|
|
|
is(db.objectStoreNames.length, 1, "Correct objectStoreNames length");
|
|
|
|
is(objectStore.indexNames.length, 1, "Correct indexNames length");
|
|
|
|
|
|
|
|
let transaction = event.target.transaction;
|
|
|
|
transaction.oncomplete = unexpectedSuccessHandler;
|
|
|
|
transaction.onabort = grabEventAndContinueHandler;
|
|
|
|
transaction.abort();
|
|
|
|
|
|
|
|
event = yield;
|
|
|
|
is(event.type, "abort", "Got transaction abort event");
|
|
|
|
is(event.target, transaction, "Right target");
|
2012-06-01 10:21:12 -07:00
|
|
|
is(event.target.transaction, null, "No transaction");
|
2012-01-04 07:43:33 -08:00
|
|
|
|
|
|
|
is(db.version, 1, "Correct version");
|
|
|
|
is(db.objectStoreNames.length, 1, "Correct objectStoreNames length");
|
|
|
|
|
2012-06-19 18:50:39 -07:00
|
|
|
request.onerror = grabEventAndContinueHandler;
|
|
|
|
request.onupgradeneeded = unexpectedSuccessHandler;
|
|
|
|
|
2012-01-04 07:43:33 -08:00
|
|
|
event = yield;
|
2012-06-19 18:50:39 -07:00
|
|
|
|
2012-01-04 07:43:33 -08:00
|
|
|
is(event.type, "error", "Got request error event");
|
|
|
|
is(event.target, request, "Right target");
|
2012-06-01 10:21:12 -07:00
|
|
|
is(event.target.transaction, null, "No transaction");
|
|
|
|
|
|
|
|
event.preventDefault();
|
2012-01-04 07:43:33 -08:00
|
|
|
|
|
|
|
request = mozIndexedDB.open(name, 1, description);
|
2012-06-19 18:50:39 -07:00
|
|
|
request.onerror = errorHandler;
|
2012-01-04 07:43:33 -08:00
|
|
|
request.onsuccess = unexpectedSuccessHandler;
|
|
|
|
request.onupgradeneeded = grabEventAndContinueHandler;
|
2012-06-19 18:50:39 -07:00
|
|
|
event = yield;
|
|
|
|
|
|
|
|
is(event.type, "upgradeneeded", "Got upgradeneeded event");
|
2012-01-04 07:43:33 -08:00
|
|
|
|
|
|
|
let db2 = event.target.result;
|
2012-06-19 18:50:39 -07:00
|
|
|
|
2012-01-04 07:43:33 -08:00
|
|
|
isnot(db, db2, "Should give a different db instance");
|
|
|
|
is(db2.version, 1, "Correct version");
|
|
|
|
is(db2.objectStoreNames.length, 0, "Correct objectStoreNames length");
|
|
|
|
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2012-06-19 18:50:39 -07:00
|
|
|
request.onupgradeneeded = unexpectedSuccessHandler;
|
|
|
|
event = yield;
|
|
|
|
|
|
|
|
is(event.target.result, db2, "Correct target");
|
|
|
|
is(event.type, "success", "Got success event");
|
|
|
|
is(db2.version, 1, "Correct version");
|
|
|
|
is(db2.objectStoreNames.length, 0, "Correct objectStoreNames length");
|
2012-01-04 07:43:33 -08:00
|
|
|
|
|
|
|
finishTest();
|
|
|
|
yield;
|
|
|
|
}
|