1 Test IndexedDB's IDBObjectStore auto-increment feature.
3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
6 dbname = "objectstore-autoincrement.html"
7 indexedDB.deleteDatabase(dbname)
10 store = db.createObjectStore('StoreWithKeyPath', {keyPath: 'id', autoIncrement: true})
11 db.createObjectStore('StoreWithAutoIncrement', {autoIncrement: true})
12 db.createObjectStore('PlainOldStore', {autoIncrement: false})
13 db.createObjectStore('StoreWithLongKeyPath', {keyPath: 'a.b.c.id', autoIncrement: true})
14 storeNames = db.objectStoreNames
15 PASS store.name is "StoreWithKeyPath"
16 PASS store.keyPath is "id"
17 PASS storeNames.contains('StoreWithKeyPath') is true
18 PASS storeNames.contains('StoreWithAutoIncrement') is true
19 PASS storeNames.contains('PlainOldStore') is true
20 PASS storeNames.length is 4
21 setVersionCompleted():
22 trans = db.transaction(['StoreWithKeyPath', 'StoreWithAutoIncrement', 'PlainOldStore'], 'readwrite')
23 store = trans.objectStore('StoreWithKeyPath')
24 Insert into object store with auto increment and key path, with key in the object.
25 store.add({name: 'Jeffersson', number: '7010', id: 3})
26 addJefferssonSuccess():
27 PASS event.target.result is 3
28 Insert into object store with auto increment and key path, without key in the object.
29 store.add({name: 'Lincoln', number: '7012'})
30 addLincolnWithInjectKeySuccess():
31 PASS event.target.result is 4
33 getLincolnAfterInjectedKeySuccess():
34 PASS event.target.result.name is "Lincoln"
35 PASS event.target.result.number is "7012"
36 PASS event.target.result.id is 4
37 store = trans.objectStore('StoreWithAutoIncrement')
38 Insert into object store with key gen using explicit key
39 store.add({name: 'Lincoln', number: '7012'}, 5)
40 addLincolnWithExplicitKeySuccess():
41 PASS event.target.result is 5
44 PASS event.target.result.name is "Lincoln"
45 PASS event.target.result.number is "7012"
46 store.put({name: 'Abraham', number: '2107'})
48 PASS event.target.result is 6
51 PASS event.target.result.name is "Abraham"
52 PASS event.target.result.number is "2107"
53 store = trans.objectStore('PlainOldStore')
54 Try adding with no key to object store without auto increment.
55 Expecting exception from store.add({name: 'Adam'})
56 PASS Exception was thrown.
58 PASS ename is 'DataError'
59 Exception message: Failed to execute 'add' on 'IDBObjectStore': The object store uses out-of-line keys and has no key generator and the key parameter was not provided.
60 store.add({name: 'Adam'}, 1)
62 PASS event.target.result is 1
64 trans = db.transaction('StoreWithLongKeyPath', 'readwrite')
65 store = trans.objectStore('StoreWithLongKeyPath')
66 store.add({foo: 'bar'})
67 store.add({foo: 'bar', a: {}})
68 store.add({foo: 'bar', a: {b: {}}})
69 store.add({foo: 'bar', a: {b: {c: {}}}})
73 expected = cursor.value.a.b.c.id + 1
74 PASS cursor.value.foo is "bar"
75 PASS cursor.value.a.b.c.id is expected
76 expected = cursor.value.a.b.c.id + 1
77 PASS cursor.value.foo is "bar"
78 PASS cursor.value.a.b.c.id is expected
79 expected = cursor.value.a.b.c.id + 1
80 PASS cursor.value.foo is "bar"
81 PASS cursor.value.a.b.c.id is expected
82 expected = cursor.value.a.b.c.id + 1
84 PASS successfullyParsed is true