Skip to content

Commit 6834933

Browse files
IndexedDB: Add tests that verify the source of IDBRequests (#7680)
Missing coverage noted in w3c/IndexedDB#213 The test cases verify the `source` property of requests returned by operations made against stores, indexes, and cursors.
1 parent 75c6dd3 commit 6834933

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!doctype html>
2+
<meta charset=utf-8>
3+
<title>IndexedDB: The source of requests made against cursors</title>
4+
<meta name="help" href="https://w3c.github.io/IndexedDB/#dom-idbrequest-source">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="support.js"></script>
8+
<script>
9+
10+
[
11+
cursor => cursor.update(0),
12+
cursor => cursor.delete()
13+
].forEach(func => indexeddb_test(
14+
(t, db) => {
15+
db.createObjectStore('store', {autoIncrement: true});
16+
},
17+
(t, db) => {
18+
const tx = db.transaction('store', 'readwrite');
19+
const store = tx.objectStore('store');
20+
store.put('value');
21+
store.openCursor().onsuccess = t.step_func(e => {
22+
const cursor = e.target.result;
23+
assert_equals(func(cursor).source, cursor,
24+
`${func}.source should be the cursor itself`);
25+
t.done();
26+
});
27+
},
28+
`The source of the request from ${func} is the cursor itself`
29+
));
30+
31+
</script>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!doctype html>
2+
<meta charset=utf-8>
3+
<title>IndexedDB: The source of requests made against indexes</title>
4+
<meta name="help" href="https://w3c.github.io/IndexedDB/#dom-idbrequest-source">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="support.js"></script>
8+
<script>
9+
10+
[
11+
index => index.get(0),
12+
index => index.getKey(0),
13+
index => index.getAll(),
14+
index => index.getAllKeys(),
15+
index => index.count(),
16+
17+
index => index.openCursor(),
18+
index => index.openKeyCursor()
19+
].forEach(func => indexeddb_test(
20+
(t, db) => {
21+
const store = db.createObjectStore('store', {autoIncrement: true});
22+
store.createIndex('index', 'kp');
23+
},
24+
(t, db) => {
25+
const tx = db.transaction('store', 'readwrite');
26+
const index = tx.objectStore('store').index('index');
27+
assert_equals(func(index).source, index,
28+
`${func}.source should be the index itself`);
29+
t.done();
30+
},
31+
`The source of the request from ${func} is the index itself`
32+
));
33+
34+
</script>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!doctype html>
2+
<meta charset=utf-8>
3+
<title>IndexedDB: The source of requests made against object stores</title>
4+
<meta name="help" href="https://w3c.github.io/IndexedDB/#dom-idbrequest-source">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="support.js"></script>
8+
<script>
9+
10+
[
11+
store => store.put(0),
12+
store => store.add(0),
13+
store => store.delete(0),
14+
store => store.clear(),
15+
16+
store => store.get(0),
17+
store => store.getKey(0),
18+
store => store.getAll(),
19+
store => store.getAllKeys(),
20+
store => store.count(),
21+
22+
store => store.openCursor(),
23+
store => store.openKeyCursor()
24+
].forEach(func => indexeddb_test(
25+
(t, db) => {
26+
db.createObjectStore('store', {autoIncrement: true});
27+
},
28+
(t, db) => {
29+
const tx = db.transaction('store', 'readwrite');
30+
const store = tx.objectStore('store');
31+
32+
assert_equals(func(store).source, store,
33+
`${func}.source should be the object store itself`);
34+
t.done();
35+
},
36+
`The source of the request from ${func} is the object store itself`
37+
));
38+
39+
</script>

0 commit comments

Comments
 (0)