2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
6 /* exported testGenerator */
7 var testGenerator = testSteps();
9 function* testSteps() {
10 const dbName = "window" in this ? window.location.pathname : "test";
11 const objName1 = "foo";
12 const objName2 = "bar";
13 const data1 = "1234567890";
14 const data2 = "0987654321";
15 const dataCount = 500;
17 let request = indexedDB.open(dbName, 1);
18 request.onerror = errorHandler;
19 request.onupgradeneeded = grabEventAndContinueHandler;
21 let event = yield undefined;
23 is(event.type, "upgradeneeded", "Got upgradeneeded");
25 request.onupgradeneeded = errorHandler;
26 request.onsuccess = grabEventAndContinueHandler;
28 let db = request.result;
30 let objectStore1 = db.createObjectStore(objName1, { autoIncrement: true });
31 let objectStore2 = db.createObjectStore(objName2, { autoIncrement: true });
33 info("Created object stores, adding data");
35 for (let i = 0; i < dataCount; i++) {
36 objectStore1.add(data1);
37 objectStore2.add(data2);
40 info("Done adding data");
42 event = yield undefined;
44 is(event.type, "success", "Got success");
46 let readResult = null;
48 let writeAborted = false;
50 info("Creating readwrite transaction");
52 objectStore1 = db.transaction(objName1, "readwrite").objectStore(objName1);
53 objectStore1.openCursor().onsuccess = grabEventAndContinueHandler;
55 event = yield undefined;
57 let cursor = event.target.result;
58 is(cursor.value, data1, "Got correct data for readwrite transaction");
60 info("Modifying object store on readwrite transaction");
65 event = yield undefined;
68 "Done modifying object store on readwrite transaction, creating " +
69 "readonly transaction"
72 objectStore2 = db.transaction(objName2, "readonly").objectStore(objName2);
73 request = objectStore2.getAll();
74 request.onsuccess = function(event) {
75 readResult = event.target.result;
79 "Got correct number of results on readonly transaction"
81 for (let i = 0; i < readResult.length; i++) {
82 is(readResult[i], data2, "Got correct data for readonly transaction");
88 request.onerror = function(event) {
90 readError = event.target.error;
92 ok(false, "Got read error: " + readError.name);
93 event.preventDefault();
100 cursor = event.target.result;
101 is(cursor.value, data1, "Got correct data for readwrite transaction");
103 info("Aborting readwrite transaction");
105 cursor.source.transaction.abort();
108 if (!readError && !readResult) {
109 info("Waiting for readonly transaction to complete");
113 ok(readResult, "Got result from readonly transaction");
114 is(readError, null, "No read error");
115 is(writeAborted, true, "Aborted readwrite transaction");