blob: 7d4b0d7f7c7c8c41be52434ea530f0358b5e6fcb [file] [log] [blame]
Joshua Bell8f171852016-06-21 16:14:331<!DOCTYPE html>
2<title>IndexedDB: Commit ordering of empty transactions</title>
Joshua Bellb5747942016-06-27 08:32:393<script src="/resources/testharness.js"></script>
4<script src="/resources/testharnessreport.js"></script>
5<script src="support.js"></script>
Joshua Bell8f171852016-06-21 16:14:336<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.
12function 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
23indexeddb_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
55indexeddb_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>