Skip to content

Commit c6cbeb6

Browse files
IndexedDB: Implement IDBIndex::getAllRecords() behind flag
This change is very similar to the `IDBObjectStore::getAllRecords()` implementation found here: https://chromium-review.googlesource.com/c/chromium/src/+/5911615 The `IDBIndex` version of `getAllRecords()` provides the index key for the `IDBRecord::key` attribute. For testing, adds `idbindex_getAllRecords.tentative.any.js`, which forks the existing `IDBIndex::getAll()` test, but adds new test cases for direction and large values. This change updates `support-get-all.js` to include common utility and setup code shared between the `IDBIndex` WPT's for `getAll()`, `getAllKeys()`, and `getAllRecords()`. Bug: 40746016 Change-Id: I69126cce9260013fb11ab09ac7b897841fa1c4ce Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5907804 Commit-Queue: Steve Becker <[email protected]> Reviewed-by: Abhishek Shanthkumar <[email protected]> Cr-Commit-Position: refs/heads/main@{#1383127}
1 parent 6d039d2 commit c6cbeb6

6 files changed

+484
-230
lines changed

IndexedDB/idbindex_getAll.any.js

+126-79
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,12 @@
1-
// META: global=window,worker
21
// META: title=IndexedDB: Test IDBIndex.getAll
2+
// META: global=window,worker
3+
// META: script=resources/nested-cloning-common.js
34
// META: script=resources/support.js
5+
// META: script=resources/support-get-all.js
6+
// META: script=resources/support-promises.js
47

58
'use_strict';
69

7-
const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
8-
const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
9-
10-
function getall_test(func, name) {
11-
indexeddb_test(
12-
function(t, connection, tx) {
13-
let store = connection.createObjectStore('generated',
14-
{autoIncrement: true, keyPath: 'id'});
15-
let index = store.createIndex('test_idx', 'upper');
16-
alphabet.forEach(function(letter) {
17-
store.put({ch: letter, upper: letter.toUpperCase()});
18-
});
19-
20-
store = connection.createObjectStore('out-of-line', null);
21-
index = store.createIndex('test_idx', 'upper');
22-
alphabet.forEach(function(letter) {
23-
store.put({ch: letter, upper: letter.toUpperCase()}, letter);
24-
});
25-
26-
store = connection.createObjectStore('out-of-line-not-unique', null);
27-
index = store.createIndex('test_idx', 'half');
28-
alphabet.forEach(function(letter) {
29-
if (letter <= 'm')
30-
store.put({ch: letter, half: 'first'}, letter);
31-
else
32-
store.put({ch: letter, half: 'second'}, letter);
33-
});
34-
35-
store = connection.createObjectStore('out-of-line-multi', null);
36-
index = store.createIndex('test_idx', 'attribs', {multiEntry: true});
37-
alphabet.forEach(function(letter) {
38-
attrs = [];
39-
if (['a', 'e', 'i', 'o', 'u'].indexOf(letter) != -1)
40-
attrs.push('vowel');
41-
else
42-
attrs.push('consonant');
43-
if (letter == 'a')
44-
attrs.push('first');
45-
if (letter == 'z')
46-
attrs.push('last');
47-
store.put({ch: letter, attribs: attrs}, letter);
48-
});
49-
50-
store = connection.createObjectStore('empty', null);
51-
index = store.createIndex('test_idx', 'upper');
52-
},
53-
func,
54-
name
55-
);
56-
}
57-
5810
function createGetAllRequest(t, storeName, connection, range, maxCount) {
5911
const transaction = connection.transaction(storeName, 'readonly');
6012
const store = transaction.objectStore(storeName);
@@ -64,7 +16,8 @@ function createGetAllRequest(t, storeName, connection, range, maxCount) {
6416
return req;
6517
}
6618

67-
getall_test(function(t, connection) {
19+
index_get_all_test(
20+
function(t, connection) {
6821
const req = createGetAllRequest(t, 'out-of-line', connection, 'C');
6922
req.onsuccess = t.step_func(function(evt) {
7023
const data = evt.target.result;
@@ -73,18 +26,22 @@ getall_test(function(t, connection) {
7326
assert_array_equals(data.map(function(e) { return e.upper; }), ['C']);
7427
t.done();
7528
});
76-
}, 'Single item get');
29+
},
30+
'Single item get');
7731

78-
getall_test(function(t, connection) {
32+
index_get_all_test(
33+
function(t, connection) {
7934
const req = createGetAllRequest(t, 'empty', connection);
8035
req.onsuccess = t.step_func(function(evt) {
8136
assert_array_equals(evt.target.result, [],
8237
'getAll() on empty object store should return an empty array');
8338
t.done();
8439
});
85-
}, 'Empty object store');
40+
},
41+
'Empty object store');
8642

87-
getall_test(function(t, connection) {
43+
index_get_all_test(
44+
function(t, connection) {
8845
const req = createGetAllRequest(t, 'out-of-line', connection);
8946
req.onsuccess = t.step_func(function(evt) {
9047
const data = evt.target.result;
@@ -93,9 +50,36 @@ getall_test(function(t, connection) {
9350
assert_array_equals(data.map(function(e) { return e.upper; }), ALPHABET);
9451
t.done();
9552
});
96-
}, 'Get all keys');
53+
},
54+
'Get all');
55+
56+
index_get_all_test((test, connection) => {
57+
const request = createGetAllRequest(test, 'large-values', connection);
58+
request.onsuccess = test.step_func(event => {
59+
const actualResults = event.target.result;
60+
assert_true(Array.isArray(actualResults), 'The results must be an array');
9761

98-
getall_test(function(t, connection) {
62+
const expectedRecords = expectedIndexRecords['large-values'];
63+
assert_equals(
64+
actualResults.length, expectedRecords.length,
65+
'The results array must contain the expected number of records');
66+
67+
// Verify each value that must contain `{ seed, randomValue }`.
68+
for (let i = 0; i < expectedRecords.length; i++) {
69+
assert_equals(
70+
actualResults[i].seed, expectedRecords[i].value.seed,
71+
'The results must contain the expected seed');
72+
73+
assert_large_array_equals(
74+
actualResults[i].randomValue, expectedRecords[i].value.randomValue,
75+
'The results must contain the expected value');
76+
}
77+
test.done();
78+
});
79+
}, 'Get all with large values');
80+
81+
index_get_all_test(
82+
function(t, connection) {
9983
const req = createGetAllRequest(t, 'out-of-line', connection, undefined,
10084
10);
10185
req.onsuccess = t.step_func(function(evt) {
@@ -105,9 +89,11 @@ getall_test(function(t, connection) {
10589
assert_array_equals(data.map(function(e) { return e.upper; }), 'ABCDEFGHIJ'.split(''));
10690
t.done();
10791
});
108-
}, 'maxCount=10');
92+
},
93+
'maxCount=10');
10994

110-
getall_test(function(t, connection) {
95+
index_get_all_test(
96+
function(t, connection) {
11197
const req = createGetAllRequest(t, 'out-of-line', connection,
11298
IDBKeyRange.bound('G', 'M'));
11399
req.onsuccess = t.step_func(function(evt) {
@@ -116,9 +102,11 @@ getall_test(function(t, connection) {
116102
assert_array_equals(data.map(function(e) { return e.upper; }), 'GHIJKLM'.split(''));
117103
t.done();
118104
});
119-
}, 'Get bound range');
105+
},
106+
'Get bound range');
120107

121-
getall_test(function(t, connection) {
108+
index_get_all_test(
109+
function(t, connection) {
122110
const req = createGetAllRequest(t, 'out-of-line', connection,
123111
IDBKeyRange.bound('G', 'M'), 3);
124112
req.onsuccess = t.step_func(function(evt) {
@@ -128,9 +116,11 @@ getall_test(function(t, connection) {
128116
assert_array_equals(data.map(function(e) { return e.upper; }), 'GHI'.split(''));
129117
t.done();
130118
});
131-
}, 'Get bound range with maxCount');
119+
},
120+
'Get bound range with maxCount');
132121

133-
getall_test(function(t, connection) {
122+
index_get_all_test(
123+
function(t, connection) {
134124
const req = createGetAllRequest(t, 'out-of-line', connection,
135125
IDBKeyRange.bound('G', 'K', false, true));
136126
req.onsuccess = t.step_func(function(evt) {
@@ -140,9 +130,11 @@ getall_test(function(t, connection) {
140130
assert_array_equals(data.map(function(e) { return e.upper; }), 'GHIJ'.split(''));
141131
t.done();
142132
});
143-
}, 'Get upper excluded');
133+
},
134+
'Get upper excluded');
144135

145-
getall_test(function(t, connection) {
136+
index_get_all_test(
137+
function(t, connection) {
146138
const req = createGetAllRequest(t, 'out-of-line', connection,
147139
IDBKeyRange.bound('G', 'K', true, false));
148140
req.onsuccess = t.step_func(function(evt) {
@@ -152,9 +144,11 @@ getall_test(function(t, connection) {
152144
assert_array_equals(data.map(function(e) { return e.upper; }), 'HIJK'.split(''));
153145
t.done();
154146
});
155-
}, 'Get lower excluded');
147+
},
148+
'Get lower excluded');
156149

157-
getall_test(function(t, connection) {
150+
index_get_all_test(
151+
function(t, connection) {
158152
const req = createGetAllRequest(t, 'generated',
159153
connection, IDBKeyRange.bound(4, 15), 3);
160154
req.onsuccess = t.step_func(function(evt) {
@@ -163,20 +157,23 @@ getall_test(function(t, connection) {
163157
assert_equals(data.length, 0);
164158
t.done();
165159
});
166-
}, 'Get bound range (generated) with maxCount');
160+
},
161+
'Get bound range (generated) with maxCount');
167162

168-
getall_test(function(t, connection) {
163+
index_get_all_test(
164+
function(t, connection) {
169165
const req = createGetAllRequest(t, 'out-of-line',
170166
connection, "Doesn't exist");
171167
req.onsuccess = t.step_func(function(evt) {
172168
assert_array_equals(evt.target.result, [],
173169
'getAll() using a nonexistent key should return an empty array');
174170
t.done();
175-
req.onerror = t.unreached_func('getAll request should succeed');
176171
});
177-
}, 'Non existent key');
172+
},
173+
'Non existent key');
178174

179-
getall_test(function(t, connection) {
175+
index_get_all_test(
176+
function(t, connection) {
180177
const req = createGetAllRequest(t, 'out-of-line', connection,
181178
undefined, 0);
182179
req.onsuccess = t.step_func(function(evt) {
@@ -186,9 +183,56 @@ getall_test(function(t, connection) {
186183
assert_array_equals(data.map(function(e) { return e.upper; }), ALPHABET);
187184
t.done();
188185
});
189-
}, 'maxCount=0');
186+
},
187+
'maxCount=0');
188+
189+
index_get_all_test(function(test, connection) {
190+
const request = createGetAllRequest(
191+
test, 'out-of-line', connection,
192+
/*query=*/ undefined, /*count=*/ 4294967295);
193+
request.onsuccess = test.step_func(function(event) {
194+
const data = event.target.result;
195+
assert_class_string(data, 'Array', 'result should be an array');
196+
assert_array_equals(
197+
data.map(function(e) {
198+
return e.ch;
199+
}),
200+
alphabet);
201+
assert_array_equals(
202+
data.map(function(e) {
203+
return e.upper;
204+
}),
205+
ALPHABET);
206+
test.done();
207+
});
208+
}, 'Max value count');
190209

191-
getall_test(function(t, connection) {
210+
index_get_all_test((test, connection) => {
211+
const request = createGetAllRequest(
212+
test, /*storeName=*/ 'out-of-line', connection,
213+
IDBKeyRange.upperBound('0'));
214+
request.onsuccess = test.step_func((event) => {
215+
assert_array_equals(
216+
event.target.result, /*expectedResults=*/[],
217+
'getAll() with an empty query range must return an empty array');
218+
test.done();
219+
});
220+
}, 'Query with empty range where first key < upperBound');
221+
222+
index_get_all_test((test, connection) => {
223+
const request = createGetAllRequest(
224+
test, /*storeName=*/ 'out-of-line', connection,
225+
IDBKeyRange.lowerBound('ZZ'));
226+
request.onsuccess = test.step_func((event) => {
227+
assert_array_equals(
228+
event.target.result, /*expectedResults=*/[],
229+
'getAll() with an empty query range must return an empty array');
230+
test.done();
231+
});
232+
}, 'Query with empty range where lowerBound < last key');
233+
234+
index_get_all_test(
235+
function(t, connection) {
192236
const req = createGetAllRequest(t, 'out-of-line-not-unique', connection,
193237
'first');
194238
req.onsuccess = t.step_func(function(evt) {
@@ -198,9 +242,11 @@ getall_test(function(t, connection) {
198242
assert_true(data.every(function(e) { return e.half === 'first'; }));
199243
t.done();
200244
});
201-
}, 'Retrieve multiEntry key');
245+
},
246+
'Retrieve multiEntry key');
202247

203-
getall_test(function(t, connection) {
248+
index_get_all_test(
249+
function(t, connection) {
204250
const req = createGetAllRequest(t, 'out-of-line-multi', connection,
205251
'vowel');
206252
req.onsuccess = t.step_func(function(evt) {
@@ -211,4 +257,5 @@ getall_test(function(t, connection) {
211257
assert_true(data.every(function(e) { return e.attribs[0] === 'vowel'; }));
212258
t.done();
213259
});
214-
}, 'Retrieve one key multiple values');
260+
},
261+
'Retrieve one key multiple values');

0 commit comments

Comments
 (0)