blob: f832f1a6d3772da84c7731ca1181d828d00b282b [file] [log] [blame]
Test IndexedDB Array-type keyPaths
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
dbname = "keypath-arrays.html"
indexedDB.deleteDatabase(dbname)
indexedDB.open(dbname)
store = db.createObjectStore('store', {keyPath: ['a', 'b']})
index = store.createIndex('index', ['c', 'd'])
PASS areArraysEqual(index.keyPath, ['c', 'd']) is true
PASS index.keyPath instanceof DOMStringList is false
Expecting exception from db.createObjectStore('store-with-generator', {keyPath: ['a', 'b'], autoIncrement: true})
PASS Exception was thrown.
PASS code is DOMException.INVALID_ACCESS_ERR
Exception message: Failed to execute 'createObjectStore' on 'IDBDatabase': The autoIncrement option was set but the keyPath option was empty or an array.
Expecting exception from store.createIndex('index-multientry', ['e', 'f'], {multiEntry: true})
PASS Exception was thrown.
PASS code is DOMException.INVALID_ACCESS_ERR
Exception message: Failed to execute 'createIndex' on 'IDBObjectStore': The keyPath argument was an array and the multiEntry option is true.
Empty arrays are not valid key paths:
Expecting exception from db.createObjectStore('store-keypath-empty-array', {keyPath: []})
PASS Exception was thrown.
PASS code is DOMException.SYNTAX_ERR
Exception message: Failed to execute 'createObjectStore' on 'IDBDatabase': The keyPath option is not a valid key path.
Expecting exception from store.createIndex('index-keypath-empty-array', [])
PASS Exception was thrown.
PASS code is DOMException.SYNTAX_ERR
Exception message: Failed to execute 'createIndex' on 'IDBObjectStore': The keyPath argument contains an invalid key path.
testKeyPaths():
transaction = db.transaction(['store'], 'readwrite')
store = transaction.objectStore('store')
index = store.index('index')
request = store.put({a: 1, b: 2, c: 3, d: 4})
request = store.openCursor()
cursor = request.result
PASS cursor is non-null.
PASS JSON.stringify(cursor.key) is "[1,2]"
request = index.openCursor()
cursor = request.result
PASS cursor is non-null.
PASS JSON.stringify(cursor.primaryKey) is "[1,2]"
PASS JSON.stringify(cursor.key) is "[3,4]"
PASS successfullyParsed is true
TEST COMPLETE