Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
1 /**
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
6 var testGenerator = testSteps();
8 function testSteps()
9 {
10 const name = this.window ? window.location.pathname : "Splendid Test";
11 const objectStoreInfo = [
12 { name: "foo", options: { keyPath: "id" }, location: 1 },
13 { name: "bar", options: { keyPath: "id" }, location: 0 },
14 ];
15 const indexInfo = [
16 { name: "foo", keyPath: "value", location: 1 },
17 { name: "bar", keyPath: "value", location: 0 },
18 ];
20 let request = indexedDB.open(name, 1);
21 request.onerror = errorHandler;
22 request.onupgradeneeded = grabEventAndContinueHandler;
23 request.onsuccess = unexpectedSuccessHandler;
24 let event = yield undefined;
25 let db = event.target.result;
27 for (let i = 0; i < objectStoreInfo.length; i++) {
28 let info = objectStoreInfo[i];
29 let objectStore = info.hasOwnProperty("options") ?
30 db.createObjectStore(info.name, info.options) :
31 db.createObjectStore(info.name);
33 // Test index creation, and that it ends up in indexNames.
34 let objectStoreName = info.name;
35 for (let j = 0; j < indexInfo.length; j++) {
36 let info = indexInfo[j];
37 let count = objectStore.indexNames.length;
38 let index = info.hasOwnProperty("options") ?
39 objectStore.createIndex(info.name, info.keyPath,
40 info.options) :
41 objectStore.createIndex(info.name, info.keyPath);
42 }
43 }
45 request.onsuccess = grabEventAndContinueHandler;
46 request.onupgradeneeded = unexpectedSuccessHandler;
48 event = yield undefined;
50 let objectStoreNames = []
51 for (let i = 0; i < objectStoreInfo.length; i++) {
52 let info = objectStoreInfo[i];
53 objectStoreNames.push(info.name);
55 is(db.objectStoreNames[info.location], info.name,
56 "Got objectStore name in the right location");
58 let trans = db.transaction(info.name);
59 let objectStore = trans.objectStore(info.name);
60 for (let j = 0; j < indexInfo.length; j++) {
61 let info = indexInfo[j];
62 is(objectStore.indexNames[info.location], info.name,
63 "Got index name in the right location");
64 }
65 }
67 let trans = db.transaction(objectStoreNames);
68 for (let i = 0; i < objectStoreInfo.length; i++) {
69 let info = objectStoreInfo[i];
71 is(trans.objectStoreNames[info.location], info.name,
72 "Got objectStore name in the right location");
73 }
75 db.close();
77 let request = indexedDB.open(name, 1);
78 request.onerror = errorHandler;
79 request.onsuccess = grabEventAndContinueHandler;
80 request.onupgradeneeded = unexpectedSuccessHandler;
81 let event = yield undefined;
83 let db = event.target.result;
85 let objectStoreNames = []
86 for (let i = 0; i < objectStoreInfo.length; i++) {
87 let info = objectStoreInfo[i];
88 objectStoreNames.push(info.name);
90 is(db.objectStoreNames[info.location], info.name,
91 "Got objectStore name in the right location");
93 let trans = db.transaction(info.name);
94 let objectStore = trans.objectStore(info.name);
95 for (let j = 0; j < indexInfo.length; j++) {
96 let info = indexInfo[j];
97 is(objectStore.indexNames[info.location], info.name,
98 "Got index name in the right location");
99 }
100 }
102 let trans = db.transaction(objectStoreNames);
103 for (let i = 0; i < objectStoreInfo.length; i++) {
104 let info = objectStoreInfo[i];
106 is(trans.objectStoreNames[info.location], info.name,
107 "Got objectStore name in the right location");
108 }
110 db.close();
112 finishTest();
113 yield undefined;
114 }