Skip to content

Commit 8f17185

Browse files
IndexedDB: Add test for commit order of empty transactions (#3154)
Tracked by w3c/IndexedDB#77 Ensure that a transaction with no requests filed against it still completes in the same order as a transaction with requests (i.e. after previous readwrite transactions with overlapping scope).
1 parent 2c227d3 commit 8f17185

File tree

4 files changed

+125
-50
lines changed

4 files changed

+125
-50
lines changed

IndexedDB/idbobjectstore_createIndex14-exception_order.htm

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,10 @@
44
<link rel="help" href="http://w3c.github.io/IndexedDB/#dom-idbobjectstore-createindex">
55
<script src="/resources/testharness.js"></script>
66
<script src="/resources/testharnessreport.js"></script>
7+
<script src="support.js"></script>
78
<script>
89

9-
function indexeddb_test(description, upgrade_func, open_func = null) {
10-
async_test(function(t) {
11-
var dbname = document.location + "-" + t.name;
12-
var del = indexedDB.deleteDatabase(dbname);
13-
del.onerror = t.unreached_func("deleteDatabase should succeed");
14-
var open = indexedDB.open(dbname, 1);
15-
open.onerror = t.unreached_func("open should succeed");
16-
open.onupgradeneeded = t.step_func(function() {
17-
var db = open.result;
18-
var tx = open.transaction;
19-
upgrade_func(t, db, tx);
20-
});
21-
if (open_func) {
22-
open.onsuccess = t.step_func(function() {
23-
var db = open.result;
24-
open_func(t, db);
25-
});
26-
}
27-
}, description);
28-
}
29-
3010
indexeddb_test(
31-
"InvalidStateError(Incorrect mode) vs. TransactionInactiveError",
3211
function(t, db, txn) {
3312
var store = db.createObjectStore("s");
3413
},
@@ -41,12 +20,12 @@
4120
}, "Mode check should precede state check of the transaction");
4221
t.done();
4322
};
44-
}
23+
},
24+
"InvalidStateError(Incorrect mode) vs. TransactionInactiveError"
4525
);
4626

4727
var gDeletedObjectStore;
4828
indexeddb_test(
49-
"InvalidStateError(Deleted ObjectStore) vs. TransactionInactiveError",
5029
function(t, db, txn) {
5130
gDeletedObjectStore = db.createObjectStore("s");
5231
db.deleteObjectStore("s");
@@ -56,11 +35,12 @@
5635
}, "Deletion check should precede transaction-state check");
5736
t.done();
5837
};
59-
}
38+
},
39+
null,
40+
"InvalidStateError(Deleted ObjectStore) vs. TransactionInactiveError"
6041
);
6142

6243
indexeddb_test(
63-
"TransactionInactiveError vs. ConstraintError",
6444
function(t, db, txn) {
6545
var store = db.createObjectStore("s");
6646
store.createIndex("index", "foo");
@@ -70,11 +50,12 @@
7050
}, "Transaction-state check should precede index name check");
7151
t.done();
7252
};
73-
}
53+
},
54+
null,
55+
"TransactionInactiveError vs. ConstraintError"
7456
);
7557

7658
indexeddb_test(
77-
"ConstraintError vs. SyntaxError",
7859
function(t, db) {
7960
var store = db.createObjectStore("s");
8061
store.createIndex("index", "foo");
@@ -86,11 +67,12 @@
8667
["invalid key path 1", "invalid key path 2"]);
8768
}, "Index name check should precede syntax check of the key path");
8869
t.done();
89-
}
70+
},
71+
null,
72+
"ConstraintError vs. SyntaxError"
9073
);
9174

9275
indexeddb_test(
93-
"SyntaxError vs. InvalidAccessError",
9476
function(t, db) {
9577
var store = db.createObjectStore("s");
9678
assert_throws("SyntaxError", function() {
@@ -99,7 +81,9 @@
9981
{ multiEntry: true });
10082
}, "Syntax check should precede multiEntry check of the key path");
10183
t.done();
102-
}
84+
},
85+
null,
86+
"SyntaxError vs. InvalidAccessError"
10387
);
10488

10589
</script>

IndexedDB/idbtransaction_objectStoreNames.html

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,9 @@
22
<title>IndexedDB: IDBTransaction.objectStoreNames attribute</title>
33
<script src="/resources/testharness.js"></script>
44
<script src="/resources/testharnessreport.js"></script>
5+
<script src="support.js"></script>
56
<script>
67

7-
function indexeddb_test(upgrade_func, open_func, description) {
8-
async_test(function(t) {
9-
var dbname = document.location + '-' + t.name;
10-
var del = indexedDB.deleteDatabase(dbname);
11-
del.onerror = t.unreached_func('deleteDatabase should succeed');
12-
var open = indexedDB.open(dbname, 1);
13-
open.onerror = t.unreached_func('open should succeed');
14-
open.onupgradeneeded = t.step_func(function() {
15-
var db = open.result;
16-
var tx = open.transaction;
17-
upgrade_func(t, db, tx);
18-
});
19-
open.onsuccess = t.step_func(function() {
20-
var db = open.result;
21-
open_func(t, db);
22-
});
23-
}, description);
24-
}
25-
268
function with_stores_test(store_names, open_func, description) {
279
indexeddb_test(function(t, db, tx) {
2810
store_names.forEach(function(name) {

IndexedDB/support.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,23 @@ function createdb_for_multiple_tests(dbname, version) {
101101
function assert_key_equals(actual, expected, description) {
102102
assert_equals(indexedDB.cmp(actual, expected), 0, description);
103103
}
104+
105+
function indexeddb_test(upgrade_func, open_func, description) {
106+
async_test(function(t) {
107+
var dbname = document.location + '-' + t.name;
108+
var del = indexedDB.deleteDatabase(dbname);
109+
del.onerror = t.unreached_func('deleteDatabase should succeed');
110+
var open = indexedDB.open(dbname, 1);
111+
open.onerror = t.unreached_func('open should succeed');
112+
open.onupgradeneeded = t.step_func(function() {
113+
var db = open.result;
114+
var tx = open.transaction;
115+
upgrade_func(t, db, tx);
116+
});
117+
open.onsuccess = t.step_func(function() {
118+
var db = open.result;
119+
if (open_func)
120+
open_func(t, db);
121+
});
122+
}, description);
123+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<!DOCTYPE html>
2+
<title>IndexedDB: Commit ordering of empty transactions</title>
3+
<script src='../../resources/testharness.js'></script>
4+
<script src='../../resources/testharnessreport.js'></script>
5+
<script src='support.js'></script>
6+
<script>
7+
8+
// Call with a test object and array of expected values. Returns a
9+
// function to call with each actual value. Once the expected number
10+
// of values is seen, asserts that the value orders match and completes
11+
// the test.
12+
function expect(t, expected) {
13+
var results = [];
14+
return result => {
15+
results.push(result);
16+
if (results.length === expected.length) {
17+
assert_array_equals(results, expected);
18+
t.done();
19+
}
20+
};
21+
}
22+
23+
indexeddb_test(
24+
(t, db) => {
25+
db.createObjectStore('store');
26+
},
27+
(t, db) => {
28+
var saw = expect(t, ['rq1.onsuccess',
29+
'rq2.onsuccess',
30+
'tx1.oncomplete',
31+
'tx2.oncomplete']);
32+
33+
var tx1 = db.transaction('store', 'readwrite');
34+
tx1.onabort = t.unreached_func('transaction should commit');
35+
tx1.oncomplete = t.step_func(() => saw('tx1.oncomplete'));
36+
37+
var store = tx1.objectStore('store');
38+
var rq1 = store.put('a', 1);
39+
rq1.onerror = t.unreached_func('put should succeed');
40+
rq1.onsuccess = t.step_func(() => {
41+
saw('rq1.onsuccess');
42+
43+
var tx2 = db.transaction('store', 'readonly');
44+
tx2.onabort = t.unreached_func('transaction should commit');
45+
tx2.oncomplete = t.step_func(() => saw('tx2.oncomplete'));
46+
47+
var rq2 = store.put('b', 2);
48+
rq2.onsuccess = t.step_func(() => saw('rq2.onsuccess'));
49+
rq2.onerror = t.unreached_func('request should succeed');
50+
});
51+
52+
},
53+
'Transactions without requests complete in the expected order');
54+
55+
indexeddb_test(
56+
(t, db) => {
57+
db.createObjectStore('store');
58+
},
59+
(t, db) => {
60+
var saw = expect(t, ['rq1.onsuccess',
61+
'rq2.onsuccess',
62+
'tx1.oncomplete',
63+
'tx2.oncomplete',
64+
'tx3.oncomplete']);
65+
var tx1 = db.transaction('store', 'readwrite');
66+
tx1.onabort = t.unreached_func('transaction should commit');
67+
tx1.oncomplete = t.step_func(() => saw('tx1.oncomplete'));
68+
69+
var store = tx1.objectStore('store');
70+
var rq1 = store.put('a', 1);
71+
rq1.onerror = t.unreached_func('put should succeed');
72+
rq1.onsuccess = t.step_func(() => {
73+
saw('rq1.onsuccess');
74+
75+
var tx2 = db.transaction('store', 'readonly');
76+
tx2.onabort = t.unreached_func('transaction should commit');
77+
tx2.oncomplete = t.step_func(() => saw('tx2.oncomplete'));
78+
79+
var tx3 = db.transaction('store', 'readonly');
80+
tx3.onabort = t.unreached_func('transaction should commit');
81+
tx3.oncomplete = t.step_func(() => saw('tx3.oncomplete'));
82+
83+
var rq2 = store.put('b', 2);
84+
rq2.onsuccess = t.step_func(() => saw('rq2.onsuccess'));
85+
rq2.onerror = t.unreached_func('request should succeed');
86+
});
87+
},
88+
'Multiple transactions without requests complete in the expected order');
89+
</script>

0 commit comments

Comments
 (0)