3 <title>Transaction active flag is set during event dispatch
</title>
4 <link rel=
"help" href=
"https://w3c.github.io/IndexedDB/#fire-success-event">
5 <link rel=
"help" href=
"https://w3c.github.io/IndexedDB/#fire-error-event">
6 <script src=/resources/testharness.js
></script>
7 <script src=/resources/testharnessreport.js
></script>
8 <script src=resources/support.js
></script>
13 db
.createObjectStore('store');
16 const tx
= db
.transaction('store', 'readonly', {durability
: 'relaxed'});
17 const release_tx
= keep_alive(tx
, 'store');
19 assert_true(is_transaction_active(tx
, 'store'),
20 'Transaction should be active after creation');
22 const request
= tx
.objectStore('store').get(0);
23 request
.onerror
= t
.unreached_func('request should succeed');
24 request
.onsuccess
= () => {
25 assert_true(is_transaction_active(tx
, 'store'),
26 'Transaction should be active during success handler');
28 let saw_handler_promise
= false;
29 Promise
.resolve().then(t
.step_func(() => {
30 saw_handler_promise
= true;
31 assert_true(is_transaction_active(tx
, 'store'),
32 'Transaction should be active in handler\'s microtasks');
35 setTimeout(t
.step_func(() => {
36 assert_true(saw_handler_promise
);
37 assert_false(is_transaction_active(tx
, 'store'),
38 'Transaction should be inactive in next task');
44 'Transactions are active during success handlers');
48 db
.createObjectStore('store');
51 const tx
= db
.transaction('store', 'readonly', {durability
: 'relaxed'});
52 const release_tx
= keep_alive(tx
, 'store');
53 assert_true(is_transaction_active(tx
, 'store'),
54 'Transaction should be active after creation');
56 const request
= tx
.objectStore('store').get(0);
57 request
.onerror
= t
.unreached_func('request should succeed');
58 request
.addEventListener('success', () => {
59 assert_true(is_transaction_active(tx
, 'store'),
60 'Transaction should be active during success listener');
62 let saw_listener_promise
= false;
63 Promise
.resolve().then(t
.step_func(() => {
64 saw_listener_promise
= true;
65 assert_true(is_transaction_active(tx
, 'store'),
66 'Transaction should be active in listener\'s microtasks');
69 setTimeout(t
.step_func(() => {
70 assert_true(saw_listener_promise
);
71 assert_false(is_transaction_active(tx
, 'store'),
72 'Transaction should be inactive in next task');
78 'Transactions are active during success listeners');
82 db
.createObjectStore('store');
85 const tx
= db
.transaction('store', 'readwrite', {durability
: 'relaxed'});
86 const release_tx
= keep_alive(tx
, 'store');
87 assert_true(is_transaction_active(tx
, 'store'),
88 'Transaction should be active after creation');
90 tx
.objectStore('store').put(0, 0);
91 const request
= tx
.objectStore('store').add(0, 0);
92 request
.onsuccess
= t
.unreached_func('request should fail');
93 request
.onerror
= e
=> {
96 assert_true(is_transaction_active(tx
, 'store'),
97 'Transaction should be active during error handler');
99 let saw_handler_promise
= false;
100 Promise
.resolve().then(t
.step_func(() => {
101 saw_handler_promise
= true;
102 assert_true(is_transaction_active(tx
, 'store'),
103 'Transaction should be active in handler\'s microtasks');
106 setTimeout(t
.step_func(() => {
107 assert_true(saw_handler_promise
);
108 assert_false(is_transaction_active(tx
, 'store'),
109 'Transaction should be inactive in next task');
115 'Transactions are active during error handlers');
119 db
.createObjectStore('store');
122 const tx
= db
.transaction('store', 'readwrite', {durability
: 'relaxed'});
123 const release_tx
= keep_alive(tx
, 'store');
124 assert_true(is_transaction_active(tx
, 'store'),
125 'Transaction should be active after creation');
127 tx
.objectStore('store').put(0, 0);
128 const request
= tx
.objectStore('store').add(0, 0);
129 request
.onsuccess
= t
.unreached_func('request should fail');
130 request
.addEventListener('error', e
=> {
133 assert_true(is_transaction_active(tx
, 'store'),
134 'Transaction should be active during error listener');
136 let saw_listener_promise
= false;
137 Promise
.resolve().then(t
.step_func(() => {
138 saw_listener_promise
= true;
139 assert_true(is_transaction_active(tx
, 'store'),
140 'Transaction should be active in listener\'s microtasks');
143 setTimeout(t
.step_func(() => {
144 assert_true(saw_listener_promise
);
145 assert_false(is_transaction_active(tx
, 'store'),
146 'Transaction should be inactive in next task');
152 'Transactions are active during error listeners');