blob: f62c903afe0a339a7aa58565f687e6072a55f9f4 [file] [log] [blame]
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;
indexedDB.deleteDatabase(dbname)
indexedDB.open(dbname)
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'], 'readwrite')
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')
transaction.objectStore('store').put({x: [7, 7, 8, 7], y: 'c'}, 'baz')
transaction.objectStore('store').put({x: [null, 9, 9], y: 'd'}, 'bloop')
transaction.objectStore('store').put({x: [1, [2, null]], y:'e'}, 'oh')
Verifying index: index
transaction = db.transaction(['store'], 'readonly')
transaction.objectStore('store').index('index').openCursor()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 1
PASS cursor.primaryKey is "foo"
PASS cursor.value.y is "a"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 1
PASS cursor.primaryKey is "oh"
PASS cursor.value.y is "e"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 2
PASS cursor.primaryKey is "foo"
PASS cursor.value.y is "a"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 3
PASS cursor.primaryKey is "foo"
PASS cursor.value.y is "a"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 4
PASS cursor.primaryKey is "bar"
PASS cursor.value.y is "b"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 5
PASS cursor.primaryKey is "bar"
PASS cursor.value.y is "b"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 6
PASS cursor.primaryKey is "bar"
PASS cursor.value.y is "b"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 7
PASS cursor.primaryKey is "baz"
PASS cursor.value.y is "c"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 8
PASS cursor.primaryKey is "baz"
PASS cursor.value.y is "c"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 9
PASS cursor.primaryKey is "bloop"
PASS cursor.value.y is "d"
cursor.continue()
cursor = event.target.result
PASS expected.length is 0
transaction = db.transaction(['store'])
transaction.objectStore('store').index('index')
index.count()
PASS event.target.result is 10
index.count(7)
PASS event.target.result is 1
Verifying unique constraint on multiEntry index
transaction = db.transaction(['store-unique'], 'readwrite')
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 (ConstraintError)
Transaction aborted as expected
Create an index on a populated store
db.close()
indexedDB.open(dbname, 2)
db = event.target.result
trans = event.target.transaction
store = trans.objectStore('store')
store.createIndex('index-new', 'x', {multiEntry: true})
Verifying index: index-new
transaction = db.transaction(['store'], 'readonly')
transaction.objectStore('store').index('index-new').openCursor()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 1
PASS cursor.primaryKey is "foo"
PASS cursor.value.y is "a"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 1
PASS cursor.primaryKey is "oh"
PASS cursor.value.y is "e"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 2
PASS cursor.primaryKey is "foo"
PASS cursor.value.y is "a"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 3
PASS cursor.primaryKey is "foo"
PASS cursor.value.y is "a"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 4
PASS cursor.primaryKey is "bar"
PASS cursor.value.y is "b"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 5
PASS cursor.primaryKey is "bar"
PASS cursor.value.y is "b"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 6
PASS cursor.primaryKey is "bar"
PASS cursor.value.y is "b"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 7
PASS cursor.primaryKey is "baz"
PASS cursor.value.y is "c"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 8
PASS cursor.primaryKey is "baz"
PASS cursor.value.y is "c"
cursor.continue()
cursor = event.target.result
PASS ex is non-null.
PASS cursor.key is 9
PASS cursor.primaryKey is "bloop"
PASS cursor.value.y is "d"
cursor.continue()
cursor = event.target.result
PASS expected.length is 0
transaction = db.transaction(['store'])
transaction.objectStore('store').index('index')
index.count()
PASS event.target.result is 10
index.count(7)
PASS event.target.result is 1
PASS successfullyParsed is true
TEST COMPLETE