Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(668)

Side by Side Diff: LayoutTests/storage/indexeddb/mozilla/resources/test_index_getAllObjects.js

Issue 1312983006: Import Mozilla's IndexedDB getAll/getAllKeys tests (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Comment update/whitespace Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Imported from:
2 // * http://mxr.mozilla.org/mozilla-central/source/dom/indexedDB/test/unit/test_ index_getAllObjects.js
3 // Changes:
4 // * added 'use strict' since some ES6 features NYI w/o it
5 // * function -> function*
6 // * this.window -> window
7 // * testGenerator.send() -> testGenerator.next()
8 // * Added deleteDatabase() step to reset storage state
9
10 'use strict';
11 /**
12 * Any copyright is dedicated to the Public Domain.
13 * http://creativecommons.org/publicdomain/zero/1.0/
14 */
15
16 var testGenerator = testSteps();
17
18 function* testSteps()
19 {
20 const name = window ? window.location.pathname : "Splendid Test";
21 indexedDB.deleteDatabase(name);
22 const objectStoreName = "People";
23
24 const objectStoreData = [
25 { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
26 { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
27 { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
28 { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
29 { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
30 { key: "237-23-7737", value: { name: "Pat", height: 65 } }
31 ];
32
33 const indexData = [
34 { name: "name", keyPath: "name", options: { unique: true } },
35 { name: "height", keyPath: "height", options: { unique: false } },
36 { name: "weight", keyPath: "weight", options: { unique: false } }
37 ];
38
39 const objectStoreDataNameSort = [
40 { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
41 { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
42 { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
43 { key: "237-23-7737", value: { name: "Pat", height: 65 } },
44 { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
45 { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } }
46 ];
47
48 const objectStoreDataWeightSort = [
49 { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
50 { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
51 { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
52 { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
53 { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
54 ];
55
56 const objectStoreDataHeightSort = [
57 { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
58 { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
59 { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
60 { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
61 { key: "237-23-7737", value: { name: "Pat", height: 65 } },
62 { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
63 ];
64
65 let request = indexedDB.open(name, 1);
66 request.onerror = errorHandler;
67 request.onupgradeneeded = grabEventAndContinueHandler;
68 request.onsuccess = grabEventAndContinueHandler;
69 let event = yield undefined;
70
71 let db = event.target.result;
72
73 let objectStore = db.createObjectStore(objectStoreName, {});
74
75 // First, add all our data to the object store.
76 let addedData = 0;
77 for (let i in objectStoreData) {
78 request = objectStore.add(objectStoreData[i].value,
79 objectStoreData[i].key);
80 request.onerror = errorHandler;
81 request.onsuccess = function(event) {
82 if (++addedData == objectStoreData.length) {
83 testGenerator.next(event);
84 }
85 }
86 }
87 event = yield undefined;
88
89 // Now create the indexes.
90 for (let i in indexData) {
91 objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
92 indexData[i].options);
93 }
94
95 is(objectStore.indexNames.length, indexData.length, "Good index count");
96 yield undefined;
97
98 objectStore = db.transaction(objectStoreName)
99 .objectStore(objectStoreName);
100
101 request = objectStore.index("height").mozGetAll(65);
102 request.onerror = errorHandler;
103 request.onsuccess = grabEventAndContinueHandler;
104 event = yield undefined;
105
106 is(event.target.result instanceof Array, true, "Got an array object");
107 is(event.target.result.length, 2, "Correct length");
108
109 for (let i in event.target.result) {
110 let result = event.target.result[i];
111 let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
112
113 is(result.name, testObj.name, "Correct name");
114 is(result.height, testObj.height, "Correct height");
115
116 if (testObj.hasOwnProperty("weight")) {
117 is(result.weight, testObj.weight, "Correct weight");
118 }
119 }
120
121 request = objectStore.index("height").mozGetAll(65, 0);
122 request.onerror = errorHandler;
123 request.onsuccess = grabEventAndContinueHandler;
124 event = yield undefined;
125
126 is(event.target.result instanceof Array, true, "Got an array object");
127 is(event.target.result.length, 2, "Correct length");
128
129 for (let i in event.target.result) {
130 let result = event.target.result[i];
131 let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
132
133 is(result.name, testObj.name, "Correct name");
134 is(result.height, testObj.height, "Correct height");
135
136 if (testObj.hasOwnProperty("weight")) {
137 is(result.weight, testObj.weight, "Correct weight");
138 }
139 }
140
141 request = objectStore.index("height").mozGetAll(65, null);
142 request.onerror = errorHandler;
143 request.onsuccess = grabEventAndContinueHandler;
144 event = yield undefined;
145
146 is(event.target.result instanceof Array, true, "Got an array object");
147 is(event.target.result.length, 2, "Correct length");
148
149 for (let i in event.target.result) {
150 let result = event.target.result[i];
151 let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
152
153 is(result.name, testObj.name, "Correct name");
154 is(result.height, testObj.height, "Correct height");
155
156 if (testObj.hasOwnProperty("weight")) {
157 is(result.weight, testObj.weight, "Correct weight");
158 }
159 }
160
161 request = objectStore.index("height").mozGetAll(65, undefined);
162 request.onerror = errorHandler;
163 request.onsuccess = grabEventAndContinueHandler;
164 event = yield undefined;
165
166 is(event.target.result instanceof Array, true, "Got an array object");
167 is(event.target.result.length, 2, "Correct length");
168
169 for (let i in event.target.result) {
170 let result = event.target.result[i];
171 let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
172
173 is(result.name, testObj.name, "Correct name");
174 is(result.height, testObj.height, "Correct height");
175
176 if (testObj.hasOwnProperty("weight")) {
177 is(result.weight, testObj.weight, "Correct weight");
178 }
179 }
180
181 request = objectStore.index("height").mozGetAll();
182 request.onerror = errorHandler;
183 request.onsuccess = grabEventAndContinueHandler;
184 event = yield undefined;
185
186 is(event.target.result instanceof Array, true, "Got an array object");
187 is(event.target.result.length, objectStoreDataHeightSort.length,
188 "Correct length");
189
190 for (let i in event.target.result) {
191 let result = event.target.result[i];
192 let testObj = objectStoreDataHeightSort[i].value;
193
194 is(result.name, testObj.name, "Correct name");
195 is(result.height, testObj.height, "Correct height");
196
197 if (testObj.hasOwnProperty("weight")) {
198 is(result.weight, testObj.weight, "Correct weight");
199 }
200 }
201
202 request = objectStore.index("height").mozGetAll(null, 4);
203 request.onerror = errorHandler;
204 request.onsuccess = grabEventAndContinueHandler;
205 event = yield undefined;
206
207 is(event.target.result instanceof Array, true, "Got an array object");
208 is(event.target.result.length, 4, "Correct length");
209
210 for (let i in event.target.result) {
211 let result = event.target.result[i];
212 let testObj = objectStoreDataHeightSort[i].value;
213
214 is(result.name, testObj.name, "Correct name");
215 is(result.height, testObj.height, "Correct height");
216
217 if (testObj.hasOwnProperty("weight")) {
218 is(result.weight, testObj.weight, "Correct weight");
219 }
220 }
221
222 request = objectStore.index("height").mozGetAll(65, 1);
223 request.onerror = errorHandler;
224 request.onsuccess = grabEventAndContinueHandler;
225 event = yield undefined;
226
227 is(event.target.result instanceof Array, true, "Got an array object");
228 is(event.target.result.length, 1, "Correct length");
229
230 for (let i in event.target.result) {
231 let result = event.target.result[i];
232 let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
233
234 is(result.name, testObj.name, "Correct name");
235 is(result.height, testObj.height, "Correct height");
236
237 if (testObj.hasOwnProperty("weight")) {
238 is(result.weight, testObj.weight, "Correct weight");
239 }
240 }
241
242 finishTest();
243 yield undefined;
244 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698