Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(592)

Side by Side Diff: LayoutTests/storage/indexeddb/microtasks.html

Issue 321433002: IndexedDB: Ensure transactions created in microtasks are deactivated (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove racy assertion Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | LayoutTests/storage/indexeddb/microtasks-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <title>IndexedDB: Verify transaction activation behavior around microtasks</titl e>
3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/testharnessreport.js"></script>
5 <script>
6
7 function idb_test(description, onUpgrade, onOpen) {
8 var t = async_test(description);
9 t.step(function() {
10 var dbName = 'db' + location.pathname + '-' + description;
11 var deleteRequest = indexedDB.deleteDatabase(dbName);
12 deleteRequest.onerror = t.unreached_func('deleteDatabase should not fail ');
13 deleteRequest.onsuccess = t.step_func(function(e) {
14 var openRequest = indexedDB.open(dbName);
15 openRequest.onerror = t.unreached_func('open should not fail');
16 openRequest.onupgradeneeded = t.step_func(function(e) {
17 onUpgrade(t, openRequest.result);
18 });
19 openRequest.onsuccess = t.step_func(function(e) {
20 onOpen(t, openRequest.result);
21 });
22 });
23 });
24 }
25
26 function isTransactionActive(tx, storeName) {
27 try {
28 tx.objectStore(storeName).get(0);
29 return true;
30 } catch (ex) {
31 // The exception could be TransactionInactiveError or InvalidStateError
32 // depending on the test and whether the transaction has committed yet.
33 return false;
34 }
35 }
36
37 idb_test(
38 'Transactions created in microtasks are deactivated when control returns to the event loop',
39 function(t, db) {
40 db.createObjectStore('store');
41 },
42 function(t, db) {
43 Promise.resolve().then(t.step_func(function() {
44 var tx = db.transaction('store');
45 var request = tx.objectStore('store').get(0);
46 request.onerror = t.unreached_func('request should not fail');
47 request.onsuccess = t.step_func(function() {
48 assert_true(isTransactionActive(tx, 'store'),
49 'Transaction should be active during event dispatch' );
50 setTimeout(t.step_func(function() {
51 assert_false(isTransactionActive(tx, 'store'),
52 'Transaction should be inactive once control re turns to event loop');
53 t.done();
54 }), 0);
55 });
56 }));
57 }
58 );
59
60 idb_test(
61 'Transactions created in microtasks remain active in subsequent microtasks',
62 function(t, db) {
63 db.createObjectStore('store');
64 },
65 function(t, db) {
66 var tx;
67 Promise.resolve().then(function() {
68 tx = db.transaction('store');
69 assert_true(isTransactionActive(tx, 'store'),
70 'Transaction should be active when created');
71 }).then(t.step_func(function() {
72 assert_true(isTransactionActive(tx, 'store'),
73 'Transaction should be active until control returns to e vent loop');
74 setTimeout(t.step_func(function() {
75 assert_false(isTransactionActive(tx, 'store'),
76 'Transaction should be inactive once control returns to event loop');
77 t.done();
78 }), 0);
79 }));
80 }
81 );
82
83 idb_test(
84 'Within request event dispatch, transactions remain active across microtasks ',
85 function(t, db) {
86 db.createObjectStore('store');
87 },
88 function(t, db) {
89 var tx = db.transaction('store');
90 var request = tx.objectStore('store').get(0);
91 request.onerror = t.unreached_func('request should not fail');
92 request.onsuccess = t.step_func(function() {
93 assert_true(isTransactionActive(tx, 'store'),
94 'Transaction should be active during event dispatch');
95 Promise.resolve().then(t.step_func(function() {
96 assert_true(isTransactionActive(tx, 'store'),
97 'Microtasks are run as part of event dispatch, so tr ansaction should still be active');
98 setTimeout(t.step_func(function() {
99 assert_false(isTransactionActive(tx, 'store'),
100 'Transaction should be inactive once control ret urns to the event loop');
101 t.done();
102 }), 0);
103 }));
104 });
105 }
106 );
107
108 </script>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/storage/indexeddb/microtasks-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698