1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// META: title=Index Tombstones
// META: script=resources/support-promises.js
// This test is used to trigger a special case in Chrome with how it deals with
// index creation & modification. This had caused issues before.
// See https://crbug.com/1033996
async function iterateAndReturnAllCursorResult(testCase, cursorRequest) {
return new Promise((resolve, reject) => {
let results = [];
cursorRequest.onsuccess = testCase.step_func(function(event) {
const cursor = event.target.result;
if (!cursor) {
resolve(results);
return;
}
results.push(cursor.value);
cursor.continue();
});
cursorRequest.onerror = reject;
});
}
async function createTombstones(testCase, db) {
const txn1 = db.transaction(['objectStore'], 'readwrite');
txn1.objectStore('objectStore').add({key: 'firstItem', indexedOn: 1});
txn1.objectStore('objectStore').add({key: 'secondItem', indexedOn: 2});
txn1.objectStore('objectStore').add({key: 'thirdItem', indexedOn: 3});
const txn2 = db.transaction(['objectStore'], 'readwrite');
txn2.objectStore('objectStore').put({key: 'firstItem', indexedOn: -10});
txn2.objectStore('objectStore').put({key: 'secondItem', indexedOn: 4});
txn2.objectStore('objectStore').put({key: 'thirdItem', indexedOn: 10});
await promiseForTransaction(testCase, txn1);
await promiseForTransaction(testCase, txn2);
}
async function run_test(testCase, transactionMode, direction) {
const db = await createDatabase(testCase, db => {
db.createObjectStore('objectStore', {keyPath: 'key'})
.createIndex('index', 'indexedOn');
});
await createTombstones(testCase, db);
const txn = db.transaction(['objectStore'], transactionMode);
cursor = txn.objectStore('objectStore').index('index').openCursor(
IDBKeyRange.bound(-11, 11), direction);
let results = await iterateAndReturnAllCursorResult(testCase, cursor);
assert_equals(results.length, 3);
db.close();
}
promise_test(async testCase => {
await run_test(testCase, 'readonly', 'next');
}, 'Forward iteration over an index in a readonly transaction');
promise_test(async testCase => {
await run_test(testCase, 'readonly', 'prev');
}, 'Backward iteration over an index in a readonly transaction');
promise_test(async testCase => {
await run_test(testCase, 'readwrite', 'next');
}, 'Forward iteration over an index in a readwrite transaction');
promise_test(async testCase => {
await run_test(testCase, 'readwrite', 'prev');
}, 'Backward iteration over an index in a readwrite transaction');
|