| Test IndexedDB's IDBObjectStore auto-increment feature. |
| |
| 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) |
| createObjectStore(): |
| store = db.createObjectStore('StoreWithKeyPath', {keyPath: 'id', autoIncrement: true}) |
| db.createObjectStore('StoreWithAutoIncrement', {autoIncrement: true}) |
| db.createObjectStore('PlainOldStore', {autoIncrement: false}) |
| db.createObjectStore('StoreWithLongKeyPathAndUTF8', {keyPath: 'a.b.c.køi', autoIncrement: true}) |
| storeNames = db.objectStoreNames |
| PASS store.name is "StoreWithKeyPath" |
| PASS store.keyPath is "id" |
| PASS storeNames.contains('StoreWithKeyPath') is true |
| PASS storeNames.contains('StoreWithAutoIncrement') is true |
| PASS storeNames.contains('PlainOldStore') is true |
| PASS storeNames.length is 4 |
| setVersionCompleted(): |
| trans = db.transaction(['StoreWithKeyPath', 'StoreWithAutoIncrement', 'PlainOldStore'], 'readwrite') |
| store = trans.objectStore('StoreWithKeyPath') |
| Insert into object store with auto increment and key path, with key in the object. |
| store.add({name: 'Jeffersson', number: '7010', id: 3}) |
| addJefferssonSuccess(): |
| PASS event.target.result is 3 |
| Insert into object store with auto increment and key path, without key in the object. |
| store.add({name: 'Lincoln', number: '7012'}) |
| addLincolnWithInjectKeySuccess(): |
| PASS event.target.result is 4 |
| store.get(4) |
| getLincolnAfterInjectedKeySuccess(): |
| PASS event.target.result.name is "Lincoln" |
| PASS event.target.result.number is "7012" |
| PASS event.target.result.id is 4 |
| store.add({name: 'Bob', number: Uint8Array.from([100, 101])}) |
| putBobSuccess(): |
| PASS event.target.result is 5 |
| store.get(5) |
| getBobSuccess(): |
| PASS event.target.result.name is "Bob" |
| PASS event.target.result.number is [100, 101] |
| store = trans.objectStore('StoreWithAutoIncrement') |
| Insert into object store with key gen using explicit key |
| store.add({name: 'Lincoln', number: '7012'}, 6) |
| addLincolnWithExplicitKeySuccess(): |
| PASS event.target.result is 6 |
| store.get(6) |
| getLincolnSuccess(): |
| PASS event.target.result.name is "Lincoln" |
| PASS event.target.result.number is "7012" |
| store.put({name: 'Abraham', number: '2107'}) |
| putAbrahamSuccess(): |
| PASS event.target.result is 7 |
| store.get(7) |
| getAbrahamSuccess(): |
| PASS event.target.result.name is "Abraham" |
| PASS event.target.result.number is "2107" |
| store = trans.objectStore('PlainOldStore') |
| Try adding with no key to object store without auto increment. |
| Expecting exception from store.add({name: 'Adam'}) |
| PASS Exception was thrown. |
| PASS code is 0 |
| PASS ename is 'DataError' |
| Exception message: Failed to store record in an IDBObjectStore: The object store uses out-of-line keys and has no key generator and the key parameter was not provided. |
| store.add({name: 'Adam'}, 1) |
| addAdamSuccess(): |
| PASS event.target.result is 1 |
| testLongKeyPath(): |
| trans = db.transaction('StoreWithLongKeyPathAndUTF8', 'readwrite') |
| store = trans.objectStore('StoreWithLongKeyPathAndUTF8') |
| store.add({foo: 'bar'}) |
| store.add({foo: 'bar', a: {}}) |
| store.add({foo: 'bar', a: {b: {}}}) |
| store.add({foo: 'bar', a: {b: {c: {}}}}) |
| store.openCursor() |
| expected = null |
| count = 0 |
| expected = cursor.value.a.b.c.køi + 1 |
| PASS cursor.value.foo is "bar" |
| PASS cursor.value.a.b.c.køi is expected |
| expected = cursor.value.a.b.c.køi + 1 |
| PASS cursor.value.foo is "bar" |
| PASS cursor.value.a.b.c.køi is expected |
| expected = cursor.value.a.b.c.køi + 1 |
| PASS cursor.value.foo is "bar" |
| PASS cursor.value.a.b.c.køi is expected |
| expected = cursor.value.a.b.c.køi + 1 |
| PASS count is 4 |
| PASS successfullyParsed is true |
| |
| TEST COMPLETE |
| |