|
1 /** |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 */ |
|
5 |
|
6 var testGenerator = testSteps(); |
|
7 |
|
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 ]; |
|
19 |
|
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; |
|
26 |
|
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); |
|
32 |
|
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 } |
|
44 |
|
45 request.onsuccess = grabEventAndContinueHandler; |
|
46 request.onupgradeneeded = unexpectedSuccessHandler; |
|
47 |
|
48 event = yield undefined; |
|
49 |
|
50 let objectStoreNames = [] |
|
51 for (let i = 0; i < objectStoreInfo.length; i++) { |
|
52 let info = objectStoreInfo[i]; |
|
53 objectStoreNames.push(info.name); |
|
54 |
|
55 is(db.objectStoreNames[info.location], info.name, |
|
56 "Got objectStore name in the right location"); |
|
57 |
|
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 } |
|
66 |
|
67 let trans = db.transaction(objectStoreNames); |
|
68 for (let i = 0; i < objectStoreInfo.length; i++) { |
|
69 let info = objectStoreInfo[i]; |
|
70 |
|
71 is(trans.objectStoreNames[info.location], info.name, |
|
72 "Got objectStore name in the right location"); |
|
73 } |
|
74 |
|
75 db.close(); |
|
76 |
|
77 let request = indexedDB.open(name, 1); |
|
78 request.onerror = errorHandler; |
|
79 request.onsuccess = grabEventAndContinueHandler; |
|
80 request.onupgradeneeded = unexpectedSuccessHandler; |
|
81 let event = yield undefined; |
|
82 |
|
83 let db = event.target.result; |
|
84 |
|
85 let objectStoreNames = [] |
|
86 for (let i = 0; i < objectStoreInfo.length; i++) { |
|
87 let info = objectStoreInfo[i]; |
|
88 objectStoreNames.push(info.name); |
|
89 |
|
90 is(db.objectStoreNames[info.location], info.name, |
|
91 "Got objectStore name in the right location"); |
|
92 |
|
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 } |
|
101 |
|
102 let trans = db.transaction(objectStoreNames); |
|
103 for (let i = 0; i < objectStoreInfo.length; i++) { |
|
104 let info = objectStoreInfo[i]; |
|
105 |
|
106 is(trans.objectStoreNames[info.location], info.name, |
|
107 "Got objectStore name in the right location"); |
|
108 } |
|
109 |
|
110 db.close(); |
|
111 |
|
112 finishTest(); |
|
113 yield undefined; |
|
114 } |