blob: 81f18f41c4bef9f43aab2d80152e35c81ec2ecbb [file] [log] [blame]
description("This tests some obvious failures that can happen while calling IDBObjectStore.put() and IDBObjectStore.clear().");
indexedDBTest(prepareDatabase);
function done()
{
finishJSTest();
}
var database;
function prepareDatabase(event)
{
debug("Initial upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
var versionTransaction = event.target.transaction;
database = event.target.result;
var objectStore = database.createObjectStore("TestObjectStore");
var request = objectStore.put("bar", "foo");
request.onsuccess = function() {
try {
objectStore.put("bar", NaN);
} catch(e) {
debug("Failed to put record into object store with an invalid key");
}
database.deleteObjectStore("TestObjectStore");
try {
objectStore.put("bar", "foo");
} catch(e) {
debug("Failed to put record into object store that has been deleted");
}
try {
objectStore.clear();
} catch(e) {
debug("Failed to clear object store that has been deleted");
}
// Recreate the objectstore because we'll need it in phase 2.
var objectStore = database.createObjectStore("TestObjectStore");
objectStore.put("bar", "foo");
}
versionTransaction.onabort = function(event) {
debug("Initial upgrade versionchange transaction unexpected aborted");
done();
}
versionTransaction.oncomplete = function(event) {
debug("Initial upgrade versionchange transaction complete");
continueTest1();
}
versionTransaction.onerror = function(event) {
debug("Initial upgrade versionchange transaction unexpected error" + event);
done();
}
}
function continueTest1()
{
var transaction = database.transaction("TestObjectStore", "readonly");
var objectStore = transaction.objectStore("TestObjectStore");
try {
objectStore.clear();
} catch(e) {
debug("Failed to clear object store in read-only transaction");
}
var transaction = database.transaction("TestObjectStore", "readwrite");
var objectStore = transaction.objectStore("TestObjectStore");
// Spin the transaction with get requests to keep it alive long enough for the setTimeout to fire.
var canFinish = false;
var spinGet = function() {
objectStore.get("foo").onsuccess = function() {
if (!canFinish)
spinGet();
}
}
spinGet();
var testWhileInactive = function() {
try {
objectStore.put("bar", "foo");
} catch(e) {
debug("Failed to put record into object store with inactive transaction");
}
try {
objectStore.clear();
} catch(e) {
debug("Failed to clear object store with inactive transaction");
}
canFinish = true;
}
setTimeout(testWhileInactive, 0);
transaction.onabort = function(event) {
debug("readwrite transaction unexpected abort" + event);
done();
}
transaction.oncomplete = function(event) {
debug("readwrite transaction complete");
done();
}
transaction.onerror = function(event) {
debug("readwrite transaction unexpected error" + event);
done();
}
}