Test features of IndexedDB's multiEntry indices.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
PASS Boolean(indexedDB && IDBCursor && IDBDatabase && IDBDatabaseError && IDBDatabaseException && IDBFactory && IDBIndex && IDBKeyRange && IDBObjectStore && IDBRequest && IDBTransaction) is true

indexedDB.open('index-multiEntry')
db = event.target.result
db.setVersion('1')

Creating empty stores and indexes
trans = event.target.result
PASS trans !== null is true
Deleted all object stores.
store = db.createObjectStore('store')
store.createIndex('index', 'x', {multiEntry: true})
store2 = db.createObjectStore('store-unique')
store2.createIndex('index-unique', 'x', {multiEntry: true, unique: true})

Populating stores (and indexes)
transaction = db.transaction(['store'], IDBTransaction.READ_WRITE)
First try some keys that aren't what we're expecting
transaction.objectStore('store').put({x: [7, 8, 9], y: 'a'}, 'foo')
Now overwrite them with what we're expecting
transaction.objectStore('store').put({x: [1, 2, 3], y: 'a'}, 'foo')
transaction.objectStore('store').put({x: [4, 5, 6], y: 'b'}, 'bar')

Verifying index: index
transaction = db.transaction(['store'], IDBTransaction.READ_ONLY)
transaction.objectStore('store').index('index').openCursor()
cursor = event.target.result
PASS ex != null is true
PASS cursor.key is 1
PASS cursor.primaryKey is "foo"
PASS cursor.value.y is "a"
cursor = event.target.result
PASS ex != null is true
PASS cursor.key is 2
PASS cursor.primaryKey is "foo"
PASS cursor.value.y is "a"
cursor = event.target.result
PASS ex != null is true
PASS cursor.key is 3
PASS cursor.primaryKey is "foo"
PASS cursor.value.y is "a"
cursor = event.target.result
PASS ex != null is true
PASS cursor.key is 4
PASS cursor.primaryKey is "bar"
PASS cursor.value.y is "b"
cursor = event.target.result
PASS ex != null is true
PASS cursor.key is 5
PASS cursor.primaryKey is "bar"
PASS cursor.value.y is "b"
cursor = event.target.result
PASS ex != null is true
PASS cursor.key is 6
PASS cursor.primaryKey is "bar"
PASS cursor.value.y is "b"
cursor = event.target.result
PASS expected.length === 0 is true

Verifying unique constraint on multiEntry index
transaction = db.transaction(['store-unique'], IDBTransaction.READ_WRITE)
transaction.objectStore('store-unique').put({x: [1, 2, 3], y: 'a'}, 'foo')
success!
Replace an existing record - this should work
transaction.objectStore('store-unique').put({x: [1, 2, 7], y: 'a'}, 'foo')
success!
This should fail the uniqueness constraint on the index, and fail:
transaction.objectStore('store-unique').put({x: [5, 2], y: 'c'}, 'should fail')
Request failed, as expected
Transaction aborted as expected

Create an index on a populated store
db.setVersion('2')
trans = event.target.result
PASS trans !== null is true
store = trans.objectStore('store')
store.createIndex('index-new', 'x', {multiEntry: true})

Verifying index: index-new
transaction = db.transaction(['store'], IDBTransaction.READ_ONLY)
transaction.objectStore('store').index('index-new').openCursor()
cursor = event.target.result
PASS ex != null is true
PASS cursor.key is 1
PASS cursor.primaryKey is "foo"
PASS cursor.value.y is "a"
cursor = event.target.result
PASS ex != null is true
PASS cursor.key is 2
PASS cursor.primaryKey is "foo"
PASS cursor.value.y is "a"
cursor = event.target.result
PASS ex != null is true
PASS cursor.key is 3
PASS cursor.primaryKey is "foo"
PASS cursor.value.y is "a"
cursor = event.target.result
PASS ex != null is true
PASS cursor.key is 4
PASS cursor.primaryKey is "bar"
PASS cursor.value.y is "b"
cursor = event.target.result
PASS ex != null is true
PASS cursor.key is 5
PASS cursor.primaryKey is "bar"
PASS cursor.value.y is "b"
cursor = event.target.result
PASS ex != null is true
PASS cursor.key is 6
PASS cursor.primaryKey is "bar"
PASS cursor.value.y is "b"
cursor = event.target.result
PASS expected.length === 0 is true
PASS successfullyParsed is true

TEST COMPLETE

