blob: 0ce1e03f8a867d213900e965cfbee586fcf17683 [file] [log] [blame]
Test IndexedDB: mutating records with a r/w cursor updates indexes on those records
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
firstValue = 'hi';
secondValue = 'bye';
objectStoreInfo = [
{ name: '1', options: {}, key: 1,
entry: { data: firstValue } },
{ name: '2', options: { keyPath: 'foo' },
entry: { foo: 1, data: firstValue } },
{ name: '3', options: { autoIncrement: true },
entry: { data: firstValue } },
{ name: '4', options: { keyPath: 'foo', autoIncrement: true },
entry: { data: firstValue } },
];
i = 0;
indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
indexedDB.deleteDatabase(dbname)
info = objectStoreInfo[i];
indexedDB.open(dbname)
setupObjectStoreAndCreateIndex():
db = event.target.result
objectStore = db.createObjectStore(info.name, info.options);
index = objectStore.createIndex('data_index', 'data', { unique: false });
uniqueIndex = objectStore.createIndex('unique_data_index', 'data', { unique: true });
request = objectStore.add(info.entry, info.key);
trans = db.transaction(info.name, 'readwrite')
trans.oncomplete = test
objectStore = trans.objectStore(info.name)
index = objectStore.index('data_index')
uniqueIndex = objectStore.index('unique_data_index')
request = objectStore.openCursor();
cursor = request.result;
value = cursor.value;
value.data = secondValue;
request = cursor.update(value);
request = index.get(secondValue);
PASS value.data is event.target.result.data
request = uniqueIndex.get(secondValue);
PASS value.data is event.target.result.data
i++;
db.close()
indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
indexedDB.deleteDatabase(dbname)
info = objectStoreInfo[i];
indexedDB.open(dbname)
setupObjectStoreAndCreateIndex():
db = event.target.result
objectStore = db.createObjectStore(info.name, info.options);
index = objectStore.createIndex('data_index', 'data', { unique: false });
uniqueIndex = objectStore.createIndex('unique_data_index', 'data', { unique: true });
request = objectStore.add(info.entry);
trans = db.transaction(info.name, 'readwrite')
trans.oncomplete = test
objectStore = trans.objectStore(info.name)
index = objectStore.index('data_index')
uniqueIndex = objectStore.index('unique_data_index')
request = objectStore.openCursor();
cursor = request.result;
value = cursor.value;
value.data = secondValue;
request = cursor.update(value);
request = index.get(secondValue);
PASS value.data is event.target.result.data
request = uniqueIndex.get(secondValue);
PASS value.data is event.target.result.data
i++;
db.close()
indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
indexedDB.deleteDatabase(dbname)
info = objectStoreInfo[i];
indexedDB.open(dbname)
setupObjectStoreAndCreateIndex():
db = event.target.result
objectStore = db.createObjectStore(info.name, info.options);
index = objectStore.createIndex('data_index', 'data', { unique: false });
uniqueIndex = objectStore.createIndex('unique_data_index', 'data', { unique: true });
request = objectStore.add(info.entry);
trans = db.transaction(info.name, 'readwrite')
trans.oncomplete = test
objectStore = trans.objectStore(info.name)
index = objectStore.index('data_index')
uniqueIndex = objectStore.index('unique_data_index')
request = objectStore.openCursor();
cursor = request.result;
value = cursor.value;
value.data = secondValue;
request = cursor.update(value);
request = index.get(secondValue);
PASS value.data is event.target.result.data
request = uniqueIndex.get(secondValue);
PASS value.data is event.target.result.data
i++;
db.close()
indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
indexedDB.deleteDatabase(dbname)
info = objectStoreInfo[i];
indexedDB.open(dbname)
setupObjectStoreAndCreateIndex():
db = event.target.result
objectStore = db.createObjectStore(info.name, info.options);
index = objectStore.createIndex('data_index', 'data', { unique: false });
uniqueIndex = objectStore.createIndex('unique_data_index', 'data', { unique: true });
request = objectStore.add(info.entry);
trans = db.transaction(info.name, 'readwrite')
trans.oncomplete = test
objectStore = trans.objectStore(info.name)
index = objectStore.index('data_index')
uniqueIndex = objectStore.index('unique_data_index')
request = objectStore.openCursor();
cursor = request.result;
value = cursor.value;
value.data = secondValue;
request = cursor.update(value);
request = index.get(secondValue);
PASS value.data is event.target.result.data
request = uniqueIndex.get(secondValue);
PASS value.data is event.target.result.data
i++;
db.close()
PASS successfullyParsed is true
TEST COMPLETE