blob: 175b5ea922f7fb5cbb0db1b7ad5214759d43e6e4 [file] [log] [blame]
Test IndexedDB: iterating backwards through an index, skipping duplicates
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)
objectStore = db.createObjectStore(objectStoreName);
First, add all our data to the object store.
request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
Now create the indexes.
objectStore.createIndex(indexData[i].name, indexData[i].keyPath, indexData[i].options);
objectStore.createIndex(indexData[i].name, indexData[i].keyPath, indexData[i].options);
objectStore.createIndex(indexData[i].name, indexData[i].keyPath, indexData[i].options);
trans = db.transaction(objectStoreName, 'readwrite')
objectStore = trans.objectStore(objectStoreName)
testPrev()
trans = db.transaction(objectStoreName)
objectStore = trans.objectStore(objectStoreName);
keyIndex = 8;
request = objectStore.index('height').openCursor(null, 'prev');
cursor = event.target.result;
PASS cursor.key is 73
PASS cursor.primaryKey is '237-23-7740'
PASS cursor.value.name is 'Sam'
PASS cursor.value.height is 73
PASS cursor.value.weight is 110
cursor.continue();
keyIndex--;
=> 7
cursor = event.target.result;
PASS cursor.key is 73
PASS cursor.primaryKey is '237-23-7734'
PASS cursor.value.name is 'Ron'
PASS cursor.value.height is 73
PASS cursor.value.weight is 180
cursor.continue();
keyIndex--;
=> 6
cursor = event.target.result;
PASS cursor.key is 65
PASS cursor.primaryKey is '237-23-7739'
PASS cursor.value.name is 'Jef'
PASS cursor.value.height is 65
PASS cursor.value.weight is 120
cursor.continue();
keyIndex--;
=> 5
cursor = event.target.result;
PASS cursor.key is 65
PASS cursor.primaryKey is '237-23-7738'
PASS cursor.value.name is 'Leo'
PASS cursor.value.height is 65
PASS cursor.value.weight is 180
cursor.continue();
keyIndex--;
=> 4
cursor = event.target.result;
PASS cursor.key is 65
PASS cursor.primaryKey is '237-23-7737'
PASS cursor.value.name is 'Pat'
PASS cursor.value.height is 65
PASS cursor.value.weight is 100
cursor.continue();
keyIndex--;
=> 3
cursor = event.target.result;
PASS cursor.key is 65
PASS cursor.primaryKey is '237-23-7736'
PASS cursor.value.name is 'Joe'
PASS cursor.value.height is 65
PASS cursor.value.weight is 150
cursor.continue();
keyIndex--;
=> 2
cursor = event.target.result;
PASS cursor.key is 60
PASS cursor.primaryKey is '237-23-7732'
PASS cursor.value.name is 'Bob'
PASS cursor.value.height is 60
PASS cursor.value.weight is 120
cursor.continue();
keyIndex--;
=> 1
cursor = event.target.result;
PASS cursor.key is 58
PASS cursor.primaryKey is '237-23-7735'
PASS cursor.value.name is 'Sue'
PASS cursor.value.height is 58
PASS cursor.value.weight is 130
cursor.continue();
keyIndex--;
=> 0
cursor = event.target.result;
PASS cursor.key is 52
PASS cursor.primaryKey is '237-23-7733'
PASS cursor.value.name is 'Ann'
PASS cursor.value.height is 52
PASS cursor.value.weight is 110
cursor.continue();
keyIndex--;
=> -1
cursor = event.target.result;
No cursor: null
PASS keyIndex is -1
testPrevNoDuplicate()
objectStore = db.transaction(objectStoreName).objectStore(objectStoreName);
keyIndex = 8;
request = objectStore.index('height').openCursor(null, 'prevunique');
cursor = event.target.result;
keyIndex -= 1
=> Entering with keyIndex = 7
PASS cursor.key is 73
PASS cursor.primaryKey is '237-23-7734'
PASS cursor.value.name is 'Ron'
PASS cursor.value.height is 73
PASS cursor.value.weight is 180
cursor.continue();
keyIndex--;
cursor = event.target.result;
keyIndex -= 3;
=> Entering with keyIndex = 3
PASS cursor.key is 65
PASS cursor.primaryKey is '237-23-7736'
PASS cursor.value.name is 'Joe'
PASS cursor.value.height is 65
PASS cursor.value.weight is 150
cursor.continue();
keyIndex--;
cursor = event.target.result;
=> Entering with keyIndex = 2
PASS cursor.key is 60
PASS cursor.primaryKey is '237-23-7732'
PASS cursor.value.name is 'Bob'
PASS cursor.value.height is 60
PASS cursor.value.weight is 120
cursor.continue();
keyIndex--;
cursor = event.target.result;
=> Entering with keyIndex = 1
PASS cursor.key is 58
PASS cursor.primaryKey is '237-23-7735'
PASS cursor.value.name is 'Sue'
PASS cursor.value.height is 58
PASS cursor.value.weight is 130
cursor.continue();
keyIndex--;
cursor = event.target.result;
=> Entering with keyIndex = 0
PASS cursor.key is 52
PASS cursor.primaryKey is '237-23-7733'
PASS cursor.value.name is 'Ann'
PASS cursor.value.height is 52
PASS cursor.value.weight is 110
cursor.continue();
keyIndex--;
cursor = event.target.result;
=> Entering with keyIndex = -1
No cursor: null
PASS keyIndex is -1
PASS successfullyParsed is true
TEST COMPLETE