Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / microtasks.html
blobe67b5513f1fdca4ab00526c25348a6ad18a4c898
1 <!DOCTYPE html>
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>
6 <script>
8 function isTransactionActive(tx, storeName) {
9 try {
10 tx.objectStore(storeName).get(0);
11 return true;
12 } catch (ex) {
13 // The exception could be TransactionInactiveError or InvalidStateError
14 // depending on the test and whether the transaction has committed yet.
15 return false;
19 indexeddb_test(
20 function(t, db) {
21 db.createObjectStore('store');
23 function(t, db) {
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');
34 t.done();
35 }), 0);
36 });
37 }));
39 'Transactions created in microtasks are deactivated when control returns to the event loop'
42 indexeddb_test(
43 function(t, db) {
44 db.createObjectStore('store');
46 function(t, db) {
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');
58 t.done();
59 }), 0);
60 });
61 }));
63 'Transactions created in microtasks resolved by host behavior are deactivated when control returns to the event loop'
66 indexeddb_test(
67 function(t, db) {
68 db.createObjectStore('store');
70 function(t, db) {
71 var tx;
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');
82 t.done();
83 }), 0);
84 }));
86 'Transactions created in microtasks remain active in subsequent microtasks'
89 indexeddb_test(
90 function(t, db) {
91 db.createObjectStore('store');
93 function(t, db) {
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');
106 t.done();
107 }), 0);
108 }));
111 'Within request event dispatch, transactions remain active across microtasks'
114 </script>