2 <title>IndexedDB: Verify transaction activation behavior around microtasks
</title>
3 <script src=
"../../resources/testharness.js"></script>
4 <script src=
"../../resources/testharnessreport.js"></script>
5 <script src=
"resources/testharness-helpers.js"></script>
8 function isTransactionActive(tx
, storeName
) {
10 tx
.objectStore(storeName
).get(0);
13 // The exception could be TransactionInactiveError or InvalidStateError
14 // depending on the test and whether the transaction has committed yet.
21 db
.createObjectStore('store');
24 Promise
.resolve().then(t
.step_func(function() {
25 var tx
= db
.transaction('store');
26 var request
= tx
.objectStore('store').get(0);
27 request
.onerror
= t
.unreached_func('request should not fail');
28 request
.onsuccess
= t
.step_func(function() {
29 assert_true(isTransactionActive(tx
, 'store'),
30 'Transaction should be active during event dispatch');
31 setTimeout(t
.step_func(function() {
32 assert_false(isTransactionActive(tx
, 'store'),
33 'Transaction should be inactive once control returns to event loop');
39 'Transactions created in microtasks are deactivated when control returns to the event loop'
44 db
.createObjectStore('store');
47 var aesAlgorithmKeyGen
= {name
: "AES-CBC", length
: 128};
48 crypto
.subtle
.generateKey(aesAlgorithmKeyGen
, false, ["encrypt"]).then(t
.step_func(function() {
49 var tx
= db
.transaction('store');
50 var request
= tx
.objectStore('store').get(0);
51 request
.onerror
= t
.unreached_func('request should not fail');
52 request
.onsuccess
= t
.step_func(function() {
53 assert_true(isTransactionActive(tx
, 'store'),
54 'Transaction should be active during event dispatch');
55 setTimeout(t
.step_func(function() {
56 assert_false(isTransactionActive(tx
, 'store'),
57 'Transaction should be inactive once control returns to event loop');
63 'Transactions created in microtasks resolved by host behavior are deactivated when control returns to the event loop'
68 db
.createObjectStore('store');
72 Promise
.resolve().then(function() {
73 tx
= db
.transaction('store');
74 assert_true(isTransactionActive(tx
, 'store'),
75 'Transaction should be active when created');
76 }).then(t
.step_func(function() {
77 assert_true(isTransactionActive(tx
, 'store'),
78 'Transaction should be active until control returns to event loop');
79 setTimeout(t
.step_func(function() {
80 assert_false(isTransactionActive(tx
, 'store'),
81 'Transaction should be inactive once control returns to event loop');
86 'Transactions created in microtasks remain active in subsequent microtasks'
91 db
.createObjectStore('store');
94 var tx
= db
.transaction('store');
95 var request
= tx
.objectStore('store').get(0);
96 request
.onerror
= t
.unreached_func('request should not fail');
97 request
.onsuccess
= t
.step_func(function() {
98 assert_true(isTransactionActive(tx
, 'store'),
99 'Transaction should be active during event dispatch');
100 Promise
.resolve().then(t
.step_func(function() {
101 assert_true(isTransactionActive(tx
, 'store'),
102 'Microtasks are run as part of event dispatch, so transaction should still be active');
103 setTimeout(t
.step_func(function() {
104 assert_false(isTransactionActive(tx
, 'store'),
105 'Transaction should be inactive once control returns to the event loop');
111 'Within request event dispatch, transactions remain active across microtasks'