diff options
Diffstat (limited to 'LayoutTests/storage/indexeddb/objectstore-basics.html')
-rw-r--r-- | LayoutTests/storage/indexeddb/objectstore-basics.html | 79 |
1 files changed, 73 insertions, 6 deletions
diff --git a/LayoutTests/storage/indexeddb/objectstore-basics.html b/LayoutTests/storage/indexeddb/objectstore-basics.html index 005247e..3d2a1d2 100644 --- a/LayoutTests/storage/indexeddb/objectstore-basics.html +++ b/LayoutTests/storage/indexeddb/objectstore-basics.html @@ -16,7 +16,7 @@ if (window.layoutTestController) function test() { - result = evalAndLog("webkitIndexedDB.open('name', 'description')"); + result = evalAndLog("webkitIndexedDB.open('name')"); verifyResult(result); result.onsuccess = openSuccess; result.onerror = unexpectedErrorCallback; @@ -49,7 +49,7 @@ function createObjectStore() { debug("createObjectStore():"); window.store = evalAndLog("store = db.createObjectStore('storeName', null)"); - var storeNames = evalAndLog("storeNames = db.objectStores"); + var storeNames = evalAndLog("storeNames = db.objectStoreNames"); shouldBeEqualToString("store.name", "storeName"); shouldBeNull("store.keyPath"); @@ -73,7 +73,7 @@ function createObjectStore() function createIndex() { debug("createIndex():"); - var index = evalAndLog("index = store.createIndex('indexName', 'x', true)"); // true == unique requirement. + var index = evalAndLog("index = store.createIndex('indexName', 'x', {unique: true})"); // true == unique requirement. shouldBeTrue("index !== null"); shouldBeTrue("store.indexNames.contains('indexName')"); index = evalAndLog("index = store.index('indexName')"); @@ -142,6 +142,41 @@ function addData() var transaction = evalAndLog("transaction = db.transaction()"); transaction.onabort = unexpectedAbortCallback; window.store = evalAndLog("store = transaction.objectStore('storeName')"); + + debug("Try to insert data with a Date key:"); + // FIXME: This should work in the future. + try { + debug("store.add({x: 'foo'}, new Date())"); + store.add({x: 'foo'}, new Date()); + testFailed("Passing a Date as key argument should have thrown."); + } catch (err) { + testPassed("Exception thrown"); + code = err.code; + shouldBe("code", "DOMException.TYPE_MISMATCH_ERR"); + } + + debug("Try to insert a value not handled by structured clone:"); + try { + debug("store.add({x: 'bar', y: document.getElementById('console')}, 'bar')"); + store.add({x: 'bar', y: document.getElementById('console')}, 'bar'); + testFailed("Passing a DOM node as value should have thrown."); + } catch (err) { + testPassed("Exception thrown"); + code = err.code; + shouldBe("code", "DOMException.NOT_SUPPORTED_ERR"); + } + + // FIXME: This should work in the future. + debug("Try to insert data where key path yields a Date key:"); + result = evalAndLog("store.add({x: new Date()}, 'foo')"); + result.onsuccess = unexpectedSuccessCallback; + result.onerror = addKeyPathYieldingDateFailure; +} + +function addKeyPathYieldingDateFailure() +{ + testPassed("Adding data where key path yielded Date key resulted in error."); + result = evalAndLog("store.add({x: 'value'}, 'key')"); verifyResult(result); result.onsuccess = addSuccess; @@ -171,6 +206,38 @@ function addAgainFailure() transaction.onabort = unexpectedErrorCallback; var store = evalAndLog("store = transaction.objectStore('storeName')"); + result = evalAndLog("store.add({x: 'othervalue'}, null)"); + verifyResult(result); + result.onsuccess = unexpectedSuccessCallback; + result.onerror = addWithNullKeyFailure; +} + +function addWithNullKeyFailure() +{ + debug("addWithNullKeyFailre():"); + verifyErrorEvent(event); + shouldBe("event.code", "webkitIDBDatabaseException.DATA_ERR"); + + transaction = evalAndLog("db.transaction()"); + transaction.onabort = unexpectedErrorCallback; + var store = evalAndLog("store = transaction.objectStore('storeName')"); + + result = evalAndLog("store.add({x: null}, 'validkey')"); + verifyResult(result); + result.onsuccess = unexpectedSuccessCallback; + result.onerror = addWithNullIndexFailure; +} + +function addWithNullIndexFailure() +{ + debug("addWithNullIndexFailure():"); + verifyErrorEvent(event); + shouldBe("event.code", "webkitIDBDatabaseException.DATA_ERR"); + + transaction = evalAndLog("db.transaction()"); + transaction.onabort = unexpectedErrorCallback; + var store = evalAndLog("store = transaction.objectStore('storeName')"); + result = evalAndLog("store.get('key')"); verifyResult(result); result.onsuccess = getSuccess; @@ -184,7 +251,7 @@ function getSuccess() shouldBeEqualToString("event.result.x", "value"); var store = evalAndLog("store = event.source"); - result = evalAndLog("store.remove('key')"); + result = evalAndLog("store.delete('key')"); verifyResult(result); result.onsuccess = removeSuccess; result.onerror = unexpectedErrorCallback; @@ -206,8 +273,8 @@ function removeSuccess() } try { - debug("Passing an invalid key into store.remove()."); - store.remove([]); + debug("Passing an invalid key into store.delete()."); + store.delete([]); testFailed("No exception thrown"); } catch (e) { testPassed("Caught exception: " + e.toString()); |