Skip to content

Commit

Permalink
IndexedDB: Speed up and refactor IDBIndex get all WPTs
Browse files Browse the repository at this point in the history
Brings the `IDBObjectStore` get all WPT improvements to `IBDIndex`

https://chromium-review.googlesource.com/c/chromium/src/+/6098322

1. Updates test setup skip creating unused `IDBObjectStores` and
`IDBIndexes`.

2. Adds `META: timeout=long`.

3. Refactors the tests to use the `get_all_test()` helper function,
   which eliminates duplicated boilerplate code.

Bug: 378869818,383436041,379457908,379479285
Change-Id: I6a3b0413801512efeefa1e7905851c32d345fe56
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6098818
Reviewed-by: Rahul Singh <rahsin@microsoft.com>
Reviewed-by: Evan Stade <estade@chromium.org>
Commit-Queue: Steve Becker <stevebe@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1397470}
  • Loading branch information
SteveBeckerMSFT authored and chromium-wpt-export-bot committed Dec 17, 2024
1 parent 810cb30 commit bc8ab39
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 714 deletions.
277 changes: 51 additions & 226 deletions IndexedDB/idbindex_getAll.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,258 +4,83 @@
// META: script=resources/support.js
// META: script=resources/support-get-all.js
// META: script=resources/support-promises.js
// META: timeout=long

'use_strict';

function createGetAllRequest(t, storeName, connection, range, maxCount) {
const transaction = connection.transaction(storeName, 'readonly');
const store = transaction.objectStore(storeName);
const index = store.index('test_idx');
const req = index.getAll(range, maxCount);
req.onerror = t.unreached_func('getAll request should succeed');
return req;
}
index_get_all_values_test(
/*storeName=*/ 'out-of-line', /*options=*/ {query: 'C'}, 'Single item get');

index_get_all_test(
function(t, connection) {
const req = createGetAllRequest(t, 'out-of-line', connection, 'C');
req.onsuccess = t.step_func(function(evt) {
const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), ['c']);
assert_array_equals(data.map(function(e) { return e.upper; }), ['C']);
t.done();
});
},
'Single item get');

index_get_all_test(
function(t, connection) {
const req = createGetAllRequest(t, 'empty', connection);
req.onsuccess = t.step_func(function(evt) {
assert_array_equals(evt.target.result, [],
'getAll() on empty object store should return an empty array');
t.done();
});
},
'Empty object store');
index_get_all_values_test(
/*storeName=*/ 'empty', /*options=*/ undefined, 'Empty object store');

index_get_all_test(
function(t, connection) {
const req = createGetAllRequest(t, 'out-of-line', connection);
req.onsuccess = t.step_func(function(evt) {
const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), alphabet);
assert_array_equals(data.map(function(e) { return e.upper; }), ALPHABET);
t.done();
});
},
'Get all');
index_get_all_values_test(
/*storeName=*/ 'out-of-line', /*options=*/ undefined, 'Get all');

index_get_all_test((test, connection) => {
const request = createGetAllRequest(test, 'large-values', connection);
request.onsuccess = test.step_func(event => {
const actualResults = event.target.result;
assert_true(Array.isArray(actualResults), 'The results must be an array');
index_get_all_values_test(
/*storeName=*/ 'generated', /*options=*/ undefined,
'Get all with generated keys');

const expectedRecords = expectedIndexRecords['large-values'];
assert_equals(
actualResults.length, expectedRecords.length,
'The results array must contain the expected number of records');
index_get_all_values_test(
/*storeName=*/ 'large-values', /*options=*/ undefined,
'Get all with large values');

// Verify each value that must contain `{ seed, randomValue }`.
for (let i = 0; i < expectedRecords.length; i++) {
assert_equals(
actualResults[i].seed, expectedRecords[i].value.seed,
'The results must contain the expected seed');

assert_large_array_equals(
actualResults[i].randomValue, expectedRecords[i].value.randomValue,
'The results must contain the expected value');
}
test.done();
});
}, 'Get all with large values');

index_get_all_test(
function(t, connection) {
const req = createGetAllRequest(t, 'out-of-line', connection, undefined,
10);
req.onsuccess = t.step_func(function(evt) {
const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), 'abcdefghij'.split(''));
assert_array_equals(data.map(function(e) { return e.upper; }), 'ABCDEFGHIJ'.split(''));
t.done();
});
},
'maxCount=10');
index_get_all_values_test(
/*storeName=*/ 'out-of-line', /*options=*/ {count: 10}, 'maxCount=10');

index_get_all_test(
function(t, connection) {
const req = createGetAllRequest(t, 'out-of-line', connection,
IDBKeyRange.bound('G', 'M'));
req.onsuccess = t.step_func(function(evt) {
const data = evt.target.result;
assert_array_equals(data.map(function(e) { return e.ch; }), 'ghijklm'.split(''));
assert_array_equals(data.map(function(e) { return e.upper; }), 'GHIJKLM'.split(''));
t.done();
});
},
'Get bound range');
index_get_all_values_test(
/*storeName=*/ 'out-of-line',
/*options=*/ {query: IDBKeyRange.bound('G', 'M')}, 'Get bound range');

index_get_all_test(
function(t, connection) {
const req = createGetAllRequest(t, 'out-of-line', connection,
IDBKeyRange.bound('G', 'M'), 3);
req.onsuccess = t.step_func(function(evt) {
const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), 'ghi'.split(''));
assert_array_equals(data.map(function(e) { return e.upper; }), 'GHI'.split(''));
t.done();
});
},
index_get_all_values_test(
/*storeName=*/ 'out-of-line',
/*options=*/ {query: IDBKeyRange.bound('G', 'M'), count: 3},
'Get bound range with maxCount');

index_get_all_test(
function(t, connection) {
const req = createGetAllRequest(t, 'out-of-line', connection,
IDBKeyRange.bound('G', 'K', false, true));
req.onsuccess = t.step_func(function(evt) {
const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), 'ghij'.split(''));
assert_array_equals(data.map(function(e) { return e.upper; }), 'GHIJ'.split(''));
t.done();
});
index_get_all_values_test(
/*storeName=*/ 'out-of-line', /*options=*/ {
query:
IDBKeyRange.bound('G', 'K', /*lowerOpen=*/ false, /*upperOpen=*/ true)
},
'Get upper excluded');

index_get_all_test(
function(t, connection) {
const req = createGetAllRequest(t, 'out-of-line', connection,
IDBKeyRange.bound('G', 'K', true, false));
req.onsuccess = t.step_func(function(evt) {
const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), 'hijk'.split(''));
assert_array_equals(data.map(function(e) { return e.upper; }), 'HIJK'.split(''));
t.done();
});
index_get_all_values_test(
/*storeName=*/ 'out-of-line', /*options=*/ {
query:
IDBKeyRange.bound('G', 'K', /*lowerOpen=*/ true, /*upperOpen=*/ false)
},
'Get lower excluded');

index_get_all_test(
function(t, connection) {
const req = createGetAllRequest(t, 'generated',
connection, IDBKeyRange.bound(4, 15), 3);
req.onsuccess = t.step_func(function(evt) {
const data = evt.target.result;
assert_true(Array.isArray(data));
assert_equals(data.length, 0);
t.done();
});
},
index_get_all_values_test(
/*storeName=*/ 'generated',
/*options=*/ {query: IDBKeyRange.bound(4, 15), count: 3},
'Get bound range (generated) with maxCount');

index_get_all_test(
function(t, connection) {
const req = createGetAllRequest(t, 'out-of-line',
connection, "Doesn't exist");
req.onsuccess = t.step_func(function(evt) {
assert_array_equals(evt.target.result, [],
'getAll() using a nonexistent key should return an empty array');
t.done();
});
},
index_get_all_values_test(
/*storeName=*/ 'out-of-line', /*options=*/ {query: 'Doesn\'t exist'},
'Non existent key');

index_get_all_test(
function(t, connection) {
const req = createGetAllRequest(t, 'out-of-line', connection,
undefined, 0);
req.onsuccess = t.step_func(function(evt) {
const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), alphabet);
assert_array_equals(data.map(function(e) { return e.upper; }), ALPHABET);
t.done();
});
},
'maxCount=0');
index_get_all_values_test(
/*storeName=*/ 'out-of-line', /*options=*/ {count: 0}, 'maxCount=0');

index_get_all_test(function(test, connection) {
const request = createGetAllRequest(
test, 'out-of-line', connection,
/*query=*/ undefined, /*count=*/ 4294967295);
request.onsuccess = test.step_func(function(event) {
const data = event.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(
data.map(function(e) {
return e.ch;
}),
alphabet);
assert_array_equals(
data.map(function(e) {
return e.upper;
}),
ALPHABET);
test.done();
});
}, 'Max value count');
index_get_all_values_test(
/*storeName=*/ 'out-of-line', /*options=*/ {count: 4294967295},
'Max value count');

index_get_all_test((test, connection) => {
const request = createGetAllRequest(
test, /*storeName=*/ 'out-of-line', connection,
IDBKeyRange.upperBound('0'));
request.onsuccess = test.step_func((event) => {
assert_array_equals(
event.target.result, /*expectedResults=*/[],
'getAll() with an empty query range must return an empty array');
test.done();
});
}, 'Query with empty range where first key < upperBound');
index_get_all_values_test(
/*storeName=*/ 'out-of-line',
/*options=*/ {query: IDBKeyRange.upperBound('0')},
'Query with empty range where first key < upperBound');

index_get_all_test((test, connection) => {
const request = createGetAllRequest(
test, /*storeName=*/ 'out-of-line', connection,
IDBKeyRange.lowerBound('ZZ'));
request.onsuccess = test.step_func((event) => {
assert_array_equals(
event.target.result, /*expectedResults=*/[],
'getAll() with an empty query range must return an empty array');
test.done();
});
}, 'Query with empty range where lowerBound < last key');
index_get_all_values_test(
/*storeName=*/ 'out-of-line',
/*options=*/ {query: IDBKeyRange.lowerBound('ZZ')},
'Query with empty range where lowerBound < last key');

index_get_all_test(
function(t, connection) {
const req = createGetAllRequest(t, 'out-of-line-not-unique', connection,
'first');
req.onsuccess = t.step_func(function(evt) {
const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), 'abcdefghijklm'.split(''));
assert_true(data.every(function(e) { return e.half === 'first'; }));
t.done();
});
},
index_get_all_values_test(
/*storeName=*/ 'out-of-line-not-unique', /*options=*/ {query: 'first'},
'Retrieve multiEntry key');

index_get_all_test(
function(t, connection) {
const req = createGetAllRequest(t, 'out-of-line-multi', connection,
'vowel');
req.onsuccess = t.step_func(function(evt) {
const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), ['a', 'e', 'i', 'o', 'u']);
assert_array_equals(data[0].attribs, ['vowel', 'first']);
assert_true(data.every(function(e) { return e.attribs[0] === 'vowel'; }));
t.done();
});
},
index_get_all_values_test(
/*storeName=*/ 'out-of-line-multi', /*options=*/ {query: 'vowel'},
'Retrieve one key multiple values');
Loading

0 comments on commit bc8ab39

Please sign in to comment.