2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
6 const dbName = "window" in this ? window.location.pathname : "test";
10 const idxName1 = "i1";
11 const idxName2 = "i2";
12 const idxKeyPathProp = "idx";
13 const objDataProp = "data";
14 const objData = "1234567890";
15 const objDataCount = 5;
16 const loopCount = 100;
18 /* exported testGenerator */
19 var testGenerator = testSteps();
21 function* testSteps() {
22 let req = indexedDB.open(dbName, dbVersion);
23 req.onerror = errorHandler;
24 req.onupgradeneeded = grabEventAndContinueHandler;
25 req.onsuccess = grabEventAndContinueHandler;
27 let event = yield undefined;
29 is(event.type, "upgradeneeded", "Got upgradeneeded event");
31 let db = event.target.result;
33 let objectStore1 = db.createObjectStore(objName1);
34 objectStore1.createIndex(idxName1, idxKeyPathProp);
36 let objectStore2 = db.createObjectStore(objName2);
37 objectStore2.createIndex(idxName2, idxKeyPathProp);
39 for (let i = 0; i < objDataCount; i++) {
41 data[objDataProp] = objData;
42 data[idxKeyPathProp] = objDataCount - i - 1;
44 objectStore1.add(data, i);
45 objectStore2.add(data, i);
48 event = yield undefined;
50 is(event.type, "success", "Got success event");
52 doReadOnlyTransaction(db, 0, loopCount);
53 doReadWriteTransaction(db, 0, loopCount);
55 // Wait for readonly and readwrite transaction loops to complete.
62 function doReadOnlyTransaction(db, key, remaining) {
64 info("Finished all readonly transactions");
70 "Starting readonly transaction for key " +
77 let objectStore = db.transaction(objName1, "readonly").objectStore(objName1);
78 let index = objectStore.index(idxName1);
80 index.openKeyCursor(key, "prev").onsuccess = function(event) {
81 let cursor = event.target.result;
82 ok(cursor, "Got readonly cursor");
84 objectStore.get(cursor.primaryKey).onsuccess = function(event) {
85 if (++key == objDataCount) {
88 doReadOnlyTransaction(db, key, remaining - 1);
93 function doReadWriteTransaction(db, key, remaining) {
95 info("Finished all readwrite transactions");
101 "Starting readwrite transaction for key " +
108 let objectStore = db.transaction(objName2, "readwrite").objectStore(objName2);
109 objectStore.openCursor(key).onsuccess = function(event) {
110 let cursor = event.target.result;
111 ok(cursor, "Got readwrite cursor");
113 let value = cursor.value;
114 value[idxKeyPathProp]++;
116 cursor.update(value).onsuccess = function(event) {
117 if (++key == objDataCount) {
120 doReadWriteTransaction(db, key, remaining - 1);